Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * roomba_500.h - Roomba Open Interface implementation for 500 series 00004 * 00005 * Created: Sat Jan 01 19:13:38 2011 00006 * Copyright 2006-2010 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU Library General Public License for more details. 00019 * 00020 * Read the full text in the LICENSE.GPL file in the doc directory. 00021 */ 00022 00023 #ifndef __PLUGINS_ROOMBA_ROOMBA_500_H_ 00024 #define __PLUGINS_ROOMBA_ROOMBA_500_H_ 00025 00026 #include <core/plugin.h> 00027 00028 #include <stdint.h> 00029 00030 namespace fawkes { 00031 class Mutex; 00032 } 00033 00034 class Roomba500 00035 { 00036 public: 00037 /** Connection type. */ 00038 typedef enum { 00039 CONNTYPE_SERIAL, ///< Use serial connection (device file). 00040 CONNTYPE_ROOTOOTH ///< Use BlueZ to find and connect to RooTooth 00041 } ConnectionType; 00042 00043 /** Connection flags. 00044 * These flags allow to influence the connection creation and operation. */ 00045 typedef enum { 00046 FLAG_FIREFLY_FASTMODE = 1 ///< Enable fast mode, assume FireFly RooTooth 00047 } ConnectionFlags; 00048 00049 /** Roomba 500 Command op codes. */ 00050 typedef enum { 00051 OPCODE_START = 128, ///< Initiate communication with Roomba. 00052 OPCODE_BAUD = 129, ///< Set baud rate. 00053 OPCODE_CONTROL = 130, ///< Old alias for SAFE. 00054 OPCODE_SAFE = 131, ///< Enter safe mode. 00055 OPCODE_FULL = 132, ///< Enter full mode. 00056 OPCODE_POWER = 133, ///< Power down Roomba. 00057 OPCODE_SPOT = 134, ///< Start spot cleaning. 00058 OPCODE_CLEAN = 135, ///< Start normal cleaning mission. 00059 OPCODE_MAX = 136, ///< Start max cleaning mode. 00060 OPCODE_DRIVE = 137, ///< Drive robot. 00061 OPCODE_MOTORS = 138, ///< Set motor state. 00062 OPCODE_LEDS = 139, ///< Control LEDs. 00063 OPCODE_SONG = 140, ///< Register song. 00064 OPCODE_PLAY = 141, ///< Play song. 00065 OPCODE_QUERY = 142, ///< Query sensor info. 00066 OPCODE_SEEK_DOCK = 143, ///< Start seeking dock. 00067 OPCODE_PWM_MOTORS = 144, ///< PWM control of motors. 00068 OPCODE_DRIVE_WHEELS = 145, ///< Drive wheels. 00069 OPCODE_DRIVE_PWM = 146, ///< Drive by PWM. 00070 OPCODE_STREAM = 148, ///< Start streaming of data. 00071 OPCODE_QUERY_LIST = 149, ///< Query multiple sensor packets. 00072 OPCODE_PAUSE_RESUME_STREAM = 150, ///< Pause or resume streaming data. 00073 OPCODE_SCHEDULE_LEDS = 162, ///< Control schedule LEDs. 00074 OPCODE_DIGIT_LEDS_RAW = 163, ///< Raw control of digit LEDs. 00075 OPCODE_DIGIT_LEDS_ASCII = 164, ///< Ascii control of digit LEDs. 00076 OPCODE_BUTTONS = 165, ///< Control buttons. 00077 OPCODE_SCHEDULE = 167, ///< Manipulate schedule. 00078 OPCODE_SET_DAY_TIME = 168 ///< Set day and time. 00079 } OpCode; 00080 00081 /** Roomba 500 sensor package IDs. */ 00082 typedef enum { 00083 SENSPACK_BUMPS_DROPS = 7, ///< Bumper and wheel drops. 00084 SENSPACK_WALL = 8, ///< Wall sensor. 00085 SENSPACK_CLIFF_LEFT = 9, ///< Left cliff sensor. 00086 SENSPACK_CLIFF_FRONT_LEFT = 10, ///< Front left cliff sensor. 00087 SENSPACK_CLIFF_FRONT_RIGHT = 11, ///< Front right cliff sensor. 00088 SENSPACK_CLIFF_RIGHT = 12, ///< Right cliff sensor. 00089 SENSPACK_VIRTUAL_WALL = 13, ///< Virtual wall detector. 00090 SENSPACK_WHEEL_OVERCURRENTS = 14, ///< Overcurrents. 00091 SENSPACK_DIRT_DETECT = 15, ///< Dirt detection sensor. 00092 SENSPACK_IR_CHAR_OMNI = 17, ///< Omnidirectional IR receiver. 00093 SENSPACK_BUTTONS = 18, ///< Button status. 00094 SENSPACK_DISTANCE = 19, ///< Travelled distance. 00095 SENSPACK_ANGLE = 20, ///< Turned angle. 00096 SENSPACK_CHARGING_STATE = 21, ///< Charging state. 00097 SENSPACK_VOLTAGE = 22, ///< Voltage. 00098 SENSPACK_CURRENT = 23, ///< Current. 00099 SENSPACK_TEMPERATURE = 24, ///< Temperature. 00100 SENSPACK_BATTERY_CHARGE = 25, ///< Battery charge. 00101 SENSPACK_BATTERY_CAPACITY = 26, ///< Battery capacity. 00102 SENSPACK_WALL_SIGNAL = 27, ///< Wall signal value. 00103 SENSPACK_CLIFF_LEFT_SIGNAL = 28, ///< Left cliff signal value. 00104 SENSPACK_CLIFF_FRONT_LEFT_SIGNAL = 29, ///< Front left cliff signal value. 00105 SENSPACK_CLIFF_FRONT_RIGHT_SIGNAL = 30, ///< Right cliff signal value. 00106 SENSPACK_CLIFF_RIGHT_SIGNAL = 31, ///<Front right cliff signal value. 00107 SENSPACK_CHARGE_SOURCES = 34, ///< Available charge sources. 00108 SENSPACK_OI_MODE = 35, ///< Open Interface mode. 00109 SENSPACK_SONG_NUMBER = 36, ///< Song number. 00110 SENSPACK_SONG_PLAYING = 37, ///< Song playing indicator. 00111 SENSPACK_STREAM_PACKETS = 38, ///< Number of stream packets. 00112 SENSPACK_REQ_VELOCITY = 39, ///< Requested velocity. 00113 SENSPACK_REQ_RADIUS = 40, ///< Requested radius. 00114 SENSPACK_REQ_RIGHT_VELOCITY = 41, ///< Requested right velocity. 00115 SENSPACK_REQ_LEFT_VELOCITY = 42, ///< Requested left velocity. 00116 SENSPACK_RIGHT_ENCODER = 43, ///< Right encoder value. 00117 SENSPACK_LEFT_ENCODER = 44, ///< Left encoder value. 00118 SENSPACK_LIGHT_BUMPER = 45, ///< Light bumper status. 00119 SENSPACK_LIGHT_BUMPER_LEFT = 46, ///< Left bumper signal. 00120 SENSPACK_LIGHT_BUMPER_FRONT_LEFT = 47, ///< Front left bumper signal. 00121 SENSPACK_LIGHT_BUMPER_CENTER_LEFT = 48, ///< Center left bumper signal. 00122 SENSPACK_LIGHT_BUMPER_CENTER_RIGHT = 49, ///< Center right bumper signal. 00123 SENSPACK_LIGHT_BUMPER_FRONT_RIGHT = 50, ///< Front right bumper signal. 00124 SENSPACK_LIGHT_BUMPER_RIGHT = 51, ///< Right bumper signal. 00125 SENSPACK_IR_CHAR_LEFT = 52, ///< Left IR character. 00126 SENSPACK_IR_CHAR_RIGHT = 53, ///< Right IR character. 00127 SENSPACK_LEFT_MOTOR_CURRENT = 54, ///< Left motor current. 00128 SENSPACK_RIGHT_MOTOR_CURRENT = 55, ///< Right motor current. 00129 SENSPACK_BRUSH_MOTOR_CURRENT = 56, ///< Brush motor current. 00130 SENSPACK_SIDE_BRUSH_MOTOR_CURRENT = 57, ///< Side brush motor current. 00131 SENSPACK_STASIS = 58, ///< Caster wheel stasis (forward 00132 ///< movement) 00133 00134 SENSPACK_GROUP_0 = 0, ///< Packet IDs 7-26 00135 SENSPACK_GROUP_1 = 1, ///< Packet IDs 7-16 00136 SENSPACK_GROUP_2 = 2, ///< Packet IDs 17-20 00137 SENSPACK_GROUP_3 = 3, ///< Packet IDs 21-26 00138 SENSPACK_GROUP_4 = 4, ///< Packet IDs 27-34 00139 SENSPACK_GROUP_5 = 5, ///< Packet IDs 35-42 00140 SENSPACK_GROUP_6 = 6, ///< Packet IDs 7-42 00141 SENSPACK_GROUP_ALL = 100, ///< All packet IDs (7-58) 00142 SENSPACK_GROUP_101 = 101, ///< Packet IDs 43-58 00143 SENSPACK_GROUP_106 = 106, ///< Packet IDs 46-51 00144 SENSPACK_GROUP_107 = 107, ///< Packet IDs 54-58 00145 } SensorPacketID; 00146 00147 /** Roomba 500 operation mode. */ 00148 typedef enum { 00149 MODE_OFF = 0, ///< No connection. 00150 MODE_PASSIVE = 1, ///< Passive mode, no control, only listening. 00151 MODE_SAFE = 2, ///< Control acquired, safety measures in place. 00152 MODE_FULL = 3 ///< Control acquired, safety measures disabled. 00153 } Mode; 00154 00155 /** Sensor stream state. */ 00156 typedef enum { 00157 STREAM_ENABLE = 1, ///< Stream enabled. 00158 STREAM_DISABLE = 0 ///< Stream disabled. 00159 } StreamState; 00160 00161 /** Charging state. */ 00162 typedef enum { 00163 CHARGING_NO = 0, ///< Not charging. 00164 CHARGING_RECONDITIONING = 1, ///< Reconditioning battery. 00165 CHARGING_FULL = 2, ///< Full charging cycle. 00166 CHARGING_TRICKLE = 3, ///< Trickle charging. 00167 CHARGING_WAITING = 4, ///< Waiting. 00168 CHARGING_ERROR = 5 ///< Fault condition. 00169 } ChargingState; 00170 00171 /** Infrared character values. */ 00172 typedef enum { 00173 IR_REMOTE_LEFT = 129, ///< IR Remote Control: left button 00174 IR_REMOTE_FORWARD = 130, ///< IR Remote Control: forward button 00175 IR_REMOTE_RIGHT = 131, ///< IR Remote Control: right button 00176 IR_REMOTE_SPOT = 132, ///< IR Remote Control: spot button 00177 IR_REMOTE_MAX = 133, ///< IR Remote Control: max button 00178 IR_REMOTE_SMALL = 134, ///< IR Remote Control: small button 00179 IR_REMOTE_MEDIUM = 135, ///< IR Remote Control: medium button 00180 IR_REMOTE_LARGE_CLEAN = 136, ///< IR Remote Control: large/clean button 00181 IR_REMOTE_STOP = 137, ///< IR Remote Control: stop button 00182 IR_REMOTE_POWER = 138, ///< IR Remote Control: power button 00183 IR_REMOTE_ARC_LEFT = 139, ///< IR Remote Control: left arc button 00184 IR_REMOTE_ARC_RIGHT = 140, ///< IR Remote Control: right arc button 00185 IR_REMOTE_STOP2 = 141, ///< IR Remote Control: stop button 00186 IR_SCHED_REMOTE_DOWNLOAD = 142, ///< IR scheduling remote: download button 00187 IR_SCHED_REMOTE_SEEK_DOCK = 143, ///< IR scheduling remote: seek dock button 00188 // just for completeness 00189 IR_DISC_DOCK_RESERVED = 240, ///< Roomba Discovery dock: reserved 00190 IR_DISC_DOCK_RED_BUOY = 248, ///< Roomba Discovery dock: red buoy 00191 IR_DISC_DOCK_GREEN_BUOY = 244, ///< Roomba Discovery dock: green buoy 00192 IR_DISC_DOCK_FORCE_FIELD = 242, ///< Roomba Discovery dock: red 00193 ///< and green buoy 00194 IR_DISC_DOCK_RED_GREEN_BUOY = 252, ///< Roomba Discovery dock: red 00195 ///< buoy and force field 00196 IR_DISC_DOCK_RED_BUOY_FORCE_FIELD = 250, ///< Roomba Discovery dock: green 00197 ///< buoy and force field 00198 IR_DISC_DOCK_GREEN_BUOY_FORCE_FIELD = 246, ///< Roomba Discovery dock: green 00199 ///< buoy and force field. 00200 IR_DISC_DOCK_RED_GREEN_BUOY_FORCE_FIELD = 254, ///< Roomba Discovery dock: red 00201 ///< and green buoy and force field 00202 IR_DOCK_RESERVED = 160, ///< Roomba 500 dock: reserved 00203 IR_DOCK_RED_BUOY = 168, ///< Roomba 500 dock: red buoy 00204 IR_DOCK_GREEN_BUOY = 164, ///< Roomba 500 dock: green buoy 00205 IR_DOCK_FORCE_FIELD = 161, ///< Roomba 500 dock: red and green buoy 00206 IR_DOCK_RED_GREEN_BUOY = 172, ///< Roomba 500 dock: red buoy and force 00207 ///< field 00208 IR_DOCK_RED_BUOY_FORCE_FIELD = 169, ///< Roomba 500 dock: green buoy 00209 ///< and force field 00210 IR_DOCK_GREEN_BUOY_FORCE_FIELD = 165, ///< Roomba 500 dock: green buoy 00211 ///< and force field. 00212 IR_DOCK_RED_GREEN_BUOY_FORCE_FIELD = 173, ///< Roomba 500 dock: red and 00213 ///< green buoy and force field. 00214 IR_VIRTUAL_WALL = 162 ///< IR Virtual Wall 00215 } InfraredCharacter; 00216 00217 /** Days for scheduler. */ 00218 typedef enum { 00219 DAY_SUNDAY = 0, ///< Sunday. 00220 DAY_MONDAY = 1, ///< Monday. 00221 DAY_TUESDAY = 2, ///< Tuesday. 00222 DAY_WEDNESDAY = 3, ///< Wednesday. 00223 DAY_THURSDAY = 4, ///< Thursday. 00224 DAY_FRIDAY = 5, ///< Friday. 00225 DAY_SATURDAY = 6 ///< Saturday. 00226 } ScheduleDay; 00227 00228 /** Turning direction. */ 00229 typedef enum { 00230 TURN_CLOCKWISE, ///< Clockwise turning. 00231 TURN_COUNTER_CLOCKWISE ///< Counter-Clockwise turning. 00232 } TurnDirection; 00233 00234 static const unsigned char BUTTON_CLEAN; ///< Cleaning button. 00235 static const unsigned char BUTTON_SPOT; ///< Spot cleaning button. 00236 static const unsigned char BUTTON_DOCK; ///< Dock button. 00237 static const unsigned char BUTTON_MINUTE; ///< Minute button. 00238 static const unsigned char BUTTON_HOUR; ///< Hour button. 00239 static const unsigned char BUTTON_DAY; ///< Day button. 00240 static const unsigned char BUTTON_SCHEDULE; ///< Schedule button. 00241 static const unsigned char BUTTON_CLOCK; ///< Clock button. 00242 00243 static const unsigned char WHEEL_DROP_LEFT; ///< Left wheel drop bit. 00244 static const unsigned char WHEEL_DROP_RIGHT; ///< Right wheel drop bit. 00245 static const unsigned char BUMP_LEFT; ///< Left bumper bit. 00246 static const unsigned char BUMP_RIGHT; ///< Right bumper bit. 00247 00248 static const unsigned char OVERCURRENT_WHEEL_LEFT; ///< Left wheel bit. 00249 static const unsigned char OVERCURRENT_WHEEL_RIGHT; ///< Right wheel bit. 00250 static const unsigned char OVERCURRENT_MAIN_BRUSH; ///< Main brush bit. 00251 static const unsigned char OVERCURRENT_SIDE_BRUSH; ///< Side brush bit. 00252 00253 static const unsigned char CHARGING_SOURCE_HOME_BASE; ///< Docking station. 00254 static const unsigned char CHARGING_SOURCE_INTERNAL; ///< Internal socket. 00255 00256 static const unsigned char BUMPER_LEFT; ///< Left bumper. 00257 static const unsigned char BUMPER_FRONT_LEFT; ///< Front left bumper. 00258 static const unsigned char BUMPER_CENTER_LEFT; ///< Center left bumper. 00259 static const unsigned char BUMPER_CENTER_RIGHT; ///< Center right bumper. 00260 static const unsigned char BUMPER_FRONT_RIGHT; ///< Front right bumper. 00261 static const unsigned char BUMPER_RIGHT; ///< Right bumper. 00262 00263 static const unsigned char LED_DEBRIS; ///< Debris LED bit. 00264 static const unsigned char LED_SPOT; ///< Spot LED bit. 00265 static const unsigned char LED_DOCK; ///< Dock LED bit. 00266 static const unsigned char LED_CHECK_ROBOT; ///< Check robot LED bit. 00267 00268 static const unsigned char WEEKDAY_LED_SUN; ///< Sunday. 00269 static const unsigned char WEEKDAY_LED_MON; ///< Monday. 00270 static const unsigned char WEEKDAY_LED_TUE; ///< Tuesday. 00271 static const unsigned char WEEKDAY_LED_WED; ///< Wednesday. 00272 static const unsigned char WEEKDAY_LED_THU; ///< Thursday. 00273 static const unsigned char WEEKDAY_LED_FRI; ///< Friday. 00274 static const unsigned char WEEKDAY_LED_SAT; ///< Saturday. 00275 00276 static const unsigned char SCHEDULING_LED_COLON; ///< Colon LED bit. 00277 static const unsigned char SCHEDULING_LED_PM; ///< PM LED bit. 00278 static const unsigned char SCHEDULING_LED_AM; ///< AM LED bit. 00279 static const unsigned char SCHEDULING_LED_CLOCK; ///< Clock LED bit. 00280 static const unsigned char SCHEDULING_LED_SCHEDULE; ///< Schedule LED bit. 00281 00282 static const unsigned char DIGIT_LED_NORTH; ///< Top segment LED. 00283 static const unsigned char DIGIT_LED_NORTH_WEST; ///< Top left segment LED. 00284 static const unsigned char DIGIT_LED_NORTH_EAST; ///< Top right segment LED. 00285 static const unsigned char DIGIT_LED_CENTER; ///< Center segment LED. 00286 static const unsigned char DIGIT_LED_SOUTH_WEST; ///< Bottom left segment. 00287 static const unsigned char DIGIT_LED_SOUTH_EAST; ///< Bottom right segment. 00288 static const unsigned char DIGIT_LED_SOUTH; ///< Bottom segment LED. 00289 00290 static const unsigned char MOTOR_SIDE_BRUSH; ///< Side brush motor bit. 00291 static const unsigned char MOTOR_VACUUM; ///< Vacuum motor bit. 00292 static const unsigned char MOTOR_MAIN_BRUSHES; ///< Main brush motor bit. 00293 static const unsigned char MOTOR_SIDE_BRUSH_BACKWARD; ///< Side backward bit. 00294 static const unsigned char MOTOR_MAIN_BRUSHES_BACKWARD; ///< Main backward bit. 00295 00296 static const unsigned char CHARGER_HOME_BASE; ///< Home base charger bit. 00297 static const unsigned char CHARGER_INTERNAL; ///< Internal charger bit. 00298 00299 00300 /// @cond OBVIOUS 00301 static const unsigned short int SENSPACK_SIZE_GROUP_0; 00302 static const unsigned short int SENSPACK_SIZE_GROUP_1; 00303 static const unsigned short int SENSPACK_SIZE_GROUP_2; 00304 static const unsigned short int SENSPACK_SIZE_GROUP_3; 00305 static const unsigned short int SENSPACK_SIZE_GROUP_4; 00306 static const unsigned short int SENSPACK_SIZE_GROUP_5; 00307 static const unsigned short int SENSPACK_SIZE_GROUP_6; 00308 static const unsigned short int SENSPACK_SIZE_GROUP_ALL; 00309 static const unsigned short int SENSPACK_SIZE_GROUP_101; 00310 static const unsigned short int SENSPACK_SIZE_GROUP_106; 00311 static const unsigned short int SENSPACK_SIZE_GROUP_107; 00312 static const unsigned short int SENSPACK_SIZE_BUMPS_DROPS; 00313 static const unsigned short int SENSPACK_SIZE_WALL; 00314 static const unsigned short int SENSPACK_SIZE_CLIFF_LEFT; 00315 static const unsigned short int SENSPACK_SIZE_CLIFF_FRONT_LEFT; 00316 static const unsigned short int SENSPACK_SIZE_CLIFF_FRONT_RIGHT; 00317 static const unsigned short int SENSPACK_SIZE_CLIFF_RIGHT; 00318 static const unsigned short int SENSPACK_SIZE_VIRTUAL_WALL; 00319 static const unsigned short int SENSPACK_SIZE_WHEEL_OVERCURRENTS; 00320 static const unsigned short int SENSPACK_SIZE_DIRT_DETECT; 00321 static const unsigned short int SENSPACK_SIZE_IR_CHAR_OMNI; 00322 static const unsigned short int SENSPACK_SIZE_IR_CHAR_LEFT; 00323 static const unsigned short int SENSPACK_SIZE_IR_CHAR_RIGHT; 00324 static const unsigned short int SENSPACK_SIZE_BUTTONS; 00325 static const unsigned short int SENSPACK_SIZE_DISTANCE; 00326 static const unsigned short int SENSPACK_SIZE_ANGLE; 00327 static const unsigned short int SENSPACK_SIZE_CHARGING_STATE; 00328 static const unsigned short int SENSPACK_SIZE_VOLTAGE; 00329 static const unsigned short int SENSPACK_SIZE_CURRENT; 00330 static const unsigned short int SENSPACK_SIZE_TEMPERATURE; 00331 static const unsigned short int SENSPACK_SIZE_BATTERY_CHARGE; 00332 static const unsigned short int SENSPACK_SIZE_BATTERY_CAPACITY; 00333 static const unsigned short int SENSPACK_SIZE_WALL_SIGNAL; 00334 static const unsigned short int SENSPACK_SIZE_CLIFF_LEFT_SIGNAL; 00335 static const unsigned short int SENSPACK_SIZE_CLIFF_FRONT_LEFT_SIGNAL; 00336 static const unsigned short int SENSPACK_SIZE_CLIFF_FRONT_RIGHT_SIGNAL; 00337 static const unsigned short int SENSPACK_SIZE_CLIFF_RIGHT_SIGNAL; 00338 static const unsigned short int SENSPACK_SIZE_CHARGE_SOURCES; 00339 static const unsigned short int SENSPACK_SIZE_OI_MODE; 00340 static const unsigned short int SENSPACK_SIZE_SONG_NUMBER; 00341 static const unsigned short int SENSPACK_SIZE_SONG_PLAYING; 00342 static const unsigned short int SENSPACK_SIZE_STREAM_PACKETS; 00343 static const unsigned short int SENSPACK_SIZE_REQ_VELOCITY; 00344 static const unsigned short int SENSPACK_SIZE_REQ_RADIUS; 00345 static const unsigned short int SENSPACK_SIZE_REQ_RIGHT_VELOCITY; 00346 static const unsigned short int SENSPACK_SIZE_REQ_LEFT_VELOCITY; 00347 static const unsigned short int SENSPACK_SIZE_RIGHT_ENCODER; 00348 static const unsigned short int SENSPACK_SIZE_LEFT_ENCODER; 00349 static const unsigned short int SENSPACK_SIZE_LIGHT_BUMPER; 00350 static const unsigned short int SENSPACK_SIZE_LIGHT_BUMPER_LEFT; 00351 static const unsigned short int SENSPACK_SIZE_LIGHT_BUMPER_FRONT_LEFT; 00352 static const unsigned short int SENSPACK_SIZE_LIGHT_BUMPER_CENTER_LEFT; 00353 static const unsigned short int SENSPACK_SIZE_LIGHT_BUMPER_CENTER_RIGHT; 00354 static const unsigned short int SENSPACK_SIZE_LIGHT_BUMPER_FRONT_RIGHT; 00355 static const unsigned short int SENSPACK_SIZE_LIGHT_BUMPER_RIGHT; 00356 static const unsigned short int SENSPACK_SIZE_LEFT_MOTOR_CURRENT; 00357 static const unsigned short int SENSPACK_SIZE_RIGHT_MOTOR_CURRENT; 00358 static const unsigned short int SENSPACK_SIZE_BRUSH_MOTOR_CURRENT; 00359 static const unsigned short int SENSPACK_SIZE_SIDE_BRUSH_MOTOR_CURRENT; 00360 static const unsigned short int SENSPACK_SIZE_STASIS; 00361 /// @endcond 00362 00363 static const float DIAMETER; ///< Robot diameter. 00364 static const float BUMPER_X_OFFSET; ///< X Offset of bumper. 00365 static const float AXLE_LENGTH; ///< Axle length. 00366 00367 static const short int MAX_LIN_VEL_MM_S; ///< Maximum linear velocity. 00368 static const short int MAX_RADIUS_MM; ///< Maximum drive radius. 00369 00370 static const short int MAX_PWM; ///< Maximum PWM value for wheels. 00371 static const unsigned short int MAX_ENCODER_COUNT; ///< Maximum encoder count. 00372 static const unsigned short int STREAM_INTERVAL_MS; ///< Time in ms between 00373 ///< streamed sensor packets. 00374 static const unsigned short int MODE_CHANGE_WAIT_MS; ///< Time in ms to wait 00375 ///< after mode changes 00376 00377 static const unsigned char CHECKSUM_SIZE; ///< Checksum byte size. 00378 00379 #pragma pack(push,1) 00380 /** Struct for packet group with everything (SENSPACK_GROUP_ALL). */ 00381 typedef struct { 00382 uint8_t bumps_wheeldrops; ///< Bumps and wheeldrops bits. 00383 uint8_t wall; ///< Wall sensor value. 00384 uint8_t cliff_left; ///< Left cliff sensor. 00385 uint8_t cliff_front_left; ///< Front left cliff sensor. 00386 uint8_t cliff_front_right; ///< Front right cliff sensor. 00387 uint8_t cliff_right; ///< Right cliff sensor. 00388 uint8_t virtual_wall; ///< Wall sensor. 00389 uint8_t overcurrents; ///< Overcurrents bits. 00390 uint8_t dirt_detect; ///< Dirt detect sensor. 00391 uint8_t unused_1; ///< Unused byte. 00392 uint8_t ir_opcode_omni; ///< Omni IR receiver character. 00393 uint8_t buttons; ///< Buttons bits. 00394 int16_t distance; ///< Traveled distance in mm. 00395 int16_t angle; ///< Turned angle in degree. 00396 uint8_t charging_state; ///< Charging state. 00397 uint16_t voltage; ///< Voltage in mV. 00398 int16_t current; ///< Current in mA. 00399 int8_t temperature; ///< Temperature in deg C. 00400 uint16_t battery_charge; ///< Battery charge in mAh. 00401 uint16_t battery_capacity; ///< Battery capacity in mAh. 00402 uint16_t wall_signal; ///< Raw wall signal. 00403 uint16_t cliff_left_signal; ///< Raw left cliff signal. 00404 uint16_t cliff_front_left_signal; ///< Raw front left cliff signal. 00405 uint16_t cliff_front_right_signal; ///< Raw front right cliff signal. 00406 uint16_t cliff_right_signal; ///< Raw right cliff signal. 00407 uint8_t unused_2; ///< Unused byte. 00408 uint16_t unused_3; ///< Unused byte. 00409 uint8_t charger_available; ///< Available chargers bits. 00410 uint8_t mode; ///< Open Interface mode. 00411 uint8_t song_number; ///< Song number. 00412 uint8_t song_playing; ///< Song playing byte. 00413 uint8_t stream_num_packets; ///< Number of streamed packets. 00414 int16_t velocity; ///< Velocity in mm/sec. 00415 int16_t radius; ///< Radius in mm. 00416 int16_t velocity_right; ///< Velocity of right wheel in mm/sec. 00417 int16_t velocity_left; ///< Velocity of left wheel in mm/sec. 00418 uint16_t encoder_counts_left; ///< Encoder counts for left wheel. 00419 uint16_t encoder_counts_right; ///< Encoder counts for right wheel. 00420 uint8_t light_bumper; ///< Light bumper bits. 00421 uint16_t light_bump_left; ///< Raw left light bumper signal. 00422 uint16_t light_bump_front_left; ///< Raw front left light bumper signal. 00423 uint16_t light_bump_center_left; ///< Raw center left light bumper signal. 00424 uint16_t light_bump_center_right; ///< Raw center right light bumper signal. 00425 uint16_t light_bump_front_right; ///< Raw front right light bumper signal. 00426 uint16_t light_bump_right; ///< Raw right light bumper signal. 00427 uint8_t ir_opcode_left; ///< Left IR receiver character. 00428 uint8_t ir_opcode_right; ///< Right IR receiver character. 00429 int16_t left_motor_current; ///< Raw left motor current signal. 00430 int16_t right_motor_current; ///< Raw right motor current signal. 00431 int16_t main_brush_current; ///< Raw main brush motor current signal. 00432 int16_t side_brush_current; ///< Raw side brush motor current signal. 00433 uint8_t stasis; ///< Castor stasis. 00434 } SensorPacketGroupAll; 00435 #pragma pack(pop) 00436 00437 public: 00438 Roomba500(ConnectionType conntype, const char *device, unsigned int flags = 0); 00439 ~Roomba500(); 00440 00441 void open(); 00442 void close(); 00443 00444 /** Check if connection has been established. 00445 * @return true if connection has been established, false otherwise. */ 00446 bool is_connected() const { return (__fd != -1); } 00447 00448 /** Get connection type. 00449 * @return connection type */ 00450 ConnectionType get_connection_type() const { return __conntype; } 00451 /** Get device string. 00452 * @return device string */ 00453 const char * get_device() const { return __device; } 00454 00455 /** Get current mode. 00456 * @return current mode. */ 00457 Mode get_mode() const { return __mode; } 00458 00459 /** Check if robot is being controlled. 00460 * @return true if robot is being controlled, false otherwise. */ 00461 bool is_controlled() const 00462 { return is_connected() && ( (__mode == MODE_SAFE) || (__mode == MODE_FULL) ); } 00463 00464 void set_mode(Mode mode); 00465 void clean(); 00466 void clean_spot(); 00467 void seek_dock(); 00468 void power_down(); 00469 void stop(); 00470 void drive_straight(short int velo_mm_per_sec); 00471 void drive_turn(TurnDirection direction); 00472 void drive_arc(short int velo_mm_per_sec, short int radius_mm); 00473 void drive(short int velocity_mm_per_sec, short int radius_mm); 00474 void drive_direct(short int left_mm_per_sec, short int right_mm_per_sec); 00475 void drive_pwm(short int left_wheel_pwm, short int right_wheel_pwm); 00476 void set_motors(bool main = true, bool side = true, bool vacuum = true, 00477 bool main_backward = false, bool side_backward = false); 00478 void set_leds(bool debris, bool spot, bool dock, bool check_robot, 00479 unsigned char clean_color, unsigned char clean_intensity); 00480 00481 void set_digit_leds(const char digits[4]); 00482 00483 void enable_sensors(); 00484 void disable_sensors(); 00485 bool is_data_available(); 00486 void read_sensors(); 00487 void query_sensors(); 00488 /** Check if sensor packet is availabe. 00489 * @return true if sensor packet is available, false otherwise 00490 */ 00491 bool has_sensor_packet() const 00492 { return __sensor_packet_received; }; 00493 const SensorPacketGroupAll get_sensor_packet() const; 00494 00495 void play_fanfare(); 00496 00497 static unsigned short int get_packet_size(SensorPacketID packet); 00498 00499 private: 00500 void send(OpCode opcode, 00501 const void *params = NULL, const size_t plength = 0); 00502 void recv(size_t index, size_t num_bytes, unsigned int timeout_ms = 0); 00503 00504 void assert_control() 00505 { 00506 if ((__mode != MODE_FULL) && (__mode != MODE_SAFE)) { 00507 throw fawkes::Exception("Command only available in FULL or SAFE mode."); 00508 } 00509 } 00510 void assert_connected() 00511 { if (__mode == MODE_OFF) throw fawkes::Exception("Not connected to robot."); } 00512 00513 private: 00514 ConnectionType __conntype; 00515 unsigned int __conn_flags; 00516 00517 Mode __mode; 00518 SensorPacketID __packet_id; 00519 unsigned char __packet_reply_id; 00520 unsigned short __packet_length; 00521 bool __sensors_enabled; 00522 SensorPacketGroupAll __sensor_packet; 00523 bool __sensor_packet_received; 00524 fawkes::Mutex *__sensor_mutex; 00525 00526 char *__device; 00527 int __fd; 00528 fawkes::Mutex *__read_mutex; 00529 fawkes::Mutex *__write_mutex; 00530 00531 unsigned char __obuffer[16]; 00532 unsigned char __ibuffer[82]; 00533 00534 int __obuffer_length; 00535 int __ibuffer_length; 00536 }; 00537 00538 #endif