I'm afraid that you may be getting tired of my rambling on about my Arduino-powered robot, but I'm so excited I cannot help myself.
One thing I plan to do is load my robot with a cornucopia of sensors: ultrasonic range sensors, infrared reflectance sensors, temperature and humidity sensors, audio sensors (so it can turn to me when I click my fingers and come to me when I whistle), accelerometers, magnetometers, and gyroscopes, oh, my. You name it, and my robot will sense it.
Of course, there is a downside to all this: You don't want your main controller to spend all its time handling boring, low-level, nitty-gritty sensor-related processing tasks. You can use a faster, more powerful processor, but we will discuss that in a separate column. For the moment, let's focus on the sensors themselves.
This started when I was pondering the use of ultrasonic range sensors. Given a choice, I like to spend as little of my hard-earned cash as possible, so I started off on Amazon. I found the HC-SR04 Arduino Ultrasonic Distance Measuring Sensor Module, a bargain at $2.40 each.
The HC-SR04 boasts a detection distance of 2-450cm. I don't want anything to sneak up behind my robot, so my idea is to have a bunch of sensors -- maybe eight or more -- pointing in all directions of the compass. An alternative might be to use fewer sensors scanning back and forth from side to side. I'll have to ponder this.
I've been told I will need to calibrate these sensors by setting targets at a selection of known distances, measuring the responses from the sensors, and comparing these responses with the actual distances. I can use these measurements to generate corrections to the sensor readings as required. I've also been told ultrasonic measurements depend somewhat on temperature and humidity, so I will need to include temperature and humidity sensor readings in my calibrations.
The main problem with cheap and cheerful sensors like the HC-SR04 is that the main controller does the bulk of the work. It initiates the ping while the sensor board handles things like pulse shaping. Some of these sensors respond with a pulse whose width is proportional to the distance to the object being sensed. The problem is that the main controller must determine the width of this pulse. If you are playing with multiple ultrasonic sensors, the controller could spend all its computational capacity on these mundane activities.
This is very similar to the problem of controlling the motors. You could use the main controller to directly pulse-width modulate output pins you use to drive an H-bridge, but your controller wouldn't have the bandwidth to do much else. The solution here is to use something like the Adafruit motor controller shield (daughter card), which can handle up to four DC motors. The main controller issues a command like "Run motor No. 4 forward at 50 percent full speed" over the I2C bus. The motor controller shield handles all the nitty-gritty details, and the main controller can concentrate on more important tasks.
The trick is to offload the main processor by having distributed subprocessors perform the boring pin-twiddling work. We can do the same thing for the sensors. My chum Duane Benson directed me to the SRF08 Ultrasonic Range Finder Module.
The main controller communicates with the SRF08 through the I2C bus (not by pin-twiddling digital inputs and outputs, as the HC-SR04 does). After instructing the SRF08 to initiate the ping, the main controller goes off to do other things. A subcontroller on the SRF08 is in charge of detecting, processing, and storing the distance measurements. When it's ready, the main controller can query the subcontroller on the SRF08 to see what it's detected. Results can be delivered in inches, centimeters, or microseconds.
This is all well and good, but the big problem is that the best price I could find for an SRF08 was around $55. If I were to use eight ultrasonic sensors, this would quickly become a very expensive hobby. I mentioned this to Duane on a Friday afternoon. The very next day, he designed a circuit board carrying a PIC microcontroller from Microchip (along with a LED and a few other bits and pieces). The fully populated board costs around $3, excluding the cheap and cheerful HC-SR04, which looks and feels exactly like the significantly more expensive SRF08.
You have to admit that this is cool. However, Duane has taken things a step further. He's working on a general-purpose, Arduino-compatible sensor board. The idea is that you can plug whatever type of sensor you wish into this board. Then you write an Arduino program (a sketch) to control the sensor and process and store the results. Duane and I will provide sketches for a couple of sensors, but this will all be open-source, so you'll be able to create and publish your own sketches for other sensors.
In the case of my ultrasonic sensors, in addition to recording the distance to the nearest object, the sensor controller could calculate how fast an object is approaching or receding. Also, you don't want to have multiple ultrasonic sensors doing their own thing, because they can easily detect reflections from other sensors' pings. We might daisy-chain the sensor boards so that they take readings in turn in a round-robin style.
I'm envisaging the main controller board telling my ultrasonic sensors to take readings in a round-robin style and report results in centimeters (or whatever). The main controller could inform the sensor boards about environmental conditions (e.g., temperature and humidity), allowing them to refine their calculations and return more accurate readings. The sensor boards would then take turns generating pings and processing the results. Meanwhile, the main controller board could go off and do whatever it does best.
Whenever it's ready, the main controller could ask any of the sensors what's going on. The sensor might respond with the equivalent of "Well, the closest object to us is 300cm away, and it's currently approaching us at 50cm/sec… Duck."
I've waffled on long enough. Duane says he will write a couple of blogs in the not-so-distant future describing his PIC-based and Arduino-compatible sensor boards in more detail. Until then, what do you think about all this? Am I tempting you to start building your own robot?
— Max Maxfield, Editor of All Things Fun & Interesting