Room Mapping Robot Using Echolocation

My first foray into Python programming was in 15-112 Fundamentals of Programming and Computer Science. One of the reasons I came back to school was to increase my programming ability, and this class allowed to build a solid programming foundation.


The term project for 15-112 required you to create some substantive programming project. Because I knew I wanted to apply programming to robotics, I figured I would build and code a robot. We weren’t graded on anything but our code, so I hacked what I could together with a Raspberry Pi and some hobby components from Amazon, so please don’t judge me too harshly on any of the mechanical or electrical aspects of this!

Screen Shot 2018-02-18 at 4.45.26 PM.png
My little robot, featuring a Raspberry Pi powered by a backup phone charger, two wheel actuated by DC motors, an H-bridge which helps control the motors, and an ultrasonic sensor actuated by a servo motor.

Looking for a suitable project that could be accomplished in a relatively short amount of time as a term project was a little difficult, but I came across a good paper by Philip John McKerrow of the University of Wollongong that you can find here. In this paper, the authors used echolocation from ultrasonic sensors to map a room. The basic premise of this method is that ultrasonic sensors send out a sound wave and then that wave bounces back if there is an object near by. The sensor and code take the time that the sound wave took to bounce back and converts that to a distance. This information isn’t enough to create a map of the room, though. The distance that the sensor calculates could be any distance to a locus of points within the angular range of the sensor. The diagrams below, taken from the McKerrow paper, illustrate that point.

Screen Shot 2018-02-18 at 4.16.52 PM

To use this data to create a 2D map, you need at least two distance measurement at different locations, and to know the relative distances between those two measurement points. After having created two arcs representing the locus of possible points that the sensor is detecting, you can draw a tangent line between those two arcs. In theory, this is the true boundary that the sensor is detecting. With a robot moving in a straight line, the McKerrow paper achieved the results below:

Screen Shot 2018-02-18 at 4.26.03 PM
True dimensions of room
Screen Shot 2018-02-18 at 4.26.08 PM
Arc grid of room
Screen Shot 2018-02-18 at 4.26.14 PM
Arc grid with tangent lines of room


The results of my robot scanning my bedroom can be seen below:

My room
Screen Shot 2016-12-08 at 3.22.55 PM
The robot’s map of my room. The red line is the path that the robot took, the gray arcs are the distances that the sensor detected, and the black lines are the tangent lines representing boundary lines that the algorithm calculated.


Neither the McKerrow paper nor my robot achieved superb results, but considering this was my first attempt at a real programming project, and all components were hobby-grade, I was pretty proud. Given more time, I think that this could work very well, even with the hobby-grade hardware. As you can see, all the arcs don’t have tangent lines drawn in-between them, so that’s one of the first bugs to fix.

Secondly, the robot only moved in a straight line, and had to be turned straight every couple of times it moved forward. I added encoders onto the wheels, but they moved too fast for the encoder to pick up all of the counts, and there wasn’t enough time to set up an interrupt that would allow for all counts to be registered. If I had some wheel position feedback, I would be able to get this robot moving in a straight line, and perhaps have it make turns and avoid obstacles.

The github link to the code can be found here and the full video of the project that was made for the class can be found below:




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s