Page 221 - Hacking Roomba
P. 221

202       Part II — Fun Things to Do





                               Listing 10-4 Continued

                                   Process p = Runtime.getRuntime().exec(radioCmd);
                                   p.waitFor();
                                 } catch(Exception e) { println(“exception:”+e); }
                               }
                               void parseRoombaSensors() {
                                 if( alarm ) {
                                   if( roombacomm.bumpLeft() &&
                                        roombacomm.bumpRight() ) {  // snooze
                                     wakeupDate.setTime(wakeupDate.getTime()+snoozeSecs*1000
                               );
                                     println(“snooze until “+wakeupDate);
                                     alarm = false;
                                   }
                                   else if( roombacomm.wheelDropLeft() &&
                                             roombacomm.wheelDropRight() &&
                                             roombacomm.wheelDropCenter() &&
                                             roombacomm.powerButton() ) {
                                     println(“alarm off! (until tomorrow)”);
                                     wakeupDate.setTime(wakeupDate.getTime() +
                               (60*60*24)*1000);
                                     alarm = false;
                                   }
                                 }
                                 if( roombacomm.cleanButton() )
                                   runRadioCmd();
                               }





                     Summary


                             Even though the Roomba’s sensors are primitive, they can be put to some interesting uses.
                             These uses need not be vacuum-related or even robotics-related. The cliff sensors are one of
                             the best examples of this, becoming non-contact proximity sensors for hands or other movable
                             objects when Roomba is turned upside down. While upside down, the wheeldrop sensors become
                             buttons to trigger actions. You could even turn the wheels when upside down and register the
                             movement as a variable function.
                             By combining the sensors into more complex aggregations, you can create a novel way to meas-
                             ure something Roomba normally cannot measure. Combining cliff and wheeldrop sensors gives
                             a sense of tilt, but you can imagine other combinations as well. Perhaps a combination of but-
                             tons and driving motor over-current sensor could make a weight sensor and turn Roomba into
                             a scale. Or using the distance and angle sensors and a little calibration could yield a Roomba
                             yardstick. Try making Roomba a DJ input device and “scratch” audio files with it by rotating it
                             back and forth like a record. The number of possible sensor combinations is huge and many of
                             them produce useful results. Even those that produce non-optimal results are fun and instructive.
   216   217   218   219   220   221   222   223   224   225   226