Anki Vector SDK examples aren’t easy to find as the SDK is very new. So we made this Anki Vector SDK tutorials, projects, and examples page. Let’s get Coding!
The Vector SDK was literally released today. So please keep in mind this is a living Draft that will be constantly updated. As we add more Vector example’s well add them here. If you have any examples please feel free share them via the comments!
If you read this, and it seems a bit over your head, check out our Ultimate Guide to Block Coding. You can program Cozmo in a much simpler format.
Updated Dec 15 2018
Vector Examples, Tutorials, and Projects
We will organize this so you can find Anki Vector SDK projects, examples, and tutorials according to certain categories. For example, we’ll sort the Vector examples, projects, and tutorials separately. We’ll also sort according to Python functions, Vector functions, and Vector features. For example, when sorting for Python we’ll look at examples that use loops, conditionals, etc. When looking at Vector features we’ll look at animations, the lift, etc. When looking at Vector functions we’ll look more at things like say_text() etc.
Examples will be pretty brief, giving a quick description and code for Vector. Tutorials will be much more in depth, and will take more work to write. Projects are ideas for things you can do at home or in the classroom.
Anki Vector Examples – Vector Functions
Here we will look at Anki Vector Python examples looking at specific functions.
anki_vector
anki_vector.anim
Find Vector examples of animations here. We will slowly be adding more and more examples using the anki_vector.anim class.
anki_vector.behavior
For now this seems to be the area that Anki has focused on the most. We have a lot of commands to use in the Vector Behaviors. We have written several examples on how to use some of these behaviors, and more are on the way.
- dock_with_cube()
- drive_off_charger()
- drive_on_charger()
- drive_straight()
- go_to_pose()
- motion_profile_map()
- set_eye_color()
- set_head_angle()
- set_lift_height()
- turn_in_place()
anki_vector.camera
There is a lot of power in Vector’s camera. For now we are just scratching the surface with the possibilities. We will be writing more Vector examples that further utilize the camera. Kinvert loves modules like OpenCV and we’ll have some tutorials on that in the near future. Please stay tuned.
- enable_camera_feed
- anki_vector.Robot.camera.latest_image
anki_vector.events.Events
Events allow Vector to watch for certain things to happen and then react.
- audio_send_mode_changed
- cube_connection_lost
- nav_map_update
- object_appeared
- object_available
- object_disappeared
- object_finished_move
- object_moved
- object_observed
- object_stopped_moving
- object_tapped
- object_up_axis
- robot_observed_face
- robot_observed_object
- robot_state
- wake_word
anki_vector.motors
- set_head_motor()
- set_lift_motors()
- set_wheel_motors()
anki_vector.proximity
One of the great features of Vector over Cozmo is the distance sensor. This will help a lot in obstacle avoidance as well as other things like mapping.
anki_vector.screen
Kinvert anticipates more functions becoming available in the future when it comes to Vector’s camera. We have a few Vector SDK examples here and will be adding more.
In particular we are looking forward to when we can draw shapes and text on Vector’s face. This is currently possible in the Cozmo SDK and Anki will almost certainly add similar functions in the future. Check out Cozmo SDK Examples to see what might be possible for Vector in the future.
- convert_image_to_screen_data()
- convert_pixels_to_screen_data()
- set_screen_with_image_data()
Anki Vector Examples – Vector Features
Here is a list of Anki Vector examples based on the features of Vector. So for example, we’ve sorted these examples based on things you can control and sense with Vector. This includes Vector examples on the head, lift, backpack light, camera, and more.
Cube
Drive
- Vector Figure 8 – anki_vector.Robot.behavior.drive_straight() and turn_in_place()
- Example – Drive Vector 2
Lift
Once Anki releases Custom Markers or improves their dock with cube command we’ll be adding more lift examples. For now the lift just doesn’t seem to do much. It functions fine, but without being able to dock with cubes reliably it’s still sort of meh. Give them time. It’s still Pre-Alpha.
- Vector Play Fetch
- Vector and Cozmo Play Fetch with Tapped Cube – set_lift_motor()
Anki Vector Distance Sensor
We are super excited about this. Cozmo really needed a distance sensor and Vector actually gets one. Kinvert is thrilled to see that Anki included the Proximity sensor in their Pre-Alpha.
- Anki Vector Distance Sensor – Proximity Verbal Ruler
- Vector Proximity Example 2
Backpack Light
I don’t yet see how to control the backpack light in the Pre-Alpha. Once we see this is updated we’ll make sure to add some examples here.
- Anki Vector Example – Vector’s Backpack Light 1
- Anki Vector Example – Vector’s Backpack Light 2
Animations
Animations are what brings Vector to life and we’re excited to bring you some Vector examples with animations in them. Check them out below.
- Anki Vector Animations 1 – anki_vector.anim.play_animation()
- Vector Example – Vector Animations 2
Camera
This camera seems much much better than the one in Cozmo. I plan to have some OpenCV examples out in the not too distant future.
- Vector Camera Stream on Screen with latest_image
- Example – Vector’s Camera 2
Face
The new color IPS Display opens a lot of possibilities. We can’t draw text and shapes yet but we can display images. Here are some examples that Kinvert wrote using the Vector SDK and the camera.
- Displaying Image on Vector’s Screen using convert_image_to_screen_data and set_screen_with_image_data
- Slideshow Using convert_image_to_screen_data and set_screen_with_image_data
- Display Text on Vector’s Screen With PIL
- Rainbow Eyes using robot.behavior.set_eye_color
- Pulsating Eyes Using robot.behavior.set_eye_color
Head
Move the head to change the camera angle, or give Vector a bit of personality. You can find examples below that show you how to move Vector’s head.
- Making Vector Nod – anki_vector.Robot.behavior.set_head_motor()
- Anki Vector Example – Vector’s Face IPS Display 2
Touch
Using the capacitive touch sensor in the SDK.
- Playing Fetch With Vector Robot – robot.touch.last_sensor_reading.is_being_touched
- Cozmo and Vector Can Talk To Each Other – robot.touch.last_sensor_reading.is_being_touched
Vector Cube Examples
Not much to see here yet. Coming soon π
- Anki Vector Play Fetch – dock_with_cube()
- Anki Vector Example – Vector’s Cube 2
Anki Vector Examples – Python Based
Here we will look at using things like for loops, if / else statements, and more in working examples. For example in case TKinter isnβt installed we use a try except to cleanly exit the program. At Kinvert we believe students learn best by seeing real working Vector examples.
For Loops
We have some Vector examples that use for loops which you might find helpful.
- Vector Nod
- Vector Figure 8
- Slideshow on Vector’s Face
- String List Python With For Loops
- Nested For Loops
While Loops
Here are some Vector examples that use a while loop to make them work.
Lists
To make these programs work we used lists.
- Vector Figure 8
- Slideshow on Vector’s Face
PIL Module
Events
Useful Links
https://developer.anki.com/blog/features/interview/from-stem-to-learn/
Anki Cozmo vs Vector Comparison Chart
How to Replace Cozmo and Vector Cube Battery
Have a Cozmo but not a Vector? Check out the Anki Cozmo SDK and our Anki Cozmo Examples Projects and Tutorials.
Please ask questions and leave feedback in the comments!
If you’re a beginner and Python isn’t your thing take a look at What is Robotics, Block Coding, and Age to Teach Kids Python.
Want to stay up to date with any new Vector example code or tips? Join our mailing list. Unsubscribe at any time if you want. We hate spam as much as you do.
When will you have some programs that use the camera? Thank you.
I don’t know exactly when but I should have at least one within a week. I have a newborn so our schedule is all over the place right now so I can’t promise it will be within a week.
We do have some examples from Cozmo, which should be fairly similar to Vector FYI. In Useful Links above we have a link to the Cozmo SDK.
I’ve tried some animations, and the only one that works is the timer chime (anim_timersup_beep_01). However the loop integer does nothing, because it won’t repeat.
Here’s my code, and I get no errors. It seems to work, (the Terminal Window says so) but Vector doesn’t show it.
I’ve tried the example they give us verbatim ‘anim_turn_left_01’ and I get no change in behavior.
I’ve tried ‘anim_dizzy_reaction_soft_03’, and I get no change in behavior.
I’ve tried ‘anim_dizzy_shake_stop_01’, and I get no change in behavior.
What am I doing wrong?
_____________________________________
#!/usr/bin/env python3
“””play_animation()
Make Vector PERFORM an Animation
“””
import anki_vector
def main():
with anki_vector.AsyncRobot() as robot:
robot.anim.play_animation(‘anim_weather_rain_01’,loop_count=1, ignore_body_track=False, ignore_head_track=False, ignore_lift_track=False)
if __name__ == “__main__”:
main()
I am actually writing an article on this right now.
Try this out. It seems to work.
import anki_vector
import time
def main():
args = anki_vector.util.parse_command_args()
with anki_vector.Robot(args.serial) as robot:
robot.behavior.drive_off_charger()
robot.anim.play_animation(‘anim_greeting_hello_01’)
if __name__ == “__main__”:
main()
Hi Keith! Thanks for the reply. What I was trying to do was test the command-line variables for Play_Animation. It seems they don’t work.
The example file “04_Animation.py” works, UNTIL I try to put in the command-line variables that are documented in the SDK kit’s Index.html file, under “Anki_Vector.Animation”. It says:
play_animation(anim, loop_count=1, ignore_body_track=False, ignore_head_track=False, ignore_lift_track=False)
But I don’t believe it works as documented.
Ah I gotcha. Sorry about that. Yeah to get the picture for this article I was trying to ignore the body, head, and lift tracks. When I put those as True, the animation still played but all those motors kept playing.
Are you seeing the same thing? Or is your behaving a bit differently?
For now ignore_body_track=True, as well as the others, don’t seem to have any effect currently in this Pre-Alpha version of the SDK.
We did just publish our Vector Example on Vector Animations by the way π
G’day,
I learnt to see and control vector through the SDK can we enable the microphone so we can hear too?
Is there anything for speech recognition too?
Oh, lastly, after controlling him through SDK he seams to have a fit when he returns to his charger and we have to restart him. Is this a common thing?
Hi Archie,
Currently the microphone is not supported in the SDK, nor is speech recognition. That said they may be in development and available later.
I’ve had times where Vector will try to charge while I’m programming him. It’s not super common but I’ve seen it a few times. Not sure if it’s the same as what your describing.
Thanks,
Keith
I do the “hey vector” and “set eye color to blue” and the eyes change to blue!
If I do “hey vector” and “set eye color to white”, they go purple.
If I do “hey vector” and “set eye color to red, they change to yellow”.
Is there a problem with my vector’s screen?
Do you have the SDK installed? You could set his screen to certain colors and see if the problem exists or goes away when isolated from speech recognition.
Hi Keith!
First of all, thank you very much for all your tutorials here. I learned a lot about vector and made my first steps in programming a robot.
Now I have a question. We’re working with vector in university, and I wondered whether I can make him follow a black line? A line following robot basically.
Is that possible? Any feedback, or ideas on how to make that possible are greatly appreciated.
Greetings from Germany
Yes this is possible. You’ll use his camera and Computer Vision. I recommend OpenCV. We use it in Python with the Vector SDK.