Using the Anki Vector set_head_motor() command we will make Vector nod. Kinvert is an educational company and we will teach you how to code with Vector.
Why Make Vector Nod?
Often times we want to make Vector appear more lifelike. In the past, with the Anki Cozmo SDK, we have made Cozmo move his head while talking. This makes the results of the program a lot more fun for students.
For this article, we will be using the Anki Vector SDK.
This is a quick and easy example. In addition, it helps students understand both for and while loops in Python.
Let’s take a look at the commands a bit before diving in to the code.
Anki Vector set_head_motor() Command
What commands will we be using? Here they are:
- for loops
- while loops
We will link to the documentation once it is available online.
Keep in mind the argument we are passing is a value in radians per second.
Time to see how we can use this command in our code.
Make Vector Nod With set_head_motor()
Let’s take a look at the code. We will be using anki_vector.Robot.behavior.set_head_motor() to make Vector nod his head.
""" 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 def main(): args = anki_vector.util.parse_command_args() with anki_vector.Robot(args.serial) as robot: robot.behavior.drive_off_charger() time.sleep(0.5) for i in range(4): while robot.head_angle_rad > -0.3: robot.motors.set_head_motor(-0.6) while robot.head_angle_rad < 0.7: robot.motors.set_head_motor(0.6) robot.motors.set_head_motor(0) anki_vector.Robot.behavior.set_head_angle if __name__ == "__main__": main()
How do you think you could get Vector to nod more quickly or slowly?
What if you wanted nods with less freedom of motion? For example only allowing his head to be 15 degrees up and 15 degrees down?
This is our very first Anki Vector Example Using the SDK. We will be making many more in the near future.
If this example was helpful, or if you have any questions or custom modifications, please let us know in the comments below :).
Cozmo Examples, Tutorials, and Projects for STEM Education Curriculum in case you are looking for Cozmo Examples.
We have a lot more information about the Anki Cozmo SDK Programmable Robot for Kids in Python. This is our main Cozmo hub where you can find more information on Cozmo animations and a whole lot more.