In this note we are going to illustrate how three (or more) HC-SR04 modules can be used to add further "intelligent" vision to your bots. Basic usage of HC-SR04 and the principles on which it is based have already be given in this note.
The idea is to position the three sensors at fixed angles one another. Each module will give its own measure. Then, we use the three measures to try to induce some "safe/unsafe" state for our bot. In a safe state you can, for example, keep running forward. In an unsafe state, you can turn left or right according to the informations of the two other sensors. Indeed, consider the situation illustrated in Figure 1.
The idea is to position the three sensors at fixed angles one another. Each module will give its own measure. Then, we use the three measures to try to induce some "safe/unsafe" state for our bot. In a safe state you can, for example, keep running forward. In an unsafe state, you can turn left or right according to the informations of the two other sensors. Indeed, consider the situation illustrated in Figure 1.
Figure 1. The general situation.
How to position the sensors
It is important to dispose the two additional ultrasonic modules (HC-SR04 #1 and #3 in Figure 1) at fixed angles on an ideal circle of radius centered in the origin. To be able to do that in practice, just place your sensor #2 and decide how much should be. Take as the origin of the axis the point that it is a distance from sensor #2 on the normal wrt the sensor #2.Then, take a stripe of length , fix one end of the stripe at P and turn the other end left of a fixed angle, say and mark this point as . Do the same to the right and mark the new point as . Finally, place sensor #1 perpendicular to the line passing through and and dock it at . Do the same for sensor #3 wrt the point .
Clearly, the question now is: which values to choose for and ? Concerning , recall that in our previous post (see it here) we said that HC-SR04 starts giving erratic results when the obstacle is at angles greater than 30°. Therefore, a good choice could be 30°. Indeed, it is a good choice also because and functions take well known values at this angle and this will ease and speed up our calculations.
Concerning we have also lots of possibilities, we should just pay attention that one sensor do not cover or interfere too much with the others. To obtain a nice visual effect and to minimize interferences, we can just that the minimal such that sensor #1 touches the left side of sensor #2 and sensor #3 touches the right part of #2. In Figure 2 we have reproduced this situation and we have indicated all the interesting quantities that will help to compute minimal .
Concerning we have also lots of possibilities, we should just pay attention that one sensor do not cover or interfere too much with the others. To obtain a nice visual effect and to minimize interferences, we can just that the minimal such that sensor #1 touches the left side of sensor #2 and sensor #3 touches the right part of #2. In Figure 2 we have reproduced this situation and we have indicated all the interesting quantities that will help to compute minimal .
Figure 2. Computation of the minimal value for .
Call the length of the HC-SR04 module (xx mm). Then, the segment has length , same as the segment .
Finally
Approximating, as usual, $\cos 30°$ with we obtain
How to extract useful informations from the three sensors
At the beginning we said that we wanted to use additional sensors to increase the "cleverness" of our bot. Hence, assume that we have our sensors operating and we get three measures , and (see Figure 3). The point is to compute the quantities and in order to understand if the robot can pass through obstacle #1 and #3, for example. We will also compute , and in order to decide toward which of the obstacle is better to go the robot cannot go through obstacle #1 and #3.
Figure 3. Trying to extract useful information.
The quantities we need are computed using basic algebra and some trigonometry. Recall that is known and, of course, , , are also known. Therefore, we have to solve the following system of equations:
which gives
Taking $R=42mm$ as above we obtain
all quantities are expressed in millimeters.
The test circuit
After lots of theory, let's turn to applications! Figure 3 presents the test circuit. Remark that here I used the Arduino Proto Shield just for fun! Of course, it is not necessary at all, you can use any breadboard or simply wire together cables that go towards the same Arduino pin.
Figure 4. The test circuit.
Needed material:
1x Arduino
3x HC-SR04 ultrasonic module
1x Arduino Proto Shield (or any breadboard)
Cables
The test program
The following diagram resumes the "intelligence" we are going to program in our bot. I leave the translation of the diagram to Arduino code to the reader :-)
Figure 4. Adding some intelligence...
RW = robot width
S = safety width
The quantity is called safety width since it should be a width that we add to our measures in order to overcome possible measurement errors or to give enough time to the robot to make another measurement before knowing the obstacle. Obviously, this quantity depends on the robot speed.
Future developments
The test circuit (Figure 3) uses lots of pins on Arduino and hence we are left only with few pins for other functions/modules of our bot. In the near future I will present a general method on how to save pins. So, once more, stay tuned!
HC-SR04: what is the distribution law for the frequencies of values? (Part 1)
HC-SR04: what is the distribution law for the frequencies of values? (Part 2)
HC-SR04: using a sonar sensor for motion detection
Look here for a practical implementation!
Enjoy!
See also
Introduction to HC-SR04HC-SR04: what is the distribution law for the frequencies of values? (Part 1)
HC-SR04: what is the distribution law for the frequencies of values? (Part 2)
HC-SR04: using a sonar sensor for motion detection
Look here for a practical implementation!
Enjoy!
This is a really great guide nice work!
ReplyDeleteOnly thing is, in reality the HC-SR04 sensors are wide enough that 42mm doesn't work well when they are next to each other. Its a nice number in theory but isn't possible
Indeed, this is the min theoretical value. In practice one should adjust a bit. In the post, the method exposed provide hints on how to recompute adjustments...
ReplyDelete