def handle(msg): chat_id = msg['chat']['id'] command = msg['text'] print 'Got command: %s' % command if command == '/ota': #do some ota jobs from repo, then restart bot.sendMessage(chat_id, str('Upgrading myself,will back soon...')) elif command == '/time': bot.sendMessage(chat_id, str(datetime.datetime.now())) elif command == '/go': agobo.forward(speed) bot.sendMessage(chat_id, str('going forward')) elif command == '/stop': agobo.stop() bot.sendMessage(chat_id, str('stopped')) elif command == '/back': agobo.reverse(speed) bot.sendMessage(chat_id, str('going backward')) elif command == '/play': os.system("omxplayer example.mp3") elif command == "/reboot": # do restart the whole machine bot.sendMessage(chat_id, str('I don't want to risk myself, ah...see you soo..'))
keyp = readkey() if keyp == 'w' or ord(keyp) == 16: agobo.forward(speed) print 'Forward', speed elif keyp == 'z' or ord(keyp) == 17: agobo.reverse(speed) print 'Reverse', speed elif keyp == 's' or ord(keyp) == 18: agobo.spinRight(speed) print 'Spin Right', speed elif keyp == 'a' or ord(keyp) == 19: agobo.spinLeft(speed) print 'Spin Left', speed elif keyp == '.' or keyp == '>': speed = min(100, speed + 10) print 'Speed+', speed elif keyp == ',' or keyp == '<': speed = max(0, speed - 10) print 'Speed-', speed elif keyp == ' ': agobo.stop() print 'Stop' elif ord(keyp) == 3: break except KeyboardInterrupt: print finally: agobo.cleanup()
def reverse(): agobo.reverse(speed) time.sleep(2) agobo.stop()
speed = 80 agobo.init() # main loop try: while True: agobo.forward(speed) print 'Forward' time.sleep(3) agobo.reverse(speed) print 'Reverse' time.sleep(3) agobo.spinRight(speed) print 'Spin Right' time.sleep(3) agobo.spinLeft(speed) print 'Spin Left' time.sleep(3) agobo.stop() print 'Stop' time.sleep(3) except KeyboardInterrupt: print finally: agobo.cleanup()
def left(): agobo.spinLeft(speed) time.sleep(1) agobo.stop()
def right(): agobo.spinRight(speed) time.sleep(1) agobo.stop()
def forward(): agobo.forward(speed) time.sleep(2) agobo.stop()