Kinvert will show you how to make Anki Cozmo Dock With Cube using their Python SDK. We wrote a Python program using robot.dock_with_cube().
Why Cozmo Docks With His Cube
Cozmo’s primary way to interact and play is with his cubes. He likes to stack them, roll them, move them around etc.
To do most of these things he needs to dock with cubes. Docking is where he drives so his lift forks at in the notches of the cubes so he can lift them.
Cozmo Dock With Cube Commands – dock_with_cube
This is a fairly straight forward version of the program we’ll be doing so the list is pretty short.
Here are the commands we’ll be using to get Cozmo to dock with his cube.
You can find more available commands for Anki Cozmo in our Anki Cozmo Examples page.
Python Code for Cozmo Dock With Cubes
Here is the code. It is pretty straight forward but I’ll go over how it works anyway.
First we import Cozmo. This is where we bring in the commands that make Cozmo work from the SDK. For example, without this the program would have no idea what dock_with_cube is.
cozmo.run_program is where we point Cozmo to execute the function that we wrote.
We define the cube using robot.world.get_light_cube(1). We noted cube 1 as it’s the easiest to recognize. It’s the one that looks like a paperclip.
Finally we use robot.dock_with_cube(cube1).wait_for_completed(). The wait_for_completed() part makes sure Cozmo is done docking with the cube before we end the program.
If you try running this without the wait_for_completed() Cozmo will end the program before he actually docks with the cube.
Here is the code itself.
""" Copyright Kinvert All Rights Reserved If you would like to use this code for business or education please contact us for permission at: www.kinvert.com/ Free for personal use """ import cozmo def kinvert_dock(robot: cozmo.robot.Robot): cube1 = robot.world.get_light_cube(1) # looks like a paperclip robot.dock_with_cube(cube1).wait_for_completed() cozmo.run_program(kinvert_dock)
You’re free to copy and paste the code above for personal use 🙂
Making Changes to the Python Code
How would you change the code so Cozmo docks with Cube 2 instead of Cube 1?
What could Cozmo do after he docks with the Cube?
Add This Reading to Your Docket
If you’re interested in coding Cozmo we probably have a lot of other stuff you’re interested in.
If you were unaware please read Anki Closed How to Save Anki Cozmo.
Oh, and one more thing. We have a mailing list where you can be kept up to date with all things Cozmo. You can unsub at any time. Form is below.