Page 44 - Hacking Roomba
P. 44

Chapter 2 — Interfacing Basics            25



                             The commands and the responses are binary, not text. Thus communication is not as simple as
                             connecting to Roomba with a terminal program and typing commands. Determining how to
                             test the connection after a physical interface has been built will be covered in Chapter 3.
                             When using the ROI, Roomba exists in one of several modes (or states). These modes repre-
                             sent both how Roomba behaves and how it responds to subsequent ROI commands. Actions
                             by Roomba can also change the mode. Several of the ROI commands are dedicated to selecting
                             the appropriate mode/state because certain commands only work in certain states. The mode
                             change commands are single bytes with no arguments and are invoked by just sending the
                             command byte for the desired mode. Other commands have arguments, like how fast to drive
                             or which vacuum motors to turn on. Those arguments are sent immediately after the command
                             byte as data bytes with a particular format. The format varies among commands and can either
                             be a single byte, a 16-bit value represented as two bytes, several binary values (bits) encapsu-
                             lated in a single byte, or some combination thereof. One of the challenges of using the ROI is
                             knowing all the data type variations. Only one command causes Roomba to return data, and
                             the block of bytes it returns must also be carved up into bits, bytes, and 16-bit words.


                             Roomba Modes
                             When using the ROI, Roomba can exist in one of five states (see Figure 2-4). The states are:

                                 Sleep (Off): Roomba responds to no commands over the ROI, but can be woken up
                                 and put into the on mode through either the Power button or by toggling the DD hard-
                                 ware line.
                                 On: Roomba is awake and is awaiting a START command over the ROI. In this mode
                                 Roomba is able to operate normally via its buttons or remote control. The only way out
                                 of this mode through the ROI is through the START command.
                                 Passive: Roomba has received the START command. In this mode, sensors can be read
                                 and songs defined, but no control of the robot is possible through the ROI. The
                                 Roomba buttons work as normal. This is the mode to use to spy on Roomba as it goes
                                 about its business. The usual path from this mode is to send the CONTROL command to
                                 enter safe mode.
                                 Safe: Roomba has received the CONTROL command from passive mode or the SAFE
                                 command from full mode. Everything that could be done in passive mode is still possi-
                                 ble, but now Roomba can be controlled. The buttons on Roomba no longer change the
                                 robot’s behavior, but instead their states are reflected in the Roomba sensors data. All
                                 commands are now available, but a built-in safety feature exists to help you not kill your
                                 Roomba. This safety feature is triggered if Roomba detects any of the following:
                                    ■ A cliff is encountered while moving forward (or moving backward with a small
                                      turning radius).

                                    ■ Any wheel drops.
                                    ■ The charger is plugged in and powered.
   39   40   41   42   43   44   45   46   47   48   49