00001 /** 00002 \file Robots/LoBot/irccm/LoCMInterface.h 00003 \brief Header file defining the interface between the low- and 00004 high-level parts of the Robolocust controller. 00005 00006 The Robolocust controller consists of two major parts: 00007 00008 1. The high-level C++ layers that run different behaviours, LGMD 00009 models, integration algorithms, etc. 00010 00011 2. The low-level layer that runs on the microcontroller that 00012 interfaces with the electromechanical systems on the physical 00013 robot platform. 00014 00015 The two parts communicate with each other by exchanging messages 00016 (commands and data) over a serial port. This file defines the 00017 interface between the higher layers and the low-level control program 00018 when the "roomba_cm" robot platform is being used. This platform 00019 identifies an iRobot Create with a Command Module in place. 00020 00021 This header file specifies the symbolic IDs and the values of the 00022 different messages that are to go back and forth between the 00023 high-level C++ part of lobot and the low-level Command Module part. It 00024 also defines other relevant things such as the size of command 00025 messages sent by the high-level to the low-level and the number of 00026 bytes of sensor data sent from the low-level to the high-level. 00027 00028 This file will have to be included by the high-level C++ codebase as 00029 well as the Command Module's low-level C codebase. 00030 */ 00031 00032 /* 00033 ************************************************************************ 00034 * The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 * 00035 * by the University of Southern California (USC) and the iLab at USC. * 00036 * See http://iLab.usc.edu for information about this project. * 00037 * * 00038 * Major portions of the iLab Neuromorphic Vision Toolkit are protected * 00039 * under the U.S. patent ``Computation of Intrinsic Perceptual Saliency * 00040 * in Visual Environments, and Applications'' by Christof Koch and * 00041 * Laurent Itti, California Institute of Technology, 2001 (patent * 00042 * pending; application number 09/912,225 filed July 23, 2001; see * 00043 * http://pair.uspto.gov/cgi-bin/final/home.pl for current status). * 00044 ************************************************************************ 00045 * This file is part of the iLab Neuromorphic Vision C++ Toolkit. * 00046 * * 00047 * The iLab Neuromorphic Vision C++ Toolkit is free software; you can * 00048 * redistribute it and/or modify it under the terms of the GNU General * 00049 * Public License as published by the Free Software Foundation; either * 00050 * version 2 of the License, or (at your option) any later version. * 00051 * * 00052 * The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope * 00053 * that it will be useful, but WITHOUT ANY WARRANTY; without even the * 00054 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR * 00055 * PURPOSE. See the GNU General Public License for more details. * 00056 * * 00057 * You should have received a copy of the GNU General Public License * 00058 * along with the iLab Neuromorphic Vision C++ Toolkit; if not, write * 00059 * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * 00060 * Boston, MA 02111-1307 USA. * 00061 ************************************************************************ 00062 */ 00063 00064 /* 00065 Primary maintainer for this file: mviswana usc edu 00066 $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/irccm/LoCMInterface.h $ 00067 $Id: LoCMInterface.h 13782 2010-08-12 18:21:14Z mviswana $ 00068 */ 00069 00070 #ifndef LOBOT_IRCCM_COMMAND_MODULE_INTERFACE_DOT_H 00071 #define LOBOT_IRCCM_COMMAND_MODULE_INTERFACE_DOT_H 00072 00073 #ifdef __cplusplus 00074 extern "C" { 00075 #endif 00076 00077 /*----------------------------- CONSTANTS -----------------------------*/ 00078 00079 /// These enumerations are for acknowledgement (ACK) messages sent from 00080 /// the low-level control program to the higher (C++) layers of the lobot 00081 /// controller. 00082 /// 00083 /// DEVNOTE: We use printable ASCII characters as the command codes to 00084 /// ensure that we can easily identify the messages going back and forth 00085 /// (when these message IDs are printed out during debugging). 00086 enum { 00087 /// The Command Module sends the READY message to the high level to 00088 /// let it know that the low-level control program is ready to accept 00089 /// high-level commands. The high level must wait to receive this 00090 /// acknowledgement from the low level before sending a motor or 00091 /// sensor query command. Once the low level has executed the 00092 /// high-level command, it will again send a READY message to indicate 00093 /// that it is ready to accept the next command; so on and so forth. 00094 /// 00095 /// The high level cannot send commands willy-nilly and must wait for 00096 /// READY ACKs because the Command Module has only one USART that can 00097 /// either talk to the (external) USB port or the (internal) serial 00098 /// port to which the robot is connected. If the high level were to 00099 /// send commands at its whim, they may never be received by the 00100 /// Command Module because it may well have redirected its USART to 00101 /// the internal serial port and not be listening to whatever the high 00102 /// level has to say. Then, when the Command Module redirects its 00103 /// USART to the USB port, it may not receive any commands because the 00104 /// high level has fallen silent in the mean time. 00105 /// 00106 /// Needless to say, the above situation will, very quickly, make the 00107 /// robot quite schizophrenic. Therefore, the high and low level 00108 /// controllers need to coordinate their activities so as to elicit 00109 /// coherent behaviour on the part of the robot. 00110 /// 00111 /// When the low level sends ACK_READY, the high level can be assured 00112 /// that its command, if sent within a predefined timeout window 00113 /// (usually, 1.5 seconds), will be received and executed by the 00114 /// robot. 00115 LOBOT_ACK_READY = ':', 00116 00117 /// The low level sends the BUMPS acknowledgement after reacting to 00118 /// the robot's bump sensors. 00119 /// 00120 /// The low level always reacts to the bump sensors by backing up a 00121 /// little and then spinning around a little bit. In case one or both 00122 /// of the rear bumpers is hit, the low level will respond by moving 00123 /// forward a little and the spinning. Thus, this message is 00124 /// accompanied by five bytes of data. 00125 /// 00126 /// The first byte indicates the sensor flags. Bit #0 is for the right 00127 /// bump sensor and bit #1 for the left bump sensor. The bit masks 00128 /// defined in LoOpenInterface.h may be used to test these bits. Bit 00129 /// #2 is for the rear right bumper and bit #3 for the rear left 00130 /// bumper. This file defines appropriate constants that can be used 00131 /// to test for the states of the rear bump sensors. 00132 /// 00133 /// The second and third data bytes make up a signed 16-bit integer 00134 /// (high byte first) indicating the distance backed up. Since the 00135 /// robot always backs up in response to a bump sensor, this number 00136 /// will always be negative. 00137 /// 00138 /// The fourth and fifth data bytes make up a signed 16-bit integer 00139 /// (high byte first) indicating the number of degrees turned in-place 00140 /// after the back-up. Positive values indicate counterclockwise turns 00141 /// and negative values are for clockwise turns. 00142 /// 00143 /// DEVNOTE: As mentioned above, the ACK_BUMPS message is followed by 00144 /// several data bytes containing bump sensor information as well as 00145 /// information about the actions the robot took in response to the 00146 /// bump sensors. This file defines a symbolic constant specifying how 00147 /// many such bytes the high level may expect to receive. Furthermore, 00148 /// this file also defines symbolic constants that can be used as 00149 /// indices into the data byte array sent as part of the 00150 /// acknowledgement. 00151 LOBOT_ACK_BUMPS = 'B', 00152 00153 /// When the robot's wheel drop sensors are activated, the low-level 00154 /// controller will immediately shut off the motors and then send this 00155 /// message to the high level to let it know what has happened. 00156 /// 00157 /// This acknowledgement is accompanied by one data byte containing 00158 /// bit flags indicating which wheel drops are active. Bit #2 is for 00159 /// the right wheel, bit #3 for the left wheel and bit #4 for the 00160 /// front caster wheel. LoOpenInterface.h defines bit masks that can 00161 /// be used to test these bits. 00162 LOBOT_ACK_WHEEL_DROPS = 'W', 00163 00164 /// When the robot's cliff sensors fire, the low-level controller 00165 /// backs up and then spins the robot to avoid falling down the stairs 00166 /// or something like that. To let the high level know what just 00167 /// happened, it sends this acknowledgement message accompanied by five 00168 /// data bytes. 00169 /// 00170 /// The first data byte contains the flags for the cliff sensors. Bit 00171 /// #3 of this data byte specifies whether the left cliff sensor is on 00172 /// or off; bit #2 is for the front left cliff sensor; bit #1 for 00173 /// front right; and bit #0 for the right cliff sensor. 00174 /// 00175 /// The second and third data bytes make up a signed 16-bit integer 00176 /// (high byte first) indicating the distance backed up. Since the 00177 /// robot always backs up in response to a cliff sensor, this number 00178 /// will always be negative. 00179 /// 00180 /// The fourth and fifth data bytes make up a signed 16-bit integer 00181 /// (high byte first) indicating the number of degrees turned in-place 00182 /// after the back-up. Positive values indicate counterclockwise turns 00183 /// and negative values are for clockwise turns. 00184 /// 00185 /// DEVNOTE: As mentioned above, the ACK_BUMPS message is followed by 00186 /// several data bytes containing bump sensor information as well as 00187 /// information about the actions the robot took in response to the 00188 /// bump sensors. This file defines a symbolic constant specifying how 00189 /// many such bytes the high level may expect to receive. Furthermore, 00190 /// this file also defines symbolic constants that can be used as 00191 /// indices into the data byte array sent as part of the 00192 /// acknowledgement. However, there are no symbolic bit mask constants 00193 /// for testing the bit flags in the first data byte. 00194 LOBOT_ACK_CLIFFS = 'C', 00195 00196 /// When the robot is being remote controlled by the user, the low 00197 /// level will handle the requested command and then inform the high 00198 /// level with an ACK_REMOTE. 00199 /// 00200 /// This message is accompanied by a single data byte, which simply 00201 /// specifies the remote control command the low level handled. 00202 /// LoOpenInterface.h defines symbolic constants for the Roomba 00203 /// Remote's infrared byte. 00204 LOBOT_ACK_REMOTE = '.', 00205 00206 /// The low level regularly polls the iRobot Create for all its sensor 00207 /// data and streams this data to the high level using the SENSORS 00208 /// acknowledgement. This message is followed by several bytes of 00209 /// sensor data sent from the low level to the high level. It is the 00210 /// high level controller's responsibility to buffer the sensor data 00211 /// being streamed by the low-level. 00212 /// 00213 /// DEVNOTE: As mentioned above, the ACK_SENSORS message is followed 00214 /// by several data bytes containing the current sensor values. This 00215 /// file defines a symbolic constant specifying how many such bytes 00216 /// the high level may expect to receive. Furthermore, this file also 00217 /// defines symbolic constants that can be used as indices into the 00218 /// sensor data byte array. 00219 LOBOT_ACK_SENSORS = '$', 00220 } ; 00221 00222 /// The following enumerations are for command (CMD) messages sent from 00223 /// the high-level controller to the low-level control program running on 00224 /// the Command Module. These commands indicate the actions the high 00225 /// level would like the robot to perform. The low-level control program 00226 /// will respond to these commands by talking in Open Interface to the 00227 /// iRobot Create. Thus, the high level need not worry about the 00228 /// low-level minutiae required to get the robot to actually execute such 00229 /// actions as "drive left at 200mm/s" or "veer right while backing up at 00230 /// 100mm/s," etc. 00231 /// 00232 /// NOTE: All commands sent by the high level must consist of exactly 00233 /// four bytes. The first byte holds the command ID (one of the CMD enums 00234 /// defined below), the second and third bytes are for a 16-bit parameter 00235 /// (e.g., the drive speed or turn radius), and the fourth byte must be a 00236 /// parity checksum byte computed by taking the bitwise XOR of the other 00237 /// three bytes. 00238 /// 00239 /// The low level will execute the command only if the parity byte checks 00240 /// out okay. If not, the low-level controller will stop the robot. It 00241 /// will also stop the robot if it gets an unknown command ID. 00242 /// 00243 /// As a matter of good form, the high level should set the two parameter 00244 /// bytes to zero if the command doesn't require a parameter (e.g., 00245 /// CMD_STOP). If a command does require a parameter, it should be sent 00246 /// high byte first followed by the low byte. 00247 /// 00248 /// DEVNOTE: We use printable ASCII characters as the command codes to 00249 /// ensure that we can easily identify the messages going back and forth 00250 /// (when these message IDs are printed out during debugging). 00251 enum { 00252 /// Since the high- and low-level controllers operate asynchronously, 00253 /// it is possible that when the low level sends ACK_READY, the high 00254 /// level doesn't have any real drive command to perform. In that 00255 /// case, it could decide not to send any command to the low level. 00256 /// 00257 /// Unfortunately, the low level policy is to stop the robot if it 00258 /// doesn't get a valid command within its predefined timeout window. 00259 /// Thus, not sending a command is probably not the best thing to do. 00260 /// Instead, the high level should send a NOP command to ensure that 00261 /// the robot continues to do whatever it is currently doing. 00262 /// 00263 /// NOTE: Although not recommended, the high level may send a long 00264 /// string of NOPs since the low level responds to the robot's bump, 00265 /// wheel drop, cliff and wall sensors to ensure that the robot 00266 /// doesn't drive off a cliff or keep its motors running even when it 00267 /// is butting heads against a wall. Whenever the low-level controller 00268 /// takes some action in response to the robot's built-in/low-level 00269 /// sensors, it sends a corresponding acknowledgement to the high 00270 /// level to let the high level know what has happened. 00271 /// 00272 /// Nonetheless, as mentioned above, the NOP command is really meant 00273 /// for occasional use when the high-level command queue is either 00274 /// freshly empty (i.e., all pending commands just got sent out and 00275 /// the low level responded with an ACK_READY sooner than expected) or 00276 /// empty because no behaviour has gotten around to voting for an 00277 /// action just yet or because no behaviour has sensed anything 00278 /// alarming that needs an immediate response. 00279 LOBOT_CMD_NOP = '@', 00280 00281 /// These commands drive the robot. CMD_FORWARD and CMD_REVERSE 00282 /// require a parameter: a positive number specifying the drive speed 00283 /// in mm/s. This number must lie in the range zero to 500. A value of 00284 /// zero is equivalent to CMD_STOP. Negative numbers will be treated 00285 /// as zero. Numbers greater than 500 will be clamped to 500. 00286 /// 00287 /// CMD_STOP does not need a parameter. 00288 //@{ 00289 LOBOT_CMD_FORWARD = 'F', 00290 LOBOT_CMD_REVERSE = 'R', 00291 LOBOT_CMD_STOP = 'S', 00292 //@} 00293 00294 /// These commands steer the robot. CMD_LEFT and CMD_RIGHT require a 00295 /// parameter: a positive number in the range [0, 2000] specifying the 00296 /// turn radius in mm. A value of zero will result in an in-place 00297 /// turn. 00298 /// 00299 /// CMD_STRAIGHT does not need a parameter. 00300 //@{ 00301 LOBOT_CMD_LEFT = '<', 00302 LOBOT_CMD_RIGHT = '>', 00303 LOBOT_CMD_STRAIGHT = '!', 00304 LOBOT_CMD_SPIN = '*', 00305 //@} 00306 00307 /// The robot sports a pair of Sharp GP2D15 IR proximity detectors on 00308 /// its rear to help prevent bumping into objects as it reverses. 00309 /// Unfortunately, these detectors also fire when the user's hand 00310 /// mucks about with the Command Module's on/off switch or when the 00311 /// robot is picked up and placed at some specific initial position. 00312 /// This behaviour can be very annoying because we might require the 00313 /// robot to remain stationary until the commencement of an 00314 /// experiment/run. 00315 /// 00316 /// To work around the above issue, the low-level controller supports 00317 /// these commands for enabling and disabling the rear bumpers. Thus, 00318 /// the high-level controller can dictate exactly when it is alright 00319 /// for the rear bumpers to be active. 00320 /// 00321 /// Additionally, the low-level controller can respond to rear bump 00322 /// events by spinning the robot in-place by a little bit and then 00323 /// moving it forward a small amount. The default response, however, 00324 /// is to simply stop the robot when either of the rear bumpers is 00325 /// active. To elicit the spin-and-move action, the high-level 00326 /// controller should send a '1' as the parameter for the 00327 /// LOBOT_CMD_ENABLE_REAR_BUMPS command. A value of zero for this 00328 /// command's parameter will result in the robot only stopping when 00329 /// one of the rear bump sensors is active. 00330 //@{ 00331 LOBOT_CMD_ENABLE_REAR_BUMPS = 'e', 00332 LOBOT_CMD_DISABLE_REAR_BUMPS = 'd', 00333 //@} 00334 } ; 00335 00336 /// These enumerations specify the sizes of different message or data 00337 /// packets exchanged between the high- and low-level controllers. 00338 enum { 00339 /// This symbolic constant specifies the number of bytes that each 00340 /// command sent by the high level to the low level must be. 00341 /// 00342 /// As described earlier, all high-level commands are expected to be 00343 /// four bytes long. The first byte holds the command ID, the next two 00344 /// bytes are for a 16-bit parameter (sent high byte first) and the 00345 /// fourth byte is an XOR parity byte. 00346 /// 00347 /// DEVNOTE: If the format of a high-level command ever changes, be 00348 /// sure to update this number to follow suit. Otherwise, expect Bad 00349 /// Things to happen. 00350 LOBOT_CMD_SIZE = 4, 00351 00352 /// The number of data bytes sent back with the ACK_BUMPS message. 00353 /// 00354 /// DEVNOTE: If the format and/or size of the ACK_BUMPS message ever 00355 /// changes, be sure to update this number to follow suit. Otherwise, 00356 /// expect Bad Things to happen. 00357 LOBOT_BUMPS_SIZE = 5, 00358 00359 /// The number of data bytes sent back with the ACK_WHEEL_DROPS 00360 /// message. 00361 /// 00362 /// Only the state of the wheel drops as returned by the Open 00363 /// Interface is sent as part of this message. Thus, there is only one 00364 /// data byte. It contains 3 bits indicating the status of the wheel 00365 /// drops. Bit #2 is for the right wheel, bit #3 for the left wheel, 00366 /// and bit #4 for the front caster wheel. LoOpenInterface.h defines 00367 /// bit masks for testing these bit flags. 00368 /// 00369 /// DEVNOTE: If the format and/or size of the ACK_WHEEL_DROPS message 00370 /// ever changes, be sure to update this number to follow suit. 00371 /// Otherwise, expect Bad Things to happen. 00372 LOBOT_WHEEL_DROPS_SIZE = 1, 00373 00374 /// The number of data bytes sent back with the ACK_CLIFFS message. 00375 /// 00376 /// DEVNOTE: If the format and/or size of the ACK_CLIFFS message ever 00377 /// changes, be sure to update this number to follow suit. Otherwise, 00378 /// expect Bad Things to happen. 00379 LOBOT_CLIFFS_SIZE = 5, 00380 00381 /// The number of data bytes sent back with the ACK_REMOTE message. 00382 /// 00383 /// Only the infrared byte received and processed by the low level is 00384 /// sent as part of this message. LoOpenInterface.h defines symbolic 00385 /// constants for the IR byte's different values. 00386 /// 00387 /// DEVNOTE: If the format and/or size of the ACK_REMOTE message ever 00388 /// changes, be sure to update this number to follow suit. Otherwise, 00389 /// expect Bad Things to happen. 00390 LOBOT_REMOTE_SIZE = 1, 00391 00392 /// This symbol specifies the number of data bytes that will be sent 00393 /// back to the high level along with the ACK_SENSORS acknowledgement 00394 /// message. 00395 /// 00396 /// DEVNOTE: At present, we send back all of the Create's sensor 00397 /// packets plus one extra byte to the high level and let it decide 00398 /// what data it wants/needs and what it doesn't want/need. Therefore, 00399 /// the number of data bytes sent back will be one more than the size 00400 /// of the sensor data buffer for group 6 sensor packets as defined in 00401 /// the Open Interface. 00402 /// 00403 /// We could simply use the LOBOT_OI_SENSOR_SIZE_GROUP_6 symbol 00404 /// defined in irccm/LoOpenInterface.h over here. However, we choose 00405 /// to "hard-code" the number 53 (i.e., 52 + 1) instead. This allows 00406 /// us to avoid having to include LoOpenInterface.h in this file, a 00407 /// consideration that seems to make sense because LoOpenInterface.h 00408 /// defines things that are pertinent to the Open Interface whereas 00409 /// this header defines things specifically pertinent to the lobot 00410 /// controller. 00411 /// 00412 /// The fact that LoOpenInterface.h defines a symbol that happens to 00413 /// match the number of sensor data bytes the low-level lobot 00414 /// controller sends to the high level is somewhat (though not 00415 /// entirely) coincidental. In the future, we may decide to send a 00416 /// subset of the available sensor packets or to preprocess/combine 00417 /// the sensor data returned by the robot before sending it off to 00418 /// the high level. In that case, LoOpenInterface.h may not define a 00419 /// convenient symbol specifying the number of data bytes sent to the 00420 /// high-level lobot controller. This is why it makes sense to 00421 /// decouple this header file from LoOpenInterface.h. 00422 /// 00423 /// DEVNOTE 2: If, as alluded to above, we do decide to change the 00424 /// sensor data that is to be sent back to the high level, be sure to 00425 /// update this number here! Otherwise, Bad Things *will* happen. 00426 LOBOT_SENSORS_SIZE = 53, 00427 } ; 00428 00429 /// These enumerations specify the indices for the data byte array sent 00430 /// from the low level to the high level as part of the ACK_BUMPS 00431 /// message. 00432 enum { 00433 /// The first data byte indicates the sensor flags. Bit #0 is for the 00434 /// right bump sensor and bit #1 for the left bump sensor. The bit 00435 /// masks defined in LoOpenInterface.h may be used to test these bits. 00436 /// 00437 /// Additionally, lobot sports two rear bump sensors. Their bit flags 00438 /// are in bits 3 (rear right) and 4 (rear left). Since these bump 00439 /// sensors are not built into the iRobot Create, they do not have 00440 /// predefined masks as part of the Open Interface. Instead, this file 00441 /// defines appropriate masks that can be used to test the status of 00442 /// the rear bumpers. 00443 LOBOT_BUMPS_FLAGS, 00444 00445 /// The second and third data bytes make up a signed 16-bit integer 00446 /// (high byte first) indicating the distance backed up or moved 00447 /// forward in response to the front or rear bumpers. 00448 LOBOT_BUMPS_DISTANCE_HI, 00449 LOBOT_BUMPS_DISTANCE_LO, 00450 00451 /// The fourth and fifth data bytes make up a signed 16-bit integer 00452 /// (high byte first) indicating the number of degrees turned in-place 00453 /// as part of the bump sensor response. Positive values indicate 00454 /// counterclockwise turns and negative values are for clockwise 00455 /// turns. 00456 LOBOT_BUMPS_ANGLE_HI, 00457 LOBOT_BUMPS_ANGLE_LO, 00458 } ; 00459 00460 /// These enumerations specify the indices for the data byte array sent 00461 /// from the low level to the high level as part of the ACK_CLIFFS 00462 /// message. 00463 enum { 00464 /// The first data byte indicates the cliff sensor flags. Bit #0 is 00465 /// for the right cliff sensor; bit #1 for the front right cliff 00466 /// sensor; bit #2 for the front left cliff sensor; and bit #3 for the 00467 /// left cliff sensor. 00468 LOBOT_CLIFFS_FLAGS, 00469 00470 /// The second and third data bytes make up a signed 16-bit integer 00471 /// (high byte first) indicating the distance backed up. Since the 00472 /// robot always backs up in response to a cliff sensor, this number 00473 /// will always be negative. 00474 LOBOT_CLIFFS_DISTANCE_HI, 00475 LOBOT_CLIFFS_DISTANCE_LO, 00476 00477 /// The fourth and fifth data bytes make up a signed 16-bit integer 00478 /// (high byte first) indicating the number of degrees turned in-place 00479 /// after the back-up. Positive values indicate counterclockwise turns 00480 /// and negative values are for clockwise turns. 00481 LOBOT_CLIFFS_ANGLE_HI, 00482 LOBOT_CLIFFS_ANGLE_LO, 00483 } ; 00484 00485 /// These enumerations specify the indices for the sensor data byte array 00486 /// sent from the low level to the high level as part of the ACK_SENSORS 00487 /// message. 00488 /// 00489 /// DEVNOTE: At present, we simply send back all of the Create's sensor 00490 /// packets to the high level plus one extra byte. Thus, the order of 00491 /// sensor data bytes matches exactly the order specified in the Open 00492 /// Interface specs for sensor packet #6. The last byte, however, is the 00493 /// extra byte alluded to above; it is not part of the Open Interface 00494 /// specs. 00495 enum { 00496 /// The first byte of the sensor data contains the bits for the bump 00497 /// sensors and the wheel drop sensors. Bits 0 and 1 are for the right 00498 /// and left bump sensors respectively. Bits 2, 3 and 4 are for the 00499 /// right, left and caster wheel drops respectively. Bits 5 and 6 are 00500 /// for the right and left bump sensors added to the rear of the 00501 /// robot. 00502 /// 00503 /// DEVNOTE: LoOpenInterface.h defines symbolic constants for bit 00504 /// masks that can be used to access these individual bits. This file 00505 /// defines bit masks for bits 5 and 6, which are for the added rear 00506 /// bumpers. 00507 LOBOT_SENSORS_BUMPS = 0, 00508 LOBOT_SENSORS_WHEEL_DROPS = LOBOT_SENSORS_BUMPS, 00509 00510 /// The second byte of sensor data contains a flag indicating whether 00511 /// the Create/Roomba's wall sensor is active (1) or not (0). 00512 LOBOT_SENSORS_WALL, 00513 00514 /// Bytes 3 through 6 are flags indicating whether the cliff sensors 00515 /// are active (1) or not (0). 00516 //@{ 00517 LOBOT_SENSORS_CLIFF_LEFT, 00518 LOBOT_SENSORS_CLIFF_FRONT_LEFT, 00519 LOBOT_SENSORS_CLIFF_FRONT_RIGHT, 00520 LOBOT_SENSORS_CLIFF_RIGHT, 00521 //@} 00522 00523 /// The seventh byte of sensor data returned by the low level specifies 00524 /// whether the virtual wall sensor is active (1) or not (0). 00525 LOBOT_SENSORS_VIRTUAL_WALL, 00526 00527 /// Byte #8 specifies the state of the low side driver and wheel 00528 /// overcurrents. 00529 /// 00530 /// DEVNOTE: As of now, LoOpenInterface.h does not provide any 00531 /// convenient means of making sense of this particular value. Refer 00532 /// to the Open Interface specs for the gory details. 00533 LOBOT_SENSORS_LSD_WHEEL_OC, 00534 00535 /// After the wheel overcurrents, come two unused bytes (always 00536 /// zero). 00537 LOBOT_UNUSED1, 00538 LOBOT_UNUSED2, 00539 00540 /// The 11th byte contains the IR command received by the robot's 00541 /// omnidirectional IR sensor located in the front of the robot on top 00542 /// of the bumper assembly. This sensor value lies in the range [0, 255]. 00543 /// 00544 /// DEVNOTE: LoOpenInterface.h defines symbolic constants for the 00545 /// different values sent by the Roomba Remote and the Home Base. 00546 LOBOT_SENSORS_INFRARED_BYTE, 00547 00548 /// The 12th byte specifies the states of the Play and Advance 00549 /// buttons. Bit #0 is for the Play button and bit #2 is for the 00550 /// Advance button. If these bits are 1, it means the corresponding 00551 /// button is currently being pressed; zero means the button is not 00552 /// being pressed. 00553 /// 00554 /// DEVNOTE: LoOpenInterface.h defines symbolic constants for bit 00555 /// masks that can be used to access the above-mentioned two bits. 00556 LOBOT_SENSORS_BUTTONS, 00557 00558 /// Bytes 13 and 14 are a two byte value (high byte first) specifying 00559 /// the distance (in mm) traveled by the robot since the last time its 00560 /// encoders were queried. Positive values indicate forward motion, 00561 /// negative values indicate backward motion. This sensor's value 00562 /// will lie in the range [-500, 500]. 00563 //@{ 00564 LOBOT_SENSORS_DISTANCE_HI, 00565 LOBOT_SENSORS_DISTANCE_LO, 00566 //@} 00567 00568 /// Bytes 15 and 16 are a two byte value (high byte first) specifying 00569 /// the angle (in degrees) turned by the robot since the last time 00570 /// its encoders were queried. Positive value indicate 00571 /// counterclockwise turns, negative values indicate clockwise turns. 00572 //@{ 00573 LOBOT_SENSORS_ANGLE_HI, 00574 LOBOT_SENSORS_ANGLE_LO, 00575 //@} 00576 00577 /// Byte #17 specifies the robot's charging state. 00578 /// 00579 /// DEVNOTE: LoOpenInterface.h provides symbolic constants for the 00580 /// different values this sensor can take on. 00581 LOBOT_SENSORS_CHARGING_STATE, 00582 00583 /// Bytes 18 and 19 specify the voltage (in mV; high byte first) 00584 /// across the robot's batteries. 00585 //@{ 00586 LOBOT_SENSORS_VOLTAGE_HI, 00587 LOBOT_SENSORS_VOLTAGE_LO, 00588 //@} 00589 00590 /// Bytes 20 and 21 specify the current (in mA; high byte first) 00591 /// flowing into or out of the robot's batteries. Negative values 00592 /// indicate current being drawn from the batteries (as would happen 00593 /// when the robot is being used); positive values indicate current 00594 /// flowing into the battery (as during charging). 00595 //@{ 00596 LOBOT_SENSORS_CURRENT_HI, 00597 LOBOT_SENSORS_CURRENT_LO, 00598 //@} 00599 00600 /// Byte #22 is the battery temperature in degrees Celcius. This is a 00601 /// signed 8-bit integer that can take on values in the range -128 to 00602 /// +127. 00603 LOBOT_SENSORS_BATTERY_TEMP, 00604 00605 /// Bytes 23 and 24 specify the battery charge (in mAh; high byte 00606 /// first) of the robot's batteries. The charge value will decrease 00607 /// when the robot is in use and its batteries get depleted; it will 00608 /// increase when the robot is being recharged. 00609 //@{ 00610 LOBOT_SENSORS_BATTERY_CHARGE_HI, 00611 LOBOT_SENSORS_BATTERY_CHARGE_LO, 00612 //@} 00613 00614 /// Bytes 25 and 26 specify the estimated charge capacity of the 00615 /// Create's battery (in mAh; high byte first) of the robot's 00616 /// batteries. 00617 //@{ 00618 LOBOT_SENSORS_BATTERY_CAPACITY_HI, 00619 LOBOT_SENSORS_BATTERY_CAPACITY_LO, 00620 //@} 00621 00622 /// The 27th and 28th bytes of sensor data contain a two-byte value 00623 /// indicating the strength of the wall sensor's signal. The high byte 00624 /// is sent first, then the low byte. The range of this sensor value 00625 /// is from zero to 4095. 00626 //@{ 00627 LOBOT_SENSORS_WALL_SIGNAL_HI, 00628 LOBOT_SENSORS_WALL_SIGNAL_LO, 00629 //@} 00630 00631 /// Bytes 29 through 36 contain byte pairs (high byte first) 00632 /// specifying the signal strengths of the cliff sensors. The range of 00633 /// each of these signals is from zero to 4095. 00634 //@{ 00635 LOBOT_SENSORS_CLIFF_LEFT_SIGNAL_HI, 00636 LOBOT_SENSORS_CLIFF_LEFT_SIGNAL_LO, 00637 LOBOT_SENSORS_CLIFF_FRONT_LEFT_SIGNAL_HI, 00638 LOBOT_SENSORS_CLIFF_FRONT_LEFT_SIGNAL_LO, 00639 LOBOT_SENSORS_CLIFF_FRONT_RIGHT_SIGNAL_HI, 00640 LOBOT_SENSORS_CLIFF_FRONT_RIGHT_SIGNAL_LO, 00641 LOBOT_SENSORS_CLIFF_RIGHT_SIGNAL_HI, 00642 LOBOT_SENSORS_CLIFF_RIGHT_SIGNAL_LO, 00643 //@} 00644 00645 /// Byte #37 specifies the state of the digital inputs on the 25-pin 00646 /// Cargo Bay Connector sent as individual bits (0 = low, 1 = high, 00647 /// i.e., 5V). 00648 /// 00649 /// DEVNOTE: LoOpenInterface.h does not yet provide symbolic bit 00650 /// masks for accessing these bits. Refer to the Open Interface 00651 /// documentation for the gory details. 00652 LOBOT_SENSORS_CARGO_BAY_DIGITAL_INPUTS, 00653 00654 /// Bytes 38 and 39 specify the 10-bit vaue of the analog signal on 00655 /// the 25-pin cargo Bay Connector. The high byte is returned first. 00656 /// A value of zero stands for 0V; a value of 1023 is for 5V; 00657 /// intermediate values are for intermediate voltages. 00658 /// 00659 /// NOTE: The analog input is on pin #4 of the Cargo Bay Connector. 00660 //@{ 00661 LOBOT_SENSORS_CARGO_BAY_ANALOG_SIGNAL_HI, 00662 LOBOT_SENSORS_CARGO_BAY_ANALOG_SIGNAL_LO, 00663 //@} 00664 00665 /// Byte #40 specifies the robot's connection to the different 00666 /// charging sources. Bit #0 is for the internal charger and bit #1 00667 /// for the Home Base. 00668 /// 00669 /// DEVNOTE: LoOpenInterface.h provides symbolic bit masks for 00670 /// accessing these bits. 00671 LOBOT_SENSORS_CHARGING_SOURCES, 00672 00673 /// Byte #41 specifies the Open Interface operating mode, which can 00674 /// be either Off, Passive, Safe or Full. 00675 /// 00676 /// DEVNOTE: LoOpenInterface.h provides symbolic constants for these 00677 /// modes. 00678 LOBOT_SENSORS_OI_MODE, 00679 00680 /// Byte #42 specifies the currently selected song number. 00681 LOBOT_SENSORS_SONG_NUMBER, 00682 00683 /// Byte #43 is flag indicating whether the robot is currently 00684 /// playing a song or not. 00685 LOBOT_SENSORS_SONG_PLAYING, 00686 00687 /// Byte #44 specifies the number of stream packets. 00688 LOBOT_SENSORS_NUM_STREAM_PACKETS, 00689 00690 /// Bytes 45 and 46 are a two byte value (high byte first) indicating 00691 /// the most recent drive speed requested by the high level. This is 00692 /// a signed 16-bit integer that can range from -500 to +500. 00693 //@{ 00694 LOBOT_SENSORS_REQUESTED_SPEED_HI, 00695 LOBOT_SENSORS_REQUESTED_SPEED_LO, 00696 //@} 00697 00698 /// Bytes 47 and 48 are a two byte value (high byte first) indicating 00699 /// the most recent turn radius requested by the high level. This 00700 /// sensor's value will be in the range [-2000, 2000] or one of the 00701 /// special case values for in-place turns or driving straight. 00702 /// 00703 /// DEVNOTE: LoOpenInterface.h provides symbolic constants for the 00704 /// special case values mentioned above. 00705 //@{ 00706 LOBOT_SENSORS_REQUESTED_RADIUS_HI, 00707 LOBOT_SENSORS_REQUESTED_RADIUS_LO, 00708 //@} 00709 00710 /// Bytes 49 and 50 are a two byte value (high byte first) indicating 00711 /// the drive speed requested by the high level for the right wheel. 00712 /// This sensor's value will be in the range [-500, 500]. 00713 //@{ 00714 LOBOT_SENSORS_REQUESTED_RIGHT_SPEED_HI, 00715 LOBOT_SENSORS_REQUESTED_RIGHT_SPEED_LO, 00716 //@} 00717 00718 /// Bytes 51 and 52 are a two byte value (high byte first) indicating 00719 /// the drive speed requested by the high level for the left wheel. 00720 /// This sensor's value will be in the range [-500, 500]. 00721 //@{ 00722 LOBOT_SENSORS_REQUESTED_LEFT_SPEED_HI, 00723 LOBOT_SENSORS_REQUESTED_LEFT_SPEED_LO, 00724 //@} 00725 00726 /// Byte 53 is an extra byte not part of the Open Interface. This byte 00727 /// holds a flag indicating whether or not the distance and angle 00728 /// packets include the actual amount spun and any unintentional 00729 /// translation in response to the most recent SPIN command sent by 00730 /// the high-level controller. 00731 /// 00732 /// DEVNOTE: The reason we need this extra byte is as follows. When 00733 /// the high level sends a SPIN command to have the robot turn 00734 /// in-place, the robot may actually end up spinning by an amount that 00735 /// differs slightly from the requested cw/ccw turn due to actuation 00736 /// errors and timing limitations in the low-level controller. 00737 /// Additionally, the robot may also experience a small amount of 00738 /// translation while rotating in-place due to wheel slippage and 00739 /// other such effects. 00740 /// 00741 /// Ideally, the low-level controller would then report the actual 00742 /// amount of rotation and any unintended translation via a SPIN 00743 /// acknowledgement. Unfortunately, the low-level controller's current 00744 /// design makes it hard to implement such an acknowledgement message 00745 /// because the drive module implements the response to the SPIN 00746 /// command but has no means of initiating an acknowledgement. 00747 /// Therefore, it requests the sensors module to record the actual 00748 /// amount of rotation and translation and tack these amounts on to 00749 /// the distance and angle reported by the encoders the next time the 00750 /// main loop requests a full sensor sweep. 00751 /// 00752 /// This extra byte in the sensors packet lets the high level know 00753 /// that the encoder packet it has just received includes the response 00754 /// to a recent SPIN command sent by it to the low level, in effect, 00755 /// acting as a crude sort of ACK_SPIN. 00756 /// 00757 /// DEVNOTE 2: Even if the low-level controller were able to send an 00758 /// ACK_SPIN in response to a CMD_SPIN, the high-level controller at 00759 /// present (circa August 2010) ignores all ACKs except for ACK_READY 00760 /// and ACK_SENSORS. Consequently, it does make some sense for the low 00761 /// level to tack on the effects of a CMD_SPIN to an ACK_SENSORS to 00762 /// ensure that the high level sees the actual amount of rotational 00763 /// and translational motion caused by a SPIN command. 00764 /// 00765 /// If we were to avoid this bit of hackery, it would become necessary 00766 /// instead to respond to all low-level ACKs and setup some sort of 00767 /// callback mechanism to report odometry updates to all interested 00768 /// high level modules (e.g., localization). 00769 /// 00770 /// Needless to say, implementing an extra flag sent as part of the 00771 /// low-level sensor packet is a lot less work and, therefore, we 00772 /// adopt this solution now in the interests of minimizing development 00773 /// time. 00774 /// 00775 /// DEVNOTE 3: Eventually, when we redesign the low-level controller 00776 /// and the interface to it in the high level, it would be a good idea 00777 /// to have the main module act as a general communication buffer that 00778 /// queues incoming commands from the high level and outgoing 00779 /// acknowledgements from the low level and to then allow all 00780 /// low-level modules to queue relevant acknowledgements. Thus, when a 00781 /// SPIN command comes in, the drive module could handle it and queue 00782 /// an ACK_SPIN in response without any trouble. 00783 /// 00784 /// Of course, the high-level thread/module interfacing with the 00785 /// low-level controller will also have to be redesigned to accept all 00786 /// low-level ACKs and implement a proper observer pattern to inform 00787 /// interested parties about the latest odometry updates, etc. 00788 LOBOT_SENSORS_SPIN_FLAG, 00789 } ; 00790 00791 /// These enumerations define bit masks for the rear bumpers. 00792 enum { 00793 /// Instead of adding a new sensor data byte for the rear bumpers to 00794 /// be sent as part of the SENSORS_ACK message, we simply use the 00795 /// unused bits of the bumps + wheel drops data byte. These bit masks 00796 /// can be used to access the states of the rear bumpers when the 00797 /// bumps data byte of the SENSORS_ACK message is being used. 00798 //@{ 00799 LOBOT_BUMP_REAR_LEFT = 0x40, 00800 LOBOT_BUMP_REAR_RIGHT = 0x20, 00801 LOBOT_BUMP_REAR_BOTH = 0x60, 00802 LOBOT_BUMP_REAR_EITHER = 0x60, 00803 //@} 00804 00805 /// When the low-level controller sends the BUMPS_ACK message to the 00806 /// high level, it packages the states of the front and rear bump 00807 /// sensors into lower four bits of the first data byte. 00808 /// LoOpenInterface.h defines bit masks for the (built-in) front 00809 /// bumpers. These bit masks specify the locations of the rear left 00810 /// and right bump sensors for the BUMPS_ACK message. 00811 //@{ 00812 LOBOT_BUMP_ACK_REAR_LEFT = 0x08, 00813 LOBOT_BUMP_ACK_REAR_RIGHT = 0x04, 00814 LOBOT_BUMP_ACK_REAR_BOTH = 0x0C, 00815 LOBOT_BUMP_ACK_REAR_EITHER = 0x0C, 00816 //@} 00817 } ; 00818 00819 /*---------------------------------------------------------------------*/ 00820 00821 #ifdef __cplusplus 00822 } // end of extern "C" 00823 #endif 00824 00825 #endif