Anki Vector Distance Sensor Verbal Ruler

Kinvert will help you use the Anki Vector distance sensor using the Proximity class. In this Python example we will make a verbal ruler in the Vector SDK.

Can’t Wait to use Vector’s Distance Sensor?

Neither can we. This is Kinvert’s first time using the distance sensor in the front of Vector. This replaced Cozmo’s IR LED to add highly needed functionality to the SDK.

If you are interested in the differences between Cozmo and Vector be sure to check out our Anki Cozmo vs Vector Comparison.

For this article, we will be using the Anki Vector SDK. This is one of many of Kinvert’s Anki Vector Examples in Python.

Unfortunately you can’t do this with Cozmo. However, Cozmo is programmable also with the Cozmo SDK.

Anki Vector distance sensor using proximity to make a verbal ruler Kinvert Vector Example

We are using some pretty simple commands to show you how to use this very handy distance sensor. You’ll also see how to make Vector say text, as well as get some practice with a for loop, conditional statements, and print commands.

Let’s take a look at the commands a bit before diving in to the code.

Anki Vector Distance Sensor Proximity Commands

What commands will we be using? Here they are:

  • robot.proximity.last_sensor_reading.distance
  • getting distance_mm and distance_inch
  • for loops
  • robot.say_text()

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.

We will use a combination of these commands to make Vector drive a figure 8 pattern.

Eventually there will likely be online documentation for this. For now, you can check out an article Anki wrote about us here:

Turning Vector into a Verbal Ruler – Code

Let’s take a look at the code. We will be using anki_vector.Robot.proximity.last_sensor_reading.distance to turn Vector into a super handy verbal ruler. At first I just had this using one unit, but then I realized the other half of the planet would get on my case. So I included both units here. So let’s dive in and see how we used the Anki Vector distance sensor to make this verbal ruler.

Copyright Kinvert All Rights Reserved
If you would like to use this code for
business or education please contact
us for permission at:

import anki_vector
import time

def main():
    args = anki_vector.util.parse_command_args()
    with anki_vector.Robot() as robot:
        for _ in range(5):
            if robot.proximity.last_sensor_reading:
                distance = robot.proximity.last_sensor_reading.distance
                robot.say_text(str(distance.distance_mm) + " millimeters or " + str("%.2f" % distance.distance_inches ) + "freedom units")
                print("Can't be bothered to work right now")
                robot.say_text("Hold your horses")

if __name__ == "__main__":

How would you get Vector to do more measurements?

What if you only wanted one of these units, and not both?

Why do you think I added the if robot.proximity.last_sensor_reading to the code? What happens if you get rid of that? What might be a better way of handling the problem than I did? Please let me know in the comments below.

How would you increase the precision of the inch value Vector says by a one more significant figure?

Vectoring the Kinvert Way

Kinvert is well known for the fun STEM classes we provide. This is especially true of our Cozmo courses (and maybe we’ll have Vector courses soon too). To make these courses possible we use the Anki Cozmo SDK and the Anki Vector SDK.

We added a couple funny things Vector says. How could you change this verbal ruler to make it more funny?

In Conclusion

We hope you enjoyed this Anki Vector Example Using the SDK using the Anki Vector distance sensor. We have a lot more of these on the way. So hold your horses πŸ™‚

Please let us know in the comments below if this helped you, or if you made any cool modifications. We’d love to hear from you.

Contact Us For Help and Advice

Cozmo Examples, Tutorials, and Projects for STEM Education Curriculum is the place for Cozmo examples, in case you don’t have Vector yet.

If you’re interested in taking a Cozmo Camp Click Here or check out our Courses Page. We also use Cozmo in our Robotics Kids Class K-12.

2 responses to “Anki Vector Distance Sensor Verbal Ruler

  1. Hmmmmm Let’s see…

    To get Vector to do more measurements I would increase the for loop number. Maybe figure out how to tap into the edge detection and have Vector drive straight but turn and continue measuring when it reaches the edge. I wonder how far it can travel continuously on one charge……

    To use only one unit of measurement you just have to remove the reference to the offending unit in the say_text function. Maybe make Vector count off every foot it travels when testing how far it can go on a charge.

    Hmmmm after looking at the documentation, I would say that the if there is a value in the robot.proximity.last_sensor_reading it means that Vector has moved and has data to present? If you got rid of it, perhaps Vector would continuously present the distance as it moved? Not sure how to make it better yet…

    Vector could use print(distance.distance_inches/12) as feet perhaps?

    How are you getting Vector to perform figure 8’s? I don’t see anything that seems like it would do that in the code.

    1. Yep looks like you know how to make the changes to the code πŸ™‚

      I don’t think he is meant to do figure 8’s in this code. If we were doing that I’d be doing it in an article related to his drive commands.

      Also yes, you could do math on the measurement the way you mentioned to get feet.

Leave a Reply

Your email address will not be published. Required fields are marked *