def main(): with pycozmo.connect() as cli: robot = Robot(cli) gesture_detector = TrackObject() # Loop until program terminates. cliff_counter = 0 while True: if cliff_counter > 6: break gesture = None # Request gesture to navigate cliff. if robot.cliff_detected: cliff_counter += 1 while gesture not in ['terminate', 'left', 'right']: gesture = gesture_detector.detect_gesture() # Request gesture to navigate obstacle. elif robot.object_detected: while gesture not in [ 'terminate', 'left', 'right', 'in', 'out' ]: gesture = gesture_detector.detect_gesture() # Perform robot action based on gesture. if gesture == 'terminate': gesture_detector.teardown() break elif gesture == 'left': robot.on_gesture_left() elif gesture == 'right': robot.on_gesture_right() elif gesture == 'in': robot.on_gesture_in() elif gesture == 'out': robot.on_gesture_out() # Perform default behavior. else: # No cliff or obstacle detected. robot.default_behavior() print("Mission complete!")
def main(): # Parse command-line. args = parse_args() # noqa try: with pycozmo.connect(log_level="DEBUG" if args.verbose else "INFO", protocol_log_level="INFO", robot_log_level="INFO") as cli: brain = pycozmo.brain.Brain(cli) brain.start() while True: try: time.sleep(1.0) except KeyboardInterrupt: break brain.stop() except Exception as e: print("ERROR: {}".format(e)) sys.exit(1)
def main(): with pycozmo.connect() as cli: # Setup camera cli.enable_camera(enable=True, color=True) camera = CameraSensor(cli) #cli.add_handler(pycozmo.event.EvtNewRawCameraImage, camera.on_camera_image) # Setup Expressions # if load_anims breaks, run 'pycozmo_resources.py download' cli.load_anims() emote = Expressions(cli) # Setup controller controller = CozmoController(cli,camera) cli.set_head_angle(angle = 0.6) # Drive off charger (call twice) # Get to charger edge, override cliff detector controller.drive_off_charger() controller.drive_off_charger() # Check for target if(not camera.find_target()): # If no target, make a sad face and quit emote.act_sad() print("no target found") #break # Center the target controller.center_target() # Be happy at target once centered emote.act_happy() # Drive to the target while keeping it centered if(controller.drive_to_target()): # If made it to the target... emote.act_happy() # Nudge/Nuzzle the person controller.nuzzle_target() else: # Else be sad and quit emote.act_sad()
def main(): global safe_file global verbose # Parse command-line. args = parse_args() safe_file = args.safe_file verbose = args.verbose # Verify .safe file. verify_safe(safe_file, args.signature) # Update robot. try: with pycozmo.connect(protocol_log_level="INFO", robot_log_level="DEBUG", auto_initialize=False) as cli: update(cli) except Exception as e: print("ERROR: {}".format(e)) sys.exit(3)
#!/usr/bin/env python import pycozmo with pycozmo.connect() as cli: # Set volume to ~75%. cli.set_volume(50000) # A 22 kHz, 16-bit, mono file is required. cli.play_audio("hello.wav") cli.wait_for(pycozmo.event.EvtAudioCompleted)
#!/usr/bin/env python from threading import Event import pycozmo e = Event() def on_nv_storage_op_result(cli: pycozmo.client.Client, pkt: pycozmo.protocol_encoder.NvStorageOpResult): print(pkt.result) print(pkt.data) if pkt.result != pycozmo.protocol_encoder.NvResult.NV_MORE: e.set() with pycozmo.connect(enable_animations=False, log_level="DEBUG") as cli: cli.add_handler(pycozmo.protocol_encoder.NvStorageOpResult, on_nv_storage_op_result) pkt = pycozmo.protocol_encoder.NvStorageOp( tag=pycozmo.protocol_encoder.NvEntryTag.NVEntry_CameraCalib, length=1, op=pycozmo.protocol_encoder.NvOperation.NVOP_READ) cli.conn.send(pkt) e.wait(timeout=20.0)
#!/usr/bin/env python import time from PIL import Image import numpy as np import pycozmo with pycozmo.connect(enable_procedural_face=False) as cli: # Raise head. angle = (pycozmo.robot.MAX_HEAD_ANGLE.radians - pycozmo.robot.MIN_HEAD_ANGLE.radians) / 2.0 cli.set_head_angle(angle) time.sleep(1) # List of face expressions. expressions = [ pycozmo.expressions.Anger(), pycozmo.expressions.Sadness(), pycozmo.expressions.Happiness(), pycozmo.expressions.Surprise(), pycozmo.expressions.Disgust(), pycozmo.expressions.Fear(), pycozmo.expressions.Pleading(), pycozmo.expressions.Vulnerability(), pycozmo.expressions.Despair(), pycozmo.expressions.Guilt(), pycozmo.expressions.Disappointment(), pycozmo.expressions.Embarrassment(),
#!/usr/bin/env python import time import pycozmo def on_robot_state(cli, pkt: pycozmo.protocol_encoder.RobotState): if pkt.pose_angle_rad < -0.4: state = "LS" elif pkt.pose_angle_rad > 0.4: state = "RS" elif pkt.pose_pitch_rad < -1.0: state = "F" elif pkt.pose_pitch_rad > 1.0: state = "B" else: state = "-" print("{:6.02f}\t{:6.03f}\t{}".format(pkt.pose_angle_rad, pkt.pose_pitch_rad, state)) with pycozmo.connect(enable_animations=False) as cli: cli.add_handler(pycozmo.protocol_encoder.RobotState, on_robot_state) while True: time.sleep(0.1)
def on_robot_orientation_change(cli, orientation: pycozmo.robot.RobotOrientation): if orientation == pycozmo.robot.RobotOrientation.ON_THREADS: print("On threads.") elif orientation == pycozmo.robot.RobotOrientation.ON_BACK: print("On back.") elif orientation == pycozmo.robot.RobotOrientation.ON_FACE: print("On front.") elif orientation == pycozmo.robot.RobotOrientation.ON_LEFT_SIDE: print("On left side.") elif orientation == pycozmo.robot.RobotOrientation.ON_RIGHT_SIDE: print("On right side.") # Change the robot log level to DEBUG to see robot debug messages related to events. with pycozmo.connect(enable_animations=False, robot_log_level="INFO") as cli: cli.add_handler(pycozmo.protocol_encoder.RobotState, on_robot_state, one_shot=True) cli.add_handler(pycozmo.protocol_encoder.RobotPoked, on_robot_poked) cli.add_handler(pycozmo.protocol_encoder.FallingStarted, on_robot_falling_started) cli.add_handler(pycozmo.protocol_encoder.FallingStopped, on_robot_falling_stopped) cli.add_handler(pycozmo.protocol_encoder.ButtonPressed, on_button_pressed) cli.add_handler(pycozmo.event.EvtRobotPickedUpChange, on_robot_picked_up) cli.add_handler(pycozmo.event.EvtRobotChargingChange, on_robot_charging) cli.add_handler(pycozmo.event.EvtCliffDetectedChange, on_cliff_detected) cli.add_handler(pycozmo.event.EvtRobotWheelsMovingChange, on_robot_wheels_moving)