Page 146 - Hacking Roomba
P. 146
Chapter 6 — Reading the Roomba Sensors 127
The printSensors() function is a simplified version of the RoombaComm.sensorsAsString()
method, which dumps out all the sensor data in a human-readable form.
When running Spy.java, you’ll notice that transitory events (like quickly tapping the bump
sensor) will get missed. This is due to the fact that if an action happens between calls to
updateSensors(), it will be missed. To minimize this problem, you can decrease the
pausetime setting between sensor readings, at the expense of the output scrolling by very
quickly. If you’re recording the output of Spy.java to a file for later analysis, set pausetime to
whatever you feel is appropriate for your application.
You may also notice the time between sensor readings varies a little. If you want a more accu-
rate fixed time between readings, compute how long updateSensors() takes to execute by
wrapping it in System.currentTimeMillis() calls, and subtract the execution time from
pausetime.
Summary
The RoombaComm library is built up enough now to be truly useful. You can read all of the
Roomba sensors and control all of its functions. The hardest part of dealing with any device is
having conversations with it. It’s one thing to only send or only receive, but to do both can be
tricky. You now have two ways of dealing with this trickiness: an easy but slightly inaccurate
way and a more complex approach that allows for greater flexibility.
Roomba contains some interesting sensors, and you probably have ideas on how to implement
similar techniques in other projects. And it’s becoming obvious where the deficiencies in the
sensors lie. For a vacuum cleaner, it has just enough ability to observe its environment to func-
tion, but for a non-vacuuming robot it should have more. I’ll discuss adding new sensors later
in this book.