create_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 CREATE_COMMS_H
24#define CREATE_COMMS_H
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30#include <limits.h>
31
32/* command opcodes */
33#define CREATE_OPCODE_START 128
34#define CREATE_OPCODE_BAUD 129
35#define CREATE_OPCODE_SAFE 131
36#define CREATE_OPCODE_FULL 132
37#define CREATE_OPCODE_SPOT 134
38#define CREATE_OPCODE_COVER 135
39#define CREATE_OPCODE_DEMO 136
40#define CREATE_OPCODE_DRIVE 137
41#define CREATE_OPCODE_MOTORS 138
42#define CREATE_OPCODE_LEDS 139
43#define CREATE_OPCODE_SONG 140
44#define CREATE_OPCODE_PLAY 141
45#define CREATE_OPCODE_SENSORS 142
46#define CREATE_OPCODE_COVERDOCK 143
47#define CREATE_OPCODE_PWM_MOTORS 144
48#define CREATE_OPCODE_DRIVE_WHEELS 145
49#define CREATE_OPCODE_DIGITAL_OUTPUTS 147
50#define CREATE_OPCODE_STREAM 148
51#define CREATE_OPCODE_QUERY_LIST 149
52#define CREATE_OPCODE_DO_STREAM 150
53#define CREATE_OPCODE_SEND_IR_CHAR 151
54#define CREATE_OPCODE_SCRIPT 152
55#define CREATE_OPCODE_PLAY_SCRIPT 153
56#define CREATE_OPCODE_SHOW_SCRIPT 154
57#define CREATE_OPCODE_WAIT_TIME 155
58#define CREATE_OPCODE_WAIT_DISTANCE 156
59#define CREATE_OPCODE_WAIT_ANGLE 157
60#define CREATE_OPCODE_WAIT_EVENT 158
61
62
63#define CREATE_DELAY_MODECHANGE_MS 20
64
65#define CREATE_MODE_OFF 0
66#define CREATE_MODE_PASSIVE 1
67#define CREATE_MODE_SAFE 2
68#define CREATE_MODE_FULL 3
69
70#define CREATE_TVEL_MAX_MM_S 500
71#define CREATE_RADIUS_MAX_MM 2000
72
73#define CREATE_SENSOR_PACKET_SIZE 26
74
75#define CREATE_CHARGING_NOT 0
76#define CREATE_CHARGING_RECOVERY 1
77#define CREATE_CHARGING_CHARGING 2
78#define CREATE_CHARGING_TRICKLE 3
79#define CREATE_CHARGING_WAITING 4
80#define CREATE_CHARGING_ERROR 5
81
82#define CREATE_AXLE_LENGTH 0.258
83
84#define CREATE_DIAMETER 0.33
85
86#define CREATE_BUMPER_XOFFSET 0.05
87
88#ifndef MIN
89 #define MIN(a,b) ((a < b) ? (a) : (b))
90#endif
91#ifndef MAX
92 #define MAX(a,b) ((a > b) ? (a) : (b))
93#endif
94#ifndef NORMALIZE
95 #define NORMALIZE(z) atan2(sin(z), cos(z))
96#endif
97
98typedef struct
99{
100 /* Serial port to which the robot is connected */
101 char serial_port[PATH_MAX];
102 /* File descriptor associated with serial connection (-1 if no valid
103 * connection) */
104 int fd;
105 /* Current operation mode; one of CREATE_MODE_* */
106 unsigned char mode;
107 /* Integrated odometric position [m m rad] */
108 double ox, oy, oa;
109
110 /* Various Boolean flags */
111 int bumper_left, bumper_right;
112 unsigned char wheeldrop_caster, wheeldrop_left, wheeldrop_right;
113 unsigned char wall;
114 unsigned char cliff_left, cliff_frontleft, cliff_frontright, cliff_right;
115 unsigned char virtual_wall;
116 unsigned char overcurrent_driveleft, overcurrent_driveright;
117 unsigned char overcurrent_mainbrush, overcurrent_sidebrush;
118 unsigned char overcurrent_vacuum;
119 unsigned char dirtdetector_right, dirtdetector_left;
120 unsigned char remote_opcode;
121 unsigned char button_power, button_spot, button_clean, button_max;
122
123 /* One of CREATE_CHARGING_* */
124 unsigned char charging_state;
125 /* Volts */
126 double voltage;
127 /* Amps */
128 double current;
129 /* degrees C */
130 double temperature;
131 /* Ah */
132 double charge;
133 /* Capacity */
134 double capacity;
136
137create_comm_t* create_create(const char* serial_port);
138void create_destroy(create_comm_t* r);
139int create_open(create_comm_t* r, unsigned char fullcontrol);
140int create_init(create_comm_t* r, unsigned char fullcontrol);
141int create_close(create_comm_t* r);
142int create_set_speeds(create_comm_t* r, double tv, double rv);
143int create_parse_sensor_packet(create_comm_t* r,
144 unsigned char* buf, size_t buflen);
145int create_get_sensors(create_comm_t* r, int timeout);
146void create_print(create_comm_t* r);
147
148int create_set_song(create_comm_t* r, unsigned char songNumber,
149 unsigned char songLength, unsigned char *notes,
150 unsigned char *noteLengths);
151int create_play_song(create_comm_t *r, unsigned char songNumber);
152
153int create_vacuum(create_comm_t *r, int state);
154int create_set_leds(create_comm_t *r, uint8_t dirt_detect, uint8_t max,
155 uint8_t clean, uint8_t spot, uint8_t status,
156 uint8_t power_color, uint8_t power_intensity );
157
158int create_run_demo(create_comm_t *r, uint8_t num);
159
160#ifdef __cplusplus
161}
162#endif
163
164#endif
165
Definition create_comms.h:99