MatrixMiniR4 1.1.9
Matrix Mini R4 Arduino Library API Documentation
Loading...
Searching...
No Matches
MMLower.cpp
Go to the documentation of this file.
1
6#include "MMLower.h"
7#include "Util/BitConverter.h"
8
9MMLower::MMLower(uint8_t rx, uint8_t tx, uint32_t baudrate)
10 : _baudrate(baudrate)
11{
12 commSerial = new SoftwareSerial(rx, tx);
13}
14
15MMLower::RESULT MMLower::Init(uint32_t timeout_ms)
16{
17 MR4_DEBUG_PRINT_HEADER(F("[Init]"));
18
19 commSerial->begin(_baudrate, SERIAL_8N1);
20
21 delay(1000);
22
23 uint32_t asd = 0;
24
25 //asd = millis() + 5000;
26 while (asd < 50) {
27
28 RESULT result = EchoTest();
29 delay(250);
30 if (result == RESULT::OK) {
31 MR4_DEBUG_PRINT_TAIL(F("OK"));
32 return RESULT::OK;
33 } else {
34 MR4_DEBUG_PRINT(F("EchoTest Failed! Result: "));
35 MR4_DEBUG_PRINTLN((int)result);
36 }
37 asd++;
38 }
39
40 MR4_DEBUG_PRINT_TAIL(F("ERROR_INIT"));
41 return RESULT::ERROR_INIT;
42 //return RESULT::OK;
43}
44
46{
47 MR4_DEBUG_PRINT_HEADER(F("[SetDCMotorDir]"));
48
49 uint8_t data[2] = {(1 << --num), (uint8_t)dir};
50 CommSendData(COMM_CMD::SET_DC_MOTOR_DIR, data, 2);
51 if (!WaitData(COMM_CMD::SET_DC_MOTOR_DIR, 100)) {
52 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
54 }
55
56 uint8_t b[1];
57 if (!CommReadData(b, 1)) {
58 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
60 }
61
62 if (b[0] == 0x00) {
63 MR4_DEBUG_PRINT_TAIL(F("OK"));
64 return RESULT::OK;
65 }
66 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
67 return RESULT::ERROR;
68}
69
71{
72 MR4_DEBUG_PRINT_HEADER(F("[SetEncoderDir]"));
73
74 uint8_t data[2] = {(1 << --num), (uint8_t)dir};
75 CommSendData(COMM_CMD::SET_ENCODER_DIR, data, 2);
76 if (!WaitData(COMM_CMD::SET_ENCODER_DIR, 100)) {
77 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
79 }
80
81 uint8_t b[1];
82 if (!CommReadData(b, 1)) {
83 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
85 }
86
87 if (b[0] == 0x00) {
88 MR4_DEBUG_PRINT_TAIL(F("OK"));
89 return RESULT::OK;
90 }
91
92 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
93 return RESULT::ERROR;
94}
95
97{
98 MR4_DEBUG_PRINT_HEADER(F("[SetServoDir]"));
99
100 uint8_t data[2] = {(1 << --num), (uint8_t)dir};
101 CommSendData(COMM_CMD::SET_SERVO_DIR, data, 2);
102 if (!WaitData(COMM_CMD::SET_SERVO_DIR, 100)) {
103 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
105 }
106
107 uint8_t b[1];
108 if (!CommReadData(b, 1)) {
109 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
111 }
112
113 if (b[0] == 0x00) {
114 MR4_DEBUG_PRINT_TAIL(F("OK"));
115 return RESULT::OK;
116 }
117
118 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
119 return RESULT::ERROR;
120}
121
122MMLower::RESULT MMLower::SetDCMotorSpeedRange(uint8_t num, uint16_t min, uint16_t max)
123{
124 MR4_DEBUG_PRINT_HEADER(F("[SetDCMotorSpeedRange]"));
125
126 uint8_t data[5];
127 data[0] = (1 << --num);
128 BitConverter::GetBytes(data + 1, min);
129 BitConverter::GetBytes(data + 3, max);
130 CommSendData(COMM_CMD::SET_DC_MOTOR_SPEED_RANGE, data, 5);
131 if (!WaitData(COMM_CMD::SET_DC_MOTOR_SPEED_RANGE, 100)) {
132 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
134 }
135
136 uint8_t b[1];
137 if (!CommReadData(b, 1)) {
138 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
140 }
141
142 if (b[0] == 0x00) {
143 MR4_DEBUG_PRINT_TAIL(F("OK"));
144 return RESULT::OK;
145 }
146
147 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
148 return RESULT::ERROR;
149}
150
151MMLower::RESULT MMLower::SetServoPulseRange(uint8_t num, uint16_t min, uint16_t max)
152{
153 MR4_DEBUG_PRINT_HEADER(F("[SetServoPulseRange]"));
154
155 uint8_t data[5];
156 data[0] = (1 << --num);
157 BitConverter::GetBytes(data + 1, min);
158 BitConverter::GetBytes(data + 3, max);
159 CommSendData(COMM_CMD::SET_SERVO_PULSE_RANGE, data, 5);
160 if (!WaitData(COMM_CMD::SET_SERVO_PULSE_RANGE, 100)) {
161 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
163 }
164
165 uint8_t b[1];
166 if (!CommReadData(b, 1)) {
167 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
169 }
170
171 if (b[0] == 0x00) {
172 MR4_DEBUG_PRINT_TAIL(F("OK"));
173 return RESULT::OK;
174 }
175 if (b[0] == 0x02) {
176 MR4_DEBUG_PRINT_TAIL(F("ERROR_SERVO_MIN_PULSE"));
178 }
179 if (b[0] == 0x03) {
180 MR4_DEBUG_PRINT_TAIL(F("ERROR_SERVO_MAX_PULSE"));
182 }
183
184 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
185 return RESULT::ERROR;
186}
187
188MMLower::RESULT MMLower::SetServoAngleRange(uint8_t num, uint16_t min, uint16_t max)
189{
190 MR4_DEBUG_PRINT_HEADER(F("[SetServoAngleRange]"));
191
192 uint8_t data[5];
193 data[0] = (1 << --num);
194 BitConverter::GetBytes(data + 1, min);
195 BitConverter::GetBytes(data + 3, max);
196 CommSendData(COMM_CMD::SET_SERVO_ANGLE_RANGE, data, 5);
197 if (!WaitData(COMM_CMD::SET_SERVO_ANGLE_RANGE, 100)) {
198 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
200 }
201
202 uint8_t b[1];
203 if (!CommReadData(b, 1)) {
204 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
206 }
207
208 if (b[0] == 0x00) {
209 MR4_DEBUG_PRINT_TAIL(F("OK"));
210 return RESULT::OK;
211 }
212 if (b[0] == 0x02) {
213 MR4_DEBUG_PRINT_TAIL(F("ERROR_SERVO_MIN_ANGLE"));
215 }
216 if (b[0] == 0x03) {
217 MR4_DEBUG_PRINT_TAIL(F("ERROR_SERVO_MAX_ANGLE"));
219 }
220
221 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
222 return RESULT::ERROR;
223}
224
226{
227 MR4_DEBUG_PRINT_HEADER(F("[SetIMUEchoMode]"));
228
229 uint8_t data[3];
230 data[0] = (uint8_t)mode;
231 BitConverter::GetBytes(data + 1, echoIntervalMs);
232 CommSendData(COMM_CMD::SET_IMU_ECHO_MODE, data, 3);
233 if (!WaitData(COMM_CMD::SET_IMU_ECHO_MODE, 100)) {
234 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
236 }
237
238 uint8_t b[1];
239 if (!CommReadData(b, 1)) {
241 }
242
243 if (b[0] == 0x00) {
244 MR4_DEBUG_PRINT_TAIL(F("OK"));
245 return RESULT::OK;
246 }
247 if (b[0] == 0x02) {
248 MR4_DEBUG_PRINT_TAIL(F("ERROR_MODE"));
249 return RESULT::ERROR_MODE;
250 }
251 if (b[0] == 0x03) {
252 MR4_DEBUG_PRINT_TAIL(F("ERROR_INTERVAL"));
254 }
255
256 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
257 return RESULT::ERROR;
258}
259
261 IMU_ACC_FSR accFSR, IMU_GYRO_FSR gyroFSR, IMU_ODR odr, IMU_FIFO fifo)
262{
263 MR4_DEBUG_PRINT_HEADER(F("[SetIMUInit]"));
264
265 uint8_t data[4];
266 data[0] = (uint8_t)accFSR;
267 data[1] = (uint8_t)gyroFSR;
268 data[2] = (uint8_t)odr;
269 data[3] = (uint8_t)fifo;
270 CommSendData(COMM_CMD::SET_IMU_INIT, data, 4);
271 if (!WaitData(COMM_CMD::SET_IMU_INIT, 100)) {
272 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
274 }
275
276 uint8_t b[1];
277 if (!CommReadData(b, 1)) {
278 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
280 }
281
282 if (b[0] == 0x00) {
283 MR4_DEBUG_PRINT_TAIL(F("OK"));
284 return RESULT::OK;
285 }
286 if (b[0] == 0x02) {
287 MR4_DEBUG_PRINT_TAIL(F("ERROR_IMU_ACC_FSR"));
289 }
290 if (b[0] == 0x03) {
291 MR4_DEBUG_PRINT_TAIL(F("ERROR_IMU_GYRO_FSR"));
293 }
294 if (b[0] == 0x04) {
295 MR4_DEBUG_PRINT_TAIL(F("ERROR_IMU_ODR"));
297 }
298
299 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
300 return RESULT::ERROR;
301}
302
303MMLower::RESULT MMLower::SetPowerParam(float fullVolt, float cutOffVolt, float alarmVolt)
304{
305 MR4_DEBUG_PRINT_HEADER(F("[SetPowerParam]"));
306
307 uint8_t data[3];
308 data[0] = (uint8_t)(fullVolt * 10.0f);
309 data[1] = (uint8_t)(cutOffVolt * 10.0f);
310 data[2] = (uint8_t)(alarmVolt * 10.0f);
311 CommSendData(COMM_CMD::SET_POWER_PARAM, data, 3);
312 if (!WaitData(COMM_CMD::SET_POWER_PARAM, 100)) {
313 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
315 }
316
317 uint8_t b[1];
318 if (!CommReadData(b, 1, 5)) {
319 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
321 }
322 if (b[0] == 0x00) {
323 MR4_DEBUG_PRINT_TAIL(F("OK"));
324 return RESULT::OK;
325 }
326 if (b[0] == 0x02) {
327 MR4_DEBUG_PRINT_TAIL(F("ERROR_POWER_VOLT_RANGE"));
329 }
330
331 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
332 return RESULT::ERROR;
333}
334// Setting-Commonly used
335
336MMLower::RESULT MMLower::SetDCMotorPower(uint8_t num, int16_t power)
337{
338 MR4_DEBUG_PRINT_HEADER(F("[SetDCMotorPower]"));
339
340 uint8_t data[4];
341 data[0] = (1 << --num);
342 data[1] = 0; // Ma
343 BitConverter::GetBytes(data + 2, power);
344 CommSendData(COMM_CMD::SET_DC_MOTOR_POWER, data, 4);
345 if (!WaitData(COMM_CMD::SET_DC_MOTOR_POWER, 100)) {
346 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
348 }
349
350 uint8_t b[1];
351 if (!CommReadData(b, 1)) {
352 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
354 }
355
356 if (b[0] == 0x00) {
357 MR4_DEBUG_PRINT_TAIL(F("OK"));
358 return RESULT::OK;
359 }
360 if (b[0] == 0x02) {
361 MR4_DEBUG_PRINT_TAIL(F("ERROR_MOTOR_POWER"));
363 }
364
365 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
366 return RESULT::ERROR;
367}
368
369MMLower::RESULT MMLower::SetDCMotorSpeed(uint8_t num, int16_t speed)
370{
371 MR4_DEBUG_PRINT_HEADER(F("[SetDCMotorSpeed]"));
372
373 uint8_t data[4];
374 data[0] = (1 << --num);
375 data[1] = 0; // Ma
376 BitConverter::GetBytes(data + 2, speed);
377 CommSendData(COMM_CMD::SET_DC_MOTOR_SPEED, data, 4);
378 if (!WaitData(COMM_CMD::SET_DC_MOTOR_SPEED, 100)) {
379 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
381 }
382
383 uint8_t b[1];
384 if (!CommReadData(b, 1)) {
385 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
387 }
388
389 if (b[0] == 0x00) {
390 MR4_DEBUG_PRINT_TAIL(F("OK"));
391 return RESULT::OK;
392 }
393 if (b[0] == 0x02) {
394 MR4_DEBUG_PRINT_TAIL(F("ERROR_MOTOR_SPEED"));
396 }
397
398 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
399 return RESULT::ERROR;
400}
401
402MMLower::RESULT MMLower::SetDCMotorRotate(uint8_t num, int16_t maxSpeed, uint16_t degree)
403{
404 MR4_DEBUG_PRINT_HEADER(F("[SetDCMotorRotate]"));
405
406 uint8_t data[5];
407 data[0] = (1 << --num);
408 BitConverter::GetBytes(data + 1, maxSpeed);
409 BitConverter::GetBytes(data + 3, degree);
410 CommSendData(COMM_CMD::SET_DC_MOTOR_ROTATE, data, 5);
411 if (!WaitData(COMM_CMD::SET_DC_MOTOR_ROTATE, 100)) {
412 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
414 }
415
416 uint8_t b[1];
417 if (!CommReadData(b, 1)) {
418 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
420 }
421
422 if (b[0] == 0x00) {
423 MR4_DEBUG_PRINT_TAIL(F("OK"));
424 return RESULT::OK;
425 }
426
427 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
428 return RESULT::ERROR;
429}
430
432{
433 MR4_DEBUG_PRINT_HEADER(F("[SetAllDCMotorSpeed]"));
434
435 uint8_t data[12];
436 data[0] = (uint8_t)param.m1_dir;
437 data[0] |= ((uint8_t)param.m2_dir) << 1;
438 data[0] |= ((uint8_t)param.m3_dir) << 2;
439 data[0] |= ((uint8_t)param.m4_dir) << 3;
440 BitConverter::GetBytes(data + 1, param.m1_speed);
441 BitConverter::GetBytes(data + 3, param.m2_speed);
442 BitConverter::GetBytes(data + 5, param.m3_speed);
443 BitConverter::GetBytes(data + 7, param.m4_speed);
444
445 CommSendData(COMM_CMD::SET_ALL_DC_MOTOR_SPEED, data, 10);
446 if (!WaitData(COMM_CMD::SET_ALL_DC_MOTOR_SPEED, 100)) {
447 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
449 }
450
451 uint8_t b[1];
452 if (!CommReadData(b, 1)) {
453 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
455 }
456
457 if (b[0] == 0x00) {
458 MR4_DEBUG_PRINT_TAIL(F("OK"));
459 return RESULT::OK;
460 }
461 if (b[0] == 0x02) {
462 MR4_DEBUG_PRINT_TAIL(F("ERROR_MOTOR1_SPEED"));
464 }
465 if (b[0] == 0x03) {
466 MR4_DEBUG_PRINT_TAIL(F("ERROR_MOTOR2_SPEED"));
468 }
469 if (b[0] == 0x04) {
470 MR4_DEBUG_PRINT_TAIL(F("ERROR_MOTOR3_SPEED"));
472 }
473 if (b[0] == 0x05) {
474 MR4_DEBUG_PRINT_TAIL(F("ERROR_MOTOR4_SPEED"));
476 }
477
478 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
479 return RESULT::ERROR;
480}
482{
483 MR4_DEBUG_PRINT_HEADER(F("[SetAllDCMotorPower]"));
484
485 uint8_t data[12];
486 data[0] = (uint8_t)param.m1_dir;
487 data[0] |= ((uint8_t)param.m2_dir) << 1;
488 data[0] |= ((uint8_t)param.m3_dir) << 2;
489 data[0] |= ((uint8_t)param.m4_dir) << 3;
490 BitConverter::GetBytes(data + 1, param.m1_power);
491 BitConverter::GetBytes(data + 3, param.m2_power);
492 BitConverter::GetBytes(data + 5, param.m3_power);
493 BitConverter::GetBytes(data + 7, param.m4_power);
494
495 CommSendData(COMM_CMD::SET_ALL_DC_MOTOR_POWER, data, 10);
496 if (!WaitData(COMM_CMD::SET_ALL_DC_MOTOR_POWER, 100)) {
497 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
499 }
500
501 uint8_t b[1];
502 if (!CommReadData(b, 1)) {
503 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
505 }
506
507 if (b[0] == 0x00) {
508 MR4_DEBUG_PRINT_TAIL(F("OK"));
509 return RESULT::OK;
510 }
511 if (b[0] == 0x02) {
512 MR4_DEBUG_PRINT_TAIL(F("ERROR_MOTOR1_SPEED"));
514 }
515 if (b[0] == 0x03) {
516 MR4_DEBUG_PRINT_TAIL(F("ERROR_MOTOR2_SPEED"));
518 }
519 if (b[0] == 0x04) {
520 MR4_DEBUG_PRINT_TAIL(F("ERROR_MOTOR3_SPEED"));
522 }
523 if (b[0] == 0x05) {
524 MR4_DEBUG_PRINT_TAIL(F("ERROR_MOTOR4_SPEED"));
526 }
527
528 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
529 return RESULT::ERROR;
530}
531
532MMLower::RESULT MMLower::SetServoAngle(uint8_t num, uint16_t angle)
533{
534 MR4_DEBUG_PRINT_HEADER(F("[SetServoAngle]"));
535
536 uint8_t data[3];
537 data[0] = (1 << --num);
538 BitConverter::GetBytes(data + 1, angle);
539 CommSendData(COMM_CMD::SET_SERVO_ANGLE, data, 3);
540 if (!WaitData(COMM_CMD::SET_SERVO_ANGLE, 100)) {
541 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
543 }
544
545 uint8_t b[1];
546 if (!CommReadData(b, 1)) {
547 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
549 }
550
551 if (b[0] == 0x00) {
552 MR4_DEBUG_PRINT_TAIL(F("OK"));
553 return RESULT::OK;
554 }
555 if (b[0] == 0x02) {
556 MR4_DEBUG_PRINT_TAIL(F("ERROR_SERVO_ANGLE"));
558 }
559
560 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
561 return RESULT::ERROR;
562}
563
565 uint16_t angle1, uint16_t angle2, uint16_t angle3, uint16_t angle4)
566{
567 MR4_DEBUG_PRINT_HEADER(F("[SetAllServoAngle]"));
568
569 uint8_t data[8];
570 BitConverter::GetBytes(data + 0, angle1);
571 BitConverter::GetBytes(data + 2, angle2);
572 BitConverter::GetBytes(data + 4, angle3);
573 BitConverter::GetBytes(data + 6, angle4);
574 CommSendData(COMM_CMD::SET_ALL_SERVO_ANGLE, data, 8);
575 if (!WaitData(COMM_CMD::SET_ALL_SERVO_ANGLE, 100)) {
576 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
578 }
579
580 uint8_t b[1];
581 if (!CommReadData(b, 1)) {
582 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
584 }
585
586 if (b[0] == 0x00) {
587 MR4_DEBUG_PRINT_TAIL(F("OK"));
588 return RESULT::OK;
589 }
590 if (b[0] == 0x02) {
591 MR4_DEBUG_PRINT_TAIL(F("ERROR_SERVO1_ANGLE"));
593 }
594 if (b[0] == 0x03) {
595 MR4_DEBUG_PRINT_TAIL(F("ERROR_SERVO2_ANGLE"));
597 }
598 if (b[0] == 0x04) {
599 MR4_DEBUG_PRINT_TAIL(F("ERROR_SERVO3_ANGLE"));
601 }
602 if (b[0] == 0x05) {
603 MR4_DEBUG_PRINT_TAIL(F("ERROR_SERVO4_ANGLE"));
605 }
606
607 return RESULT::ERROR;
608}
609
611 MOVE_TYPE type, MOVE_ACTION action, uint16_t speed, uint16_t enCounter)
612{
613 MR4_DEBUG_PRINT_HEADER(F("[SetMoveDistance]"));
614
615 uint8_t data[6];
616 data[0] = (uint8_t)type;
617 data[1] = (uint8_t)action;
618 BitConverter::GetBytes(data + 2, speed);
620 CommSendData(COMM_CMD::SET_MOVE_DISTANCE, data, 6);
621 if (!WaitData(COMM_CMD::SET_MOVE_DISTANCE, 100)) {
622 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
624 }
625
626 uint8_t b[1];
627 if (!CommReadData(b, 1)) {
628 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
630 }
631
632 if (b[0] == 0x00) {
633 MR4_DEBUG_PRINT_TAIL(F("OK"));
634 return RESULT::OK;
635 }
636 if (b[0] == 0x02) {
637 MR4_DEBUG_PRINT_TAIL(F("ERROR_MOVE_ACTION"));
639 }
640 if (b[0] == 0x03) {
641 MR4_DEBUG_PRINT_TAIL(F("ERROR_MOVE_SPEED"));
643 }
644 if (b[0] == 0x04) {
645 MR4_DEBUG_PRINT_TAIL(F("ERROR_MOVE_ENCODER"));
647 }
648
649 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
650 return RESULT::ERROR;
651}
652
654{
655 MR4_DEBUG_PRINT_HEADER(F("[SetEncoderResetCounter]"));
656
657 uint8_t data[1] = {(1 << --num)};
658 CommSendData(COMM_CMD::SET_ENCODER_RESET_COUNTER, data, 1);
659 if (!WaitData(COMM_CMD::SET_ENCODER_RESET_COUNTER, 100)) {
660 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
662 }
663
664 uint8_t b[1];
665 if (!CommReadData(b, 1)) {
666 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
668 }
669 if (b[0] == 0x00) {
670 MR4_DEBUG_PRINT_TAIL(F("OK"));
671 return RESULT::OK;
672 }
673
674 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
675 return RESULT::ERROR;
676}
677
679{
680 uint8_t data[30];
681 data[0] = 1;
682 data[1] = 1;
683 BitConverter::FloatGetBytes(data+2, bufdata[0]);
684 BitConverter::FloatGetBytes(data+6, bufdata[1]);
685 BitConverter::FloatGetBytes(data+10, bufdata[2]);
686 BitConverter::FloatGetBytes(data+14, bufdata[3]);
687 BitConverter::FloatGetBytes(data+18, bufdata[4]);
688 BitConverter::FloatGetBytes(data+22, bufdata[5]);
689
690 CommSendData(COMM_CMD::SET_IMU_Calib_Data, data, 26);
691 if (!WaitData(COMM_CMD::SET_IMU_Calib_Data, 100)) {
692 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
694 }
695
696 uint8_t b[1];
697 if (!CommReadData(b, 1)) {
698 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
700 }
701 if (b[0] == 0x00) {
702 MR4_DEBUG_PRINT_TAIL(F("OK"));
703 return RESULT::OK;
704 }
705
706 return RESULT::ERROR;
707}
708
709MMLower::RESULT MMLower::SetPIDParam(uint8_t num, uint8_t pidNum, float kp, float ki, float kd)
710{
711 uint8_t data[8] = {(1 << --num), pidNum};
712 BitConverter::GetBytes(data + 2, (uint16_t)(kp * 100.0f));
713 BitConverter::GetBytes(data + 4, (uint16_t)(ki * 100.0f));
714 BitConverter::GetBytes(data + 6, (uint16_t)(kd * 100.0f));
715
716 CommSendData(COMM_CMD::SET_PID_PARAM, data, 8);
717 if (!WaitData(COMM_CMD::SET_PID_PARAM, 100)) {
718 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
720 }
721
722 uint8_t b[1];
723 if (!CommReadData(b, 1)) {
724 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
726 }
727 if (b[0] == 0x00) {
728 MR4_DEBUG_PRINT_TAIL(F("OK"));
729 return RESULT::OK;
730 }
731
732 return RESULT::ERROR;
733}
734
736{
737 MR4_DEBUG_PRINT_HEADER(F("[SetDCBrake]"));
738
739 uint8_t data[1] = {(1 << --num)};
740 CommSendData(COMM_CMD::SET_DC_BRAKE, data, 1);
741 if (!WaitData(COMM_CMD::SET_DC_BRAKE, 100)) {
742 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
744 }
745
746 uint8_t b[1];
747 if (!CommReadData(b, 1)) {
748 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
750 }
751 if (b[0] == 0x00) {
752 MR4_DEBUG_PRINT_TAIL(F("OK"));
753 return RESULT::OK;
754 }
755
756 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
757 return RESULT::ERROR;
758}
759
761{
762 MR4_DEBUG_PRINT_HEADER(F("[SetALLDCBrake]"));
763
764 uint8_t data[2];
765 data[0] = 1;
766 CommSendData(COMM_CMD::SET_ALL_DC_BRAKE, data, 1);
767 if (!WaitData(COMM_CMD::SET_ALL_DC_BRAKE, 100)) {
768 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
770 }
771
772 uint8_t b[1];
773 if (!CommReadData(b, 1)) {
774 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
776 }
777 if (b[0] == 0x00) {
778 MR4_DEBUG_PRINT_TAIL(F("OK"));
779 return RESULT::OK;
780 }
781
782 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
783 return RESULT::ERROR;
784}
785
787{
788 MR4_DEBUG_PRINT_HEADER(F("[SetALLDC_TypeBrake]"));
789
790 uint8_t data[8];
791 data[0] = 1;
792 data[1] = type[0];
793 data[2] = type[1];
794 data[3] = type[2];
795 data[4] = type[3];
796 CommSendData(COMM_CMD::SET_DC_ALL_BRAKE_TYPE, data, 5);
797 if (!WaitData(COMM_CMD::SET_DC_ALL_BRAKE_TYPE, 100)) {
798 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
800 }
801
802 uint8_t b[1];
803 if (!CommReadData(b, 1)) {
804 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
806 }
807 if (b[0] == 0x00) {
808 MR4_DEBUG_PRINT_TAIL(F("OK"));
809 return RESULT::OK;
810 }
811
812 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
813 return RESULT::ERROR;
814}
815
817{
818 MR4_DEBUG_PRINT_HEADER(F("[SetDC_TypeBrake]"));
819
820 uint8_t data[3];
821 data[0] = 1;
822 data[1] = type;
823 CommSendData(COMM_CMD::SET_DC_BRAKE_TYPE, data, 2);
824 if (!WaitData(COMM_CMD::SET_DC_BRAKE_TYPE, 100)) {
825 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
827 }
828
829 uint8_t b[1];
830 if (!CommReadData(b, 1)) {
831 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
833 }
834 if (b[0] == 0x00) {
835 MR4_DEBUG_PRINT_TAIL(F("OK"));
836 return RESULT::OK;
837 }
838
839 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
840 return RESULT::ERROR;
841}
842
843MMLower::RESULT MMLower::SetEncode_PPR_MaxRPM(uint8_t num, uint16_t ppr, uint16_t Maxspeed)
844{
845 MR4_DEBUG_PRINT_HEADER(F("[Set_Encode_PPR]"));
846
847 uint8_t data[6];
848 data[0] = num - 1;
849 data[1] = 0;
850 BitConverter::GetBytes(data + 2, (uint16_t)(ppr));
851 BitConverter::GetBytes(data + 4, (uint16_t)(Maxspeed));
852
853 CommSendData(COMM_CMD::SET_ENCODER_PPR_MAXSPEED, data, 6);
854 if (!WaitData(COMM_CMD::SET_ENCODER_PPR_MAXSPEED, 100)) {
855 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
857 }
858
859 uint8_t b[1];
860 if (!CommReadData(b, 1)) {
861 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
863 }
864 if (b[0] == 0x00) {
865 MR4_DEBUG_PRINT_TAIL(F("OK"));
866 return RESULT::OK;
867 }
868
869 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
870 return RESULT::ERROR;
871}
872
874{
875 MR4_DEBUG_PRINT_HEADER(F("[Set_ALL_Encode_PPR]"));
876
877 uint8_t data[12];
878 data[0] = 1;
879 data[1] = 0;
880 BitConverter::GetBytes(data + 2, (uint16_t)(ppr[0]));
881 BitConverter::GetBytes(data + 4, (uint16_t)(ppr[1]));
882 BitConverter::GetBytes(data + 6, (uint16_t)(ppr[2]));
883 BitConverter::GetBytes(data + 8, (uint16_t)(ppr[3]));
884
885 CommSendData(COMM_CMD::SET_ALL_ENCODER_PPR, data, 10);
886 if (!WaitData(COMM_CMD::SET_ALL_ENCODER_PPR, 100)) {
887 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
889 }
890
891 uint8_t b[1];
892 if (!CommReadData(b, 1)) {
893 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
895 }
896 if (b[0] == 0x00) {
897 MR4_DEBUG_PRINT_TAIL(F("OK"));
898 return RESULT::OK;
899 }
900
901 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
902 return RESULT::ERROR;
903}
904
905MMLower::RESULT MMLower::SetStateLED(uint8_t brightness, uint32_t colorRGB)
906{
907 MR4_DEBUG_PRINT_HEADER(F("[SetStateLED]"));
908
909 uint8_t data[4];
910 data[0] = brightness;
911 data[1] = (uint8_t)(colorRGB >> 16);
912 data[2] = (uint8_t)(colorRGB >> 8);
913 data[3] = (uint8_t)(colorRGB);
914 CommSendData(COMM_CMD::SET_STATE_LED, data, 4);
915 if (!WaitData(COMM_CMD::SET_STATE_LED, 100)) {
916 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
918 }
919
920 uint8_t b[1];
921 if (!CommReadData(b, 1, 10)) {
922 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
924 }
925 if (b[0] == 0x00) {
926 MR4_DEBUG_PRINT_TAIL(F("OK"));
927 return RESULT::OK;
928 }
929
930 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
931 return RESULT::ERROR;
932}
933
935{
936 MR4_DEBUG_PRINT_HEADER(F("[SetIMUToZero]"));
937
938 CommSendData(COMM_CMD::SET_IMU_TO_ZERO);
939 if (!WaitData(COMM_CMD::SET_IMU_TO_ZERO, 1000)) {
940 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
942 }
943
944 uint8_t b[1];
945 if (!CommReadData(b, 1, 10)) {
946 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
948 }
949 if (b[0] == 0x00) {
950 MR4_DEBUG_PRINT_TAIL(F("OK"));
951 return RESULT::OK;
952 }
953
954 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
955 return RESULT::ERROR;
956}
957// Getting
958MMLower::RESULT MMLower::GetButtonState(uint8_t num, bool& btnState)
959{
960 MR4_DEBUG_PRINT_HEADER(F("[GetButtonState]"));
961
962 uint8_t data[1] = {--num};
963 CommSendData(COMM_CMD::GET_BUTTON_STATE, data, 1);
964 if (!WaitData(COMM_CMD::GET_BUTTON_STATE, 100)) {
965 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
967 }
968
969 uint8_t b[1];
970 if (!CommReadData(b, 1)) {
971 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
973 }
974
975 btnState = (bool)b[0];
976
977 MR4_DEBUG_PRINT_TAIL(F("OK"));
978 return RESULT::OK;
979}
980
982{
983 MR4_DEBUG_PRINT_HEADER(F("[GetButtonsState]"));
984
985 CommSendData(COMM_CMD::GET_BUTTONS_STATE);
986 if (!WaitData(COMM_CMD::GET_BUTTONS_STATE, 100)) {
987 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
989 }
990
991 uint8_t b[2];
992 if (!CommReadData(b, 2)) {
993 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
995 }
996 uint16_t flag = BitConverter::ToUInt16(b, 0);
997 btnsState[0] = (bool)(flag);
998 btnsState[1] = (bool)(flag >> 1);
999
1000 MR4_DEBUG_PRINT_TAIL(F("OK"));
1001 return RESULT::OK;
1002}
1003
1005{
1006 MR4_DEBUG_PRINT_HEADER(F("[Get_ALL_Encoder_SPEED]"));
1007
1009 if (!WaitData(COMM_CMD::GET_SPEED_ALL_DC_MOTOR, 100)) {
1010 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1012 }
1013
1014 uint8_t b[17];
1015 if (!CommReadData(b, 17)) {
1016 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1018 }
1019 enSpeed[0] = BitConverter::ToInt32(b, 1);
1020 enSpeed[1] = BitConverter::ToInt32(b, 5);
1021 enSpeed[2] = BitConverter::ToInt32(b, 9);
1022 enSpeed[3] = BitConverter::ToInt32(b, 13);
1023
1024 MR4_DEBUG_PRINT_TAIL(F("OK"));
1025 return RESULT::OK;
1026}
1027
1028
1030{
1031 MR4_DEBUG_PRINT_HEADER(F("[Get_IMU_nancalib_acc]"));
1032
1033 CommSendData(COMM_CMD::GET_IMU_ACC_NOcal);
1034 if (!WaitData(COMM_CMD::GET_IMU_ACC_NOcal, 100)) {
1035 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1037 }
1038
1039 uint8_t b[13];
1040 if (!CommReadData(b, 13)) {
1041 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1043 }
1044 accdata[0] = BitConverter::Tofloat(b, 1);
1045 accdata[1] = BitConverter::Tofloat(b, 5);
1046 accdata[2] = BitConverter::Tofloat(b, 9);
1047
1048 MR4_DEBUG_PRINT_TAIL(F("OK"));
1049 return RESULT::OK;
1050}
1051
1052MMLower::RESULT MMLower::GetEncoderDegrees(uint8_t num, int32_t& enDeges)
1053{
1054 MR4_DEBUG_PRINT_HEADER(F("[GetEncoderDegrees]"));
1055
1056 uint8_t data[1] = {--num};
1057 CommSendData(COMM_CMD::GET_ENCODER_DEGREES, data, 1);
1058 if (!WaitData(COMM_CMD::GET_ENCODER_DEGREES, 100)) {
1059 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1061 }
1062
1063 uint8_t b[4];
1064 if (!CommReadData(b, 4)) {
1065 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1067 }
1068 enDeges = BitConverter::ToInt32(b, 0);
1069
1070 MR4_DEBUG_PRINT_TAIL(F("OK"));
1071 return RESULT::OK;
1072}
1073
1075{
1076 MR4_DEBUG_PRINT_HEADER(F("[GetEncoderCounter]"));
1077
1078 uint8_t data[1] = {--num};
1079 CommSendData(COMM_CMD::GET_ENCODER_COUNTER, data, 1);
1080 if (!WaitData(COMM_CMD::GET_ENCODER_COUNTER, 100)) {
1081 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1083 }
1084
1085 uint8_t b[4];
1086 if (!CommReadData(b, 4)) {
1087 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1089 }
1091
1092 MR4_DEBUG_PRINT_TAIL(F("OK"));
1093 return RESULT::OK;
1094}
1095
1097{
1098 MR4_DEBUG_PRINT_HEADER(F("[GetAllEncoderCounter]"));
1099
1101 if (!WaitData(COMM_CMD::GET_ALL_ENCODER_COUNTER, 100)) {
1102 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1104 }
1105
1106 uint8_t b[16];
1107 if (!CommReadData(b, 16)) {
1108 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1110 }
1114 enCounter[3] = BitConverter::ToInt32(b, 12);
1115
1116 MR4_DEBUG_PRINT_TAIL(F("OK"));
1117 return RESULT::OK;
1118}
1119
1120MMLower::RESULT MMLower::GetIMUEuler(double& roll, double& pitch, double& yaw)
1121{
1122 MR4_DEBUG_PRINT_HEADER(F("[GetIMUEuler]"));
1123
1124 CommSendData(COMM_CMD::GET_IMU_EULER);
1125 if (!WaitData(COMM_CMD::GET_IMU_EULER, 100)) {
1126 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1128 }
1129
1130 uint8_t b[6];
1131 if (!CommReadData(b, 6)) {
1132 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1134 }
1135
1136 roll = BitConverter::ToInt16(b, 0) / 100.0f;
1137 pitch = BitConverter::ToInt16(b, 2) / 100.0f;
1138 yaw = BitConverter::ToInt16(b, 4) / 100.0f;
1139
1140 MR4_DEBUG_PRINT_TAIL(F("OK"));
1141 return RESULT::OK;
1142}
1143
1144MMLower::RESULT MMLower::GetIMUGyro(double& x, double& y, double& z)
1145{
1146 MR4_DEBUG_PRINT_HEADER(F("[GetIMUGyro]"));
1147
1148 CommSendData(COMM_CMD::GET_IMU_GYRO);
1149 if (!WaitData(COMM_CMD::GET_IMU_GYRO, 100)) {
1150 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1152 }
1153
1154 uint8_t b[6];
1155 if (!CommReadData(b, 6)) {
1156 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1158 }
1159 x = BitConverter::ToInt16(b, 0) / 100.0f;
1160 y = BitConverter::ToInt16(b, 2) / 100.0f;
1161 z = BitConverter::ToInt16(b, 4) / 100.0f;
1162
1163 MR4_DEBUG_PRINT_TAIL(F("OK"));
1164 return RESULT::OK;
1165}
1166
1167MMLower::RESULT MMLower::GetIMUAcc(double& x, double& y, double& z)
1168{
1169 MR4_DEBUG_PRINT_HEADER(F("[GetIMUAcc]"));
1170
1171 CommSendData(COMM_CMD::GET_IMU_ACC);
1172 if (!WaitData(COMM_CMD::GET_IMU_ACC, 100)) {
1173 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1175 }
1176
1177 uint8_t b[6];
1178 if (!CommReadData(b, 6)) {
1179 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1181 }
1182 x = BitConverter::ToInt16(b, 0) / 1000.0f;
1183 y = BitConverter::ToInt16(b, 2) / 1000.0f;
1184 z = BitConverter::ToInt16(b, 4) / 1000.0f;
1185
1186 MR4_DEBUG_PRINT_TAIL(F("OK"));
1187 return RESULT::OK;
1188}
1189
1190MMLower::RESULT MMLower::GetPowerInfo(float& curVolt, float& curVoltPerc)
1191{
1192 MR4_DEBUG_PRINT_HEADER(F("[GetPowerInfo]"));
1193
1194 CommSendData(COMM_CMD::GET_POWER_INFO);
1195 if (!WaitData(COMM_CMD::GET_POWER_INFO, 100)) {
1196 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1198 }
1199
1200 uint8_t b[3];
1201 if (!CommReadData(b, 3)) {
1202 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1204 }
1205
1206 uint16_t voltRaw = BitConverter::ToUInt16(b, 0);
1207 curVolt = (float)voltRaw / 1000.0f;
1208 curVoltPerc = (float)b[2];
1209
1210 MR4_DEBUG_PRINT_TAIL(F("OK"));
1211 return RESULT::OK;
1212}
1213
1215{
1216 MR4_DEBUG_PRINT_HEADER(F("[GetRotateState]"));
1217
1218 uint8_t data[1] = {--num};
1219 CommSendData(COMM_CMD::GET_ROTATE_STATE, data, 1);
1220 if (!WaitData(COMM_CMD::GET_ROTATE_STATE, 100)) {
1221 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1223 }
1224
1225 uint8_t b[1];
1226 if (!CommReadData(b, 1)) {
1227 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1229 }
1230 isEnd = b[0];
1231
1232 MR4_DEBUG_PRINT_TAIL(F("OK"));
1233 return RESULT::OK;
1234}
1235// Other-Info
1237{
1238
1239 MR4_DEBUG_PRINT_HEADER(F("[EchoTest]"));
1240
1241 uint8_t data[1] = {0x55};
1242 CommSendData(COMM_CMD::ECHO_TEST, data, 1);
1243 if (!WaitData(COMM_CMD::ECHO_TEST, 100)) {
1244 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1246 }
1247
1248 uint8_t b[8];
1249 if (!CommReadData(b, 1)) {
1250 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1252 }
1253
1254 if (b[0] == data[0]) {
1255 MR4_DEBUG_PRINT_TAIL(F("OK"));
1256 return RESULT::OK;
1257 }
1258 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
1259 return RESULT::ERROR;
1260}
1261
1263{
1264 MR4_DEBUG_PRINT_HEADER(F("[GetFWVersion]"));
1265
1266 CommSendData(COMM_CMD::F_VERSION);
1267 if (!WaitData(COMM_CMD::F_VERSION, 100)) {
1268 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1270 }
1271
1272 uint8_t b[1];
1273 if (!CommReadData(b, 1)) {
1274 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1276 }
1277
1278 version = String(b[0] / 10.0f);
1279
1280 MR4_DEBUG_PRINT_TAIL(F("OK"));
1281 return RESULT::OK;
1282}
1283
1285{
1286 MR4_DEBUG_PRINT_HEADER(F("[GetFWBuildDay]"));
1287
1288 CommSendData(COMM_CMD::F_BUILD_DAY);
1289 if (!WaitData(COMM_CMD::F_BUILD_DAY, 100)) {
1290 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1292 }
1293
1294 uint8_t b[4];
1295 if (!CommReadData(b, 4)) {
1296 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1298 }
1299
1300 uint16_t year = BitConverter::ToUInt16(b, 0);
1301 uint8_t month = b[2];
1302 uint8_t day = b[3];
1303
1304 char str[10];
1305 sprintf(str, "%04d-%02d-%02d", year, month, day);
1306 date = String(str);
1307
1308 MR4_DEBUG_PRINT_TAIL(F("OK"));
1309 return RESULT::OK;
1310}
1311
1313{
1314 MR4_DEBUG_PRINT_HEADER(F("[GetFWDescriptor]"));
1315
1316 CommSendData(COMM_CMD::F_DESCRIPTOR);
1317 if (!WaitData(COMM_CMD::F_DESCRIPTOR, 100)) {
1318 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1320 }
1321
1322 uint8_t b[1];
1323 if (!CommReadData(b, 1)) {
1324 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1326 }
1327
1328 uint8_t len = b[0];
1329 uint8_t str[len + 1];
1330 if (!CommReadData(str, len)) {
1331 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1333 }
1334 str[len] = '\0';
1335 descriptor = String((char*)str);
1336 MR4_DEBUG_PRINT_TAIL(F("OK"));
1337 return RESULT::OK;
1338}
1339
1341{
1342 MR4_DEBUG_PRINT_HEADER(F("[GetModelIndex]"));
1343
1344 CommSendData(COMM_CMD::READ_MODEL_INDEX);
1345 if (!WaitData(COMM_CMD::READ_MODEL_INDEX, 100)) {
1346 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1348 }
1349
1350 uint8_t b[1];
1351 if (!CommReadData(b, 1)) {
1352 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1354 }
1355 index = b[0];
1356
1357 MR4_DEBUG_PRINT_TAIL(F("OK"));
1358 return RESULT::OK;
1359}
1360
1362{
1363 MR4_DEBUG_PRINT_HEADER(F("[GetAllInfo]"));
1364
1365 CommSendData(COMM_CMD::F_VERSION);
1366 if (!WaitData(COMM_CMD::F_VERSION, 100)) {
1367 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1369 }
1370
1371 uint8_t b[6];
1372 if (!CommReadData(b, 6)) {
1373 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1375 }
1376 uint16_t year = BitConverter::ToUInt16(b, 0);
1377 uint8_t month = b[2];
1378 uint8_t day = b[3];
1379
1380 char str[10];
1381 sprintf(str, "%04d-%02d-%02d", year, month, day);
1382
1383 info.fwVersion = String(b[0] / 10.0f);
1384 info.fwBuildDay = String(str);
1385 info.modelIndex = b[5];
1386
1387 MR4_DEBUG_PRINT_TAIL(F("OK"));
1388 return RESULT::OK;
1389}
1390
1392{
1393 MR4_DEBUG_PRINT_HEADER(F("[RunAutoQC]"));
1394
1395 CommSendData(COMM_CMD::RUN_AUTO_QC);
1396 if (!WaitData(COMM_CMD::RUN_AUTO_QC, 100)) {
1397 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1399 }
1400
1401 uint8_t b[1];
1402 if (!CommReadData(b, 1)) {
1403 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1405 }
1406
1407 if ((b[0] & 0x01) == 0x00) {
1408 MR4_DEBUG_PRINT_TAIL(F("ERROR_QC_IMU"));
1409 return RESULT::ERROR_QC_IMU;
1410 }
1411
1412 MR4_DEBUG_PRINT_TAIL(F("OK"));
1413 return RESULT::OK;
1414}
1415
1416//--------------------------------------------------------------//
1417//--------------------------------------------------------------//
1418// New Drive DC 2 Motor Function //
1419//--------------------------------------------------------------//
1420//--------------------------------------------------------------//
1421MMLower::Drive_RESULT MMLower::Set_Drive2Motor_PARAM(uint8_t m1_num, uint8_t m2_num, DIR m1_dir, DIR m2_dir, uint8_t num)
1422{
1423 MR4_DEBUG_PRINT_HEADER(F("[SetDriveDC_2motor_Param]"));
1424
1425 uint8_t data[5] = {m1_num, m2_num, (uint8_t)m1_dir, (uint8_t)m2_dir, (num - 1)};
1426
1427 CommSendData(COMM_CMD::SET_DC_TWO_MOTOR_PARAM, data, 5);
1428 if (!WaitData(COMM_CMD::SET_DC_TWO_MOTOR_PARAM, 100)) {
1429 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1431 }
1432
1433 uint8_t b[1];
1434 if (!CommReadData(b, 1)) {
1435 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1437 }
1438
1439 if (b[0] == 0x00) {
1440 MR4_DEBUG_PRINT_TAIL(F("OK"));
1441 return Drive_RESULT::OK;
1442 }else if(b[0] == 0x08){
1443 MR4_DEBUG_PRINT_TAIL(F("Drive_Param_ERROR"));
1445 }else if(b[0] == 0x09){
1446 MR4_DEBUG_PRINT_TAIL(F("Drive_IMU_Idle"));
1448 }
1449
1450 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
1451 return Drive_RESULT::ERROR;
1452
1453}
1454
1455MMLower::RESULT MMLower::Set_Drive_MoveSync_PID(float Kp, float Ki, float Kd, uint8_t num)
1456{
1457 uint8_t data[13];
1459 BitConverter::FloatGetBytes(data+4, Ki);
1460 BitConverter::FloatGetBytes(data+8, Kd);
1461 data[12] = num - 1;
1462
1463 CommSendData(COMM_CMD::SET_DC_TWO_MoveSync_PID, data, 13);
1464 if (!WaitData(COMM_CMD::SET_DC_TWO_MoveSync_PID, 100)) {
1465 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1467 }
1468
1469 uint8_t b[1];
1470 if (!CommReadData(b, 1)) {
1471 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1473 }
1474 if (b[0] == 0x00) {
1475 MR4_DEBUG_PRINT_TAIL(F("OK"));
1476 return RESULT::OK;
1477 }
1478
1479 return RESULT::ERROR;
1480}
1481
1482MMLower::RESULT MMLower::Set_Drive_MoveGyro_PID(float Kp, float Ki, float Kd, uint8_t num)
1483{
1484 uint8_t data[13];
1486 BitConverter::FloatGetBytes(data+4, Ki);
1487 BitConverter::FloatGetBytes(data+8, Kd);
1488 data[12] = num - 1;
1489
1490 CommSendData(COMM_CMD::SET_DC_TWO_MoveGyro_PID, data, 13);
1491 if (!WaitData(COMM_CMD::SET_DC_TWO_MoveGyro_PID, 100)) {
1492 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1494 }
1495
1496 uint8_t b[1];
1497 if (!CommReadData(b, 1)) {
1498 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1500 }
1501 if (b[0] == 0x00) {
1502 MR4_DEBUG_PRINT_TAIL(F("OK"));
1503 return RESULT::OK;
1504 }
1505
1506 return RESULT::ERROR;
1507 return RESULT::ERROR;
1508}
1509
1510MMLower::RESULT MMLower::Set_Drive_MoveTurn_PID(float Kp, float Ki, float Kd, uint8_t num)
1511{
1512 uint8_t data[13];
1514 BitConverter::FloatGetBytes(data+4, Ki);
1515 BitConverter::FloatGetBytes(data+8, Kd);
1516 data[12] = num - 1;
1517
1518 CommSendData(COMM_CMD::SET_DC_TWO_TurnGyro_PID, data, 13);
1519 if (!WaitData(COMM_CMD::SET_DC_TWO_TurnGyro_PID, 100)) {
1520 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1522 }
1523
1524 uint8_t b[1];
1525 if (!CommReadData(b, 1)) {
1526 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1528 }
1529 if (b[0] == 0x00) {
1530 MR4_DEBUG_PRINT_TAIL(F("OK"));
1531 return RESULT::OK;
1532 }
1533
1534 return RESULT::ERROR;
1535}
1536
1538{
1539 MR4_DEBUG_PRINT_HEADER(F("[Set_Drive_Encode_PPR]"));
1540
1541 uint8_t data[12];
1542
1543 BitConverter::GetBytes(data, (uint16_t)(ppr[0]));
1544 BitConverter::GetBytes(data + 2, (uint16_t)(ppr[1]));
1545 data[4] = num - 1;
1546
1547 CommSendData(COMM_CMD::SET_DC_TWO_MOTOR_PPR, data, 5);
1548 if (!WaitData(COMM_CMD::SET_DC_TWO_MOTOR_PPR, 100)) {
1549 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1551 }
1552
1553 uint8_t b[1];
1554 if (!CommReadData(b, 1)) {
1555 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1557 }
1558
1559 if (b[0] == 0x00) {
1560 MR4_DEBUG_PRINT_TAIL(F("OK"));
1561 return Drive_RESULT::OK;
1562 }else if(b[0] == 0x07){
1563 MR4_DEBUG_PRINT_TAIL(F("Drive_No Defined"));
1565 }
1566
1567 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
1568 return Drive_RESULT::ERROR;
1569}
1570
1572{
1573 MR4_DEBUG_PRINT_HEADER(F("[Set_Drive_Motor_Type]"));
1574
1575 uint8_t data[2];
1576
1577 data[0] = num - 1;
1578 data[1] = type;
1579
1580 CommSendData(COMM_CMD::SET_DC_MOTOR_TYPE, data, 2);
1581 if (!WaitData(COMM_CMD::SET_DC_MOTOR_TYPE, 100)) {
1582 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1583 Serial.println(F("ERROR_WAIT_TIMEOUT"));
1585 }
1586
1587 uint8_t b[1];
1588 if (!CommReadData(b, 1)) {
1589 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1591 }
1592
1593 if (b[0] == 0x00) {
1594 MR4_DEBUG_PRINT_TAIL(F("OK"));
1595 return Drive_RESULT::OK;
1596 }else if(b[0] == 0x07){
1597 MR4_DEBUG_PRINT_TAIL(F("Drive_No Defined"));
1599 }
1600
1601 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
1602 return Drive_RESULT::ERROR;
1603}
1604
1605/*********************************************************************
1606*********************************************************************/
1607
1608MMLower::Drive_RESULT MMLower::Set_Drive_Move_Func(int16_t power_left, int16_t power_right, uint8_t num)
1609{
1610 MR4_DEBUG_PRINT_HEADER(F("[Set_Drive_MovePower]"));
1611
1612 uint8_t data[5];
1613
1614 BitConverter::GetBytes(data + 0, power_left);
1615 BitConverter::GetBytes(data + 2, power_right);
1616 data[4] = num - 1;
1617
1618 CommSendData(COMM_CMD::SET_Drive_Move, data, 5);
1619 if (!WaitData(COMM_CMD::SET_Drive_Move, 100)) {
1620 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1622 }
1623
1624 uint8_t b[1];
1625 if (!CommReadData(b, 1)) {
1626 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1628 }
1629
1630 if (b[0] == 0x00) {
1631 MR4_DEBUG_PRINT_TAIL(F("OK"));
1632 return Drive_RESULT::OK;
1633 }else if (b[0] == 0x02) {
1634 MR4_DEBUG_PRINT_TAIL(F("ERROR_MOTOR_POWER"));
1636 }else if(b[0] == 0x07){
1637 MR4_DEBUG_PRINT_TAIL(F("Drive_No Defined"));
1639 }
1640
1641 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
1642 return Drive_RESULT::ERROR;
1643}
1644
1645MMLower::Drive_RESULT MMLower::Set_Drive_Move_Degs(int16_t power_left, int16_t power_right, uint16_t Degree_c, bool brake, bool async, uint8_t num)
1646{
1647 MR4_DEBUG_PRINT_HEADER(F("[Set_Drive_MoveDegs]"));
1648
1649 uint8_t data[9];
1650
1651 BitConverter::GetBytes(data + 0, power_left);
1652 BitConverter::GetBytes(data + 2, power_right);
1653 BitConverter::GetBytes(data + 4, Degree_c);
1654 data[6] = brake;
1655 data[7] = async;
1656 data[8] = num - 1;
1657
1658 CommSendData(COMM_CMD::SET_Drive_MoveDegs, data, 9);
1659 if (!WaitData(COMM_CMD::SET_Drive_MoveDegs, 100)) {
1660 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1662 }
1663
1664 uint8_t b[1];
1665 if (!CommReadData(b, 1)) {
1666 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1668 }
1669
1670 if (b[0] == 0x00) {
1671 MR4_DEBUG_PRINT_TAIL(F("OK"));
1672 return Drive_RESULT::OK;
1673 }else if (b[0] == 0x02) {
1674 MR4_DEBUG_PRINT_TAIL(F("ERROR_MOVE_DEGS"));
1676 }else if(b[0] == 0x07){
1677 MR4_DEBUG_PRINT_TAIL(F("Drive_No Defined"));
1679 }
1680
1681 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
1682 return Drive_RESULT::ERROR;
1683}
1684
1685MMLower::Drive_RESULT MMLower::Set_Drive_Move_Time(int16_t power_left, int16_t power_right, uint32_t Time_mS, bool brake, bool async, uint8_t num)
1686{
1687 MR4_DEBUG_PRINT_HEADER(F("[Set_Drive_MoveTime]"));
1688
1689 uint8_t data[11];
1690
1691 BitConverter::GetBytes(data + 0, power_left);
1692 BitConverter::GetBytes(data + 2, power_right);
1693 BitConverter::GetBytes(data + 4, Time_mS);
1694 data[8] = brake;
1695 data[9] = async;
1696 data[10] = num -1;
1697
1698 CommSendData(COMM_CMD::SET_Drive_MoveTime, data, 11);
1699 if (!WaitData(COMM_CMD::SET_Drive_MoveTime, 100)) {
1700 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1702 }
1703
1704 uint8_t b[1];
1705 if (!CommReadData(b, 1)) {
1706 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1708 }
1709
1710 if (b[0] == 0x00) {
1711 MR4_DEBUG_PRINT_TAIL(F("OK"));
1712 return Drive_RESULT::OK;
1713 }else if (b[0] == 0x02) {
1714 MR4_DEBUG_PRINT_TAIL(F("ERROR_MOTOR_TIME"));
1716 }else if(b[0] == 0x07){
1717 MR4_DEBUG_PRINT_TAIL(F("Drive_No Defined"));
1719 }
1720
1721 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
1722 return Drive_RESULT::ERROR;
1723}
1724
1725MMLower::Drive_RESULT MMLower::Set_Drive_MoveSync_Func(int16_t power_left, int16_t power_right, uint8_t num)
1726{
1727 MR4_DEBUG_PRINT_HEADER(F("[Set_Drive_Move_SyncPower]"));
1728
1729 uint8_t data[5];
1730
1731 BitConverter::GetBytes(data + 0, power_left);
1732 BitConverter::GetBytes(data + 2, power_right);
1733 data[4] = num - 1;
1734
1735 CommSendData(COMM_CMD::SET_Drive_MoveSync, data, 5);
1736 if (!WaitData(COMM_CMD::SET_Drive_MoveSync, 100)) {
1737 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1739 }
1740
1741 uint8_t b[1];
1742 if (!CommReadData(b, 1)) {
1743 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1745 }
1746
1747 if (b[0] == 0x00) {
1748 MR4_DEBUG_PRINT_TAIL(F("OK"));
1749 return Drive_RESULT::OK;
1750 }else if (b[0] == 0x02) {
1751 MR4_DEBUG_PRINT_TAIL(F("ERROR_MOTOR_POWER"));
1753 }else if(b[0] == 0x07){
1754 MR4_DEBUG_PRINT_TAIL(F("Drive_No Defined"));
1756 }
1757
1758 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
1759 return Drive_RESULT::ERROR;
1760}
1761
1762MMLower::Drive_RESULT MMLower::Set_Drive_MoveSync_Degs(int16_t power_left, int16_t power_right, uint16_t Degree_c, bool brake, bool async, uint8_t num)
1763{
1764 MR4_DEBUG_PRINT_HEADER(F("[SET_Drive_MoveSync_Degs]"));
1765
1766 uint8_t data[9];
1767
1768 BitConverter::GetBytes(data + 0, power_left);
1769 BitConverter::GetBytes(data + 2, power_right);
1770 BitConverter::GetBytes(data + 4, Degree_c);
1771 data[6] = brake;
1772 data[7] = async;
1773 data[8] = num - 1;
1774
1775 CommSendData(COMM_CMD::SET_Drive_MoveSyncDegs, data, 9);
1776 if (!WaitData(COMM_CMD::SET_Drive_MoveSyncDegs, 100)) {
1777 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1779 }
1780
1781 uint8_t b[1];
1782 if (!CommReadData(b, 1)) {
1783 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1785 }
1786
1787 if (b[0] == 0x00) {
1788 MR4_DEBUG_PRINT_TAIL(F("OK"));
1789 return Drive_RESULT::OK;
1790 }else if (b[0] == 0x02) {
1791 MR4_DEBUG_PRINT_TAIL(F("ERROR_MOVE_DEGS"));
1793 }else if(b[0] == 0x07){
1794 MR4_DEBUG_PRINT_TAIL(F("Drive_No Defined"));
1796 }
1797
1798 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
1799 return Drive_RESULT::ERROR;
1800}
1801
1802MMLower::Drive_RESULT MMLower::Set_Drive_MoveSync_Time(int16_t power_left, int16_t power_right, uint32_t Time_mS, bool brake, bool async, uint8_t num)
1803{
1804 MR4_DEBUG_PRINT_HEADER(F("[SET_Drive_MoveSync_Time]"));
1805
1806 uint8_t data[11];
1807
1808 BitConverter::GetBytes(data + 0, power_left);
1809 BitConverter::GetBytes(data + 2, power_right);
1810 BitConverter::GetBytes(data + 4, Time_mS);
1811 data[8] = brake;
1812 data[9] = async;
1813 data[10] = num -1;
1814
1815 CommSendData(COMM_CMD::SET_Drive_MoveSyncTime, data, 11);
1816 if (!WaitData(COMM_CMD::SET_Drive_MoveSyncTime, 100)) {
1817 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1819 }
1820
1821 uint8_t b[1];
1822 if (!CommReadData(b, 1)) {
1823 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1825 }
1826
1827 if (b[0] == 0x00) {
1828 MR4_DEBUG_PRINT_TAIL(F("OK"));
1829 return Drive_RESULT::OK;
1830 }else if (b[0] == 0x02) {
1831 MR4_DEBUG_PRINT_TAIL(F("ERROR_MOTOR_TIME"));
1833 }else if(b[0] == 0x07){
1834 MR4_DEBUG_PRINT_TAIL(F("Drive_No Defined"));
1836 }
1837
1838 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
1839 return Drive_RESULT::ERROR;
1840}
1841
1842MMLower::Drive_RESULT MMLower::Set_Drive_MoveGyro_Func(int16_t power, int16_t Target_dri, uint8_t num)
1843{
1844 MR4_DEBUG_PRINT_HEADER(F("[SET_Drive_MoveGyro]"));
1845
1846 uint8_t data[5];
1847
1848 BitConverter::GetBytes(data + 0, power);
1849 BitConverter::GetBytes(data + 2, Target_dri);
1850 data[4] = num - 1;
1851
1852 CommSendData(COMM_CMD::SET_Drive_Gyro, data, 5);
1853 if (!WaitData(COMM_CMD::SET_Drive_Gyro, 100)) {
1854 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1856 }
1857
1858 uint8_t b[1];
1859 if (!CommReadData(b, 1)) {
1860 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1862 }
1863
1864 if (b[0] == 0x00) {
1865 MR4_DEBUG_PRINT_TAIL(F("OK"));
1866 return Drive_RESULT::OK;
1867 }else if (b[0] == 0x02) {
1868 MR4_DEBUG_PRINT_TAIL(F("ERROR_MOTOR_POWER"));
1870 }else if(b[0] == 0x07){
1871 MR4_DEBUG_PRINT_TAIL(F("Drive_No Defined"));
1873 }
1874
1875 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
1876 return Drive_RESULT::ERROR;
1877}
1878
1879MMLower::Drive_RESULT MMLower::Set_Drive_MoveGyro_Degs(int16_t power, int16_t Target_dri, uint16_t Degree_c, bool brake, bool async, uint8_t num)
1880{
1881 MR4_DEBUG_PRINT_HEADER(F("[SET_Drive_MoveGyro_Degs]"));
1882
1883 uint8_t data[9];
1884
1885 BitConverter::GetBytes(data + 0, power);
1886 BitConverter::GetBytes(data + 2, Target_dri);
1887 BitConverter::GetBytes(data + 4, Degree_c);
1888 data[6] = brake;
1889 data[7] = async;
1890 data[8] = num - 1;
1891
1892 CommSendData(COMM_CMD::SET_Drive_GyroDegs, data, 9);
1893 if (!WaitData(COMM_CMD::SET_Drive_GyroDegs, 100)) {
1894 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1896 }
1897
1898 uint8_t b[1];
1899 if (!CommReadData(b, 1)) {
1900 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1902 }
1903
1904 if (b[0] == 0x00) {
1905 MR4_DEBUG_PRINT_TAIL(F("OK"));
1906 return Drive_RESULT::OK;
1907 }else if (b[0] == 0x02) {
1908 MR4_DEBUG_PRINT_TAIL(F("ERROR_MOVE_DEGS"));
1910 }else if(b[0] == 0x07){
1911 MR4_DEBUG_PRINT_TAIL(F("Drive_No Defined"));
1913 }
1914
1915 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
1916 return Drive_RESULT::ERROR;
1917}
1918
1919MMLower::Drive_RESULT MMLower::Set_Drive_MoveGyro_Time(int16_t power, int16_t Target_dri, uint32_t Time_mS, bool brake, bool async, uint8_t num)
1920{
1921 MR4_DEBUG_PRINT_HEADER(F("[SET_Drive_MoveGyro_Time]"));
1922
1923 uint8_t data[11];
1924
1925 BitConverter::GetBytes(data + 0, power);
1926 BitConverter::GetBytes(data + 2, Target_dri);
1927 BitConverter::GetBytes(data + 4, Time_mS);
1928 data[8] = brake;
1929 data[9] = async;
1930 data[10] = num -1;
1931
1932 CommSendData(COMM_CMD::SET_Drive_GyroTime, data, 11);
1933 if (!WaitData(COMM_CMD::SET_Drive_GyroTime, 100)) {
1934 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1936 }
1937
1938 uint8_t b[1];
1939 if (!CommReadData(b, 1)) {
1940 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1942 }
1943
1944 if (b[0] == 0x00) {
1945 MR4_DEBUG_PRINT_TAIL(F("OK"));
1946 return Drive_RESULT::OK;
1947 }else if (b[0] == 0x02) {
1948 MR4_DEBUG_PRINT_TAIL(F("ERROR_MOTOR_TIME"));
1950 }else if(b[0] == 0x07){
1951 MR4_DEBUG_PRINT_TAIL(F("Drive_No Defined"));
1953 }
1954
1955 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
1956 return Drive_RESULT::ERROR;
1957}
1958
1959MMLower::Drive_RESULT MMLower::Set_Drive_TurnGyro(int16_t power, int16_t Target_dri, uint8_t mode, bool brake, bool async, uint8_t num)
1960{
1961 MR4_DEBUG_PRINT_HEADER(F("[SET_Drive_MoveGyro_Time]"));
1962
1963 uint8_t data[10];
1964
1965 BitConverter::GetBytes(data + 0, power);
1966 BitConverter::GetBytes(data + 2, Target_dri);
1967 data[4] = mode;
1968 data[5] = brake;
1969 data[6] = async;
1970 data[7] = num -1;
1971
1972 CommSendData(COMM_CMD::SET_Drive_Turn, data, 8);
1973 if (!WaitData(COMM_CMD::SET_Drive_Turn, 100)) {
1974 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1976 }
1977
1978 uint8_t b[1];
1979 if (!CommReadData(b, 1)) {
1980 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1982 }
1983
1984 if (b[0] == 0x00) {
1985 MR4_DEBUG_PRINT_TAIL(F("OK"));
1986 return Drive_RESULT::OK;
1987 }else if (b[0] == 0x02) {
1988 MR4_DEBUG_PRINT_TAIL(F("ERROR_MOTOR_TIME"));
1990 }else if(b[0] == 0x07){
1991 MR4_DEBUG_PRINT_TAIL(F("Drive_No Defined"));
1993 }
1994
1995 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
1996 return Drive_RESULT::ERROR;
1997}
1998
1999//=========================================//
2000//=========================================//
2001//=========================================//
2002
2003
2005{
2006 MR4_DEBUG_PRINT_HEADER(F("[GET_Task_Done_Status]"));
2007
2008 uint8_t data[2];
2009 data[0] = 1;
2010 data[1] = num -1;
2011
2012 CommSendData(COMM_CMD::GET_Task_Done_Status, data, 2);
2013 if (!WaitData(COMM_CMD::GET_Task_Done_Status, 100)) {
2014 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
2016 }
2017
2018 uint8_t b[1];
2019 if (!CommReadData(b, 1)) {
2020 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
2022 }
2023
2024 if(b[0] == 0x01){
2025 isEnd[0] = false;
2026 }else if(b[0] == 0x02){
2027 isEnd[0] = true;
2028 }else if(b[0] == 0x07){
2029 MR4_DEBUG_PRINT_TAIL(F("Drive_No Defined"));
2031 }
2032
2033 MR4_DEBUG_PRINT_TAIL(F("OK"));
2034 return Drive_RESULT::OK;
2035}
2036
2038{
2039 MR4_DEBUG_PRINT_HEADER(F("[Set_Drive_Brake]"));
2040
2041 uint8_t data[3];
2042
2043 data[0] = brake;
2044 data[1] = num -1;
2045
2046 CommSendData(COMM_CMD::SET_Drive_Brake, data, 2);
2047 if (!WaitData(COMM_CMD::SET_Drive_Brake, 100)) {
2048 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
2050 }
2051
2052 uint8_t b[1];
2053 if (!CommReadData(b, 1)) {
2054 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
2056 }
2057
2058 if (b[0] == 0x00) {
2059 MR4_DEBUG_PRINT_TAIL(F("OK"));
2060 return Drive_RESULT::OK;
2061 }else if (b[0] == 0x02) {
2062 MR4_DEBUG_PRINT_TAIL(F("ERROR_MOTOR_TIME"));
2064 }else if(b[0] == 0x07){
2065 MR4_DEBUG_PRINT_TAIL(F("Drive_No Defined"));
2067 }
2068
2069 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
2070 return Drive_RESULT::ERROR;
2071}
2072
2074{
2075 MR4_DEBUG_PRINT_HEADER(F("[SET_DC_TWO_MOTOR_Reset_count]"));
2076
2077 uint8_t data[3];
2078
2079 data[0] = (uint8_t)reset;
2080 data[1] = num -1;
2081
2082 CommSendData(COMM_CMD::SET_DC_TWO_MOTOR_Reset_count, data, 2);
2083 if (!WaitData(COMM_CMD::SET_DC_TWO_MOTOR_Reset_count, 100)) {
2084 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
2086 }
2087
2088 uint8_t b[1];
2089 if (!CommReadData(b, 1)) {
2090 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
2092 }
2093
2094 if (b[0] == 0x00) {
2095 MR4_DEBUG_PRINT_TAIL(F("OK"));
2096 return Drive_RESULT::OK;
2097 }else if (b[0] == 0x02) {
2098 MR4_DEBUG_PRINT_TAIL(F("ERROR_MOTOR_TIME"));
2100 }else if(b[0] == 0x07){
2101 MR4_DEBUG_PRINT_TAIL(F("Drive_No Defined"));
2103 }
2104
2105 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
2106 return Drive_RESULT::ERROR;
2107}
2108
2110{
2111 MR4_DEBUG_PRINT_HEADER(F("[Get_Drive_EncoderCounter]"));
2112
2113 uint8_t data[2];
2114 data[0] = num - 1;
2115
2116 CommSendData(COMM_CMD::GET_Drive_Counter, data, 1);
2117 if (!WaitData(COMM_CMD::GET_Drive_Counter, 100)) {
2118 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
2120 }
2121
2122 uint8_t b[4];
2123 if (!CommReadData(b, 4)) {
2124 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
2126 }
2127
2128 if(b[0] == 0x07){
2129 MR4_DEBUG_PRINT_TAIL(F("Drive_No Defined"));
2131 }
2132
2134
2135 MR4_DEBUG_PRINT_TAIL(F("OK"));
2136 return Drive_RESULT::OK;
2137}
2138
2140{
2141 MR4_DEBUG_PRINT_HEADER(F("[Get_Drive_Degrees]"));
2142
2143 uint8_t data[2];
2144 data[0] = num - 1;
2145
2146 CommSendData(COMM_CMD::GET_Drive_Degress, data, 1);
2147 if (!WaitData(COMM_CMD::GET_Drive_Degress, 100)) {
2148 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
2150 }
2151
2152 uint8_t b[4];
2153 if (!CommReadData(b, 4)) {
2154 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
2156 }
2157
2158 if(b[0] == 0x07){
2159 MR4_DEBUG_PRINT_TAIL(F("Drive_No Defined"));
2161 }
2162
2163 Degs = BitConverter::ToInt32(b, 0);
2164
2165 MR4_DEBUG_PRINT_TAIL(F("OK"));
2166 return Drive_RESULT::OK;
2167}
2168
2169
2170
2171//--------------------------------------------------------------//
2172//--------------------------------------------------------------//
2173
2174
2176{
2177 WaitData(COMM_CMD::NONE);
2178}
2179
2181{
2182 callbackFunc = callback;
2183}
2184
2185void MMLower::CommSendData(COMM_CMD cmd, uint8_t* data, uint16_t size)
2186{
2187 uint8_t arr[3 + size];
2188 uint8_t* ptr = arr;
2189
2190 *ptr++ = MatrixR4_COMM_LEAD;
2191 *ptr++ = ((~MatrixR4_COMM_LEAD) & 0xFF);
2192 *ptr++ = (uint8_t)cmd;
2193
2194 for (uint16_t i = 0; i < size; i++) {
2195 *ptr++ = data[i];
2196 }
2197 commSerial->write(arr, 3 + size);
2198 commSerial->flush();
2199}
2200
2201void MMLower::CommSendData(COMM_CMD cmd, uint8_t data)
2202{
2203 uint8_t _data[1] = {data};
2204 CommSendData((COMM_CMD)cmd, _data, 1);
2205}
2206
2207bool MMLower::CommReadData(uint8_t* data, uint16_t size, uint32_t timeout_ms)
2208{
2209 uint32_t timeout = millis() + timeout_ms;
2210 while (millis() <= timeout) {
2211 if (commSerial->available() >= size) {
2212 for (uint16_t i = 0; i < size; i++) {
2213 data[i] = commSerial->read();
2214 }
2215 return true;
2216 }
2217 }
2218 // Timeout
2219 // Clear Buffer
2220 while (commSerial->available() > 0) {
2221 commSerial->read();
2222 }
2223 return false;
2224}
2225
2226bool MMLower::WaitData(COMM_CMD cmd, uint32_t timeout_ms)
2227{
2228 static COMM_STATE state = COMM_STATE::WAIT_LEAD;
2229
2230 uint32_t timeout = millis() + timeout_ms;
2231 while (millis() <= timeout) {
2232 if (commSerial->available() <= 0) {
2233 continue;
2234 }
2235 switch (state) {
2237 {
2238 uint8_t b = commSerial->read();
2239 if (b == MatrixR4_COMM_LEAD) {
2241 }
2242 } break;
2243
2245 {
2246 uint8_t b = commSerial->read();
2247 if (b == ((~MatrixR4_COMM_LEAD) & 0xFF))
2248 state = COMM_STATE::WAIT_CMD;
2249 else
2250 state = COMM_STATE::WAIT_LEAD;
2251 } break;
2252
2254 {
2255 uint8_t b = commSerial->read();
2256 if (b == (uint8_t)cmd) {
2257 state = COMM_STATE::WAIT_LEAD;
2258 return true;
2259 } else {
2260 state = COMM_STATE::WAIT_LEAD;
2261 HandleCommand(b);
2262 }
2263 } break;
2264
2265 case COMM_STATE::ERROR:
2266 {
2267 // TODO: Handle Error
2268 MR4_DEBUG_PRINTLN("COMM_STATE: ERROR");
2269 state = COMM_STATE::WAIT_LEAD;
2270 } break;
2271
2272 default: state = COMM_STATE::WAIT_LEAD; break;
2273 }
2274 }
2275 // Timeout
2276 state = COMM_STATE::WAIT_LEAD;
2277 return false;
2278}
2279
2280void MMLower::HandleCommand(uint8_t cmd)
2281{
2282 switch (cmd) {
2284 {
2285 uint8_t b[2];
2286 if (CommReadData(b, 2)) {
2287 if (callbackFunc == NULL) break;
2288 if (b[0] < MatrixR4_BUTTON_NUM) {
2289 callbackFunc(b[0] + 1, (BTN_STATE)b[1]);
2290 }
2291 }
2292 } break;
2294 {
2295 uint8_t b[8];
2296 if (CommReadData(b, 8)) {
2297 for (uint8_t i = 0; i < MatrixR4_ENCODER_NUM; i++) {
2298 enCounter[i] = BitConverter::ToInt16(b, i * 2);
2299 }
2300 }
2301 } break;
2302 case (uint8_t)COMM_CMD::AUTO_SEND_IMU_EULER:
2303 {
2304 uint8_t b[6];
2305 if (CommReadData(b, 6)) {}
2306 } break;
2307 case (uint8_t)COMM_CMD::AUTO_SEND_IMU_GYRO:
2308 {
2309 uint8_t b[6];
2310 if (CommReadData(b, 6)) {
2311 imuGyroX = BitConverter::ToInt16(b, 0) / 100.0f;
2312 imuGyroY = BitConverter::ToInt16(b, 2) / 100.0f;
2313 imuGyroZ = BitConverter::ToInt16(b, 4) / 100.0f;
2314 }
2315 } break;
2316 case (uint8_t)COMM_CMD::AUTO_SEND_IMU_ACC:
2317 {
2318 uint8_t b[6];
2319 if (CommReadData(b, 6)) {
2320 imuAccX = BitConverter::ToInt16(b, 0) / 1000.0f;
2321 imuAccY = BitConverter::ToInt16(b, 2) / 1000.0f;
2322 imuAccZ = BitConverter::ToInt16(b, 4) / 1000.0f;
2323 }
2324 } break;
2325 default: break;
2326 }
2327}
2328
2329MMLower mmL(8, 9, 57600);
MiniR4 low level functions.
MMLower mmL(8, 9, 57600)
Handling the Lower MCU (STM32) communication.
#define MR4_DEBUG_PRINT_HEADER(...)
Definition MMLower.h:32
#define MatrixR4_ENCODER_NUM
Definition MMLower.h:42
#define MR4_DEBUG_PRINTLN(...)
Definition MMLower.h:35
#define MatrixR4_BUTTON_NUM
Definition MMLower.h:43
#define MR4_DEBUG_PRINT_TAIL(...)
Definition MMLower.h:33
#define MatrixR4_COMM_LEAD
Definition MMLower.h:38
#define MR4_DEBUG_PRINT(...)
Definition MMLower.h:34
#define min(a, b)
static int16_t ToInt16(uint8_t *value, int startIdx)
static void GetBytes(uint8_t *buff, uint32_t value)
static int32_t ToInt32(uint8_t *value, int startIdx)
static float Tofloat(uint8_t *value, int startIdx)
static uint16_t ToUInt16(uint8_t *value, int startIdx)
static void FloatGetBytes(uint8_t *buff, float value)
Handling the Lower MCU (STM32) communication.
Definition MMLower.h:52
RESULT SetAllServoAngle(uint16_t angle1, uint16_t angle2, uint16_t angle3, uint16_t angle4)
Definition MMLower.cpp:564
IMU_GYRO_FSR
Definition MMLower.h:208
Drive_RESULT Set_Drive_Move_Time(int16_t power_left, int16_t power_right, uint32_t Time_mS, bool brake, bool async, uint8_t num)
Definition MMLower.cpp:1685
RESULT Set_Drive_MoveGyro_PID(float Kp, float Ki, float Kd, uint8_t num)
Definition MMLower.cpp:1482
Drive_RESULT Set_Drive_Motor_Type(uint8_t num, uint8_t type)
Definition MMLower.cpp:1571
RESULT GetAllInfo(AllInfo_t &info)
Definition MMLower.cpp:1361
COMM_STATE
Definition MMLower.h:57
double imuGyroX
Definition MMLower.h:440
RESULT SetALLDCBrake(void)
Definition MMLower.cpp:760
RESULT GetRotateState(uint8_t num, bool &isEnd)
Definition MMLower.cpp:1214
RESULT SetEncoderDir(uint8_t num, DIR dir)
Definition MMLower.cpp:70
MOVE_ACTION
Definition MMLower.h:246
Drive_RESULT Set_Drive_Move_Degs(int16_t power_left, int16_t power_right, uint16_t Degree_c, bool brake, bool async, uint8_t num)
Definition MMLower.cpp:1645
RESULT SetStateLED(uint8_t brightness, uint32_t colorRGB)
Definition MMLower.cpp:905
RESULT SetServoAngleRange(uint8_t num, uint16_t min, uint16_t max)
Definition MMLower.cpp:188
RESULT SetServoPulseRange(uint8_t num, uint16_t min, uint16_t max)
Definition MMLower.cpp:151
Drive_RESULT Set_Drive_MoveSync_Degs(int16_t power_left, int16_t power_right, uint16_t Degree_c, bool brake, bool async, uint8_t num)
Definition MMLower.cpp:1762
Drive_RESULT Set_Drive_MoveSync_Func(int16_t power_left, int16_t power_right, uint8_t num)
Definition MMLower.cpp:1725
RESULT GetIMUEuler(double &roll, double &pitch, double &yaw)
Definition MMLower.cpp:1120
Drive_RESULT Set_Drive_MoveGyro_Time(int16_t power, int16_t Target_dri, uint32_t Time_mS, bool brake, bool async, uint8_t num)
Definition MMLower.cpp:1919
RESULT Set_Drive_MoveSync_PID(float Kp, float Ki, float Kd, uint8_t num)
Definition MMLower.cpp:1455
RESULT SetDCMotorPower(uint8_t num, int16_t power)
Definition MMLower.cpp:336
@ SET_ENCODER_RESET_COUNTER
Definition MMLower.h:91
@ SET_DC_TWO_MOTOR_Reset_count
Definition MMLower.h:127
@ AUTO_SEND_ENCODER_COUNTER
Definition MMLower.h:115
@ SET_ENCODER_PPR_MAXSPEED
Definition MMLower.h:79
@ SET_DC_MOTOR_SPEED_RANGE
Definition MMLower.h:71
RESULT RunAutoQC(void)
Definition MMLower.cpp:1391
RESULT SetALL_Encode_PPR(uint16_t *ppr)
Definition MMLower.cpp:873
Drive_RESULT Get_Drive_isTaskDone(uint8_t num, bool *isEnd)
Definition MMLower.cpp:2004
int32_t enCounter[MatrixR4_ENCODER_NUM]
Definition MMLower.h:438
Drive_RESULT Set_Drive_Brake(bool brake, uint8_t num)
Definition MMLower.cpp:2037
RESULT SetDCMotorRotate(uint8_t num, int16_t maxSpeed, uint16_t degree)
Definition MMLower.cpp:402
RESULT SetIMU_Calib_data(float *bufdata)
Definition MMLower.cpp:678
RESULT GetIMUGyro(double &x, double &y, double &z)
Definition MMLower.cpp:1144
RESULT SetServoAngle(uint8_t num, uint16_t angle)
Definition MMLower.cpp:532
double imuAccX
Definition MMLower.h:441
RESULT EchoTest(void)
Definition MMLower.cpp:1236
RESULT GetFWVersion(String &version)
Definition MMLower.cpp:1262
RESULT GetFWBuildDay(String &date)
Definition MMLower.cpp:1284
void loop(void)
Definition MMLower.cpp:2175
IMU_ECHO_MODE
Definition MMLower.h:192
RESULT Init(uint32_t timeout_ms=1000)
Definition MMLower.cpp:15
RESULT GetFWDescriptor(String &descriptor)
Definition MMLower.cpp:1312
RESULT GetEncoderCounter(uint8_t num, int32_t &enCounter)
Definition MMLower.cpp:1074
RESULT SetDCMotorSpeed(uint8_t num, int16_t speed)
Definition MMLower.cpp:369
RESULT GetPowerInfo(float &curVolt, float &curVoltPerc)
Definition MMLower.cpp:1190
RESULT GetButtonState(uint8_t num, bool &btnState)
Definition MMLower.cpp:958
Drive_RESULT Set_Drive_Reset_Count(uint8_t num, bool reset)
Definition MMLower.cpp:2073
double imuGyroY
Definition MMLower.h:440
RESULT SetEncoderResetCounter(uint8_t num)
Definition MMLower.cpp:653
RESULT GetIMUAcc(double &x, double &y, double &z)
Definition MMLower.cpp:1167
RESULT SetIMUEchoMode(IMU_ECHO_MODE mode, uint16_t echoIntervalMs)
Definition MMLower.cpp:225
double imuAccZ
Definition MMLower.h:441
Drive_RESULT Get_Drive_Degrees(uint8_t num, int32_t &Degs)
Definition MMLower.cpp:2139
RESULT GetModelIndex(uint8_t &index)
Definition MMLower.cpp:1340
RESULT Get_IMU_nancalib_acc(float *accdata)
Definition MMLower.cpp:1029
RESULT SetAllDCMotorSpeed(Motors_Param_t param)
Definition MMLower.cpp:431
void onBtnChg(BtnChgCallback callback)
Definition MMLower.cpp:2180
RESULT SetServoDir(uint8_t num, DIR dir)
Definition MMLower.cpp:96
Drive_RESULT Set_Drive_MoveGyro_Func(int16_t power, int16_t Target_dri, uint8_t num)
Definition MMLower.cpp:1842
RESULT SetMoveDistance(MOVE_TYPE type, MOVE_ACTION action, uint16_t speed, uint16_t enCounter)
Definition MMLower.cpp:610
RESULT GetALLEncoderSpeed(int32_t *enSpeed)
Definition MMLower.cpp:1004
RESULT Set_Drive_MoveTurn_PID(float Kp, float Ki, float Kd, uint8_t num)
Definition MMLower.cpp:1510
Drive_RESULT
Definition MMLower.h:306
Drive_RESULT Set_Drive_MoveSync_Time(int16_t power_left, int16_t power_right, uint32_t Time_mS, bool brake, bool async, uint8_t num)
Definition MMLower.cpp:1802
Drive_RESULT Set_Drive_Move_Func(int16_t power_left, int16_t power_right, uint8_t num)
Definition MMLower.cpp:1608
RESULT SetAllDCMotorPower(Motors_Param_t param)
Definition MMLower.cpp:481
@ ERROR_SERVO_MAX_PULSE
Definition MMLower.h:265
@ ERROR_SERVO_MIN_PULSE
Definition MMLower.h:264
@ ERROR_POWER_VOLT_RANGE
Definition MMLower.h:302
@ ERROR_SERVO_MAX_ANGLE
Definition MMLower.h:269
@ ERROR_SERVO_MIN_ANGLE
Definition MMLower.h:268
Drive_RESULT Get_Drive_EncoderCounter(uint8_t num, int32_t &enCounter)
Definition MMLower.cpp:2109
Drive_RESULT Set_Drive2Motor_PARAM(uint8_t m1_num, uint8_t m2_num, DIR m1_dir, DIR m2_dir, uint8_t num)
Definition MMLower.cpp:1421
double imuGyroZ
Definition MMLower.h:440
RESULT GetAllEncoderCounter(int32_t *enCounter)
Definition MMLower.cpp:1096
double imuAccY
Definition MMLower.h:441
IMU_ACC_FSR
Definition MMLower.h:200
RESULT SetPIDParam(uint8_t num, uint8_t pidNum, float kp, float ki, float kd)
Definition MMLower.cpp:709
RESULT SetIMUToZero(void)
Definition MMLower.cpp:934
MMLower(uint8_t rx, uint8_t tx, uint32_t baudrate)
Definition MMLower.cpp:9
RESULT SetALLDC_Type_Brake(uint8_t *type)
Definition MMLower.cpp:786
RESULT SetDCMotorSpeedRange(uint8_t num, uint16_t min, uint16_t max)
Definition MMLower.cpp:122
RESULT GetButtonsState(bool *btnsState)
Definition MMLower.cpp:981
RESULT SetDCBrake(uint8_t num)
Definition MMLower.cpp:735
RESULT SetIMUInit(IMU_ACC_FSR accFSR, IMU_GYRO_FSR gyroFSR, IMU_ODR odr, IMU_FIFO fifo)
Definition MMLower.cpp:260
void(* BtnChgCallback)(uint8_t num, BTN_STATE newState)
Definition MMLower.h:347
Drive_RESULT Set_Drive_MoveGyro_Degs(int16_t power, int16_t Target_dri, uint16_t Degree_c, bool brake, bool async, uint8_t num)
Definition MMLower.cpp:1879
RESULT SetDC_Type_Brake(uint8_t num, uint8_t type)
Definition MMLower.cpp:816
Drive_RESULT Set_Drive_TurnGyro(int16_t power, int16_t Target_dri, uint8_t mode, bool brake, bool async, uint8_t num)
Definition MMLower.cpp:1959
Drive_RESULT Set_Drive_Encode_PPR(uint8_t num, uint16_t *ppr)
Definition MMLower.cpp:1537
RESULT SetEncode_PPR_MaxRPM(uint8_t num, uint16_t ppr, uint16_t Maxspeed)
Definition MMLower.cpp:843
RESULT SetDCMotorDir(uint8_t num, DIR dir)
Definition MMLower.cpp:45
RESULT GetEncoderDegrees(uint8_t num, int32_t &enDeges)
Definition MMLower.cpp:1052
RESULT SetPowerParam(float fullVolt, float cutOffVolt, float alarmVolt)
Definition MMLower.cpp:303
uint8_t modelIndex
Definition MMLower.h:344