Anki Cozmo Drive Straight

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.

  • cozmo.robot.Robot.drive_straight
  • cozmo.robot.Robot.drive_wheel_motors
  • cozmo.robot.Robot.drive_wheels

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 Cozmo drive straight by using cozmo.robot.Robot.drive_straight() in Python with Kinvert

cozmo.robot.Robot.drive_straight()

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:

  • distance
  • speed
  • should_play_anim
  • in_parallel
  • num_retries

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.

Cozmo Examples, Tutorials, and Projects for STEM Education Curriculum

You can also do similar things with the Anki Vector SDK and should check out Anki Vector Coding Examples.

If Python seems a bit tough check out Age to Teach Kids Python, What is Robotics, and Block Coding.

2 responses to “Anki Cozmo Drive Straight

    1. We might not have one dedicated specifically to data types yet. But we do have programs that are using conditionals and loops. Check out the Cozmo Examples page 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *