Well, as Vector owners around the world waited for their trusty companion to take it’s last beeps, Anki released a public statement:So, for now, it seems our robot buddies will remain connected.
But it is worth noting that when/if we lose connection with the cloud, the following code won’t run.
User Intent ExampleGetting back to the topic, the team over at Anki have created 18 examples as part of the SDK, to help us get started writing basic programs for Vector.
Example 13 is the one we will be using, titled user_intent_subscription.
When you open the file, this is what you should see:You dont need to pay attention to the red lines, but the green writing at the top, before the imports, tells you what this program is for.
Essentially, when you run the program, Vector will wait for you to say “Hey Vector” then he will process the command you follow with, e.
“roll your cube”.
The example program is pretty bare.
There are no responses programmed to execute the commands that are given.
But it does give a good insight into the kind of commands that can be customised.
Vector SDK APIFor a better understanding, I went to the Vector SDK API, and delved into the user intent information.
This page lists a range of possible voice commands, or user intents, that you can program Vector to respond to, anyway you want.
It’s also worth noting that at the present time, you can’t modify Vectors response to “Go to your charger”, or “Go to sleep”.
Modifying the example codeSo, with a couple of the different voice commands in mind, you can navigate back to the example code, save it with a new program name (mine is unhelpful Vector), and start editing.
This can be broken down into three steps:Including the right importsAdding if statements to respond to user intentsAdditional response options to keep Vector’s responses interestingIncluding the right importsFor any python program to work correctly, you need to import the right modules.
These are the imports included for the example program to run:To add responses to user intents, you will need to add one more import, UserIntentEvent.
This should make your import lines look like this:Responding to user intentsTo respond to user intents, you will need to use an if statement.
This means that once your voice command has been processed, and transformed to text, it can be compared to a range of user intent events, like “hello”, or “fistbump”.
If the voice command matches the hook for the user intent event, Vector can then execute your specific response.
This guide is all about turning Vector into a robot with attitude.
So when someone says “hello” to Vector, I want him to have a bit of sass about him, and maybe even be quite rude.
After all, we all have “off days”, right?.So, starting with the hello user intent event, I programmed Vector to respond, like this:Basically, the if statement needs to be added just after the user intent has been received.
The beady eyed out there will also note that I added a While True loop near the end of the script.
This just keeps the code looping forever, while the example program only looped once.
But what if Vector is asked to play with his cube, or pop a wheelie?.Well, as he is normally, he responds cheerfully to any command, when he hears it (which can be temperamental)!.But there can be such a thing as too cheerful, so to make Vector push back a little, you could change the code, like so:You can do the same thing for the full range of user intent events as listed in the API.
The imperative_scold, imperative_love, weather_response, show_clock, and names_ask are a lot of fun to play around with.
Adding additional responsesNow you have a Vector with attitude, you could think about adding additional responses.
After all, if Vector responds with the same line every time you ask him, he might get a little repetitive.
So, to add more responses, one of the possible options is to use a random variable to determine which piece of text Vector should say.
To use the random option in python, you will need to import the random module, adding it to the import options at the top of the program.
So now, your imports should look like this:Once imported, you can create a variable with a random value, and use if statements, to match the random value generated to the line Vector will say.
Like this:Tidying upSome voice commands are similar to others, like “find your cube”, “fetch your cube” and “Pick up your cube”.
In this piece of code it really doesn’t matter what you ask specifically, because Vector isn’t going to do it (spoiler, he’s a robot with attitude).
But each different command has a different user intent event associated with it.
So to prevent multiple if statements covering similar commands, you can just use or statements to group similar commands together.
This means that the code will then look like this:Anki Vector, programming a robot with attitudeImprovementsFor a beginner, this program is a fun way to trick other members of your household, and get started creating customized responses to voice commands.
Vector doesn’t have to be a sassbot though.
You can use the same code, but change the speech, and Vector could become whatever you want.
Animations and movements could also easily be added to this program, to give Vector’s responses even more oomph.
And you could even pair it with Vector’s face recognition to add personal insults for the people in Vector’s life.
Or even compliments if a robot with attitude becomes a little too much! The possibilities are endless.
So, if you think you could handle Vector with a rebellious streak, and a bad attitude, try out this basic program.
I’m sure you’ll find plenty of areas to improve on :).. More details