def perform(self, parameter): args = anki_vector.util.parse_command_args() with anki_vector.Robot(args.serial) as robot: try: robot.behavior.drive_on_charger() time.sleep(10) robot.behavior.drive_off_charger() time.sleep(10) degr = 360 robot.behavior.say_text("now i will begin turning %s degrees" % degr) robot.behavior.turn_in_place(degrees(360), is_absolute=1, num_retries=3) time.sleep(10) robot.behavior.say_text("i have finished turning") except Exception as err: print(err)
def main(): args = anki_vector.util.parse_command_args() with anki_vector.Robot(args.serial) as robot: robot.behavior.drive_off_charger() # Play an animation via a trigger. # A trigger can pick from several appropriate animations for variety. print("Playing Animation Trigger 1:") robot.anim.play_animation_trigger('GreetAfterLongTime') # Play the same trigger, but this time ignore the track that plays on the # body (i.e. don't move the wheels). See the play_animation_trigger documentation # for other available settings. print("Playing Animation Trigger 2: (Ignoring the body track)") robot.anim.play_animation_trigger('GreetAfterLongTime', ignore_body_track=True) # Play an animation via its name. # # Warning: Future versions of the app might change these, so for future-proofing # we recommend using play_animation_trigger above instead. # # See the remote_control.py example in apps for an easy way to see # the available animations. animation = 'anim_pounce_success_02' print("Playing animation by name: " + animation) robot.anim.play_animation(animation)
def main(): args = anki_vector.util.parse_command_args() with anki_vector.Robot(args.serial, requires_behavior_control=False, cache_animation_list=False) as robot: evt = threading.Event() async def on_wake_word(event_type, event): await robot.conn.request_control() global wake_word_heard if not wake_word_heard: wake_word_heard = True await robot.say_text("Hello") evt.set() robot.events.subscribe(on_wake_word, Events.wake_word) print( '------ Vector is waiting to hear "Hey Vector!" Press ctrl+c to exit early ------' ) try: if not evt.wait(timeout=10): print('------ Vector never heard "Hey Vector!" ------') except KeyboardInterrupt: pass
def run(self): # get the vector's database entry vector = Vectors.query.filter_by(id=self.vector_id).first() # try to send to command to the robot, log the result with anki_vector.Robot(vector.serial) as robot: try: if self.command == "dock": output = str(robot.behavior.drive_on_charger()) elif self.command == "undock": output = str(robot.behavior.drive_off_charger()) except Exception as e: output = e if self.log == "true": info = f"vector_id: {self.vector_id} \n \n output: {output}" run_plugin( "logbook", { "name": f"{vector.name} ran {self.command}", "vector_id": vector.id, "info": info, "log_type": "success", }, ) run_plugin("stats", {"vector_id": vector.id, "log": False}) return output
def main(): def on_robot_observed_face(robot, event_type, event): """on_robot_observed_face is called when a face is seen""" print("Vector sees a face") args = anki_vector.util.parse_command_args() with anki_vector.Robot(args.serial, enable_vision_mode=True) as robot: # If necessary, Move Vector's Head and Lift to make it easy to see his face robot.behavior.set_head_angle(degrees(50.0)) robot.behavior.set_lift_height(0.0) on_robot_observed_face = functools.partial(on_robot_observed_face, robot) robot.events.subscribe(on_robot_observed_face, Events.robot_observed_face) print( "------ waiting for face events, press ctrl+c to exit early ------" ) try: # Wait 5 seconds to see a face time.sleep(5) except KeyboardInterrupt: pass
def main(): args = anki_vector.util.parse_command_args() with anki_vector.Robot(args.serial) as robot: print('Vector Provides an Introduction') robot.behavior.say_text( 'Hi! My name is Vector. Ive been working with a team of Python developers this past week. They helped me solve mazes!' )
def dock(): flash('Dock Command Complete!', 'success') args = anki_vector.util.parse_command_args() with anki_vector.Robot(args.serial) as robot: robot.behavior.drive_on_charger() time.sleep(1) return redirect("/")
def main(): args = anki_vector.util.parse_command_args() with anki_vector.Robot(args.serial) as robot: time.sleep(1) robot.say_text("Richard") robot.behavior.set_eye_color(hue=0.00, saturation=1.00) robot.say_text("Of") robot.behavior.set_eye_color(hue=0.05, saturation=1.00) robot.say_text("York") robot.behavior.set_eye_color(hue=0.10, saturation=1.00) robot.say_text("Gave") robot.behavior.set_eye_color(hue=0.30, saturation=1.00) robot.say_text("Battle") robot.behavior.set_eye_color(hue=0.50, saturation=1.00) robot.say_text("In") robot.behavior.set_eye_color(hue=0.70, saturation=1.00) robot.say_text("Vain") robot.behavior.set_eye_color(hue=0.80, saturation=1.00) time.sleep(1)
def get_status(): current_states = [] with anki_vector.Robot(args.serial, behavior_control_level=None) as robot: if robot.status.is_on_charger: current_states.append("is_on_charger") if robot.status.are_motors_moving: current_states.append("are_motors_moving") if robot.status.are_wheels_moving: current_states.append("are_wheels_moving") if robot.status.is_animating: current_states.append("is_animating") if robot.status.is_being_held: current_states.append("is_being_held") if robot.status.is_button_pressed: current_states.append("is_button_pressed") if robot.status.is_carrying_block: current_states.append("is_carrying_block") if robot.status.is_charging: current_states.append("is_charging") if robot.status.is_cliff_detected: current_states.append("is_cliff_detected") if robot.status.is_docking_to_marker: current_states.append("is_docking_to_marker") if robot.status.is_falling: current_states.append("is_falling") if robot.status.is_head_in_pos: current_states.append("is_head_in_pos") if robot.status.is_in_calm_power_mode: current_states.append("is_in_calm_power_mode") if robot.status.is_lift_in_pos: current_states.append("is_lift_in_pos") if robot.status.is_pathing: current_states.append("is_pathing") if robot.status.is_picked_up: current_states.append("is_picked_up") if robot.status.is_robot_moving: current_states.append("is_robot_moving") return Response((json.dumps(current_states)), mimetype='application/json')
def main(): args = anki_vector.util.parse_command_args() with anki_vector.Robot(args.serial, behavior_control_level=ControlPriorityLevel. OVERRIDE_BEHAVIORS_PRIORITY) as robot: robot.behavior.say_text("Pick me up!") pickup_countdown = 20 print( "------ waiting for Vector to be picked up, press ctrl+c to exit early ------" ) try: while not robot.status.is_picked_up and pickup_countdown: time.sleep(0.5) pickup_countdown -= 1 if not pickup_countdown: print("Did not get picked up") sys.exit() print("Vector is picked up...") robot.behavior.say_text("Hold on tight") print("Setting wheel motors...") robot.motors.set_wheel_motors(75, -75) time.sleep(0.5) robot.motors.set_wheel_motors(-75, 75) time.sleep(0.5) robot.motors.set_wheel_motors(0, 0) except KeyboardInterrupt: pass
def main(): with anki_vector.Robot(requires_behavior_control=True) as robot: try: while True: robot.behavior.set_eye_color(0.0, 1.0) robot.anim.play_animation('anim_eyepose_furious') robot.events.subscribe(on_oo, Events.robot_observed_object) robot.say_text("WHERE IS MY CUBE?", duration_scalar=0.5) robot.behavior.set_head_angle(degrees(0)) observed_event.clear() while not observed_event.wait(timeout=0.4): robot.behavior.turn_in_place(degrees(22.5), accel=degrees(5000), speed=degrees(5000)) robot.events.unsubscribe(on_oo, Events.robot_observed_object) robot.world.connect_cube() robot.behavior.dock_with_cube(robot.world.connected_light_cube, num_retries=3) robot.say_text("GOTCHA!", duration_scalar=0.6) robot.behavior.set_lift_height(1.0, accel=255, max_speed=255) robot.behavior.set_lift_height(0, accel=255, max_speed=255) moved_event.clear() robot.events.subscribe(on_om, Events.object_moved) while not moved_event.wait(): robot.events.unsubscribe(on_om, Events.object_moved) except KeyboardInterrupt: sys.exit()
def main(): args = anki_vector.util.parse_command_args() with anki_vector.Robot(args.serial) as robot: #drive off charger robot.behavior.drive_off_charger() robot.world.connect_cube() #pick up cube object if robot.world.connected_light_cube: robot.behavior.pickup_object(robot.world.connected_light_cube) #get current position of robot current_robot_pose = robot.pose.position print(current_robot_pose) #got to desired position with cube pose = Pose(x=10, y=10, z=0, angle_z=Angle(degrees=0)) robot.behavior.go_to_pose(pose) print(robot.pose.position) #drop off the cube object time.sleep(3.0) pose_future.cancel() robot.behavior.place_object_on_ground_here()
def main(): #with anki_vector.Robot(show_viewer=True) as robot: with anki_vector.Robot(enable_camera_feed=True) as robot: robot.show_viewer=True robot.viewer.show_video() time.sleep(10)
def main(): args = anki_vector.util.parse_command_args() with anki_vector.Robot(args.serial) as robot: print("fzbosfuzho") robot.behavior.say_text( "I don't need no molly to be savage, uh, but when I'm on that molly I feel savage, uh uh, she the definition of a bad, uh, " )
def main(): args = anki_vector.util.parse_command_args() # Get GIFs list from Giphy request = requests.get(giphy_url, { 'q': keywords, 'api_key': giphy_api_key, 'limit': giphy_limit }) # print(request.url) data = json.loads(request.content) # print(json.dumps(data, sort_keys=True, indent=2)) if data and data['data'] and len(data['data']) > 0: # Load a random GIF selected_gif_index = random.randrange(len(data['data'])) gif_url = data['data'][selected_gif_index]['images']['original']['url'] gif = Image.open(io.BytesIO(requests.get(gif_url).content)) with anki_vector.Robot(args.serial) as robot: # Get vector'screen dimension (height, width) vector_screen_width, vector_screen_height = anki_vector.screen.dimensions( ) background = Image.new('RGB', (vector_screen_width, vector_screen_height), (0, 0, 0)) background_w, background_h = background.size # Build the vector'sscreen-compliant gif images = list() for frame in ImageSequence.Iterator(gif): frame = frame.convert('RGB') # Resize the frame image frame.thumbnail((vector_screen_width, vector_screen_height), Image.ANTIALIAS) frame_w, frame_h = frame.size # Define the black background image = background.copy() # Paste the frame image on the black background offset = (background_w - frame_w) // 2, (background_h - frame_h) // 2 image.paste(frame, offset) images.append(image) # If necessary, move Vector's Head and Lift to make it easy to see his face robot.behavior.set_head_angle(degrees(45.0)) robot.behavior.set_lift_height(0.0) for image in images: # Convert the image to the format used by the Screen screen_data = anki_vector.screen.convert_image_to_screen_data( image) # Display image on Vector's face robot.screen.set_screen_with_image_data(screen_data, 1.0 / 24) time.sleep(1.0 / 24)
def display_image(self, file_name): with anki_vector.Robot() as robot: print('display image = {}'.format(file_name)) image = Image.open(file_name) screen_data = anki_vector.screen.convert_image_to_screen_data( image.resize(screen_dimensions)) robot.screen.set_screen_with_image_data(screen_data, 10.0, True)
def main(): args = anki_vector.util.parse_command_args() with anki_vector.Robot(args.serial) as robot: robot.behavior.drive_off_charger() str = "nothing" while True: str = input( "\nWhat should Vector say? \nthink \t= show thinking\nsad \t= do a sad thing\nhappy\t= do a happy thing\nr \t= turn right\nl \t= turn left\nexit \t= exit\n >>" ) if str == "exit": break elif str == "r": robot.anim.play_animation('anim_rtmotion_turn45right_01') elif str == "l": robot.anim.play_animation('anim_rtmotion_turn45left_01') elif str == "think": playFromList(robot, "think", 3) elif str == "sad": playFromList(robot, "sad", 2) elif str == "happy": playFromList(robot, "happy", 5) else: playFromList(robot, "happy") robot.say_text(str) playFromList(robot, "happy", 3) robot.behavior.turn_in_place(degrees(360 * 1)) robot.anim.play_animation('anim_reacttoblock_happydetermined_02')
def main(): args = anki_vector.util.parse_command_args() with anki_vector.Robot(args.serial) as robot: while (1): current_gyro = robot.gyro print("Robot gyro {0}".format(current_gyro)) time.sleep(0.050)
def run(self): # get the vector's database entry vector = Vectors.query.filter_by(id=self.vector_id).first() # try to send to command to the robot, log the result if log is True with anki_vector.Robot(vector.serial) as robot: try: output = str(robot.behavior.say_text(self.text_to_say)) except Exception as e: output = e if self.log == "true": info = ( f"text_to_say: {self.text_to_say} \n \n" f"vector_id: {self.vector_id} \n \n" f"output: {output}" ) run_plugin( "logbook", { "name": f"{vector.name} ran custom say", "vector_id": vector.id, "info": info, "log_type": "success", }, ) return output
def main(): args = anki_vector.util.parse_command_args() with anki_vector.Robot(args.serial, enable_face_detection=True) as robot: evt = threading.Event() async def on_robot_observed_face(event_type, event): print("Vector sees a face") global said_text if not said_text: said_text = True await robot.say_text("I see a face!") evt.set() # If necessary, move Vector's Head and Lift to make it easy to see his face robot.behavior.set_head_angle(degrees(50.0)) robot.behavior.set_lift_height(0.0) robot.events.subscribe(on_robot_observed_face, Events.robot_observed_face) print("------ waiting for face events, press ctrl+c to exit early ------") try: if not evt.wait(timeout=5): print("------ Vector never saw your face! ------") except KeyboardInterrupt: pass
def get_stats(output): vector_status = { 'status_version': '0', 'status_voltage': '0', 'status_battery_level': '0', 'status_charging': '0', 'status_cube_battery_level': '0', 'status_cube_id': '0', 'status_cube_battery_volts': '0' } args = anki_vector.util.parse_command_args() with anki_vector.Robot(args.serial) as robot: version_state = robot.get_version_state() if version_state: vector_status['status_version'] = version_state.os_version battery_state = robot.get_battery_state() if battery_state: vector_status['status_voltage'] = battery_state.battery_volts vector_status['status_battery_level'] = battery_state.battery_level vector_status[ 'status_charging'] = battery_state.is_on_charger_platform vector_status[ 'status_cube_battery_level'] = battery_state.cube_battery.level vector_status[ 'status_cube_id'] = battery_state.cube_battery.factory_id vector_status[ 'status_cube_battery_volts'] = battery_state.cube_battery.battery_volts output.put(vector_status)
def main(): args = anki_vector.util.parse_command_args() with anki_vector.Robot(args.serial) as robot: secret = randint(1, 10) print("Welcome!") robot.behavior.say_text("Welcome") time.sleep(1) guess = 0 while guess != secret: robot.behavior.say_text("Guess the number") g = input("Guess the number: ") guess = int(g) time.sleep(1) if guess == secret: print("You win!") robot.behavior.say_text("You win") time.sleep(1) else: if guess > secret: print("Too high") robot.behavior.say_text("Too high") else: print("Too low") robot.behavior.say_text("Too low") time.sleep(1) print("Game over!") robot.behavior.say_text("Game over") time.sleep(1)
def connect_vector(serial): try: robot = anki_vector.Robot(serial) robot.connect() return robot except Exception as e: print(e)
def main(): args = anki_vector.util.parse_command_args() with anki_vector.Robot(args.serial, show_viewer=True, enable_face_detection=True) as robot: robot.camera.image_annotator.add_static_text( "text", "Vec-Cam", position=annotate.AnnotationPosition.TOP_RIGHT) robot.camera.image_annotator.add_annotator("clock", clock) robot.camera.image_annotator.add_annotator("battery", Battery) time.sleep(10) print("Turning off all annotations for 5 seconds") robot.camera.image_annotator.annotation_enabled = False time.sleep(5) print("Re-enabling all annotations") robot.camera.image_annotator.annotation_enabled = True print("------ Press ctrl+c to exit early ------") try: # Shutdown the program after 30 seconds time.sleep(30) except KeyboardInterrupt: pass
def __init__(self, img_path="block_pattern.jpg"): ANKI_SERIAL = '0090452f' ANKI_BEHAVIOR = \ av.connection.ControlPriorityLevel.OVERRIDE_BEHAVIORS_PRIORITY # initialise our sift stuff self.img = cv2.imread(img_path, cv2.IMREAD_GRAYSCALE) # cv2.imshow("our image", self.img) # cv2.waitKey(1000) self.sift = cv2.xfeatures2d.SIFT_create() self.kp_image, self.desc_image = self.sift.detectAndCompute( self.img, None) # feature matching self.index_params = dict(algorithm=0, trees=5) self.search_params = dict() self.flann = cv2.FlannBasedMatcher(self.index_params, self.search_params) # initialise and run Watty Ember with av.Robot(serial=ANKI_SERIAL, behavior_control_level=ANKI_BEHAVIOR) as robot: self.robot = robot self.img_width = 0 self.last_error = 0 self.closeness_threshold = 12000 self.closeness_range = 1000 self.def_speed_mmps = 20 self.robot.camera.init_camera_feed() self.setupBot() # self.recite_hamlet() self.track_box()
def sound(): args = anki_vector.util.parse_command_args() with anki_vector.Robot(args.serial) as robot: #robot.behavior.drive_off_charger() print("Playing music...") robot.audio.stream_wav_file("coolPatrol.wav", 100) print("Music ends...")
def ping(args): name, serial = args try: with anki_vector.Robot(serial=serial, default_logging=False) as _: return name except: return None
def run(self): self.detected_faces = set() with anki_vector.Robot(enable_face_detection=True) as robot: self.robot = robot robot.vision.enable_face_detection(estimate_expression=True) robot.vision.enable_display_camera_feed_on_face() robot.behavior.set_head_angle(degrees(45.0)) robot.behavior.set_lift_height(0.0) evt = threading.Event() robot.events.subscribe(self._on_robot_observed_face, Events.robot_observed_face, evt) threading.Timer(10, self.__find_faces).start() threading.Timer(60, self.__find_jira_tickets).start() print( "------ waiting for face events, press ctrl+c to exit early ------" ) try: if not evt.wait(timeout=12000): print("----- that's all folks ------") except KeyboardInterrupt: pass robot.events.unsubscribe(self._on_robot_observed_face, Events.robot_observed_face)
def main(): args = anki_vector.util.parse_command_args() robot = anki_vector.Robot(serial=args.serial, default_logging=True, enable_nav_map_feed=True) robot.connect() pretty_name = args.serial if pretty_name == None: pretty_name = '' #robot.say_text("Vector %s Ready" % pretty_name) # subscribe to nav map update events on_nav_map_update_mod = functools.partial(on_nav_map_update, robot) robot.events.subscribe(on_nav_map_update_mod, Events.nav_map_update) if not (robot.status.is_on_charger): print('Vector needs to start on the charger') print('Put him there and re-run the program...') robot.say_text("Uh Oh") robot.disconnect() exit() # make Vector wander a bit robot.behavior.drive_off_charger() robot.behavior.turn_in_place(angle=degrees(360), speed=degrees(45)) robot.behavior.drive_on_charger() # robot.events.unsubscribe(on_nav_map_update, Events.nav_map_update) #robot.say_text("All Done") robot.disconnect()
def main(): args = anki_vector.util.parse_command_args() with anki_vector.Robot(args.serial) as robot: print("Say 'Hello World'...") robot.behavior.say_text( "Daddy? Have you come back? Oh, sorry. I thought you were someone else." )