-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatbotics.h
354 lines (312 loc) · 9.06 KB
/
Matbotics.h
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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
/**
* @file
*
* @section desc File description
*
* Control Matrix Robotics System Motor & Servo controller with an Arduino board
*
* @section copyright Copyright
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; version 2
* of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @section infos File informations
*
* @date 2015/06/10
* @author Benjamin Sientzoff
* @version 0.2
*
*
* \page info Servos Control
*
* The Servo 1/2/3/4 speed bytes allow the rate, at which changes to the
* servo positions are made, to be controlled. If the value is set to zero,
* changes to the servo position is immediate. If the value is non-zero,
* changes will occur at a rate equal 10*value milliseconds per step.
* The angle range is from 0 to 250 corresponding of the pulse ariation (to set
* the angle) between 0.75ms and 2.25ms.
*
*/
#ifndef _MATBOTICS_H_
#define _MATBOTICS_H_
// matbotics address
#define CONTROLLER_ADDRESS 0x08
// register address to write in to control motors/servos
// for more details see MatriX Controller specification
// controller vars
/// controller firmware version
#define MTBS_VRS 0x00
/// controller manufacturer name
#define MTBS_MANU 0x08
/// controller type
#define MTBS_TYPE 0x10
/// controller status
#define MTBS_STATUS 0x41
/// set timeout
#define MTBS_TIME_OUT 0x42
/// get battery level
#define MTBS_BATT_LEVEL 0x43
/// set motors start flag ? (see doc)
#define MTBS_STRT_FLAG 0x44
// servos commands
#define MTBS_SERVOS_STATE 0x45
/**
* actived all servos
* Matrix Controller uses for bits to enable each one.
* SERVOS 1 2 3 4
* 0xF = 1 1 1 1
*/
#define MTBS_USE_ALL_SERVOS 0xF
// desactived all servos
#define MTBS_USE_NO_SERVO 0x0
// SERVO 1
#define MTBS_SRV1_SPEED 0x46
#define MTBS_SRV1_TRGT 0x47
// SERVO 2
#define MTBS_SRV2_SPEED 0x48
#define MTBS_SRV2_TRGT 0x49
// SERVO 3
#define MTBS_SRV3_SPEED 0x4A
#define MTBS_SRV3_TRGT 0x4B
// SERVO 4
#define MTBS_SRV4_SPEED 0x4C
#define MTBS_SRV4_TRGT 0x4D
// motors commands
// MOTOR 1
#define MTBS_MTR1_POS 0x4E
#define MTBS_MTR1_TRGT 0x52
#define MTBS_MTR1_SPEED 0x56
#define MTBS_MTR1_MODE 0x57
// MOTOR 2
#define MTBS_MTR2_POS 0x58
#define MTBS_MTR2_TRGT 0x5C
#define MTBS_MTR2_SPEED 0x60
#define MTBS_MTR2_MODE 0x61
// MOTOR 3
#define MTBS_MTR3_POS 0x62
#define MTBS_MTR3_TRGT 0x66
#define MTBS_MTR3_SPEED 0x6A
#define MTBS_MTR3_MODE 0x6B
// MOTOR 4
#define MTBS_MTR4_POS 0x6C
#define MTBS_MTR4_TRGT 0x70
#define MTBS_MTR4_SPEED 0x74
#define MTBS_MTR4_MODE 0x75
/**
* motor modes
* \todo read/set motor modes
*/
enum MTBS_MOTOR_MODES {
/// Float mode
MTBS_MTR_MODE_FLOAT = 0, // B00000000,
/// Brake mode
MTBS_MTR_MODE_BRAKE, // B00000001,
/// Speed mode
MTBS_MTR_MODE_SPEED, // B00000010,
/// Slew mode
MTBS_MTR_MODE_SLEW, // B00000011,
/// reset motor channel
MTBS_MTR_MODE_RESET // B00000100,
};
/**
* Controller status
*/
enum MTBS_STATUS_VALUES {
MTBS_STATUS_OK = 0,
MTBS_STATUS_FAULT, // fault status
MTBS_STATUS_LOWBATT // low battery
};
/**
* MTController
* object to encapsulate Matrix Robotic System controller control
*/
class MTController
{
public:
/**
* Create MTController object
*/
MTController();
/**
* Get the controller version manufacturer
* @return Controller version manufacturer
*/
String manufacturer();
/**
* Get the controller version type
* @return Controller version type
*/
String type();
/**
* Get the controller version number
* @return Controller version number
*/
String version();
/**
* Get battery level
* @return The Battery level returns the current battery voltage in volts.
*/
float batteryLevel();
/**
* Return the status of the box
* @return the status of the controller
*/
MTBS_STATUS_VALUES status();
/**
* Shut down motors and servos automaticcally within if no I2C transactions
* are received within the specified time, in the seconds
* @param time Amount of time to shut down automatically motors and
* servos in seconds. Zero (0) means no timeout.
*/
void timeout( int time );
/**
* enable servo motors
*/
void enableServos();
/**
* disable servos
*/
void disableServos();
/**
* Set speed of the servo one
* @param servo_speed the speed to set
*/
void servoOneSpeed( int servo_speed );
/**
* Set the angle of the servo one
* @param angle angle to reach
*/
void servoOneAngle( int angle );
/**
* Set speed of the servo two
* @param servo_speed the speed to set
*/
void servoTwoSpeed( int servo_speed );
/**
* Set the angle of the servo two
* @param angle angle to reach
*/
void servoTwoAngle( int angle );
/**
* Set speed of the servo three
* @param servo_speed the speed to set
*/
void servoThreeSpeed( int servo_speed );
/**
* Set the angle of the servo three
* @param angle angle to reach
*/
void servoThreeAngle( int angle );
/**
* Set speed of the servo four
* @param servo_speed the speed to set
*/
void servoFourSpeed( int servo_speed );
/**
* Set the angle of the servo four
* @param angle angle to reach
*/
void servoFourAngle( int angle );
/**
* Set the speed of the motor one, zero (0) causes the motor to stop.
* @param motor_speed The speed of the motor ( from -100 to 100 )
*/
void motorOneSpeed( int motor_speed );
/**
* get the position of the motor one
* @return Value of the current motor encoder value
*/
long motorOnePosition();
/**
* Set the position of the motor one encoder, if the motor is in *slew* mode.
* @param target Position to reach
*/
void motorOneReach( long target );
/**
* Set the motor one mode
* @param mode the mode for the motor one
*/
void motorOneMode( MTBS_MOTOR_MODES mode );
/**
* Set the speed of the motor two, zero (0) causes the motor to stop.
* @param motor_speed The speed of the motor ( from -100 to 100 )
*/
void motorTwoSpeed( int motor_speed );
/**
* get the position of the motor two
* @return Value of the current motor encoder value
*/
long motorTwoPosition();
/**
* Set the position of the motor two encoder, if the motor is in *slew* mode.
* @param target Position to reach
*/
void motorTwoReach( long target );
/**
* Set the motor two mode
* @param mode the mode for the motor two
*/
void motorTwoMode( MTBS_MOTOR_MODES mode );
/**
* Set the speed of the motor three, zero (0) causes the motor to stop.
* @param motor_speed The speed of the motor ( from -100 to 100 )
*/
void motorThreeSpeed( int motor_speed );
/**
* get the position of the motor three
* @return Value of the current motor encoder value
*/
long motorThreePosition();
/**
* Set the position of the motor three encoder, if the motor is in *slew*
* mode.
* @param target Position to reach
*/
void motorThreeReach( long target );
/**
* Set the motor three mode
* @param mode the mode for the motor three
*/
void motorThreeMode( MTBS_MOTOR_MODES mode );
/**
* Set the speed of the motor four, zero (0) causes the motor to stop.
* @param motor_speed The speed of the motor ( from -100 to 100 )
*/
void motorFourSpeed( int motor_speed );
/**
* get the position of the motor four
* @return Value of the current motor encoder
*/
long motorFourPosition();
/**
* Set the position of the motor four encoder, if the motor is in *slew* mode.
* @param target Position to reach
*/
void motorFourReach( long target );
/**
* Set the motor four mode
* @param mode the mode for the motor four
*/
void motorFourMode( MTBS_MOTOR_MODES mode );
private:
// controller manufacturer
char __manufacturer[9];
// controller type
char __type[9];
// Controller version number
char __vers_number[5];
uint8_t __battery_level;
MTBS_STATUS_VALUES __status;
};
#endif // _MATBOTICS_H_