Moving Cozmo’s Head With move_head()

Kinvert will show you how to move Cozmo’s head with this simple Python program using the move_head() command in the Anki Cozmo SDK.

This is one of many of Kinvert’s Anki Cozmo Examples in Python.

Moving Cozmo’s Head

There are a few reasons to move Cozmo’s head. One is to make him look and act a certain way. For example in his animations he’ll move his head a lot.

Another reason we use a lot is when you want his camera pointing a certain way. He has a camera in his mouth basically and you can help tilt that with the move_head command.

We’ll show you how to program Cozmo’s head to move.

First we’ll go over the commands, then look at the code, followed by some improvements you can make to the code and some other reading you might be interested in.

Commands in This Head Turning Program

https://www.youtube.com/watch?v=D73KvjlixAg

This is another straight forward program where we just show how to move his head without application.

You can find other examples of us moving Cozmo’s head in our Cozmo Examples page linked to above.

Here are the commands we’ll be using to move Cozmo’s head:

  • cozmo.run_program()
  • robot.move_head()
  • time.sleep()

This is a pretty simple one so let’s briefly go over the code next.

Moving Along to the Python Code

Time for a look at the Python code.

As usual, we begin by importing Cozmo. We also import time as we want to use the time.sleep() method.

Another thing we usually do is call cozmo.run_program which makes Cozmo run the function we want. In this case he is running the kinvert_move_head function which is the main chunk of the code.

To move Cozmo’s head we call the robot.move_head() command. We give it a number 1 to indicate we want him to move his head at 1 radian per second. That’s basically just the speed we want his head to turn.

Finally, we call time.sleep() to tell Cozmo to turn his head at that speed for 3 seconds.

Here is the code in all it’s glory.


"""
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
import time

def kinvert_move_head(robot: cozmo.robot.Robot):
    robot.move_head(1)
    time.sleep(3)

cozmo.run_program(kinvert_move_head)

Now it’s time to look at some of the changes we can make to the code to make this a bit more interesting.

Changes to the Python Code

What would you change if you wanted Cozmo’s head to turn down instead of up?

If you wanted his head to turn for a shorter amount of time, what modification would you make?

How would you get his head to turn up and then down?

Other Cool Kinvert Stuff

If you landed here chances are you have an interest in Robotics and Python.

For some people this material might be a bit tough. If so take a look at What is Robotics, Age to Teach Kids Python, and Block Coding.

We also have some cool stuff on 3D Printer Repair, What is ABS, and TPU Filament.

For other Cozmo and Vector related articles check out Anki Cozmo SDK, Anki Vector SDK, Cozmo Cube Battery, and Anki Vector Examples.

We also wrote some Games for Cozmo With Python SDK.

In case you didn’t know Anki Closed How to Save Anki Cozmo.

If you want to stay up to date with all things Cozmo, check out our mailing list. The form is below and you can unsub at any time.

Leave a Reply

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