Anki Vector Pulsating Eyes

A lot of people loved our Vector Rainbow Eyes article. Keeping on the eyes theme we’ve programmed Vector with Python to do something else with his eyes.

Cozmo and Vector are both amazing ways to learn how to program in Python. We have an article comparing the two at Cozmo vs Vector.

This is one of many fun Vector Coding Examples.

Controlling Vectors Eyes?

With the Anki Vector SDK you can control many things including Vector’s eyes.

Many people have been wanting to customize Vector and one of the best ways is with his color screen.

In the previous article with Vector’s eyes, we were changing the hue of his eyes to create a rainbow effect.

This time we will be controlling the saturation. Long story short, saturation is the difference between pink and red.

We will be pulsating this saturation value to get Vector’s eyes to pulsate.

Keep your Eye on the Commands

Customizing Anki Vector Robot's eyes with the python SDK Coding Vector

What commands will we be using? Let’s take a look:

  • robot.behavior.set_eye_color()
  • time.sleep()
  • math.cos()

The program itself is very simple. There is a little math going on which might be tough for non Engineers. But remember you can just copy and paste this code. No biggie!

Looking at the Code

https://youtu.be/WLIr04Cu2sU
Nice and short here. We import anki_vector and time as we often do.

We import cos from math. This is what will give us the ability to easily pulsate the eyes.

We set things up so the main function will fire, and set up the connection to the robot. This is pretty standard and I won’t go in to detail.

Next is what makes the program special. We have two for loops. This is actually very similar to our article on Vector’s Rainbow Eyes.

We’re just basically saying to pulsate 100 times. And to change the j value between 0-50 so we can do the math on that j value.

We use robot.behavior.set_eye_color() and input the hue (blue) and saturation (this is what we pulsate).

The math is in there to make things work. Don’t worry if you don’t understand it.


"""
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
from math import cos

def main():
    args = anki_vector.util.parse_command_args()

    with anki_vector.Robot(args.serial) as robot:
        for i in range(100):
            for j in range(50):
                robot.behavior.set_eye_color(hue=0.65, saturation=0.6+0.1*cos(3.14*(j+1)/25))
                print(cos(3.14*(j+1)/50))
                time.sleep(0.01)

if __name__ == '__main__':
    main()


Python Code Improvements

What would you change to make the pulsating eyes go to a more pure blue?

How would you change the program to get his eyes to pulsate more on the white side?

To get Vector’s eyes to pulsate different shades of green, what would you have to change?

You Might Also Want to Read

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

If you’re a fan of Vector we’ve got other material you’ll want to read.

If Python is a little over your head read What is Robotics and Kinvert’s Ultimate Guide to Block Coding.

Want to learn more Python? Check out Anki Vector Examples and Anki Cozmo Examples.

If you want to be kept up to date with all things Vector and Cozmo try out the mailing list above. A lot of good stuff in there and we’re getting raving reviews.

Questions? Comments? Let us know in the comments below 🙂

Leave a Reply

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