Fawkes API  Fawkes Development Version
roomba_500.h
1 
2 /***************************************************************************
3  * roomba_500.h - Roomba Open Interface implementation for 500 series
4  *
5  * Created: Sat Jan 01 19:13:38 2011
6  * Copyright 2006-2010 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #ifndef __PLUGINS_ROOMBA_ROOMBA_500_H_
24 #define __PLUGINS_ROOMBA_ROOMBA_500_H_
25 
26 #include <core/plugin.h>
27 
28 #include <stdint.h>
29 
30 namespace fawkes {
31  class Mutex;
32 }
33 
34 class Roomba500
35 {
36  public:
37  /** Connection type. */
38  typedef enum {
39  CONNTYPE_SERIAL, ///< Use serial connection (device file).
40  CONNTYPE_ROOTOOTH ///< Use BlueZ to find and connect to RooTooth
42 
43  /** Connection flags.
44  * These flags allow to influence the connection creation and operation. */
45  typedef enum {
46  FLAG_FIREFLY_FASTMODE = 1 ///< Enable fast mode, assume FireFly RooTooth
48 
49  /** Roomba 500 Command op codes. */
50  typedef enum {
51  OPCODE_START = 128, ///< Initiate communication with Roomba.
52  OPCODE_BAUD = 129, ///< Set baud rate.
53  OPCODE_CONTROL = 130, ///< Old alias for SAFE.
54  OPCODE_SAFE = 131, ///< Enter safe mode.
55  OPCODE_FULL = 132, ///< Enter full mode.
56  OPCODE_POWER = 133, ///< Power down Roomba.
57  OPCODE_SPOT = 134, ///< Start spot cleaning.
58  OPCODE_CLEAN = 135, ///< Start normal cleaning mission.
59  OPCODE_MAX = 136, ///< Start max cleaning mode.
60  OPCODE_DRIVE = 137, ///< Drive robot.
61  OPCODE_MOTORS = 138, ///< Set motor state.
62  OPCODE_LEDS = 139, ///< Control LEDs.
63  OPCODE_SONG = 140, ///< Register song.
64  OPCODE_PLAY = 141, ///< Play song.
65  OPCODE_QUERY = 142, ///< Query sensor info.
66  OPCODE_SEEK_DOCK = 143, ///< Start seeking dock.
67  OPCODE_PWM_MOTORS = 144, ///< PWM control of motors.
68  OPCODE_DRIVE_WHEELS = 145, ///< Drive wheels.
69  OPCODE_DRIVE_PWM = 146, ///< Drive by PWM.
70  OPCODE_STREAM = 148, ///< Start streaming of data.
71  OPCODE_QUERY_LIST = 149, ///< Query multiple sensor packets.
72  OPCODE_PAUSE_RESUME_STREAM = 150, ///< Pause or resume streaming data.
73  OPCODE_SCHEDULE_LEDS = 162, ///< Control schedule LEDs.
74  OPCODE_DIGIT_LEDS_RAW = 163, ///< Raw control of digit LEDs.
75  OPCODE_DIGIT_LEDS_ASCII = 164, ///< Ascii control of digit LEDs.
76  OPCODE_BUTTONS = 165, ///< Control buttons.
77  OPCODE_SCHEDULE = 167, ///< Manipulate schedule.
78  OPCODE_SET_DAY_TIME = 168 ///< Set day and time.
79  } OpCode;
80 
81  /** Roomba 500 sensor package IDs. */
82  typedef enum {
83  SENSPACK_BUMPS_DROPS = 7, ///< Bumper and wheel drops.
84  SENSPACK_WALL = 8, ///< Wall sensor.
85  SENSPACK_CLIFF_LEFT = 9, ///< Left cliff sensor.
86  SENSPACK_CLIFF_FRONT_LEFT = 10, ///< Front left cliff sensor.
87  SENSPACK_CLIFF_FRONT_RIGHT = 11, ///< Front right cliff sensor.
88  SENSPACK_CLIFF_RIGHT = 12, ///< Right cliff sensor.
89  SENSPACK_VIRTUAL_WALL = 13, ///< Virtual wall detector.
90  SENSPACK_WHEEL_OVERCURRENTS = 14, ///< Overcurrents.
91  SENSPACK_DIRT_DETECT = 15, ///< Dirt detection sensor.
92  SENSPACK_IR_CHAR_OMNI = 17, ///< Omnidirectional IR receiver.
93  SENSPACK_BUTTONS = 18, ///< Button status.
94  SENSPACK_DISTANCE = 19, ///< Travelled distance.
95  SENSPACK_ANGLE = 20, ///< Turned angle.
96  SENSPACK_CHARGING_STATE = 21, ///< Charging state.
97  SENSPACK_VOLTAGE = 22, ///< Voltage.
98  SENSPACK_CURRENT = 23, ///< Current.
99  SENSPACK_TEMPERATURE = 24, ///< Temperature.
100  SENSPACK_BATTERY_CHARGE = 25, ///< Battery charge.
101  SENSPACK_BATTERY_CAPACITY = 26, ///< Battery capacity.
102  SENSPACK_WALL_SIGNAL = 27, ///< Wall signal value.
103  SENSPACK_CLIFF_LEFT_SIGNAL = 28, ///< Left cliff signal value.
104  SENSPACK_CLIFF_FRONT_LEFT_SIGNAL = 29, ///< Front left cliff signal value.
105  SENSPACK_CLIFF_FRONT_RIGHT_SIGNAL = 30, ///< Right cliff signal value.
106  SENSPACK_CLIFF_RIGHT_SIGNAL = 31, ///<Front right cliff signal value.
107  SENSPACK_CHARGE_SOURCES = 34, ///< Available charge sources.
108  SENSPACK_OI_MODE = 35, ///< Open Interface mode.
109  SENSPACK_SONG_NUMBER = 36, ///< Song number.
110  SENSPACK_SONG_PLAYING = 37, ///< Song playing indicator.
111  SENSPACK_STREAM_PACKETS = 38, ///< Number of stream packets.
112  SENSPACK_REQ_VELOCITY = 39, ///< Requested velocity.
113  SENSPACK_REQ_RADIUS = 40, ///< Requested radius.
114  SENSPACK_REQ_RIGHT_VELOCITY = 41, ///< Requested right velocity.
115  SENSPACK_REQ_LEFT_VELOCITY = 42, ///< Requested left velocity.
116  SENSPACK_RIGHT_ENCODER = 43, ///< Right encoder value.
117  SENSPACK_LEFT_ENCODER = 44, ///< Left encoder value.
118  SENSPACK_LIGHT_BUMPER = 45, ///< Light bumper status.
119  SENSPACK_LIGHT_BUMPER_LEFT = 46, ///< Left bumper signal.
120  SENSPACK_LIGHT_BUMPER_FRONT_LEFT = 47, ///< Front left bumper signal.
121  SENSPACK_LIGHT_BUMPER_CENTER_LEFT = 48, ///< Center left bumper signal.
122  SENSPACK_LIGHT_BUMPER_CENTER_RIGHT = 49, ///< Center right bumper signal.
123  SENSPACK_LIGHT_BUMPER_FRONT_RIGHT = 50, ///< Front right bumper signal.
124  SENSPACK_LIGHT_BUMPER_RIGHT = 51, ///< Right bumper signal.
125  SENSPACK_IR_CHAR_LEFT = 52, ///< Left IR character.
126  SENSPACK_IR_CHAR_RIGHT = 53, ///< Right IR character.
127  SENSPACK_LEFT_MOTOR_CURRENT = 54, ///< Left motor current.
128  SENSPACK_RIGHT_MOTOR_CURRENT = 55, ///< Right motor current.
129  SENSPACK_BRUSH_MOTOR_CURRENT = 56, ///< Brush motor current.
130  SENSPACK_SIDE_BRUSH_MOTOR_CURRENT = 57, ///< Side brush motor current.
131  SENSPACK_STASIS = 58, ///< Caster wheel stasis (forward
132  ///< movement)
133 
134  SENSPACK_GROUP_0 = 0, ///< Packet IDs 7-26
135  SENSPACK_GROUP_1 = 1, ///< Packet IDs 7-16
136  SENSPACK_GROUP_2 = 2, ///< Packet IDs 17-20
137  SENSPACK_GROUP_3 = 3, ///< Packet IDs 21-26
138  SENSPACK_GROUP_4 = 4, ///< Packet IDs 27-34
139  SENSPACK_GROUP_5 = 5, ///< Packet IDs 35-42
140  SENSPACK_GROUP_6 = 6, ///< Packet IDs 7-42
141  SENSPACK_GROUP_ALL = 100, ///< All packet IDs (7-58)
142  SENSPACK_GROUP_101 = 101, ///< Packet IDs 43-58
143  SENSPACK_GROUP_106 = 106, ///< Packet IDs 46-51
144  SENSPACK_GROUP_107 = 107, ///< Packet IDs 54-58
145  } SensorPacketID;
146 
147  /** Roomba 500 operation mode. */
148  typedef enum {
149  MODE_OFF = 0, ///< No connection.
150  MODE_PASSIVE = 1, ///< Passive mode, no control, only listening.
151  MODE_SAFE = 2, ///< Control acquired, safety measures in place.
152  MODE_FULL = 3 ///< Control acquired, safety measures disabled.
153  } Mode;
154 
155  /** Sensor stream state. */
156  typedef enum {
157  STREAM_ENABLE = 1, ///< Stream enabled.
158  STREAM_DISABLE = 0 ///< Stream disabled.
159  } StreamState;
160 
161  /** Charging state. */
162  typedef enum {
163  CHARGING_NO = 0, ///< Not charging.
164  CHARGING_RECONDITIONING = 1, ///< Reconditioning battery.
165  CHARGING_FULL = 2, ///< Full charging cycle.
166  CHARGING_TRICKLE = 3, ///< Trickle charging.
167  CHARGING_WAITING = 4, ///< Waiting.
168  CHARGING_ERROR = 5 ///< Fault condition.
169  } ChargingState;
170 
171  /** Infrared character values. */
172  typedef enum {
173  IR_REMOTE_LEFT = 129, ///< IR Remote Control: left button
174  IR_REMOTE_FORWARD = 130, ///< IR Remote Control: forward button
175  IR_REMOTE_RIGHT = 131, ///< IR Remote Control: right button
176  IR_REMOTE_SPOT = 132, ///< IR Remote Control: spot button
177  IR_REMOTE_MAX = 133, ///< IR Remote Control: max button
178  IR_REMOTE_SMALL = 134, ///< IR Remote Control: small button
179  IR_REMOTE_MEDIUM = 135, ///< IR Remote Control: medium button
180  IR_REMOTE_LARGE_CLEAN = 136, ///< IR Remote Control: large/clean button
181  IR_REMOTE_STOP = 137, ///< IR Remote Control: stop button
182  IR_REMOTE_POWER = 138, ///< IR Remote Control: power button
183  IR_REMOTE_ARC_LEFT = 139, ///< IR Remote Control: left arc button
184  IR_REMOTE_ARC_RIGHT = 140, ///< IR Remote Control: right arc button
185  IR_REMOTE_STOP2 = 141, ///< IR Remote Control: stop button
186  IR_SCHED_REMOTE_DOWNLOAD = 142, ///< IR scheduling remote: download button
187  IR_SCHED_REMOTE_SEEK_DOCK = 143, ///< IR scheduling remote: seek dock button
188  // just for completeness
189  IR_DISC_DOCK_RESERVED = 240, ///< Roomba Discovery dock: reserved
190  IR_DISC_DOCK_RED_BUOY = 248, ///< Roomba Discovery dock: red buoy
191  IR_DISC_DOCK_GREEN_BUOY = 244, ///< Roomba Discovery dock: green buoy
192  IR_DISC_DOCK_FORCE_FIELD = 242, ///< Roomba Discovery dock: red
193  ///< and green buoy
194  IR_DISC_DOCK_RED_GREEN_BUOY = 252, ///< Roomba Discovery dock: red
195  ///< buoy and force field
196  IR_DISC_DOCK_RED_BUOY_FORCE_FIELD = 250, ///< Roomba Discovery dock: green
197  ///< buoy and force field
198  IR_DISC_DOCK_GREEN_BUOY_FORCE_FIELD = 246, ///< Roomba Discovery dock: green
199  ///< buoy and force field.
200  IR_DISC_DOCK_RED_GREEN_BUOY_FORCE_FIELD = 254, ///< Roomba Discovery dock: red
201  ///< and green buoy and force field
202  IR_DOCK_RESERVED = 160, ///< Roomba 500 dock: reserved
203  IR_DOCK_RED_BUOY = 168, ///< Roomba 500 dock: red buoy
204  IR_DOCK_GREEN_BUOY = 164, ///< Roomba 500 dock: green buoy
205  IR_DOCK_FORCE_FIELD = 161, ///< Roomba 500 dock: red and green buoy
206  IR_DOCK_RED_GREEN_BUOY = 172, ///< Roomba 500 dock: red buoy and force
207  ///< field
208  IR_DOCK_RED_BUOY_FORCE_FIELD = 169, ///< Roomba 500 dock: green buoy
209  ///< and force field
210  IR_DOCK_GREEN_BUOY_FORCE_FIELD = 165, ///< Roomba 500 dock: green buoy
211  ///< and force field.
212  IR_DOCK_RED_GREEN_BUOY_FORCE_FIELD = 173, ///< Roomba 500 dock: red and
213  ///< green buoy and force field.
214  IR_VIRTUAL_WALL = 162 ///< IR Virtual Wall
216 
217  /** Days for scheduler. */
218  typedef enum {
219  DAY_SUNDAY = 0, ///< Sunday.
220  DAY_MONDAY = 1, ///< Monday.
221  DAY_TUESDAY = 2, ///< Tuesday.
222  DAY_WEDNESDAY = 3, ///< Wednesday.
223  DAY_THURSDAY = 4, ///< Thursday.
224  DAY_FRIDAY = 5, ///< Friday.
225  DAY_SATURDAY = 6 ///< Saturday.
226  } ScheduleDay;
227 
228  /** Turning direction. */
229  typedef enum {
230  TURN_CLOCKWISE, ///< Clockwise turning.
231  TURN_COUNTER_CLOCKWISE ///< Counter-Clockwise turning.
232  } TurnDirection;
233 
234  static const unsigned char BUTTON_CLEAN; ///< Cleaning button.
235  static const unsigned char BUTTON_SPOT; ///< Spot cleaning button.
236  static const unsigned char BUTTON_DOCK; ///< Dock button.
237  static const unsigned char BUTTON_MINUTE; ///< Minute button.
238  static const unsigned char BUTTON_HOUR; ///< Hour button.
239  static const unsigned char BUTTON_DAY; ///< Day button.
240  static const unsigned char BUTTON_SCHEDULE; ///< Schedule button.
241  static const unsigned char BUTTON_CLOCK; ///< Clock button.
242 
243  static const unsigned char WHEEL_DROP_LEFT; ///< Left wheel drop bit.
244  static const unsigned char WHEEL_DROP_RIGHT; ///< Right wheel drop bit.
245  static const unsigned char BUMP_LEFT; ///< Left bumper bit.
246  static const unsigned char BUMP_RIGHT; ///< Right bumper bit.
247 
248  static const unsigned char OVERCURRENT_WHEEL_LEFT; ///< Left wheel bit.
249  static const unsigned char OVERCURRENT_WHEEL_RIGHT; ///< Right wheel bit.
250  static const unsigned char OVERCURRENT_MAIN_BRUSH; ///< Main brush bit.
251  static const unsigned char OVERCURRENT_SIDE_BRUSH; ///< Side brush bit.
252 
253  static const unsigned char CHARGING_SOURCE_HOME_BASE; ///< Docking station.
254  static const unsigned char CHARGING_SOURCE_INTERNAL; ///< Internal socket.
255 
256  static const unsigned char BUMPER_LEFT; ///< Left bumper.
257  static const unsigned char BUMPER_FRONT_LEFT; ///< Front left bumper.
258  static const unsigned char BUMPER_CENTER_LEFT; ///< Center left bumper.
259  static const unsigned char BUMPER_CENTER_RIGHT; ///< Center right bumper.
260  static const unsigned char BUMPER_FRONT_RIGHT; ///< Front right bumper.
261  static const unsigned char BUMPER_RIGHT; ///< Right bumper.
262 
263  static const unsigned char LED_DEBRIS; ///< Debris LED bit.
264  static const unsigned char LED_SPOT; ///< Spot LED bit.
265  static const unsigned char LED_DOCK; ///< Dock LED bit.
266  static const unsigned char LED_CHECK_ROBOT; ///< Check robot LED bit.
267 
268  static const unsigned char WEEKDAY_LED_SUN; ///< Sunday.
269  static const unsigned char WEEKDAY_LED_MON; ///< Monday.
270  static const unsigned char WEEKDAY_LED_TUE; ///< Tuesday.
271  static const unsigned char WEEKDAY_LED_WED; ///< Wednesday.
272  static const unsigned char WEEKDAY_LED_THU; ///< Thursday.
273  static const unsigned char WEEKDAY_LED_FRI; ///< Friday.
274  static const unsigned char WEEKDAY_LED_SAT; ///< Saturday.
275 
276  static const unsigned char SCHEDULING_LED_COLON; ///< Colon LED bit.
277  static const unsigned char SCHEDULING_LED_PM; ///< PM LED bit.
278  static const unsigned char SCHEDULING_LED_AM; ///< AM LED bit.
279  static const unsigned char SCHEDULING_LED_CLOCK; ///< Clock LED bit.
280  static const unsigned char SCHEDULING_LED_SCHEDULE; ///< Schedule LED bit.
281 
282  static const unsigned char DIGIT_LED_NORTH; ///< Top segment LED.
283  static const unsigned char DIGIT_LED_NORTH_WEST; ///< Top left segment LED.
284  static const unsigned char DIGIT_LED_NORTH_EAST; ///< Top right segment LED.
285  static const unsigned char DIGIT_LED_CENTER; ///< Center segment LED.
286  static const unsigned char DIGIT_LED_SOUTH_WEST; ///< Bottom left segment.
287  static const unsigned char DIGIT_LED_SOUTH_EAST; ///< Bottom right segment.
288  static const unsigned char DIGIT_LED_SOUTH; ///< Bottom segment LED.
289 
290  static const unsigned char MOTOR_SIDE_BRUSH; ///< Side brush motor bit.
291  static const unsigned char MOTOR_VACUUM; ///< Vacuum motor bit.
292  static const unsigned char MOTOR_MAIN_BRUSHES; ///< Main brush motor bit.
293  static const unsigned char MOTOR_SIDE_BRUSH_BACKWARD; ///< Side backward bit.
294  static const unsigned char MOTOR_MAIN_BRUSHES_BACKWARD; ///< Main backward bit.
295 
296  static const unsigned char CHARGER_HOME_BASE; ///< Home base charger bit.
297  static const unsigned char CHARGER_INTERNAL; ///< Internal charger bit.
298 
299 
300  /// @cond OBVIOUS
301  static const unsigned short int SENSPACK_SIZE_GROUP_0;
302  static const unsigned short int SENSPACK_SIZE_GROUP_1;
303  static const unsigned short int SENSPACK_SIZE_GROUP_2;
304  static const unsigned short int SENSPACK_SIZE_GROUP_3;
305  static const unsigned short int SENSPACK_SIZE_GROUP_4;
306  static const unsigned short int SENSPACK_SIZE_GROUP_5;
307  static const unsigned short int SENSPACK_SIZE_GROUP_6;
308  static const unsigned short int SENSPACK_SIZE_GROUP_ALL;
309  static const unsigned short int SENSPACK_SIZE_GROUP_101;
310  static const unsigned short int SENSPACK_SIZE_GROUP_106;
311  static const unsigned short int SENSPACK_SIZE_GROUP_107;
312  static const unsigned short int SENSPACK_SIZE_BUMPS_DROPS;
313  static const unsigned short int SENSPACK_SIZE_WALL;
314  static const unsigned short int SENSPACK_SIZE_CLIFF_LEFT;
315  static const unsigned short int SENSPACK_SIZE_CLIFF_FRONT_LEFT;
316  static const unsigned short int SENSPACK_SIZE_CLIFF_FRONT_RIGHT;
317  static const unsigned short int SENSPACK_SIZE_CLIFF_RIGHT;
318  static const unsigned short int SENSPACK_SIZE_VIRTUAL_WALL;
319  static const unsigned short int SENSPACK_SIZE_WHEEL_OVERCURRENTS;
320  static const unsigned short int SENSPACK_SIZE_DIRT_DETECT;
321  static const unsigned short int SENSPACK_SIZE_IR_CHAR_OMNI;
322  static const unsigned short int SENSPACK_SIZE_IR_CHAR_LEFT;
323  static const unsigned short int SENSPACK_SIZE_IR_CHAR_RIGHT;
324  static const unsigned short int SENSPACK_SIZE_BUTTONS;
325  static const unsigned short int SENSPACK_SIZE_DISTANCE;
326  static const unsigned short int SENSPACK_SIZE_ANGLE;
327  static const unsigned short int SENSPACK_SIZE_CHARGING_STATE;
328  static const unsigned short int SENSPACK_SIZE_VOLTAGE;
329  static const unsigned short int SENSPACK_SIZE_CURRENT;
330  static const unsigned short int SENSPACK_SIZE_TEMPERATURE;
331  static const unsigned short int SENSPACK_SIZE_BATTERY_CHARGE;
332  static const unsigned short int SENSPACK_SIZE_BATTERY_CAPACITY;
333  static const unsigned short int SENSPACK_SIZE_WALL_SIGNAL;
334  static const unsigned short int SENSPACK_SIZE_CLIFF_LEFT_SIGNAL;
335  static const unsigned short int SENSPACK_SIZE_CLIFF_FRONT_LEFT_SIGNAL;
336  static const unsigned short int SENSPACK_SIZE_CLIFF_FRONT_RIGHT_SIGNAL;
337  static const unsigned short int SENSPACK_SIZE_CLIFF_RIGHT_SIGNAL;
338  static const unsigned short int SENSPACK_SIZE_CHARGE_SOURCES;
339  static const unsigned short int SENSPACK_SIZE_OI_MODE;
340  static const unsigned short int SENSPACK_SIZE_SONG_NUMBER;
341  static const unsigned short int SENSPACK_SIZE_SONG_PLAYING;
342  static const unsigned short int SENSPACK_SIZE_STREAM_PACKETS;
343  static const unsigned short int SENSPACK_SIZE_REQ_VELOCITY;
344  static const unsigned short int SENSPACK_SIZE_REQ_RADIUS;
345  static const unsigned short int SENSPACK_SIZE_REQ_RIGHT_VELOCITY;
346  static const unsigned short int SENSPACK_SIZE_REQ_LEFT_VELOCITY;
347  static const unsigned short int SENSPACK_SIZE_RIGHT_ENCODER;
348  static const unsigned short int SENSPACK_SIZE_LEFT_ENCODER;
349  static const unsigned short int SENSPACK_SIZE_LIGHT_BUMPER;
350  static const unsigned short int SENSPACK_SIZE_LIGHT_BUMPER_LEFT;
351  static const unsigned short int SENSPACK_SIZE_LIGHT_BUMPER_FRONT_LEFT;
352  static const unsigned short int SENSPACK_SIZE_LIGHT_BUMPER_CENTER_LEFT;
353  static const unsigned short int SENSPACK_SIZE_LIGHT_BUMPER_CENTER_RIGHT;
354  static const unsigned short int SENSPACK_SIZE_LIGHT_BUMPER_FRONT_RIGHT;
355  static const unsigned short int SENSPACK_SIZE_LIGHT_BUMPER_RIGHT;
356  static const unsigned short int SENSPACK_SIZE_LEFT_MOTOR_CURRENT;
357  static const unsigned short int SENSPACK_SIZE_RIGHT_MOTOR_CURRENT;
358  static const unsigned short int SENSPACK_SIZE_BRUSH_MOTOR_CURRENT;
359  static const unsigned short int SENSPACK_SIZE_SIDE_BRUSH_MOTOR_CURRENT;
360  static const unsigned short int SENSPACK_SIZE_STASIS;
361  /// @endcond
362 
363  static const float DIAMETER; ///< Robot diameter.
364  static const float BUMPER_X_OFFSET; ///< X Offset of bumper.
365  static const float AXLE_LENGTH; ///< Axle length.
366 
367  static const short int MAX_LIN_VEL_MM_S; ///< Maximum linear velocity.
368  static const short int MAX_RADIUS_MM; ///< Maximum drive radius.
369 
370  static const short int MAX_PWM; ///< Maximum PWM value for wheels.
371  static const unsigned short int MAX_ENCODER_COUNT; ///< Maximum encoder count.
372  static const unsigned short int STREAM_INTERVAL_MS; ///< Time in ms between
373  ///< streamed sensor packets.
374  static const unsigned short int MODE_CHANGE_WAIT_MS; ///< Time in ms to wait
375  ///< after mode changes
376 
377  static const unsigned char CHECKSUM_SIZE; ///< Checksum byte size.
378 
379 #pragma pack(push,1)
380  /** Struct for packet group with everything (SENSPACK_GROUP_ALL). */
381  typedef struct {
382  uint8_t bumps_wheeldrops; ///< Bumps and wheeldrops bits.
383  uint8_t wall; ///< Wall sensor value.
384  uint8_t cliff_left; ///< Left cliff sensor.
385  uint8_t cliff_front_left; ///< Front left cliff sensor.
386  uint8_t cliff_front_right; ///< Front right cliff sensor.
387  uint8_t cliff_right; ///< Right cliff sensor.
388  uint8_t virtual_wall; ///< Wall sensor.
389  uint8_t overcurrents; ///< Overcurrents bits.
390  uint8_t dirt_detect; ///< Dirt detect sensor.
391  uint8_t unused_1; ///< Unused byte.
392  uint8_t ir_opcode_omni; ///< Omni IR receiver character.
393  uint8_t buttons; ///< Buttons bits.
394  int16_t distance; ///< Traveled distance in mm.
395  int16_t angle; ///< Turned angle in degree.
396  uint8_t charging_state; ///< Charging state.
397  uint16_t voltage; ///< Voltage in mV.
398  int16_t current; ///< Current in mA.
399  int8_t temperature; ///< Temperature in deg C.
400  uint16_t battery_charge; ///< Battery charge in mAh.
401  uint16_t battery_capacity; ///< Battery capacity in mAh.
402  uint16_t wall_signal; ///< Raw wall signal.
403  uint16_t cliff_left_signal; ///< Raw left cliff signal.
404  uint16_t cliff_front_left_signal; ///< Raw front left cliff signal.
405  uint16_t cliff_front_right_signal; ///< Raw front right cliff signal.
406  uint16_t cliff_right_signal; ///< Raw right cliff signal.
407  uint8_t unused_2; ///< Unused byte.
408  uint16_t unused_3; ///< Unused byte.
409  uint8_t charger_available; ///< Available chargers bits.
410  uint8_t mode; ///< Open Interface mode.
411  uint8_t song_number; ///< Song number.
412  uint8_t song_playing; ///< Song playing byte.
413  uint8_t stream_num_packets; ///< Number of streamed packets.
414  int16_t velocity; ///< Velocity in mm/sec.
415  int16_t radius; ///< Radius in mm.
416  int16_t velocity_right; ///< Velocity of right wheel in mm/sec.
417  int16_t velocity_left; ///< Velocity of left wheel in mm/sec.
418  uint16_t encoder_counts_left; ///< Encoder counts for left wheel.
419  uint16_t encoder_counts_right; ///< Encoder counts for right wheel.
420  uint8_t light_bumper; ///< Light bumper bits.
421  uint16_t light_bump_left; ///< Raw left light bumper signal.
422  uint16_t light_bump_front_left; ///< Raw front left light bumper signal.
423  uint16_t light_bump_center_left; ///< Raw center left light bumper signal.
424  uint16_t light_bump_center_right; ///< Raw center right light bumper signal.
425  uint16_t light_bump_front_right; ///< Raw front right light bumper signal.
426  uint16_t light_bump_right; ///< Raw right light bumper signal.
427  uint8_t ir_opcode_left; ///< Left IR receiver character.
428  uint8_t ir_opcode_right; ///< Right IR receiver character.
429  int16_t left_motor_current; ///< Raw left motor current signal.
430  int16_t right_motor_current; ///< Raw right motor current signal.
431  int16_t main_brush_current; ///< Raw main brush motor current signal.
432  int16_t side_brush_current; ///< Raw side brush motor current signal.
433  uint8_t stasis; ///< Castor stasis.
435 #pragma pack(pop)
436 
437  public:
438  Roomba500(ConnectionType conntype, const char *device, unsigned int flags = 0);
439  ~Roomba500();
440 
441  void open();
442  void close();
443 
444  /** Check if connection has been established.
445  * @return true if connection has been established, false otherwise. */
446  bool is_connected() const { return (__fd != -1); }
447 
448  /** Get connection type.
449  * @return connection type */
450  ConnectionType get_connection_type() const { return __conntype; }
451  /** Get device string.
452  * @return device string */
453  const char * get_device() const { return __device; }
454 
455  /** Get current mode.
456  * @return current mode. */
457  Mode get_mode() const { return __mode; }
458 
459  /** Check if robot is being controlled.
460  * @return true if robot is being controlled, false otherwise. */
461  bool is_controlled() const
462  { return is_connected() && ( (__mode == MODE_SAFE) || (__mode == MODE_FULL) ); }
463 
464  void set_mode(Mode mode);
465  void clean();
466  void clean_spot();
467  void seek_dock();
468  void power_down();
469  void stop();
470  void drive_straight(short int velo_mm_per_sec);
471  void drive_turn(TurnDirection direction);
472  void drive_arc(short int velo_mm_per_sec, short int radius_mm);
473  void drive(short int velocity_mm_per_sec, short int radius_mm);
474  void drive_direct(short int left_mm_per_sec, short int right_mm_per_sec);
475  void drive_pwm(short int left_wheel_pwm, short int right_wheel_pwm);
476  void set_motors(bool main = true, bool side = true, bool vacuum = true,
477  bool main_backward = false, bool side_backward = false);
478  void set_leds(bool debris, bool spot, bool dock, bool check_robot,
479  unsigned char clean_color, unsigned char clean_intensity);
480 
481  void set_digit_leds(const char digits[4]);
482 
483  void enable_sensors();
484  void disable_sensors();
485  bool is_data_available();
486  void read_sensors();
487  void query_sensors();
488  /** Check if sensor packet is availabe.
489  * @return true if sensor packet is available, false otherwise
490  */
491  bool has_sensor_packet() const
492  { return __sensor_packet_received; };
493  const SensorPacketGroupAll get_sensor_packet() const;
494 
495  void play_fanfare();
496 
497  static unsigned short int get_packet_size(SensorPacketID packet);
498 
499  private:
500  void send(OpCode opcode,
501  const void *params = NULL, const size_t plength = 0);
502  void recv(size_t index, size_t num_bytes, unsigned int timeout_ms = 0);
503 
504  void assert_control()
505  {
506  if ((__mode != MODE_FULL) && (__mode != MODE_SAFE)) {
507  throw fawkes::Exception("Command only available in FULL or SAFE mode.");
508  }
509  }
510  void assert_connected()
511  { if (__mode == MODE_OFF) throw fawkes::Exception("Not connected to robot."); }
512 
513  private:
514  ConnectionType __conntype;
515  unsigned int __conn_flags;
516 
517  Mode __mode;
518  SensorPacketID __packet_id;
519  unsigned char __packet_reply_id;
520  unsigned short __packet_length;
521  bool __sensors_enabled;
522  SensorPacketGroupAll __sensor_packet;
523  bool __sensor_packet_received;
524  fawkes::Mutex *__sensor_mutex;
525 
526  char *__device;
527  int __fd;
528  fawkes::Mutex *__read_mutex;
529  fawkes::Mutex *__write_mutex;
530 
531  unsigned char __obuffer[16];
532  unsigned char __ibuffer[82];
533 
534  int __obuffer_length;
535  int __ibuffer_length;
536 };
537 
538 #endif
uint8_t cliff_front_left
Front left cliff sensor.
Definition: roomba_500.h:385
static const unsigned short int STREAM_INTERVAL_MS
Time in ms between.
Definition: roomba_500.h:372
static const unsigned char MOTOR_SIDE_BRUSH
Side brush motor bit.
Definition: roomba_500.h:290
ScheduleDay
Days for scheduler.
Definition: roomba_500.h:218
bool has_sensor_packet() const
Check if sensor packet is availabe.
Definition: roomba_500.h:491
static const unsigned char CHARGER_HOME_BASE
Home base charger bit.
Definition: roomba_500.h:296
static const unsigned char OVERCURRENT_WHEEL_RIGHT
Right wheel bit.
Definition: roomba_500.h:249
static const unsigned char CHARGING_SOURCE_INTERNAL
Internal socket.
Definition: roomba_500.h:254
uint8_t stasis
Castor stasis.
Definition: roomba_500.h:433
uint8_t cliff_front_right
Front right cliff sensor.
Definition: roomba_500.h:386
bool is_controlled() const
Check if robot is being controlled.
Definition: roomba_500.h:461
static const short int MAX_LIN_VEL_MM_S
Maximum linear velocity.
Definition: roomba_500.h:367
static const unsigned char BUMPER_CENTER_RIGHT
Center right bumper.
Definition: roomba_500.h:259
static const unsigned char WEEKDAY_LED_THU
Thursday.
Definition: roomba_500.h:272
static const unsigned char WHEEL_DROP_RIGHT
Right wheel drop bit.
Definition: roomba_500.h:244
uint8_t overcurrents
Overcurrents bits.
Definition: roomba_500.h:389
static const unsigned char BUTTON_DAY
Day button.
Definition: roomba_500.h:239
static const unsigned char WHEEL_DROP_LEFT
Left wheel drop bit.
Definition: roomba_500.h:243
static const unsigned short int MODE_CHANGE_WAIT_MS
Time in ms to wait after mode changes.
Definition: roomba_500.h:374
static const short int MAX_RADIUS_MM
Maximum drive radius.
Definition: roomba_500.h:368
static const unsigned char CHECKSUM_SIZE
Checksum byte size.
Definition: roomba_500.h:377
static const short int MAX_PWM
Maximum PWM value for wheels.
Definition: roomba_500.h:370
int16_t velocity_left
Velocity of left wheel in mm/sec.
Definition: roomba_500.h:417
static const unsigned char LED_DEBRIS
Debris LED bit.
Definition: roomba_500.h:263
static const float DIAMETER
Robot diameter.
Definition: roomba_500.h:363
Fawkes library namespace.
const char * get_device() const
Get device string.
Definition: roomba_500.h:453
uint8_t unused_1
Unused byte.
Definition: roomba_500.h:391
int16_t angle
Turned angle in degree.
Definition: roomba_500.h:395
static const unsigned char LED_SPOT
Spot LED bit.
Definition: roomba_500.h:264
uint8_t mode
Open Interface mode.
Definition: roomba_500.h:410
static const float BUMPER_X_OFFSET
X Offset of bumper.
Definition: roomba_500.h:364
uint16_t battery_capacity
Battery capacity in mAh.
Definition: roomba_500.h:401
static const unsigned char BUTTON_CLEAN
Cleaning button.
Definition: roomba_500.h:234
static const unsigned char SCHEDULING_LED_PM
PM LED bit.
Definition: roomba_500.h:277
int16_t radius
Radius in mm.
Definition: roomba_500.h:415
static const unsigned char DIGIT_LED_NORTH_EAST
Top right segment LED.
Definition: roomba_500.h:284
static const unsigned char BUTTON_DOCK
Dock button.
Definition: roomba_500.h:236
uint8_t stream_num_packets
Number of streamed packets.
Definition: roomba_500.h:413
static const unsigned char BUTTON_HOUR
Hour button.
Definition: roomba_500.h:238
static const unsigned char BUMPER_LEFT
Left bumper.
Definition: roomba_500.h:256
static const unsigned char MOTOR_SIDE_BRUSH_BACKWARD
Side backward bit.
Definition: roomba_500.h:293
static const unsigned char DIGIT_LED_NORTH_WEST
Top left segment LED.
Definition: roomba_500.h:283
static const unsigned char BUMPER_FRONT_LEFT
Front left bumper.
Definition: roomba_500.h:257
Use serial connection (device file).
Definition: roomba_500.h:39
uint16_t encoder_counts_left
Encoder counts for left wheel.
Definition: roomba_500.h:418
static const unsigned char SCHEDULING_LED_AM
AM LED bit.
Definition: roomba_500.h:278
uint8_t ir_opcode_left
Left IR receiver character.
Definition: roomba_500.h:427
uint8_t ir_opcode_omni
Omni IR receiver character.
Definition: roomba_500.h:392
static const unsigned char DIGIT_LED_SOUTH_EAST
Bottom right segment.
Definition: roomba_500.h:287
int16_t current
Current in mA.
Definition: roomba_500.h:398
static const unsigned char LED_CHECK_ROBOT
Check robot LED bit.
Definition: roomba_500.h:266
int16_t right_motor_current
Raw right motor current signal.
Definition: roomba_500.h:430
Mode get_mode() const
Get current mode.
Definition: roomba_500.h:457
uint16_t light_bump_front_right
Raw front right light bumper signal.
Definition: roomba_500.h:425
static const unsigned char LED_DOCK
Dock LED bit.
Definition: roomba_500.h:265
uint8_t cliff_left
Left cliff sensor.
Definition: roomba_500.h:384
Mode
Roomba 500 operation mode.
Definition: roomba_500.h:148
static const unsigned short int MAX_ENCODER_COUNT
Maximum encoder count.
Definition: roomba_500.h:371
uint16_t light_bump_center_left
Raw center left light bumper signal.
Definition: roomba_500.h:423
uint8_t virtual_wall
Wall sensor.
Definition: roomba_500.h:388
static const unsigned char SCHEDULING_LED_SCHEDULE
Schedule LED bit.
Definition: roomba_500.h:280
static const unsigned char BUMPER_CENTER_LEFT
Center left bumper.
Definition: roomba_500.h:258
uint8_t song_number
Song number.
Definition: roomba_500.h:411
static const unsigned char BUTTON_SPOT
Spot cleaning button.
Definition: roomba_500.h:235
static const unsigned char OVERCURRENT_WHEEL_LEFT
Left wheel bit.
Definition: roomba_500.h:248
SensorPacketID
Roomba 500 sensor package IDs.
Definition: roomba_500.h:82
uint8_t light_bumper
Light bumper bits.
Definition: roomba_500.h:420
static const unsigned char MOTOR_MAIN_BRUSHES_BACKWARD
Main backward bit.
Definition: roomba_500.h:294
static const unsigned char CHARGER_INTERNAL
Internal charger bit.
Definition: roomba_500.h:297
uint16_t light_bump_right
Raw right light bumper signal.
Definition: roomba_500.h:426
static const unsigned char OVERCURRENT_MAIN_BRUSH
Main brush bit.
Definition: roomba_500.h:250
Base class for exceptions in Fawkes.
Definition: exception.h:36
ConnectionType
Connection type.
Definition: roomba_500.h:38
static const unsigned char DIGIT_LED_CENTER
Center segment LED.
Definition: roomba_500.h:285
static const unsigned char BUTTON_SCHEDULE
Schedule button.
Definition: roomba_500.h:240
bool is_connected() const
Check if connection has been established.
Definition: roomba_500.h:446
int16_t velocity
Velocity in mm/sec.
Definition: roomba_500.h:414
uint16_t light_bump_center_right
Raw center right light bumper signal.
Definition: roomba_500.h:424
static const unsigned char WEEKDAY_LED_FRI
Friday.
Definition: roomba_500.h:273
StreamState
Sensor stream state.
Definition: roomba_500.h:156
static const unsigned char BUTTON_CLOCK
Clock button.
Definition: roomba_500.h:241
static const unsigned char WEEKDAY_LED_SAT
Saturday.
Definition: roomba_500.h:274
uint8_t buttons
Buttons bits.
Definition: roomba_500.h:393
static const unsigned char BUTTON_MINUTE
Minute button.
Definition: roomba_500.h:237
uint8_t charging_state
Charging state.
Definition: roomba_500.h:396
int16_t left_motor_current
Raw left motor current signal.
Definition: roomba_500.h:429
int16_t main_brush_current
Raw main brush motor current signal.
Definition: roomba_500.h:431
uint16_t cliff_front_right_signal
Raw front right cliff signal.
Definition: roomba_500.h:405
static const unsigned char SCHEDULING_LED_CLOCK
Clock LED bit.
Definition: roomba_500.h:279
int16_t side_brush_current
Raw side brush motor current signal.
Definition: roomba_500.h:432
uint8_t unused_2
Unused byte.
Definition: roomba_500.h:407
static const unsigned char MOTOR_MAIN_BRUSHES
Main brush motor bit.
Definition: roomba_500.h:292
uint16_t light_bump_front_left
Raw front left light bumper signal.
Definition: roomba_500.h:422
ConnectionFlags
Connection flags.
Definition: roomba_500.h:45
static const unsigned char WEEKDAY_LED_TUE
Tuesday.
Definition: roomba_500.h:270
uint16_t battery_charge
Battery charge in mAh.
Definition: roomba_500.h:400
static const unsigned char OVERCURRENT_SIDE_BRUSH
Side brush bit.
Definition: roomba_500.h:251
uint16_t unused_3
Unused byte.
Definition: roomba_500.h:408
static const unsigned char WEEKDAY_LED_WED
Wednesday.
Definition: roomba_500.h:271
uint16_t cliff_right_signal
Raw right cliff signal.
Definition: roomba_500.h:406
static const unsigned char BUMPER_RIGHT
Right bumper.
Definition: roomba_500.h:261
uint16_t wall_signal
Raw wall signal.
Definition: roomba_500.h:402
int16_t velocity_right
Velocity of right wheel in mm/sec.
Definition: roomba_500.h:416
ConnectionType get_connection_type() const
Get connection type.
Definition: roomba_500.h:450
uint8_t charger_available
Available chargers bits.
Definition: roomba_500.h:409
static const unsigned char DIGIT_LED_SOUTH
Bottom segment LED.
Definition: roomba_500.h:288
uint8_t song_playing
Song playing byte.
Definition: roomba_500.h:412
uint8_t wall
Wall sensor value.
Definition: roomba_500.h:383
uint8_t cliff_right
Right cliff sensor.
Definition: roomba_500.h:387
static const unsigned char WEEKDAY_LED_MON
Monday.
Definition: roomba_500.h:269
ChargingState
Charging state.
Definition: roomba_500.h:162
int16_t distance
Traveled distance in mm.
Definition: roomba_500.h:394
uint16_t cliff_left_signal
Raw left cliff signal.
Definition: roomba_500.h:403
static const unsigned char DIGIT_LED_NORTH
Top segment LED.
Definition: roomba_500.h:282
uint8_t bumps_wheeldrops
Bumps and wheeldrops bits.
Definition: roomba_500.h:382
InfraredCharacter
Infrared character values.
Definition: roomba_500.h:172
Clockwise turning.
Definition: roomba_500.h:230
Roomba 500 series communication class.
Definition: roomba_500.h:34
Struct for packet group with everything (SENSPACK_GROUP_ALL).
Definition: roomba_500.h:381
Mutex mutual exclusion lock.
Definition: mutex.h:32
static const unsigned char BUMP_RIGHT
Right bumper bit.
Definition: roomba_500.h:246
static const unsigned char CHARGING_SOURCE_HOME_BASE
Docking station.
Definition: roomba_500.h:253
uint16_t encoder_counts_right
Encoder counts for right wheel.
Definition: roomba_500.h:419
int8_t temperature
Temperature in deg C.
Definition: roomba_500.h:399
static const unsigned char BUMPER_FRONT_RIGHT
Front right bumper.
Definition: roomba_500.h:260
uint16_t light_bump_left
Raw left light bumper signal.
Definition: roomba_500.h:421
static const unsigned char MOTOR_VACUUM
Vacuum motor bit.
Definition: roomba_500.h:291
uint16_t voltage
Voltage in mV.
Definition: roomba_500.h:397
OpCode
Roomba 500 Command op codes.
Definition: roomba_500.h:50
static const unsigned char DIGIT_LED_SOUTH_WEST
Bottom left segment.
Definition: roomba_500.h:286
TurnDirection
Turning direction.
Definition: roomba_500.h:229
uint16_t cliff_front_left_signal
Raw front left cliff signal.
Definition: roomba_500.h:404
static const unsigned char SCHEDULING_LED_COLON
Colon LED bit.
Definition: roomba_500.h:276
static const unsigned char BUMP_LEFT
Left bumper bit.
Definition: roomba_500.h:245
static const unsigned char WEEKDAY_LED_SUN
Sunday.
Definition: roomba_500.h:268
uint8_t ir_opcode_right
Right IR receiver character.
Definition: roomba_500.h:428
uint8_t dirt_detect
Dirt detect sensor.
Definition: roomba_500.h:390
static const float AXLE_LENGTH
Axle length.
Definition: roomba_500.h:365