roomba_comms.h
1 /*
2  * Player - One Hell of a Robot Server
3  * Copyright (C) 2006 -
4  * Brian Gerkey
5  *
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  *
21  */
22 
23 #ifndef ROOMBA_COMMS_H
24 #define ROOMBA_COMMS_H
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 #include <limits.h>
31 
32 /* command opcodes */
33 #define ROOMBA_OPCODE_START 128
34 #define ROOMBA_OPCODE_BAUD 129
35 #define ROOMBA_OPCODE_CONTROL 130
36 #define ROOMBA_OPCODE_SAFE 131
37 #define ROOMBA_OPCODE_FULL 132
38 #define ROOMBA_OPCODE_POWER 133
39 #define ROOMBA_OPCODE_SPOT 134
40 #define ROOMBA_OPCODE_CLEAN 135
41 #define ROOMBA_OPCODE_MAX 136
42 #define ROOMBA_OPCODE_DRIVE 137
43 #define ROOMBA_OPCODE_MOTORS 138
44 #define ROOMBA_OPCODE_LEDS 139
45 #define ROOMBA_OPCODE_SONG 140
46 #define ROOMBA_OPCODE_PLAY 141
47 #define ROOMBA_OPCODE_SENSORS 142
48 #define ROOMBA_OPCODE_FORCEDOCK 143
49 
50 #define ROOMBA_DELAY_MODECHANGE_MS 20
51 
52 #define ROOMBA_MODE_OFF 0
53 #define ROOMBA_MODE_PASSIVE 1
54 #define ROOMBA_MODE_SAFE 2
55 #define ROOMBA_MODE_FULL 3
56 
57 #define ROOMBA_TVEL_MAX_MM_S 500
58 #define ROOMBA_RADIUS_MAX_MM 2000
59 
60 #define ROOMBA_SENSOR_PACKET_SIZE 26
61 
62 #define ROOMBA_CHARGING_NOT 0
63 #define ROOMBA_CHARGING_RECOVERY 1
64 #define ROOMBA_CHARGING_CHARGING 2
65 #define ROOMBA_CHARGING_TRICKLE 3
66 #define ROOMBA_CHARGING_WAITING 4
67 #define ROOMBA_CHARGING_ERROR 5
68 
69 #define ROOMBA_AXLE_LENGTH 0.258
70 
71 #define ROOMBA_DIAMETER 0.33
72 
73 #define ROOMBA_BUMPER_XOFFSET 0.05
74 
75 #define ROOMBA_DISCOVERY 0
76 #define ROOMBA_500 1
77 
78 #ifndef MIN
79  #define MIN(a,b) ((a < b) ? (a) : (b))
80 #endif
81 #ifndef MAX
82  #define MAX(a,b) ((a > b) ? (a) : (b))
83 #endif
84 #ifndef NORMALIZE
85  #define NORMALIZE(z) atan2(sin(z), cos(z))
86 #endif
87 
88 typedef struct
89 {
90  /* Serial port to which the robot is connected */
91  char serial_port[PATH_MAX];
92  /* File descriptor associated with serial connection (-1 if no valid
93  * connection) */
94  int fd;
95  /* Current operation mode; one of ROOMBA_MODE_* */
96  unsigned char mode;
97  /* Integrated odometric position [m m rad] */
98  double ox, oy, oa;
99  /* Roomba type (there are differences between roomba discovery & 500 interfaces) */
100  unsigned int roomba_type;
101 
102  /* Various Boolean flags */
103  int bumper_left, bumper_right;
104  unsigned char wheeldrop_caster, wheeldrop_left, wheeldrop_right;
105  unsigned char wall;
106  unsigned char cliff_left, cliff_frontleft, cliff_frontright, cliff_right;
107  unsigned char virtual_wall;
108  unsigned char overcurrent_driveleft, overcurrent_driveright;
109  unsigned char overcurrent_mainbrush, overcurrent_sidebrush;
110  unsigned char overcurrent_vacuum;
111  unsigned char dirtdetector_right, dirtdetector_left;
112  unsigned char remote_opcode;
113  unsigned char button_power, button_spot, button_clean, button_max;
114 
115  /* One of ROOMBA_CHARGING_* */
116  unsigned char charging_state;
117  /* Volts */
118  double voltage;
119  /* Amps */
120  double current;
121  /* degrees C */
122  double temperature;
123  /* Ah */
124  double charge;
125  /* Capacity */
126  double capacity;
127 } roomba_comm_t;
128 
129 roomba_comm_t* roomba_create(const char* serial_port, unsigned int roomba_type);
130 void roomba_destroy(roomba_comm_t* r);
131 int roomba_open(roomba_comm_t* r, unsigned char fullcontrol);
132 int roomba_init(roomba_comm_t* r, unsigned char fullcontrol);
133 int roomba_close(roomba_comm_t* r);
134 int roomba_set_speeds(roomba_comm_t* r, double tv, double rv);
135 int roomba_parse_sensor_packet(roomba_comm_t* r,
136  unsigned char* buf, size_t buflen);
137 int roomba_get_sensors(roomba_comm_t* r, int timeout);
138 void roomba_print(roomba_comm_t* r);
139 int roomba_clean(roomba_comm_t* r);
140 int roomba_forcedock(roomba_comm_t* r);
141 
142 int roomba_set_song(roomba_comm_t* r, unsigned char songNumber,
143  unsigned char songLength, unsigned char *notes,
144  unsigned char *noteLengths);
145 int roomba_play_song(roomba_comm_t *r, unsigned char songNumber);
146 
147 int roomba_vacuum(roomba_comm_t *r, int state);
148 int roomba_set_leds(roomba_comm_t *r, uint8_t dirt_detect, uint8_t max,
149  uint8_t clean, uint8_t spot, uint8_t status,
150  uint8_t power_color, uint8_t power_intensity );
151 
152 #ifdef __cplusplus
153 }
154 #endif
155 
156 #endif
157 
T max(T a, T b)
Return the maximum of a, b.
Definition: utility.h:104
Definition: roomba_comms.h:89