The easy_cozmo Package¶
Running a program in Cozmo¶
-
run_program(program)¶ Run a program in Cozmo
This is the entry point for a Cozmo program. Under the hood, it sets up the communication link with your Cozmo, initilizes the robot, and executes your code on it.
Parameters: program (python function) – The code that you want to execute on Cozmo
-
run_program_with_viewer(program)¶ Run a program in Cozmo in debug mode and launch the viewer to display what Cozmo sees
This is the entry point for a Cozmo program. Under the hood, it sets up the communication link with your Cozmo, initializes the robot, and executes your code on it.
Parameters: program (python function) – The code that you want to execute on Cozmo
Basic movements¶
-
drive()¶
-
move()¶
-
move_backward(distance)¶
-
move_forward(distance=None)¶
-
move_forward_avoiding_landmark(distance)¶ Move forward for a given distance while avoiding landmarks on the way
Parameters: duration (float) – Distance in centimeters Returns: True (succeeded) or False (failed)
-
move_forward_in_seconds(distance)¶
-
move_head_looking_down()¶ Move head in looking down position
Returns: True (succeededed) or False (failed)
-
move_head_looking_forward()¶ Position head in looking forward (at ground level) position
Returns: True (succeededed) or False (failed)
-
move_head_looking_up()¶ Move head in looking up position
Returns: True (suceeded) or False (failed)
-
move_lift_down()¶ Move lift close to the ground level
Returns: True (succeededed) or False (failed)
-
move_lift_ground()¶ Move lift to lowest (ground-level) position
Returns: True (succeededed) or False (failed)
-
move_lift_up()¶ Move lift close to the highest position
Returns: True (succeededed) or False (failed)
-
reverse(distance)¶
-
reverse_in_seconds(duration)¶ Reverse for certain amount of time in seconds :param duration: Amount of time in seconds to apply reverse :type duration: float
Returns: True (succeededed) or False (failed)
-
rotate(angle)¶
-
rotate_in_place(angle)¶ Rotate in place for a given angle in degrees
Parameters: angle (float) – Rotation angle (in degrees) Returns: True (succeeded) or False (failed)
-
rotate_left(angle)¶
-
rotate_right(angle)¶
-
set_wheels_speeds(left_speed, right_speed)¶ Set the wheels speeds in cm
-
start_moving()¶
-
steer(value)¶
-
steer_left(value)¶
-
steer_right(value)¶
-
steer_straight()¶
-
stop()¶
-
stop_moving()¶
Making Cozmo speak¶
-
say(txtmsg, *args)¶ Say a simple message
Cozmo will read a message and display the message in the console.
Note
This function receives a variable number or arguments. All arguments will be concatenated and delimited by a space, in order to compose the message. This is useful to compose sentences.
Returns: True (suceeded) or False (failed)
-
say_error(errormsg)¶ Say “ERROR” followed by a message
Cozmo will indicate using its voice that an error occurred. It also prints a message in the console indicating the error message.
Returns: True (suceeded) or False (failed)
Actions with cubes¶
-
align_with_nearest_cube(distance=150, refined=True)¶ Align with nearest cube
Takes Cozmo toward the nearest cube, and aligns it to the cube’s nearest face.
Parameters: distance (float) – Desired distance between Cozmo and the cube Returns: True (suceeded) or False (failed)
-
center_cube(cube_id)¶
-
distance_to_cube(cube_id)¶
-
double_scan_for_any_cube(angle, scan_speed=20, headlight_switching_enabled=True)¶ Symmetric frontal scan for any cube
A double scan is a more precise scanning procedure where Cozmo performs two passes with an aperture angle of 2*angle. It ensures that each point within the angle is scanned twice. If the head light is used (by default), it increases the chances that Cozmo will spot a cube in front of it.
Parameters: angle (float) – Angle to scan Returns: True (suceeded) or False (failed)
-
drop_cube()¶ Drop a cube in the current location
This function involves a sequence of two actions.
- Moving the lift to the ground
- Moving in reverse for two seconds (which takes Cozmo approximately 10 centimeters behind the cube
Returns: True if the cube could be dropped, or False if an error occurred.
-
pickup_cube()¶
-
pickup_cube_by_id(cube_id)¶ Pick up the cube with specified id
This function executes a pickup action that involves the following sequence of step. - Moving Cozmo’s head to straight position. We assume that the cube lies on the same place as Cozmo. - Setting the head light off. Note that the head light helps Cozmo seeing cubes at medium/far distances, while it is not good at close distances. - Checking that a cube with the indicated id is visible. Note that it does not attempt to search for it. Cozmo must be able to see the cube in its current position. If Cozmo cannot see the cube, it may complain with a message. - Doing the pickup action using the lift. Note that Cozmo does it best to pickup the cube, but sometimes it fails. When it fails, it may detect the failure and apologize for the incovenience. In a few cases, it could wrongly believe that it suceeded when it actually failed. Be patient and give Cozmo another chance.
Parameters: cube_id (int) – Id of the cube to be picked up, either 1, 2, or 3. If the cube id is wrong, Cozmo will complain with a sound. Returns: True (suceeded) or False (failed) according to what Cozmo believes it happened.
-
pickup_cube_one()¶ Pick up cube with id=1
Same as pickup_by_cube_id(1)
Returns: True (suceeded) or False (failed) according to what Cozmo thinks is the result.
-
pickup_cube_three()¶ Pick up cube with id=3
Same as pickup_by_cube_id(3)
Returns: True (suceeded) or False (failed) according to what Cozmo thinks is the result.
-
pickup_cube_two()¶ Pick up cube with id=2
Same as pickup_by_cube_id(2)
Returns: True (suceeded) or False (failed) according to what Cozmo thinks is the result.
-
place_on_top(cube_id)¶
-
place_on_top_of_one()¶
-
place_on_top_of_three()¶
-
place_on_top_of_two()¶
-
scan_for_cube(angle, scan_speed=20)¶ Rotate in place while looking for any cube
This function executes a rotation, with certain angular speed and angle, while at the same time looking for a specific cube defined by its id. As soon as Cozmo identifies a cube in its field of view (not necessarily at the center of the camera), it stops. As a result, Cozmo will keep seeing the cube after it stops.
Parameters: angle (float) – Angle to scan Note
If the angle is positive, Cozmo rotates in clockwise order. A negative angle is a counter clockwise rotation.
Returns: True (suceeded) or False (failed).
-
scan_for_cube_by_id(angle, cube_id, scan_speed=20)¶ Rotate in place while looking for a cube with specified id
This function executes a rotation, with certain angular speed and angle, while at the same time looking for a specific cube defined by its id. As soon as Cozmo identifies a cube in its field of view (not necessarily at the center of the camera), it stops. As a result, Cozmo will keep seeing the cube after it stops.
Parameters: - angle (float) – Angle to scan
- cube_id (int) – Id of the cube to be picked up, either 1, 2, or 3. If the cube id is wrong, Cozmo will complain with a sound.
Note
If the angle is positive, Cozmo rotates in clockwise order. A negative angle is a counter clockwise rotation.
Returns: True (suceeded) or False (failed).
-
scan_for_cube_one(angle, scan_speed=20)¶ Scan for cube with id=1
Same as scan_for_cube_by_id(3)
Parameters: angle (float) – Angle to scan Returns: True (suceeded) or False (failed)
-
scan_for_cube_three(angle, scan_speed=20)¶ Scan for cube with id=1
Same as scan_for_cube_by_id(3)
Parameters: angle (float) – Angle to scan Returns: True (suceeded) or False (failed)
-
scan_for_cube_two(angle, scan_speed=20)¶ Scan for cube with id=1
Same as scan_for_cube_by_id(3)
Parameters: angle (float) – Angle to scan Returns: True (suceeded) or False (failed)
Making Cozmo identifying (familiar) faces¶
-
align_with_face()¶ Align with any visible face
Align Cozmo’s body with a visible teammate. As a result, the face will appear centered in Cozmo’s camera.
Returns: True (suceeded) or False (failed) Note
This action is useful to control Cozmo’s heading angle using your face.
-
disable_facial_expression_recognition()¶ Disable facial expresion recognition
-
enable_facial_expression_recognition()¶ Enable facial expresion recognition to identify mood
-
is_face_visible()¶
-
is_teammate_visible()¶
-
say_something_to_visible_teammate(text_before='', text_after='', *args)¶ Identify a visible teammate, and say something mentioning the teammate’s name
This action comprises a sequence of three steps.
- Aligning Cozmo toward a visible teammate
- Identifying the teammate by checking the record of familiar faces
- Constructing a sentence that mentions the name of teammate
- Using Cozmo’s speech synthesis capabilities to say the sentence.
Parameters: - text_before (string) – Text to be said BEFORE the name
- text_after (string) – Text to be said AFTER the name
Note
This function receives a variable number or arguments. All arguments will be concatenated and delimited by a space, and appended at the end of the message. This is useful to compose sentences.
Returns: True (suceeded) or False (failed)
-
scan_for_faces(angle=360, scan_speed=17)¶ Rotate in place while looking for any human faces
This function executes a rotation, with certain angular speed and angle, while at the same time looking for any face previously registered using the Meet Cozmo App. As soon as Cozmo identifies a human face (not necessarily registered) in its field of view (not necessarily at the center of the camera), it stops the rotation. As a result, Cozmo should keep seeing the cube after it stops.
Parameters: angle – Angle to scan (in degrees) Returns: True (suceeded) or False (failed)
-
scan_for_teammates(angle=360, scan_speed=17)¶
-
wait_for_a_smiling_face_visible(timeout=False)¶ Look for a smiling expression
Parameters: timeout (int) – amount of time, in seconds, to wait for a smiling face. If zero, false, or None, no waiting time is used and instant check is done
Misc functions¶
-
abort()¶ Abort the entire program execution
-
disable_camera_settings_for_bright_light()¶
-
disable_head_light()¶ Disable head light
-
enable_camera_settings_for_bright_light()¶
-
enable_head_light()¶ Enable head light to see in low light conditions
-
pause(time_in_seconds)¶ Pause for certain amount of time in seconds
Parameters: time_in_seconds (float) – time to pause
-
set_volume_high()¶
-
set_volume_low()¶
-
set_volume_med()¶