def pycozmo_program(cli: pycozmo.client.Client): angle = (pycozmo.robot.MAX_HEAD_ANGLE.radians - pycozmo.robot.MIN_HEAD_ANGLE.radians) / 2.0 pkt = pycozmo.protocol_encoder.SetHeadAngle(angle_rad=angle) cli.send(pkt) for _ in range(3): pkt = pycozmo.protocol_encoder.NextFrame() cli.send(pkt) pkt = pycozmo.protocol_encoder.DisplayImage( pycozmo.util.hex_load( "11:9c:b6:a4:98:be:40:94:c6:40:90:ce:5b:94:c6:9c:98:be:a0:" "9c:b6:06:a0:ae:40:9c:b6:40:98:be:5d:9c:b6:40:a0:ae:1b")) cli.send(pkt) time.sleep(1) pkt = pycozmo.protocol_encoder.NextFrame() cli.send(pkt) pkt = pycozmo.protocol_encoder.DisplayImage( pycozmo.util.hex_load( "16:a0:b6:41:9c:be:40:98:c6:5b:9c:be:9c:a0:b6:40:06:a4:ae:" "a4:a0:b6:40:9c:be:40:98:c6:5b:9c:be:40:a0:b6:40:16")) cli.send(pkt) time.sleep(1)
def pycozmo_program(cli: pycozmo.client.Client): lights = [ pycozmo.lights.red_light, pycozmo.lights.green_light, pycozmo.lights.blue_light, pycozmo.lights.white_light, pycozmo.lights.off_light, ] for light in lights: pkt = pycozmo.protocol_encoder.LightStateCenter(states=(light, light, light)) cli.send(pkt) pkt = pycozmo.protocol_encoder.LightStateSide(states=(light, light)) cli.send(pkt) time.sleep(2)
def pycozmo_program(cli: pycozmo.client.Client): print("Waiting for cube...") cube_factory_id = None while not cube_factory_id: available_objects = dict(cli.available_objects) for factory_id, obj in available_objects.items(): if obj.object_type == pycozmo.protocol_encoder.ObjectType.Block_LIGHTCUBE1: cube_factory_id = factory_id break print("Cube with S/N 0x{:08x} available.".format(cube_factory_id)) print("Connecting to cube...") pkt = pycozmo.protocol_encoder.ObjectConnect(factory_id=cube_factory_id, connect=True) cli.send(pkt) cli.wait_for(pycozmo.protocol_encoder.ObjectConnectionState) cube_id = list(cli.connected_objects.keys())[0] print("Cube connected - ID {}.".format(cube_id)) lights = [ pycozmo.lights.red_light, pycozmo.lights.green_light, pycozmo.lights.blue_light, pycozmo.lights.off_light, ] for light in lights: # Select cube pkt = pycozmo.protocol_encoder.CubeId(object_id=cube_id) cli.send(pkt) # Set lights pkt = pycozmo.protocol_encoder.CubeLights(states=(light, light, light, light)) cli.send(pkt) time.sleep(2)
def pycozmo_program(cli: pycozmo.client.Client): angle = (pycozmo.robot.MAX_HEAD_ANGLE.radians - pycozmo.robot.MIN_HEAD_ANGLE.radians) / 2.0 pkt = pycozmo.protocol_encoder.SetHeadAngle(angle_rad=angle) cli.send(pkt) pkt = pycozmo.protocol_encoder.EnableCamera(enable=True) cli.send(pkt) pkt = pycozmo.protocol_encoder.EnableColorImages(enable=True) cli.send(pkt) # Wait for image to stabilize. time.sleep(2.0) cli.add_handler(pycozmo.client.EvtNewRawCameraImage, on_camera_image, one_shot=True) # Wait for image to be captured. time.sleep(1)
def pycozmo_program(cli: pycozmo.client.Client): print("Waiting for cube...") cube_factory_id = None while not cube_factory_id: available_objects = dict(cli.available_objects) for factory_id, obj in available_objects.items(): if obj.object_type == pycozmo.protocol_encoder.ObjectType.Block_LIGHTCUBE1: cube_factory_id = factory_id break print("Cube with S/N 0x{:08x} available.".format(cube_factory_id)) print("Connecting to cube...") pkt = pycozmo.protocol_encoder.ObjectConnect(factory_id=cube_factory_id, connect=True) cli.send(pkt) cli.wait_for(pycozmo.protocol_encoder.ObjectConnectionState) cube_id = list(cli.connected_objects.keys())[0] print("Cube connected - ID {}.".format(cube_id)) color = pycozmo.lights.Color(int_color=0x00ff00ff) light = pycozmo.lights.LightState(on_color=color.to_int16(), off_color=pycozmo.lights.off.to_int16(), on_frames=5, off_frames=20, transition_on_frames=5, transition_off_frames=10) # Select cube pkt = pycozmo.protocol_encoder.CubeId(object_id=cube_id, rotation_period_frames=40) cli.send(pkt) # Set lights pkt = pycozmo.protocol_encoder.CubeLights( states=(light, pycozmo.lights.off_light, pycozmo.lights.off_light, pycozmo.lights.off_light)) cli.send(pkt) time.sleep(30.0)
def pycozmo_program(cli: pycozmo.client.Client): cli.send( pycozmo.protocol_encoder.SetHeadAngle( angle_rad=pycozmo.MAX_HEAD_ANGLE.radians)) time.sleep(1) cli.send( pycozmo.protocol_encoder.SetHeadAngle( angle_rad=pycozmo.MIN_HEAD_ANGLE.radians)) time.sleep(1) cli.send(pycozmo.protocol_encoder.DriveHead()) cli.send( pycozmo.protocol_encoder.SetLiftHeight( height_mm=pycozmo.MAX_LIFT_HEIGHT.mm)) time.sleep(1) cli.send( pycozmo.protocol_encoder.SetLiftHeight( height_mm=pycozmo.MIN_LIFT_HEIGHT.mm)) time.sleep(1) cli.send(pycozmo.protocol_encoder.DriveLift())