Chapter 7. Avoiding Obstacles Using Sensors
In the previous two chapters, we covered wheeled and tracked movement and then legged movement. Now your robot can move around. But what if you want the robot to sense the outside world, so you don't run into things? In this project, you'll discover how to add some sensors to help us avoid barriers.
We've covered creating robots using a wheeled/track base and robots that can move using legs. In this chapter, you will be introduced to some of the basics of sensors, particularly sensors that can help you avoid objects by alerting you to them.
Your robot will take quite a beating if it continually runs into walls, or off the edge of a surface. Let's help your robot avoid these so that it looks intelligent.
In this chapter, you will:
Connect the BeagleBone Black to a USB sonar sensor to detect the world around it
Use a servo to change the position of your sensor so that a single sensor can view a large field, eliminating the need for additional sensors
Tip
Downloading the example code and colored images
You can download the example code files and colored images for this Packt book you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to...
Connecting the BeagleBone Black to a USB sonar sensor
Now that you have a mobile platform and your robot can move, you will want to check if your robot could run into something. One of my favorite ways to do this is using a sonar sensor. First: a little tutorial on sonar sensors. This type of sensor uses ultrasonic sound to calculate the distance to an object. The sound wave travels out from the sensor, as illustrated here:
The device sends out a sound wave ten times a second. If an object is in the path of these waves, then the waves reflect off the object, sending waves that return to the sensor, as shown here:
The sensor then measures any return. It uses the time difference between when the sound wave was sent out and when it returned, to measure the distance to the object.
The first thing you'll want to do is connect the USB sonar sensor to your PC, just to make sure everything works well. Here are the steps:
Using a servo to move a single sensor
You now have your sensor, but if you want to sense in more than just one direction, you could use several sensors, each mounted to a different side of the robot. However, there is a way to use servos to move your sensor, which allows you to use a single sensor to sense in several directions.
The simplest way to avoid having to purchase and configure several sensors is to mount the sensor on a single servo, then use a servo bracket to connect this assembly to the platform. Using the sonar sensor, the assembly will look something like this:
Make sure you connect your servo to the servo controller; it can fit into any open connection. I am connecting mine to my quadruped that has eight servos to control, so I have connected mine to the eighth connection on the servo controller board. Here is an image:
I'll assume you already have your sensor up and working and know how to read data. In this section, you will add the ability...
Congratulations! You can now detect and avoid walls and other barriers to your robot. You can also use these sensors to detect objects that you might want to find.