-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathiRobotCreate2.h
More file actions
333 lines (304 loc) · 6.93 KB
/
iRobotCreate2.h
File metadata and controls
333 lines (304 loc) · 6.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
#ifndef IROBOTCREATE2_H
#define IROBOTCREATE2_H
// Arduino versioning.
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include "SoftwareSerial.h"
#define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
#define clamp(value, min, max) (value < min ? min : value > max ? max : value)
enum ScheduleDayOfWeek {
Sunday = 1,
Monday = 2,
Tuesday = 4,
Wednesday = 8,
Thursday = 16,
Friday = 32,
Saturday = 64
};
enum SetDayOfWeek {
Sun = 0,
Mon = 1,
Tues = 2,
Weds = 3,
Thurs = 4,
Fri = 5,
Sat = 6
};
enum iRobotButtons {
Clean = 1,
Spot = 2,
Dock = 4,
Minute = 8,
Hour = 16,
Day = 32,
Schedule = 64,
Clock = 128
};
struct Notes {
byte note;
byte duration;
};
enum Drive
{
DriveStraight = 0x8000,
DriveInPlaceClockwise = 0xFFFF,
DriveInPlaceCounterClockwise = 0x0001,
};
enum ChargeState
{
ChargeStateNotCharging = 0,
ChargeStateReconditioningCharging = 1,
ChargeStateFullChanrging = 2,
ChargeStateTrickleCharging = 3,
ChargeStateWaiting = 4,
ChargeStateFault = 5,
};
enum packetIds {
//all sent within packet 7, need to unpack byte upon retrival
rightBumper = 101,
leftBumper = 102,
rightWheelDrop = 103,
leftWheelDrop = 104,
//all sent within packet 14, need to unpack byte upon retrival
sideBrushOvercurrent = 105,
mainBrushOvercurrent = 106,
rightWheelOvercurrent = 107,
leftWheelOvercurrent = 108,
//all sent within packet 18, need to unpack byte upon retrival
cleanButton = 109,
spotButton = 110,
dockButton = 111,
minuteButton = 112,
hourButton = 113,
dayButton = 114,
scheduleButton = 115,
clockButton = 116,
//all sent within packet 45, need to unpack byte upon retrival
lightBumperLeft = 117,
lightBumperFrontLeft = 118,
lightBumperCenterLeft = 119,
lightBumperCenterRight = 120,
lightBumperFrontRight = 121,
lightBumperRight = 122,
//boolean values
wallSensor = 8,
leftCliff = 9,
frontLeftCliff = 10,
frontRightCliff = 11,
rightCliff = 12,
virtualWall = 13,
songPlaying = 37,
stasis = 58,
//byte values
dirtDetector = 15,
irOmnidirectional = 17,
irLeft = 52,
irRight = 53,
chargingState = 21, //0-5
chargingSources = 34, //0-3
operationalMode = 35, //0-3
songNumber = 36, //0-15
streamPackets = 38, //0-108
//char values
batteryTempInC = 24,
//int values
distanceTraveled = 19,
degreesTurned = 20,
currentFlow = 23,
wallSignal = 27, //0-1027
leftCliffSignal = 28, //0-4095
frontLeftCliffSignal = 29, //0-4095
frontRightCliffSignal = 30, //0-4095
rightCliffSignal = 31, //0-4095
requestedVelocity = 39, //-500 - 500
requestedRadius = 40,
requestedRightVelocity = 41, //-500 - 500
requestedLeftVelocity = 42, //-500 - 500
lightBumperLeftSignal = 46, //0-4095
lightBumperFrontLeftSignal = 47, //0-4095
lightBumperCenterLeftSignal = 48, //0-4095
lightBumperCenterRightSignal = 49, //0-4095
lightBumperFrontRightSignal = 50, //0-4095
lightBumperRightSignal = 51, //0-4095
leftMotorCurrent = 54,
rightMotorCurrent = 55,
mainBrushCurrent = 56,
sideBrushCurrent = 57,
//unsigned int values
batteryVoltage = 22,
batterCharge = 25,
batteryCapacity = 26,
leftEncoderCount = 43,
rightEncoderCount = 44
};
enum notes{
N_G1 = 31,
N_G1S = 32,
N_A1 = 33,
N_A1S = 34,
N_B1 = 35,
N_C1 = 36,
N_C1S = 37,
N_D1 = 38,
N_D1S = 39,
N_E1 = 40,
N_F1 = 41,
N_F1S = 42,
N_G2 = 43,
N_G2S = 44,
N_A2 = 45,
N_A2S = 46,
N_B2 = 47,
N_C2 = 48,
N_C2S = 49,
N_D2 = 50,
N_D2S = 51,
N_E2 = 52,
N_F2 = 53,
N_F2S = 54,
N_G3 = 55,
N_G3S = 56,
N_A3 = 57,
N_A3S = 58,
N_B3 = 59,
N_C3 = 60,
N_C3S = 61,
N_D3 = 62,
N_D3S = 63,
N_E3 = 64,
N_F3 = 65,
N_F3S = 66,
N_G4 = 67,
N_G4S = 68,
N_A4 = 69,
N_A4S = 70,
N_B4 = 71,
N_C4 = 72,
N_C4S = 73,
N_D4 = 74,
N_D4S = 75,
N_E4 = 76,
N_F4 = 77,
N_F4S = 78,
N_G5 = 79,
N_G5S = 80,
N_A5 = 81,
N_A5S = 82,
N_B5 = 83,
N_C5 = 84,
N_C5S = 85,
N_D5 = 86,
N_D5S = 87,
N_E5 = 88,
N_F5 = 89,
N_F5S = 90,
N_G6 = 91,
N_G6S = 92,
N_A6 = 93,
N_A6S = 94,
N_B6 = 95,
N_C6 = 96,
N_C6S = 97,
N_D6 = 98,
N_D6S = 99,
N_E6 = 100,
N_F6 = 101,
N_F6S = 102,
N_G7 = 103,
N_G7S = 104,
N_A7 = 105,
N_A7S = 106,
N_B7 = 107
};
class iRobotCreate2 {
public:
iRobotCreate2();
iRobotCreate2(bool useSoftSerial, byte rxPin, byte txPin, byte baudRateChangePin);
//available as passive safe or full modes
void start();
void reset();
void stop();
void resetBaudRate();
void baud(long rate);
void safeMode();
void fullMode();
void passiveMode();
void clean();
void maxClean();
void spotClean();
void seekDock();
void turnOff();
void schedule(byte days, byte hour[], byte minute[]);
void setTime(SetDayOfWeek day, byte hour, byte minute);
void pushButton(byte button);
void createSong(byte songNumber, byte numberOfNotes, Notes notes[]);
void playSong(byte songNumber);
//available is safe or full modes
//wheel motors
void drive(int velocity, int radius);
void driveWheels(int right, int left);
void driveLeft(int left);
void driveRight(int right);
void driveWheelsPWM(int rightPWM, int leftPWM);
void turnCW(unsigned short velocity,unsigned short degrees);
void turnCCW(unsigned short velocity, unsigned short degrees);
//cleaning motors
void enableBrushes(bool mainBrushDirection, bool sideBrushDirection, bool mainBrush, bool vacuum, bool sideBrush);
void setMainBrush(bool direction, bool enable);
void setSideBrush(bool direction, bool enable);
void enableVacuum(bool enable);
void setMainBrushSpeed(char speed);
void setSideBrushSpeed(char speed);
void setVaccumSpeed(char speed);
//leds
void setPowerLEDs(byte color, byte intensity);
void setDebrisLED(bool enable);
void setSpotLED(bool enable);
void setDockLED(bool enable);
void setWarningLED(bool enable);
void setScheduleLEDs(byte days, bool schedule, bool clock, bool am, bool pm, bool colon);
void setDigitLEDs(byte digit1, byte digit2, byte digit3, byte digit4);
void setDigitLEDFromASCII(byte digit, char letter);
//non blocking sensor functions
void requestSensorData(byte sensorID);
void requestSensorDataList(byte numOfRequests, byte requestIDs[]);
void beginDataStream(byte numOfRequests, byte requestIDs[]);
void pauseStream();
void resumeSteam();
//blocking sensor functions - these will request data and wait until a response is recieved, then return the response
int getSensorData(byte sensorID);
int * getSensorData(byte numOfRequests, byte requestIDs[]);
void decodeIR(byte value);
bool getSensorData(byte * buffer, byte bufferLength);
protected:
byte _color;
byte _intensity;
byte _brcPin;
bool _mainBrushDirection;
bool _sideBrushDirection;
bool _mainBrush;
bool _sideBrush;
bool _vacuum;
int _mainBrushSpeed;
int _sideBrushSpeed;
int _vacuumSpeed;
bool _debrisLED;
bool _spotLED;
bool _dockLED;
bool _warningLED;
bool _isPaused;
bool _isStreaming;
char _digit1;
char _digit2;
char _digit3;
char _digit4;
bool usingSoftSerial;
SoftwareSerial softSerial;
private:
byte single_byte_packets[22] = { 7, 8, 9, 10, 11, 12, 13, 14, 15, 17, 18, 21, 24, 34, 35, 36, 37, 38, 45, 52, 53, 58};
bool is_in_array(byte val);
};
#endif