Anki Vector Programming using the SDK

When you first unpack your Anki Vector, you’ll probably spend at least a few hours getting to know him. With a range of voice activated commands available, Vector can keep you entertained with cube tricks, his AI smarts, a few rounds of blackjack, or even his general knowledge. While Vector is the most advanced desk robot available, with an ever expanding range of functions, it’s actually the SDK that really gives Vector the edge. Creating unique programs for your Vector is a great way to expand this AI robot. And programming Vector using the SDK is easier than you might think. So what is the SDK and how can you use it? Well, here at Hexnub, we have been tinkering with the SDK since release, and we are eager to help other Vector owners get started and create their own programs for Vector. Take a look at what we’ve found out.

What is the SDK?

Vector Trax Pack- Buy now from Amazon

The Vector SDK is the Software Development Kit for Anki Vector. This is the software that will allow you to create your own programs for Vector, using Python, as well as remotely operate your robot. You will need to download and install Python for the device you wish to use first, and then follow the download instructions on the Anki website. Don’t forget the upgrade command, to make sure you have the most up to date version of the SDK. Once installed, you will have access to Vector, under the hood. And you can finally ask him to bring you a drink, instead of pushing it off the table!

Inside the SDK

The SDK is simply a collection of Python files that allow your device to send instructions to Vector. There are a couple of different folders including apps and tutorials. These are the two folders you will be working with for the majority of the time.

In the apps folder you will find the code for remote controlling your Vector robot, with a live stream of video data from Vector to your device. There is also the proximity mapper which provides a fascinating insight into the real time mapping and changes that Vector records.

The SDK is currently in Alpha, so there may be some bugs.

Buy from Amazon

In the tutorials folder there are 18 example programs for you take a look at. Just right click on the file, and click on the edit with idle option. This will open up the Python programming environment, where you can take a look at different pieces of code. Click on run, and then run module, to run the code. This will open up another window with the console log. This is useful for helping you to understand which part of the program is running when, and can also be useful for bug finding.

Do I need to learn python?

Programming Anki Vector using the SDK does require python code. And learning python will really help you expand on Vector’s capabilities, and create much more complex programs. Your imagination is the only limit when creating programs for Vector. But to get started, you can simply take a look at the examples in the tutorials folder, and make small changes to create your own program.

Programming Vector using the SDK

With 18 different tutorials to choose from, finding a starting point can be tricky. But thankfully, the nice people of Anki have made sure the first three examples, are the easiest. These are the “hello_world”, “drive square”, and “motors” tutorials. And these will allow you to:

  • Make Anki Vector say anything you can think of
  • Get Anki Vector drive around
  • Program Anki Vector move his head and lift

Making Vector talk

Vector will say anything you can think of using this example. And it’s really straightforward to understand. Once you open the file to edit with idle, you should see something like this:

The red notes at the top are not part of the code, and not relevant. Simply find the “Hello World” text in the two different lines of code. Change these words to anything you want, and save the program with a new name. Then hit run, and run module, to hear Vector deliver his script. People have been using this for all sorts of fun, like singing, rapping, and delivering speeches. There’s also something endearing about the little robot voice.

If you want to build on this, keep your file open to add to as you look at more tutorials. Lines of code from other examples can simply be copy and pasted into this program, and changed to fit your ideas. This is how our program looks so far:

Make Vector move

Once Vector has learnt his lines, you can move onto the next tutorial. This is the “drive_square” file. When you open this file in the programming environment, you’ll see more lines of code than in the previous example, as well as more accompanying notes. The first thing to take note of is the extra import line at the start of the code, shown below in orange and white. This program needs to use degrees, distance_mm, speed_mmps, so these all need to be imported for the program to run.

You’ll also see that this program is using a for loop. You won’t need to use this yet, but it’s good to note for future reference. The for loop allows the indented code to run four times, before moving on with the program.

Your main focus now should turn to the lines of code that actually make Vector move. Take a look at the three different numbers in brackets. These are the numbers that control how far Vector moves, how fast, and what angle he should turn. Change these numbers, and unless you want to repeat the movement 4 times, remove the for loop. And Vector will be scooting around your desk or floorspace in no time. Why not set up a maze or a path for Vector to navigate? You could even program some new dance moves?

You can copy and paste these four lines into your previous program, to have Vector move before, during or after delivering his speech. You’ll also need to copy and paste the additional import line at the top of the code. Just make sure that for all your copied and pasted lines of code, the indents at the start of each line are identical to the ones above, otherwise your program won’t run.

This is how our example looks so far. Vector drives straight forward for 100mm, turns 90 degrees, and says “Hello from Hexnub”.

Moving Vector’s head and lift

Now he’s got the motion, and the words, you might feel like Vector’s delivery could use some more character. Maybe he needs to look you in the eye? Well, tutorial number 3 will help you there. This is the tutorial that shows you how Vector’s head and lift move. You can even move Vector’s wheel motors with this code too.

One of the key details to notice is that this code has an import line for time. The movement of the motors relies on time, so this needs to be imported into the program too.

Take a look at these lines of code for raising and lowering Vector’s head and lift:

You will see that the numbers in brackets controls the speed of the motor movement. Experiment with these for a range of results. You’ll see that the difference in speed creates the difference between a cube tap, and a wheel-stand. And the different range of motions can be really helpful for dance moves and creating your own animations.

Once you understand how the code works, copy and paste the lines of code into your previous program to have Vector deliver his speech directly to your face. You’ll also need to import time too, otherwise your program won’t run. At this stage, you should have a cool program for Vector to speak, drive around and move the head and lift.

This is how our program looks now. Vector raises his lift, drives straight forward for 100mm, lowers his lift, turns 90 degrees, lifts his head, before saying “Hello from Hexnub”.

Programming Vector using the SDK

From just these three different tutorials, you should be able to create a cool program for Vector that will amaze your friends, family, and Instagram followers. Changing and editing existing code is a good way to understand what the different lines of code mean, and what they do. But if you want to create something more detailed or complicated, you will have to learn some Python first! The SDK is a great opportunity to learn something new this year, and the possibilities for Vector’s abilities are endless.