I've made a new video which involves my Anki Vector.
I started using the SDK for him and programming him. Vector is programmed using the language Python. I started off with Hello World which is pretty much the first thing you learn when you learn a programming language. This was already done as an example program, but I rewrote it myself in order to help me learn the language, as I am not new to programming but I am pretty new to Python. I then changed the words to make him say the quotes from the other robots and also learned how to use his animations and run them.
You can watch this video here on Dtube as well as on YouTube here:
How to Hello World?
Hello World is a relatively simple script. I created my scripts and explored the makeup of the tutorial scripts in the program, Notepad++.
The first thing you do is import what you need from the SDK.
For the most basic scripts you type:
For some it gets more complicated. Mine all ended up getting slightly more complicated, as I set his head to be on particular angles in all of them and made him move forward certain distances in some of them. However, hello world and any script that only makes him say something and doesn't need movement or adjusting the angles of parts of him, only requires import anki_vector.
To make vector say something you use the code:
The full code for Hello World is as follows:
def main ():
args = anki_vector.util.parse_command_args()
with anki_vector.Robot(args.serial) as robot:
print("Say 'Hello World'...")
if name == "main":
To run this program (on windows) you use command prompt. You navigate to the folder the script is in and then type either:
Sometimes the py one might not work but python might, but generally actually running the code is pretty easy once you have the hang of command prompt.
The bit that says:
print("Say 'Hello World'...")
makes the contents of the brackets, minus the " on each end (Say 'Hello World'...) print in the command prompt. It will run the program and after it determines that control of Vector is granted (you can't control him when he is too low on charge or in an unsuitable position etc) it will print that as a line in the command prompt, as well as do the other parts of the script (in this case making him say "hello world").
What about saying something other than Hello World?
Saying something other than hello world is easy and simply requires changing the words within this part of the script:
You can type anything there instead of Hello World and he will say that instead.
Here is the code for one of Bender's lines showing this:
from anki_vector.util import degrees
from anki_vector.behavior import MIN_HEAD_ANGLE, MAX_HEAD_ANGLE
with anki_vector.Robot (args.serial) as robot:
print ("Say 'Bender Line 1'...")
robot.say_text("I failed at my life long dream again. How can I be so bad at everything i try and still be
if name == "main":
This script makes Vector say Bender's line about failing his life long dream. However it does more than just say the line.
The code to use Vector's animations is:
But how we do know what animations he has?
The animation names are held as strings inside of Vector. We need to first create a script that retrieves the animation names from Vector.
The code for this is:
import anki_vector #this imports what we need from the sdk for this script
with anki_vector.AsyncRobot() as robot:
print ("list all animation names:") #This prints the text "List all animation names" to the command prompt
anim_request = robot.anim.load_animation_list() #This requests the list of animations from Vector
anim_names= robot.anim.anim_list #anim_list holds the set of animation names (in string format) returned
from the robot
for anim_name in anim_names:
print (anim_name) #in these last two lines, the code goes through the list called
anim_names (it is a list because it was made equal to anim_list in the
previous line of code and anim_list is a list) and prints (to the command
prompt, just like when we told it to print "list all animation names"
earlier) each animation name (anim_name) that is in the list, for the
whole list until there is no more list. The for statement (for anim_name
in anim_names) is being used to iterate over the list (sequence) and
print each anim_name within the anim_names list.
So after doing this we get a big list of animations for Vector in the command prompt. I will have to run this from time to time as the animations will likely change and new ones will likely be added, but I currently have copied and pasted all of the list out of the command prompt into a word document. I then use this to select suitable animations for my projects.
The animation used in the code for this particular Bender line was anim_eyepose_sad_down01
The code to use this particular animation is:
For any other animations it will be the same but with a different animation name in the ' ' in the brackets.
The animations are fun to play with and I enjoyed experimenting with this. At least one is even basically a tantrum which I did use in the video.
Angling his head
To set Vector's head angle, more things need to be imported.
It goes from just being:
import anki_vector.util import degrees
import anki_vector.behavior import MIN_HEAD_ANGLE, MAX_HEAD_ANGLE
Importing these allows us to control his head angle, and these are also used for some other things too.
The code to control Vector's head angle is:
robot.behavior.set_head_angle(degrees(no of degrees in decimal))
In the case of the Bender script shown earlier it is for 3 degrees and is:
The head angle also goes into the negative too just shown as (degrees(-3.0)) with -3 being the example number chosen. If you set it too far either way it will pop up with an error in the command prompt telling you the limits. The limits appear to be -22 and 45. I mostly set the head angle for Vector somewhere between 3 and 6 depending on the voice line, with the exceptions to the rule being one of Dolores' lines as she looks upwards between the two parts of the line, and the ending doom song as I wanted him to lift his head up at the end after saying "the end" after lifting his lift up just like how Gir stretches out saying "The end".
For Dolores' line, Vector's head starts at 0 degrees but after saying the first part of the line, he lifts his head to 20 degrees. For Gir's line, his head starts at 5 degrees and then at the end goes up to 30 degrees.
It goes in my butt
For BMO's line "Yes Finn. It goes in my butt", I didn't use an animation to make him turn around, but a behaviour instead. Just like the head angle, this behaviour required the use of degrees (and hence required from anki_vector.util import degrees).
The code to make him turn around to show his butt to everyone is as follows:
Again this could be used for other turns that aren't 180 degrees, however this one was the only one I needed.
Making Vector Drive
There were two character lines in this video that required Vector to drive straight.
Driving straight is also a behavior just like set_head_angle and turn_in_place.
The code to make Vector drive forward is as follows:
robot.behavior.drive_straight (distance_mm(100), speed_mmps(40))
These are example numbers but are numbers I actually used for one of the lines.
Okay enough code, what are the special features of this video?
- Vector in a starring role
- The video has a snap / picture / thumbnail!
- Voice Lines
Thanks for watching and reading! ________________________________________________________________________________________
Birchmark Website / Portfolio: http://birchmark.com.au/
Calico Cactus - Courage:
VECTOR PROGRAMMING LINKS
Anki Forums on the Vector SDK: https://forums.anki.com/c/vector-sdk
Information on Vector SDK, animations etc on from Anki: https://developer.anki.com/vector/docs/api.html
Animation specific information from Anki: https://developer.anki.com/vector/docs/generated/anki_vector.animation.html
Behavior specific information from Anki: https://developer.anki.com/vector/docs/generated/anki_vector.behavior.html
Getting started with Vector SDK (Anki's info): https://developer.anki.com/vector/docs/getstarted.html
Thank you for watching and reading!
Please consider commenting, upvoting or resteeming this post / video if you enjoyed it.
ANOTHER POST OF MINE YOU MIGHT LIKE: https://steemit.com/robot/@birchmark/meet-anki-vector-h2n1
A POST I ENJOYED BY SOMEONE ELSE: https://steemit.com/gaming/@methus/bacon-the-game