def forward(): print('robot_controller, forward, robot_debug =', robot_debug) if not robot_debug: gopigo_client.set_speed(robot_speed) gopigo_client.stop() gopigo_client.fwd() time.sleep(robot_wait) gopigo_client.stop()
def right(): print('robot_controller, right, robot_debug =', robot_debug) if not robot_debug: gopigo_client.set_speed(robot_speed) gopigo_client.stop() gopigo_client.right_rot() time.sleep(robot_wait) gopigo_client.stop()
def right_rot(duration=0.5): print('robot_controller, right_rot, robot_debug =', robot_debug) if not robot_debug: gopigo_client.set_speed(robot_speed) gopigo_client.stop() gopigo_client.right_rot() pause(duration) gopigo_client.stop()
def backward(duration=0.5): print('robot_controller, backward, robot_debug =', robot_debug) if not robot_debug: gopigo_client.set_speed(robot_speed) gopigo_client.stop() gopigo_client.bwd() pause(duration) gopigo_client.stop()
def forward(duration=0.5): print('robot_controller, forward, robot_debug =', robot_debug) if not robot_debug: gopigo_client.set_speed(robot_speed) gopigo_client.set_left_speed(robot_speed+5) gopigo_client.stop() gopigo_client.fwd() pause(duration) gopigo_client.stop()
def stop(): print('robot_controller, stop, robot_debug =', robot_debug) if not robot_debug: gopigo_client.set_speed(robot_speed) gopigo_client.stop()
def stop(duration=SHORT_DURATION): print('robot_controller, stop, robot_debug =', robot_debug) if not robot_debug: gopigo_client.set_speed(robot_speed) gopigo_client.stop() pause(duration)
def message(self, pubnub, message): try: action = message.message.lower() if 'forward' in action: gopigo_client.fwd() time.sleep(self.CRAB_DURATION) gopigo_client.stop() elif 'backward' in action: gopigo_client.bwd() time.sleep(self.CRAB_DURATION) gopigo_client.stop() elif 'rotate' in action: if 'left' in action: gopigo_client.left_rot() time.sleep(self.TURN_DURATION) gopigo_client.stop() elif 'right in action': gopigo_client.right_rot() time.sleep(self.TURN_DURATION) gopigo_client.stop() elif 'left' in action: gopigo_client.left() time.sleep(self.TURN_DURATION) gopigo_client.stop() elif 'right' in action: gopigo_client.right() time.sleep(self.TURN_DURATION) gopigo_client.stop() elif 'dance' in action: gopigo_client.right() time.sleep(self.TURN_DURATION) gopigo_client.left_rot() time.sleep(self.TURN_DURATION) gopigo_client.right_rot() time.sleep(self.TURN_DURATION) gopigo_client.fwd() time.sleep(self.TURN_DURATION) gopigo_client.right() time.sleep(self.TURN_DURATION) gopigo_client.bwd() time.sleep(self.TURN_DURATION) gopigo_client.stop() elif 'stop' in action: gopigo_client.stop() elif 'blink' in action: for i in range(5): gopigo_client.led_on(0) gopigo_client.led_off(1) time.sleep(self.BLINK_DURATION) gopigo_client.led_off(0) gopigo_client.led_on(1) time.sleep(self.BLINK_DURATION) gopigo_client.led_off(0) gopigo_client.led_off(1) elif 'faster' in action: gopigo_client.set_speed(self.FAST_SPEED) elif 'slower' in action: gopigo_client.set_speed(self.SLOW_SPEED) else: pass log_it(self.get_status(action)) except IndexError: pass # do nothing except Exception as e: print("problem: %s" % str(e))
def get_status(action): result = {} result['voltage'] = gopigo_client.volt() result['distance'] = gopigo_client.us_dist(0) result['action'] = action return result def my_publish_callback(envelope, status): if not status.is_error(): pass # Message successfully published to specified chatroomChannel. else: pass # Handle message publish error. Check 'category' property to find out possible issue def log_it(content): print(str(content)) # todo get stats - ultrasonic, voltage, last direction, image pubnub.publish().channel(pn_chatbotlog_channel).message(content). async ( my_publish_callback) if __name__ == '__main__': print("initialize robot...") gopigo_client.servo(90) gopigo_client.set_speed(MySubscribeCallback.FAST_SPEED) print("starting pnlistener...") pubnub.add_listener(MySubscribeCallback()) pubnub.subscribe().channels([pn_robot_channel]).execute() print('end')
def stop(duration=0.5): print('robot_controller, stop, robot_debug =', robot_debug) if not robot_debug: gopigo_client.set_speed(robot_speed) gopigo_client.stop() pause(duration)