Simple Ultrasonic Radar using an Arduino

A while back I wanted to use an arduino, a servo, and 2 ultrasonic sensors to generate a map of the environment. Alternatively the sensor  data could be used for cheap localization with particle filters on a known map of the area.

Layout
An arduino, a servo, and 2 ultrasonic sensors put on top of the servo facing opposite to each other
The setup is pretty straightforward: 2 ultrasonic sensors facing in opposite directions are placed on a breadboard. The breadboard is placed on a servo, which since it's a cheap one can only turn about 130 degrees, that'll give us 260 degrees of scan with 2 blind spots. The program is pretty much:


// pseudo-code
loop() {
  left = sensor_left.getReading();
  right = sensor_right.getReading();
  print out position and sensor data
  servo_controller.update(); 
}

A few scans show that there's pretty consistent readings even with varying scan speeds and motor step sizes. I settled on a roughly ~50ms scan step time and increment servo position by one each time, back and forth.
Imgur
Polar plotted scanned points of the kitchen 
 Imgur
Scanning the kitchen

Interesting, the kitchen shows up very roughly. A guess as to why the walls are not getting straight sides is that the sonar will pick up the first echo as the distance, so for walls angled to the sensor, even if it's center is facing the angled wall at distance X, the closest point of the wall within a small cone radiating out from the sensor is the first to echo back, resulting in that as the reading.
Imgur
A step beyond using just the raw data is using it to fill out an occupancy grid taking account of the ultrasonic sensor's noise profile. In this case the probability would fill out a curved arc. As the grid gets filled over time, the points of highest probability would demarcate the kitchen edges, providing a more accurate map. Conversely the probability distribution can be used to predict location.

Source on Github

Popular posts from this blog

Building a PID hover controller for Kerbal Space Program with kOS and IPython Notebook

Learning TensorFlow #1 - Using Computer Vision to turn a Chessboard image into chess tiles

Learning TensorFlow #2 - Predicting chess pieces from images using a single-layer classifier