Page 209 - Hacking Roomba
P. 209

190       Part II — Fun Things to Do




                             Digital Sensors

                             All of the distance sensors Roomba employs are digital sensors. Whether it is the distance to
                             the floor, to the wall, or from the wheels to the ground, all these distances are distilled down
                             to a single Boolean value. Instead of “How far away is the wall?” the question is just “Is there
                             a wall nearby?” The single-mindedness of these types of sensors makes them reliable but also
                             harder to use for other purposes. However, by combining the readings from multiple sensors,
                             or reading a single sensors multiple times, it may be possible to gather additional data. For
                             example, by reading a button bit over time, you can determine how long the button was held
                             down. A quick tap would mean one thing, but a longer hold would mean something else.

                             Analog Sensors
                             The only external sensor with a graduated value is the dirt sensor. This sensor doesn’t seem as
                             accessible to hacking because it appears to be tuned to the normal vacuuming environment
                             (brushes moving, air moving past, and so on). It’s difficult to get readings from the dirt sensor
                             when Roomba is running its vacuum and brushes. The next most interesting analog sensor is
                             the current drain value. By watching this value and the motor over-current sensor values, it may
                             be possible to detect how hard Roomba is working as it moves its wheels. This could prove use-
                             ful if the wheels are purposefully strained in a known way.
                             The distance and angle sensor values are a derived analog value from the digital sensors in the
                             wheels. They offer high resolution but because they are “cooked” in a way that the other sensor
                             values aren’t, the distance values can sometimes be hard to use.


                     Using Roomba as a Mouse

                             The original computer mouse created in 1970 was a wooden box with two wheels mounted on
                             its underside at right angles. When dragged along a desktop, one or both of the wheels would
                             rotate in correspondence with the motion. The well-known ball mouse came soon after. The
                             wheels were moved inside and a small rubber ball carried the mouse motion to the wheels.
                             Roomba has two wheels with sensors almost exactly like the sensors in a ball mouse. These
                             sensors work and the data is available through the DISTANCE and ANGLE ROI commands even
                             when Roomba isn’t being driven. This means that the computeRoombaLocation() method
                             used in several of your previous Roomba programs can be used verbatim. The difference in use
                             now is that instead of using the rx,ry position pair from that function to represent the on-screen
                             position of a controlled Roomba, you can use it as a virtual mouse pointer (in lieu of the mouseX,
                             mouseY position pair) to represent how you are moving the robot.
                             Recall from Chapter 5 that Roomba only moves in straight or circular paths. This applies to
                             it being either driven by its motors or positioned by you moving it. Figure 10-1 demonstrates
                             some of the preferred ways Roomba moves. As discussed in Chapter 9, however, you can
                             approximate almost any curve with many circle segments.
   204   205   206   207   208   209   210   211   212   213   214