Program Cozmo and Vector to Talk

A lot of people have been trying to figure out how to get Cozmo and Vector to talk. After some feedback from the mailing list Kinvert programmed them, and now Cozmo and Vector talk.

Both Vector and Cozmo are an amazing way to learn programming. If you want to know the differences between the two check out Cozmo vs Vector.

This is one of many wonderful Vector Coding Examples. Actually, it’s also a Cozmo Coding Example. This is a Kinvert first! Both robots being programmed in one article.

Vector and Cozmo Talking?

You’ll really want to watch the video. It’s well worth the <2 minutes. Here is a link in case you need it: https://www.youtube.com/watch?v=c_i_lVhOUBw

Again, this is something a lot of people have been wanting a long time.

Please keep in mind, this is in the very early stages and they can only say “Hi.”

What is really exciting is the potential of the method we are using. It will be pretty easy to get them to each have 4 options of what to say. But honestly they could also easily have 256 things to say. Or more.

More on that later.

Speaking of Cozmo and Vector Commands…

Program Cozmo and Vector to recognize each other and talk with Python and Kinvert

What commands will we be using? Here they are:

  • robot.behavior.drive_off_charger()
  • robot.behavior.set_lift_height()
  • robot.say_text()
  • time.sleep()
  • robot.world.wait_until_observe_num_objects()
  • cozmo.anim.Triggers
  • robot.play_anim_trigger()

The program itself isn’t that hard. The hard part for most people will be having two systems running the SDK for Vector and Cozmo.

Let’s Talk About the Cozmo and Vector Code

There are two different programs here. One is for Cozmo and the other is for Vector.

I’ll get a more detailed description soon. For now I’m trying to get the code out ASAP then get more detailed later.

To make this work you’ll need both the Anki Vector SDK and the Anki Cozmo SDK.

Vector’s Code

Anki Vector SDK Python programmable robot Kinvert face screen example


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

def main():
    '''Make Cozmo and Vector Talk - Version 0.00potato
    
    Vector's Code
    
    Run program on both. Put cube in Vector's lift. Touch Vector's back. Laugh milk out your nose.
    '''
    args = anki_vector.util.parse_command_args()

    with anki_vector.Robot(args.serial) as robot:
        robot.behavior.drive_off_charger()
        robot.behavior.set_lift_height(0.0)

        print("ready")
        robot.say_text("Ready")
        
        while not robot.touch.last_sensor_reading.is_being_touched:
            time.sleep(0.1)
            
        #Note incorrect spelling
        robot.say_text("Hi Cosmo")
        robot.motors.set_lift_motor(0.5)
        time.sleep(4)
        
        robot.say_text("I'm glad we found a way to talk")
        time.sleep(1)
        
        robot.motors.set_lift_motor(-100)
        
        #This wasn't part of the YouTube video
        #But after that surprise I figured I'd add it
        #Uncomment the line below if you want
        #robot.say_text("Trololololo, lololo, lololo")

if __name__ == "__main__":
    main()


Cozmo’s Code

Using the Anki Cozmo SDK to change oled and cube lights using Python part of our Cozmo Curriculum


"""
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
from cozmo.objects import CustomObject, CustomObjectMarkers, CustomObjectTypes

def kinvert_competition(robot: cozmo.robot.Robot):
    '''Make Cozmo and Vector Talk - Version 0.00potato
    Cozmo's Code Run program on both.
    Make Cozmo face his marker. Laugh milk out your nose. '''
    cube_obj2 = robot.world.define_custom_cube(CustomObjectTypes.CustomType02,
                                              CustomObjectMarkers.Hexagons5,
                                              44,
                                              25, 25, False)
    cube = None
    while not cube:
        #cubes = look_for_cubes_4(robot, end_time, 1)
        #cube = choose_cube(robot, cubes)  
        cube = robot.world.wait_until_observe_num_objects(num=1, timeout=0.5, include_existing=True)
    while True:
        cube = robot.world.wait_until_observe_num_objects(num=1, timeout=0.5, include_existing=True)
        height = cube[0].pose.position.z
        print("Cube Height is {}".format(height))
        if height > 40:
            robot.say_text("Hello Vector").wait_for_completed()
            animation = cozmo.anim.Triggers.CodeLabHappy    
            robot.play_anim_trigger(animation).wait_for_completed()
            break

cozmo.run_program(kinvert_competition, use_3d_viewer=False, use_viewer=False)


Python Code Improvements

Anki Vector Coding Example using the touch sensor in the Anki Vector SDK with Kinvert

Eventually we want to trigger this without touching Vector’s back. Can you think of ways to accomplish that?

How would you reverse it so Vector is waiting for Cozmo to talk?

What method could we use to increase the number of things Cozmo and Vector can say to each other?

Have any cool ideas for what they should do? Please let the world know in the comments below.

You Might Also Be Interested In…

Cozmo drawing for online coding class learn to program anki cozmo robot in python

If you are interested in programming Cozmo and Vector, I think we have a lot of cool stuff for you.

This is true whether your somewhat advanced or a complete newb like I once was.

If a fully written language seems difficult, read What is Robotics and Kinvert’s Ultimate Guide to Block Coding.

Now That Anki Closed Here’s How to Keep Cozmo Safe

Interested in more stuff a bit deeper in Python? Check out the examples pages. They have links toward the top of this article.

The first people to find out about this were on the mailing list. The form is right up there ^ and you can unsubscribe at any time. We’ll keep you up to date with Cozmo and Vector and occasionally tell you about other robots and cool programming stuff we find.

If you have any questions, please let us know in the comments below. Hope this helped!

2 responses to “Program Cozmo and Vector to Talk

  1. Do you think they could read custom object symbols from each other screens?` For cue..and triggered behaviour..such as follow me..

    1. Great idea. Possible but difficult. You’d have to train a neural net on each robot to recognize the symbols on the other robots face. Certainly possible.

Leave a Reply

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