Anki Vector Python SDK - gregory-j-r/Anki-Vector-ROS2 GitHub Wiki
The Anki Vector Python SDK is a python interface that allows for communication and control of the Anki Vector Robot. It is the main tool used when writing software to control Vector, and has many built in functions that are very helpful. In this section I will go through how to set up the SDK, the useful tools the SDK has to offer, and it’s limitations.
Installation Instructions
The SDK is easily installed on linux machines (Tested on lubuntu 18.04 and 20.04) by using the following commands:
sudo apt-get update
python3 -m pip install --user anki_vector
python3 -m pip install --user --upgrade anki_vector
Before being able to control Vector you will also have to sort out some certificate files and keys. This is because Anki was concerned with security and accessibility of Vectors camera and microphone. If your Vector robot has been authenticated you should have 2 files, one titled sdk_config.ini, and another called Vector-XXXX-YYYYYYYY.cert, where XXXX is Vectors name and YYYYYYYY is Vectors serial number. These 2 files should be placed in the following location:
~/.anki_vector/
If you do not have these files then you will first need to authenticate your robot, then run the following command:
python3 -m anki_vector.configure
And enter the authentication account information when prompted. The SDK should now be installed and Vector should be authenticated and ready to be controlled. Further instructions can be found at: https://developer.anki.com/vector/docs/install-linux.html#install-linux
Functionality/Usable commands and Their Limitations
The SDK is very helpful and can control many of Vectors actuators as well as report many of Vectors sensor readings. I Have compiled a list of all Vectors functionalities that can or cannot be commanded/monitored by the SDK and to what degree. Where robot is an instance of a anki_vector.Robot() object.
Sensor/Actuator | Available functionality | Related SDK Commands |
---|---|---|
Head Motor | Can control the speed at which the head rotates (up/down rotation) and can set the angle of the head to be at between -22.0 and 45 degrees. | robot.motors.set_head_motor(), robot.behavior.set_head_angle() |
Lift Motor | Can control the speed at which the lift is raised and lowered and can set the lift height in mm off the ground | robot.motors.set_lift_motor(), robot.behavior.set_lift_height() |
Wheel Motors | Can set each wheel motor individually, can set the speed or acceleration to be a certain value | robot.motors.set_wheel_motors() |
Position Encoders | Known in the SDK as “Pose”, a pose describes Vectors position in space, and after driving around a new pose can be obtained and compared to the previous one to tell distance travelled. Pose is reset when vector is picked up, and cannot be reset through the SDK as of now. | robot.behavior.go_to_pose(), robot.pose, robot.pose.define_pose_relative_this() |
Laser range sensor | An infrared sensor on the front of vector that detects his distance from objects in front of him. It works up to about 400mm but loses accuracy after 300mm. 30mm is about the closest it can measure a wall that Vector is colliding with if the forklift is the point of contact. | robot.proximity.last_sensor_reading.distance() |
Microphone | Inaccessible at this time through the SDK. | None |
Speakers | Can make Vector say strings of words. | robot.behavior.say_text() |
Face Screen | Can put up any image that is 184x96 pixels onto vectors face screen | anki_vector.screen.convert_image_to_screen_data(), robot.screen.set_screen_with_image_data() |
Floor Sensors | Minimal functionality available, the SDK allows only for a True or False collective reading meaning if at least 1 sensor detects an edge the value will be True and if no sensor detects an edge the value will be False | robot.status.is_cliff_detected |
Capacitive Back | Raw values available through the SDK | robot.touch.last_sensor_reading.raw_touch_value |
Accelerometer | Raw values available through the SDK | robot.accel |
Gyro | Raw values available through the SDK | robot.gyro |
Camera | Camera feed is available through the SDK, with a latency of approximately 0.5 seconds | robot.camera.init_camera_feed(), robot.camera.latest_image.raw_image |
The API Reference section of this page https://developer.anki.com/vector/docs is very helpful when looking for SDK commands for specific functionalities.
Events and Their Limitations
Vector and the SDK have a very helpful tool known as Events. Events are triggered when Vector sees (through it’s camera) a familiar symbol. Familiar symbols are those found on the Vector LightCube faces, the Vector charging pad, and many custom symbols that can be found here https://developer.anki.com/vector/docs/generated/anki_vector.objects.html. In the SDK you can initialize a subscription to specific types of Events, so that whenever Vector sees a specific symbol, a callback function you write is called (much like subscriber callback nodes in ROS). Information about the seen object is then available (pose, type, etc.). This is a very versatile tool that can be used for finding objects or even regions to drive to, so long as they have a visible symbol.
The largest issue with events is that they are not triggered while driving. This means that in order to “search for” a LightCube you would need to drive the wheels for a bit, then stop them, allow some time for the event to trigger or not, then repeat. Another option apart from Events that gives a similar functionality is anki_vector.Robot.world.visible_objects which is a list of all the objects visible by Vector at a given time. But much like the Events this functionality is not usable while driving.
Known Issues
If you are running the sdk and encounter the Error:
Unknown Event type
then you will need to follow these steps to fix it:
Step 1: Navigate to and open ~.local/lib/python3.8/site_packages/anki_vector/events.py
Step 2: Replace line 250 self.logger.warning('Unknown Event type')
with continue
I noticed the error when I updated my robots firmware.
Some other issues include:
- The go_to_pose function will lower Vectors lift when it is called.
- If Vector is lifting something heavy (even its LightCube) it will tip forward, lowering its traction and affecting its mobility.
- If Vector lifts something heavy (even its LightCube) it has a tendency to drop it’s lift as the object is to heavy for sustained lifting.
- Vectors Camera exposure cannot be set through the sdk and sometimes take a long period to adjust causing images to be over or under exposed.