def led_on(self, led_id): _grab_read() try: gopigo.led_on(led_id) except: pass _release_read()
def led_on(self,led_id): _ifMutexAcquire(self.use_mutex) try: gopigo.led_on(led_id) except: pass finally: _ifMutexRelease(self.use_mutex)
def right_led_button_OnButtonClick(self, event): global right_led if right_led == 0: gopigo.led_on(0) right_led = 1 else: gopigo.led_off(0) right_led = 0
def left_led_button_OnButtonClick(self, event): global left_led if left_led == 0: gopigo.led_on(1) left_led = 1 else: gopigo.led_off(1) left_led = 0
def left_led_button_OnButtonClick(self,event): global left_led if left_led==0: gopigo.led_on(1) left_led=1 else : gopigo.led_off(1) left_led=0
def right_led_button_OnButtonClick(self,event): global right_led if right_led==0: gopigo.led_on(0) right_led=1 else : gopigo.led_off(0) right_led=0
def led_on(self,led_id): _ifMutexAcquire(self.use_mutex) try: gopigo.led_on(led_id) except: pass finally: _ifMutexRelease(self.use_mutex)
def process_command(_command, _time): data = _command if not data: print "received data:", data if len(data) != 1: print ("Invalid command") return "Invalid command" elif data == 'w': gopigo.fwd() # return "Moving forward" elif data == 'x': gopigo.stop() # return "Stopping" elif data == 's': gopigo.bwd() # return "Moving back" elif data == 'a': gopigo.left() # return "Turning left" elif data == 'd': gopigo.right() # return "Turning right" elif data == 't': gopigo.increase_speed() # return "Increase speed" elif data == 'g': gopigo.decrease_speed() # return "Decrease speed" elif data == 'v': # print gopigo.volt(), 'V' return str(gopigo.volt()) elif data == 'l': gopigo.led_on(0) gopigo.led_on(1) time.sleep(1) gopigo.led_off(0) gopigo.led_off(1) return "Flash LED" else: print ("Invalid command") return "Invalid command" # run as a app if _time: time.sleep(_time) gopigo.stop()
import gopigo as go import time go.set_speed(130) go.fwd() go.led_on(0) go.led_on(1) time.sleep(1.9) go.led_off(0) go.led_off(1) go.right() go.led_on(0) time.sleep(0.2) go.fwd() go.led_on(0) go.led_on(1) time.sleep(0.8) go.led_off(0) go.led_off(1) go.left() go.led_on(1) time.sleep(0.8) for i in range(4): go.right() go.led_on(0) time.sleep(0.1) go.fwd() go.led_on(0) go.led_on(1)
conn.send("Turning right") elif data=='right_rot': gopigo.right_rot() conn.send("Turning right") elif data=='i': gopigo.increase_speed() conn.send("Increase speed") elif data=='d': gopigo.decrease_speed() conn.send("Decrease speed") elif data=='ledOn': gopigo.led_on() conn.send("Led ON") elif data=='ledOff': gopigo.led_off() conn.send("Led OFF") elif data=='set_right_speed': gopigo.set_right_speed() conn.send("Set Right Speed") elif data=='set_left_speed': gopigo.set_left_speed() conn.send("Set Left Speed") else:
def do_command(command=None): logging.debug(command) if command in ["forward", "fwd"]: gopigo.fwd() elif command == "left": gopigo.left() elif command == "left_rot": gopigo.left_rot() elif command == "right": gopigo.right() elif command == "right_rot": gopigo.right_rot() elif command == "stop": gopigo.stop() elif command == "leftled_on": gopigo.led_on(0) elif command == "leftled_off": gopigo.led_off(0) elif command == "rightled_on": gopigo.led_on(1) elif command == "rightled_off": gopigo.led_off(1) elif command in ["back", "bwd"]: gopigo.bwd() elif command == "speed": logging.debug("speed") speed = flask.request.args.get("speed") logging.debug("speed:" + str(speed)) if speed: logging.debug("in if speed") gopigo.set_speed(int(speed)) left_speed = flask.request.args.get("left_speed") logging.debug("left_speed:" + str(left_speed)) if left_speed: logging.debug("in if left_speed") gopigo.set_left_speed(int(left_speed)) right_speed = flask.request.args.get("right_speed") logging.debug("right_speed:" + str(right_speed)) if right_speed: logging.debug("in if right_speed") gopigo.set_right_speed(int(right_speed)) speed_result = gopigo.read_motor_speed() logging.debug(speed_result) return flask.json.jsonify({"speed": speed_result, "right": speed_result[0], "left": speed_result[1]}) elif command == "get_data": speed_result = gopigo.read_motor_speed() enc_right = gopigo.enc_read(0) enc_left = gopigo.enc_read(1) volt = gopigo.volt() timeout = gopigo.read_timeout_status() return flask.json.jsonify( { "speed": speed_result, "speed_right": speed_result[0], "speed_left": speed_result[1], "enc_right": enc_right, "enc_left": enc_left, "volt": volt, "timeout": timeout, "fw_ver": gopigo.fw_ver(), } ) elif command in ["enc_tgt", "step"]: tgt = flask.request.args.get("tgt") direction = flask.request.args.get("dir") if tgt: gopigo.gopigo.enc_tgt(1, 1, int(tgt)) if dir: if dir == "bwd": gopigo.bwd() else: gopigo.fwd() else: gopigo.fwd() return ""
#!/usr/bin/env python import gopigo gopigo.led_on(sys.argv[1])
conn.send("Stopping") elif data == 's': gopigo.bwd() conn.send("Moving back") elif data == 'a': gopigo.left() conn.send("Turning left") elif data == 'd': gopigo.right() conn.send("Turning right") elif data == 't': gopigo.increase_speed() conn.send("Increase speed") elif data == 'g': gopigo.decrease_speed() conn.send("Decrease speed") elif data == 'v': # print gopigo.volt(), 'V' conn.send(str(gopigo.volt())) elif data == 'l': gopigo.led_on(0) gopigo.led_on(1) time.sleep(1) gopigo.led_off(0) gopigo.led_off(1) conn.send("Flash LED") else: print ("Invalid command") conn.send("Invalid command") conn.close()
def led_on(kargs): r = {'return_value': gopigo.led_on(int(kargs['l_id']))} return r