This article will show you how to let Cozmo drive straight. We will be showing you how to use cozmo.robot.Robot.drive_straight().
Driving Cozmo’s Wheels
We can control Cozmo’s wheels. There are multiple methods to accomplish this.
In our case, since we’re driving a known distance of 50mm, the easiest option is cozmo.robot.Robot.drive_straight(). The other commands involve setting a speed for Cozmo’s left and right wheel, and a duration to go at that speed.
Let’s take a close look at the cozmo.robot.Robot.drive_straight() function.
What is special about this method over others, is that you can specify a specific distance. For the other methods, you have Cozmo drive straight by setting the wheel speeds and time. So to drive a specific distance, you have to calculate how far Cozmo will drive straight.
cozmo.robot.Robot.drive_straight() takes the following parameters:
You can find more details on this at http://cozmosdk.anki.com/docs/generated/cozmo.robot.html?#cozmo.robot.Robot.drive_straight
The Code to Have Cozmo Drive Straight
""" 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/ """ import cozmo from cozmo.util import distance_mm, speed_mmps def kinvert_drive(robot: cozmo.robot.Robot): robot.drive_straight(distance_mm(50), speed_mmps(50)).wait_for_completed() cozmo.run_program(kinvert_drive)
Note how we used distance_mm(50) as the argument rather than simply putting in a 50. Cozmo doesn’t want an integer, but rather the cozmo.util.Distance class.
Wrapping Up Cozmo Drive Straight
There are several ways to make Cozmo drive straight. If you want him to drive for a specific distance, probably cozmo.robot.Robot.drive_straight() is the best bet. That said, Cozmo can drive curves, he can accelerate, all kinds of stuff. There is a lot more flexibility in the other methods. We’ll go over those another time and link to them here.
In the meantime, here are some links you might find useful.
You can find our main article Introducing the Anki Cozmo SDK Programmable Robot for Kids in Python.
If you are an educator looking for help getting Cozmo in your classroom, check out Anki Cozmo Curriculum for STEM Classes K-12.
Cozmo is one of the robots we use in our Robotics for Kids and Teens Classes.