Mapping With The Roomba




The objective of this project is to place a Roomba in an unknown area and have it detect how many objects are in its immediate vicinity and their locations in reference to the Roombaís starting position.




In order to have the Roomba detect physical objects I used a Basic Stamp 2 microcontroller in conjunction with a MIT Handyboard v1.2 and an SRF04 ultrasonic rangefinder and a standard Hobby Town 53 series PWM controlled servo.


The Basic Stamp 2, BS2, is used for the communication and control of the Roomba via a serial connection at a baud rate of 2400bps.The BS2 is capable of controlling the movement of the Roomba as well as reading the output of the sensor data.The BS2 programmed to communicate with the Handyboard, HB, via a 7 bit parallel connection with no interrupt.


The HB is being used as a programmable servo controller.I have used the *.icb routine for the HB called servo_a7.icb, which is freely available on the internet, to control the 20Hz PWM output on digital IO pin A7 oh the HB primary processor, the Motorola 6811 microcontroller.The data that the BS2 sends to the HB is the command position for the servo motor, 0000000 being 0o and 1111111 being 180o.See Appendix 4 for the source code for the Handyboard servo controller source code.


The SRF04 ultrasonic sensor is placed on top of the servo motor to allow the direction that the motor is facing to be changed without moving the Roomba itís self.The SRF04 is then connected to the BS2 which is able to record the distance of the closest object in the direction that the SRF04 is facing as well as the angle it is facing for that measurement.Please see Figure 1 below for the angle and distance accuracy range of the SRF04 ultrasonic sensor.See Figure 2 below for a block diagram of the setup Roomba with the BS2, HB, servo, and ultrasonic sensor with communication information.



Figure 1

Figure 2


See Figure 2.1 below for a picture of the setup from Figure 2 above connected to a Roomba.Also see Figure 2.2 for an annotated diagram of the physical parts of Figure 2.


Figure 2.1






Parallel to Handyboard


Serial to Roomba


SRF04 ultrasonic sensor




Basic Stamp 2


Figure 2.2


Data Recording and Communication:


The data that the BS2 records the distance using the SRF04 ultrasonic sensor by telling the sensor to send out a pulse of high frequency sound, above human hearing of 20kHz, and records the amount of time that it takes for the SRF04 to hear the echo of the pulse.This time would be divided by two, because it is the time for the sound to get to the object and return again, and then multiplied by the speed of sound.The resulting number is the distance of the object.I have chosen to use metric, cm, for my unit of measurement for this project because I am recording the data in the BS2ís EEProm, which is a total of 2kbytes, including program memory.There for I only have about 500 bytes of available for data storage, thus I wanted to keep the number between 0 and 255.Because the maximum range of the SRF04 being about 8ft, 244cm, I chose the units to be cm because it was the most efficient common unit of measurement that would fit in the one byte storage location and span the whole of the SRF04ís range.


The data structure of the recorded data is as follows:

Each session records a sweep of 128 data points, 0o to 180o.The first byte of this set is a marker of $ff minus the direction you are facing, 0 for North, 4 for East, 8 for South, and 12 for West.The next bit is the distance forward of you, 90o or a command of 64.The next byte is the x axis offset, aka the amount that the Roomba has moved from itís original position in the forward and backward direction.The next byte is the y axis offset, aka the amount that the Roomba has moved off its original position in the left and right direction.


The next portion of the data is the recorded data from the sweep.Each set of data takes up two bytes of storage space.The first byte is the angle that the ultrasonic sensor is facing relative to the Roomba, and the second byte is the distance in that direction.The program will send the HB a command of 0-127, sweep of 0o to 180o respectively, and record the command and distance at each point command point.It is important to note that the distance at each point is taken three times and then averaged in order to reduce error.In order to further reduce error each sweep is done twice.


Because the data is stored in EEProm, which is non-volatile memory, I am able to turn off the BS2 with out loosing the recorded data.See Appendix 1 for the code that controls and records the data to the BS2 and Appendix 2 for the code to retrieve the recorded data from the BS2/Roomba.


After I have retrieved the data from the BS2/Roomba I import that data into Matlab for analysis.My first step was to parse the data and correct the recorded angles and distances with the offsets.This data is then plotted in a polar plot.See Figure 3 below for the latter polar plot.It is important to note that the distances are in cm and the angles are in degrees.


Figure 3


When looking at the polar plot in Figure 3 you can see that it seems that there are at least two close objects to the Roomba, each at fewer than 50 cm, one between 210o and 270o and a second between about 300o and 330o.


The next part of the code is to have the computer decide how many objects there are.I did this by transferring the recorded data into rectangular coordinates; see Figure 4 below, and locating edges.


Figure 4


Locating edges will be done by looking for areas of high derivatives, or areas with a great change between adjacent points.See Appendix 3 for the code to find the areas of high derivatives as well as all of the latter and former Matlab code.See Figure 5 below for a plot of the high derivatives vs. angle.


Edges (High Derivatives)


Figure 5


As one can see from Figure 5 above there are three obvious corners.Matlab counted the number of rising corners to be 2 and falling corners to be 1, see Appendix 3, by setting a threshold and searching the data from Figure 5 for a magnitude larger than that threshold, see green lines in Figure 5for threshold.The computer will then count the number of objects by counting the maximum number of rising or falling edges.From this set of data the computer determines that there are two objects close to it.


In order to see how well this worked see Figure 6 for the actual field that was being mapped.




Figure 6


Observations and Conclusions:


While attempting to get the Roomba to recognize if there are objects near it I found that using range finders, ultrasonic sensors, I have found that the Roomba, with added hardware, namely the Basic Stamp 2 microcontroller and a servo controller, done by the Handyboard, the Roomba was able to get sufficient data to recognize that there are objects in itís vicinity.The Basic Stamp however, to my opinion, needs more memory in order to make a proper mapping of a room using the method that I have just demonstrated.


I also found that it was necessary to take measurements more than one time per point in an attempt to reduce the percent error.You will note that the Figure 4 clearly shows that there is a 50 cm gap between the two objects but the real gap is about 100 cm.I believe that this discrepancy is due to a non-linear response to a position command to the servo.This error could be fixed with further testing and calibration of the servo controller, the HB.The distances from the origin, the place where the Roomba started, to the cardboard box was shown to be about 70 cm in Figure 4 and is really 75 cm away from the origin in the forward direction.The displacement in the left right direction was measured to be 60 cm but in reality is measured to be 45 cm.Tor the trashcan the forward distance was measured to be about 60 cm and the real distance was 65 cm.The distance that was displaced in the left right direction was measured to be 10cm but was in reality is 55 cm.This tells me that there is an error of 8% in the forward direction but an error of 42% in the left right direction.


A way that I could improve the way that the Roomba maps the universe is by decreasing the resolution of the world so I can store the location of things on in the memory of the BS2.The latter in conjunction with taking the derivative in delayed real time, aka done in real time but a few time steps behind in order to collect multiple data points of a sweep.After each full sweep I could clear the memory move again and start the process over.This would be more taxing on the Basic Stamp 2 because I would need to calculate in the offset information on the fly which will take up not only more time but also more memory.At the moment my biggest constraint is the fact that I am limited to 2kBytes of total storage space on the Basic Stamp 2ís EEprom.