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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 #ifndef MIN
76  #define MIN(a,b) ((a < b) ? (a) : (b))
77 #endif
78 #ifndef MAX
79  #define MAX(a,b) ((a > b) ? (a) : (b))
80 #endif
81 #ifndef NORMALIZE
82  #define NORMALIZE(z) atan2(sin(z), cos(z))
83 #endif
84 
85 typedef struct
86 {
87  /* Serial port to which the robot is connected */
88  char serial_port[PATH_MAX];
89  /* File descriptor associated with serial connection (-1 if no valid
90  * connection) */
91  int fd;
92  /* Current operation mode; one of ROOMBA_MODE_* */
93  unsigned char mode;
94  /* Integrated odometric position [m m rad] */
95  double ox, oy, oa;
96 
97  /* Various Boolean flags */
98  int bumper_left, bumper_right;
99  unsigned char wheeldrop_caster, wheeldrop_left, wheeldrop_right;
100  unsigned char wall;
101  unsigned char cliff_left, cliff_frontleft, cliff_frontright, cliff_right;
102  unsigned char virtual_wall;
103  unsigned char overcurrent_driveleft, overcurrent_driveright;
104  unsigned char overcurrent_mainbrush, overcurrent_sidebrush;
105  unsigned char overcurrent_vacuum;
106  unsigned char dirtdetector_right, dirtdetector_left;
107  unsigned char remote_opcode;
108  unsigned char button_power, button_spot, button_clean, button_max;
109 
110  /* One of ROOMBA_CHARGING_* */
111  unsigned char charging_state;
112  /* Volts */
113  double voltage;
114  /* Amps */
115  double current;
116  /* degrees C */
117  double temperature;
118  /* Ah */
119  double charge;
120  /* Capacity */
121  double capacity;
122 } roomba_comm_t;
123 
124 roomba_comm_t* roomba_create(const char* serial_port);
125 void roomba_destroy(roomba_comm_t* r);
126 int roomba_open(roomba_comm_t* r, unsigned char fullcontrol, int roomba500);
127 int roomba_init(roomba_comm_t* r, unsigned char fullcontrol);
128 int roomba_close(roomba_comm_t* r);
129 int roomba_set_speeds(roomba_comm_t* r, double tv, double rv);
130 int roomba_parse_sensor_packet(roomba_comm_t* r,
131  unsigned char* buf, size_t buflen);
132 int roomba_get_sensors(roomba_comm_t* r, int timeout);
133 void roomba_print(roomba_comm_t* r);
134 int roomba_clean(roomba_comm_t* r);
135 int roomba_forcedock(roomba_comm_t* r);
136 
137 int roomba_set_song(roomba_comm_t* r, unsigned char songNumber,
138  unsigned char songLength, unsigned char *notes,
139  unsigned char *noteLengths);
140 int roomba_play_song(roomba_comm_t *r, unsigned char songNumber);
141 
142 int roomba_vacuum(roomba_comm_t *r, int state);
143 int roomba_set_leds(roomba_comm_t *r, uint8_t dirt_detect, uint8_t max,
144  uint8_t clean, uint8_t spot, uint8_t status,
145  uint8_t power_color, uint8_t power_intensity );
146 
147 #ifdef __cplusplus
148 }
149 #endif
150 
151 #endif
152 

Last updated 12 September 2005 21:38:45