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 
#define PLAYER_MSG1(level, msg, a)
Definition: error.h:106
#define PLAYER_MSG3(level, msg, a, b, c)
Definition: error.h:108
static bool MatchMessage(player_msghdr_t *hdr, int type, int subtype, player_devaddr_t addr)
Helper for message processing.
Definition: message.h:159
Definition: roomba_comms.h:89
double ReadFloat(int section, const char *name, double value)
Read a floating point (double) value.
A pose in the plane.
Definition: player.h:218
Generic message header.
Definition: player.h:162
virtual int MainSetup(void)
Sets up the resources needed by the driver thread.
Definition: driver.h:658
virtual void MainQuit(void)
Cleanup method for driver thread (called when main exits)
Definition: driver.h:664
uint8_t type
Message type; must be one of PLAYER_MSGTYPE_*.
Definition: player.h:166
#define PLAYER_WARN3(msg, a, b, c)
Definition: error.h:92
Encapsulates a device (i.e., a driver bound to an interface)
Definition: device.h:75
const char * ReadString(int section, const char *name, const char *value)
Read a string value.
double pyaw
yaw [rad]
Definition: player.h:241
uint8_t subtype
Message subtype; interface specific.
Definition: player.h:168
double ReadTupleFloat(int section, const char *name, int index, double value)
Read a float (double) from a tuple field.
virtual void Main(void)=0
Main method for driver thread.
const char * ReadTupleString(int section, const char *name, int index, const char *value)
Read a string from a tuple field.
int ReadInt(int section, const char *name, int value)
Read an integer value.
#define PLAYER_MSGTYPE_DATA
A data message.
Definition: player.h:95
Request to get a double property.
Definition: player.h:470
#define PLAYER_MSGTYPE_RESP_ACK
A positive response message.
Definition: player.h:112
virtual int ProcessMessage(QueuePointer &resp_queue, player_msghdr *hdr, void *data)
Message handler.
bool ReadBool(int section, const char *name, bool value)
Read a boolean value (one of: yes, no, true, false, 1, 0)
#define PLAYER_MSGTYPE_REQ
A request message.
Definition: player.h:106
#define PLAYER_MSGTYPE_RESP_NACK
A negative response message.
Definition: player.h:125
int ReadDeviceAddr(player_devaddr_t *addr, int section, const char *name, int code, int index, const char *key)
Read a device id.
int GetTupleCount(int section, const char *name)
Get the number of values in a tuple.
Class for loading configuration file information.
Definition: configfile.h:197
virtual int Setup()
Initialize the driver.
Definition: driver.h:386
A device address.
Definition: player.h:146
An autopointer for the message queue.
Definition: message.h:74
Double property class.
Definition: property.h:143
#define PLAYER_ERROR1(msg, a)
Definition: error.h:82
char * key
The property key.
Definition: player.h:474
A pose in space.
Definition: player.h:229
#define PLAYER_ERROR(msg)
Definition: error.h:81
Base class for drivers which oeprate with a thread.
Definition: driver.h:553
#define PLAYER_GET_DBLPROP_REQ
Double property get request subtype.
Definition: player.h:434
uint32_t size
Size in bytes of the payload to follow.
Definition: player.h:174
#define PLAYER_WARN(msg)
Warning message macros.
Definition: error.h:89
#define PLAYER_MSGTYPE_CMD
A command message.
Definition: player.h:99
virtual int Shutdown()
Finalize the driver.
Definition: driver.h:393
Base class for all drivers.
Definition: driver.h:109
#define PLAYER_MSG0(level, msg)
General messages.
Definition: error.h:105
uint16_t index
Which device of that interface.
Definition: player.h:155
player_devaddr_t addr
Device to which this message pertains.
Definition: player.h:164
#define PLAYER_MSGQUEUE_DEFAULT_MAXLEN
Default maximum length for a message queue.
Definition: player.h:76
T max(T a, T b)
Return the maximum of a, b.
Definition: utility.h:104