Qwerk Customization and Tekkotsu
Index
Adding a switch
Adding a bump sensor
Adding an LED
Adding raygun special effects
Adding a range sensor
Adding A Range Sensor
While considerably more complicated than the bump sensors, the Range
sensor can provide much more information. The range sensors we used,
Sharp GP2D12 available here,
allows us to determine our distance from walls up to 100 cms away!
Wiring
A major plus to this particular version of IR sensor is the ease of
which we can attach it to the Qwerkbot. Simply screw the sensor to the
front of the qwerkbot, hook power and ground up, and wire the output to
an analog input. The analog input allows us to see a wide range of
values that reflect our approximate distance from the object in front
of us.
Limitations
Unfortunately, there is a serious issue with this type of IR sensor.
While it gets very good detection in the range of 8 to 80 cms, in 0 to
8 cms the signal inverts. What that means is that the voltage it
outputs peaks at 8 cm's, and descents down to 0 in both diretions,
making for example the voltage at 5 and 15 cms identical. To us this
means we can't tell if somethings far or close. Still we've improvised
a solution to this connundrum.
Attach a Second IR Sensor!
The second IR sensor needs to be fairly far in front or behind the
current IR sensor. For us, the most convenient position was tied to the
battery. This was done using some string to secure the second sensor
only a few cms behind the first.

Now in theory, comparing which signal is greater than the other should
tell us whether we're close or far from on object, unfortunately this
is not the case as sensors are never exact. So I placed the Qwerkbot
next to a meter stick, pointed at a wall and observed the data at each
point. Below is a chart of my results. I used a short program I wrote
that
gathered 1000 data points and averaged them to achieve the best
results. That code is available here.
Do note, however, that this data will only work on objects that are
taller than both sensors, and are not slanted in anyway.

As you can see, the data is far from perfect.
Making Your Inputs Useful!
There are a number of ways to approach this, and your method should
depend on what you're looking for. If you only want to know if you're
about to run into a wall, then your best bet is to compare the
difference in the values, as you can see when it is far the values are
much closer together. I did exactly this in some example code here. However if you'd
like to get more from your data
you certainly can. The simplest way to get real cm data out
of your inputs is to first divide the distances up into regions.
Looking at both of the input values you should be able to
determine what section of the graph you are in. Once you've
determined that you can make much better lines of best fits to
determine your distance from the object. In my case, I
divided the input data into 6 regions: (0, 0.5), (.5, 6), (6, 7), (7,
20), (20, 100), 100+. That example code can be found here.
Here's all that source again
IRgatherer.h Averages 1000 points; used for generating an accurate graph
IRdemo.h Simple "hot-cold" interface allows you to determine if you're close or far
IRfinal.h Outputs distance from object in centimenters
Data Gathered ods xls
Scott McCaffrey and Dave Touretzky
Last
modified: Thu May 13th 2008