Hey this is Elliot - I had a remote control wheelbarrow and thought it would be handy if it would follow me around the yard. Using the same concept as Jesse's luggage I made up my own version about a year ago. I used different hardware - this time a pair of ESP32s and three HC-SR04 ultrasonic rangefinder modules (the common Arduino starter kit type things).
The operating principle is the same as the luggage:
- Transmit a simultaneous radio and ultrasound signal from a beacon
- Receive the radio signal on the robot first, then start listening for the ultrasound signal to arrive
- Mark the time of the ultrasound signal on both right and left transducers
Once I have these three timestamps I can do some math to calculate both the distance and the angle to the beacon.
The distance calculation relies on the difference between the speed of sound and the speed of light: if we pretend that the radio signal is instantaneous then on the receiving end we have a start time for the ultrasonic pulse that was sent, and it is simple to measure the time until it arrives. Using the measured time and the approximate speed of sound we can calculate a distance.
The angle calculation is possible without the radio signal at all, but I still use it to keep everything synchronized. This works just like our ears - listening to two receivers (right and left), we can tell if something is straight ahead or off to the side based on which receiver hears it first. With a known difference between right and left we can translate the time difference into an angle.
Initially I used 433mhz radio modules but found them to have poor range and poor reliability; ultimately I used the ESP-NOW protocol for the radio signal because it looked easy - and that turned out the be the case. Unlike proper WIFI there is no authentication or anything else, so it is quick and easy to set up. It is limited to 250 bytes of data, but has the benefit of being able to use an interrupt when a packet is received. There are some challenges with this approach over a pure radio setup I will discuss in another post.
The transmitter and receivers are the ubiquitous HC-SR04 modules. The way these normally work is:
- Trigger the module and it sends out a 40khz signal
- It waits a short period of time then listens for the echo
- A single square wave is output where the duration represents the distance
On the transmitter end this is no problem - we only care about sending the signal and can ignore the echo entirely.
On the receiving end there is a challenge - the output pulse is only generated after the module has been triggered and sent it's own signal. I removed the transmitting can from the board which eliminates generating more signals - this is easy. The other problem is that the module doesn't listen passively - there is only a small window of time where it will respond to a signal (usually it's own echo). The trick I used was to use the radio signal to trigger the receivers at the right moment - no pulse would be sent, but it would begin listening. We will eliminate all this fuss in the future by designing our own receiver and transmitter hardware.
At the end of all this the ESP just spits out two numbers over UART to represent the distance and angle to the beacon, mission accomplished. I kept the code for deciding how to move on the robot, separate from the rangefinder.
There are a bunch of other challenges to think about: line of sight, echoes and reflections, how to handle signal loss, angle resolution, timing variability (particularly for ESP-NOW), variability of the speed of sound in the atmosphere... that is for future updates.
There is some more information and code/schematics for this prototype here. For now here's a video of this POC working (somewhat):