Page 46 - Hacking Roomba
P. 46

Chapter 2 — Interfacing Basics            27



                             There is no way to determine which state the robot is in. If you are unsure, explicitly set its state
                             to what you want.



                             If the Roomba battery is removed or when the battery is too low for Roomba to operate reliably,
                             the system will switch to the off state.
                             One undocumented event that has happened a few times to me is an over-current event. If the
                             Roomba battery is low and the robot attempts to do something that uses a lot of current (like
                             drive across thick carpet), it appears to trigger an over-current sensor that switches Roomba out
                             of safe or even full mode and into passive mode.

                             ROI Command Structure

                             All ROI commands start with a command opcode, a single byte with a value between 128 (0x80)
                             and 143 (0x8F), inclusive. Only 16 opcodes have been published, but these 16 allow almost
                             complete control. There may be more, unpublished opcodes.
                             In addition to the command opcode byte, an ROI command may include one or more data bytes
                             that are arguments to the command. Many commands, like the START command, consist of only
                             the command opcode byte and no data bytes.The PLAY command is an example of a command
                             that takes one extra command byte, a data byte with the number 1–16 of the song to play. All
                             commands except the SONG command have a fixed number of data bytes.The SONG command
                             has a variable number of data bytes, depending on the length of the song, N.The number of data
                             bytes is determined by the formula 2+2N. Therefore, if the song to be sent is one note long
                             (N=1), the number of data bytes to send is 4. For a 10-note song (N=10), 22 data bytes are sent.
                             To send a complete ROI command, send the appropriate command byte and the appropriate
                             data bytes, if any, from the serial port of your controlling computer and to the RXD pin of the
                             ROI port.
                             Table 2-3 shows the opcodes and the number of data bytes for each command. Hexadecimal
                             representation of the opcode values is useful since each hexadecimal digit represents exactly
                             four bits, so two hex digits exactly represent 8 bits, or one byte.



                              Table 2-3  Command Opcodes and Data Bytes
                              Command     Opcode     Hexadecimal Values  Number of Data Bytes
                              START       128        0x80               0
                              BAUD        129        0x81               1
                              CONTROL     130        0x82               0
                              SAFE        131        0x83               0
                              FULL        132        0x84               0
                              POWER       133        0x85               0

                                                                                              Continued
   41   42   43   44   45   46   47   48   49   50   51