def build_map(mapfile): sticks = joystick.detect_joysticks() if len(sticks) < 1: print "No joysticks found. Exiting..." shutdown(1) jsctrl = sticks[0] jsctrl.set_observer(sys.stdout) jsctrl.calibrate() dist = 0 map = CourseMap() global running, client running = client.ready() lap_start = client.getOdometerDistance() while running: print "Awaiting input..." event = jsctrl.await_event() if joystick.is_motion_event(event): x = jsctrl.getX() t = jsctrl.getT() print "(%.2f, %.2f)" % (x, t) steer = int(100 * x * abs(x)) throt = int(MAX_THROTTLE * t) client.setSteering(steer) client.setThrottle(throt) dist = client.getOdometerDistance() - lap_start print "dist %.2f steer %i" % (dist, steer) map.take_reading(dist, steer) elif joystick.is_button_event(event): if joystick.get_event_button(event) == 0: lap_start = client.getOdometerDistance() # new lap else: running = False # Exit map.save(mapfile)