MatrixMiniR4 1.1.5
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 timeout_ms = millis() + timeout_ms;
22 while (millis() < timeout_ms) {
23 RESULT result = EchoTest();
24 if (result == RESULT::OK) {
25 MR4_DEBUG_PRINT_TAIL(F("OK"));
26 return RESULT::OK;
27 } else {
28 MR4_DEBUG_PRINT(F("EchoTest Failed! Result: "));
29 MR4_DEBUG_PRINTLN((int)result);
30 }
31 }
32 MR4_DEBUG_PRINT_TAIL(F("ERROR_INIT"));
33 return RESULT::ERROR_INIT;
34}
35
37{
38 MR4_DEBUG_PRINT_HEADER(F("[SetDCMotorDir]"));
39
40 uint8_t data[2] = {(1 << --num), (uint8_t)dir};
41 CommSendData(COMM_CMD::SET_DC_MOTOR_DIR, data, 2);
42 if (!WaitData(COMM_CMD::SET_DC_MOTOR_DIR, 100)) {
43 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
45 }
46
47 uint8_t b[1];
48 if (!CommReadData(b, 1)) {
49 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
51 }
52
53 if (b[0] == 0x00) {
54 MR4_DEBUG_PRINT_TAIL(F("OK"));
55 return RESULT::OK;
56 }
57 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
58 return RESULT::ERROR;
59}
60
62{
63 MR4_DEBUG_PRINT_HEADER(F("[SetEncoderDir]"));
64
65 uint8_t data[2] = {(1 << --num), (uint8_t)dir};
66 CommSendData(COMM_CMD::SET_ENCODER_DIR, data, 2);
67 if (!WaitData(COMM_CMD::SET_ENCODER_DIR, 100)) {
68 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
70 }
71
72 uint8_t b[1];
73 if (!CommReadData(b, 1)) {
74 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
76 }
77
78 if (b[0] == 0x00) {
79 MR4_DEBUG_PRINT_TAIL(F("OK"));
80 return RESULT::OK;
81 }
82
83 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
84 return RESULT::ERROR;
85}
86
88{
89 MR4_DEBUG_PRINT_HEADER(F("[SetServoDir]"));
90
91 uint8_t data[2] = {(1 << --num), (uint8_t)dir};
92 CommSendData(COMM_CMD::SET_SERVO_DIR, data, 2);
93 if (!WaitData(COMM_CMD::SET_SERVO_DIR, 100)) {
94 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
96 }
97
98 uint8_t b[1];
99 if (!CommReadData(b, 1)) {
100 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
102 }
103
104 if (b[0] == 0x00) {
105 MR4_DEBUG_PRINT_TAIL(F("OK"));
106 return RESULT::OK;
107 }
108
109 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
110 return RESULT::ERROR;
111}
112
113MMLower::RESULT MMLower::SetDCMotorSpeedRange(uint8_t num, uint16_t min, uint16_t max)
114{
115 MR4_DEBUG_PRINT_HEADER(F("[SetDCMotorSpeedRange]"));
116
117 uint8_t data[5];
118 data[0] = (1 << --num);
119 BitConverter::GetBytes(data + 1, min);
120 BitConverter::GetBytes(data + 3, max);
121 CommSendData(COMM_CMD::SET_DC_MOTOR_SPEED_RANGE, data, 5);
122 if (!WaitData(COMM_CMD::SET_DC_MOTOR_SPEED_RANGE, 100)) {
123 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
125 }
126
127 uint8_t b[1];
128 if (!CommReadData(b, 1)) {
129 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
131 }
132
133 if (b[0] == 0x00) {
134 MR4_DEBUG_PRINT_TAIL(F("OK"));
135 return RESULT::OK;
136 }
137
138 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
139 return RESULT::ERROR;
140}
141
142MMLower::RESULT MMLower::SetServoPulseRange(uint8_t num, uint16_t min, uint16_t max)
143{
144 MR4_DEBUG_PRINT_HEADER(F("[SetServoPulseRange]"));
145
146 uint8_t data[5];
147 data[0] = (1 << --num);
148 BitConverter::GetBytes(data + 1, min);
149 BitConverter::GetBytes(data + 3, max);
150 CommSendData(COMM_CMD::SET_SERVO_PULSE_RANGE, data, 5);
151 if (!WaitData(COMM_CMD::SET_SERVO_PULSE_RANGE, 100)) {
152 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
154 }
155
156 uint8_t b[1];
157 if (!CommReadData(b, 1)) {
158 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
160 }
161
162 if (b[0] == 0x00) {
163 MR4_DEBUG_PRINT_TAIL(F("OK"));
164 return RESULT::OK;
165 }
166 if (b[0] == 0x02) {
167 MR4_DEBUG_PRINT_TAIL(F("ERROR_SERVO_MIN_PULSE"));
169 }
170 if (b[0] == 0x03) {
171 MR4_DEBUG_PRINT_TAIL(F("ERROR_SERVO_MAX_PULSE"));
173 }
174
175 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
176 return RESULT::ERROR;
177}
178
179MMLower::RESULT MMLower::SetServoAngleRange(uint8_t num, uint16_t min, uint16_t max)
180{
181 MR4_DEBUG_PRINT_HEADER(F("[SetServoAngleRange]"));
182
183 uint8_t data[5];
184 data[0] = (1 << --num);
185 BitConverter::GetBytes(data + 1, min);
186 BitConverter::GetBytes(data + 3, max);
187 CommSendData(COMM_CMD::SET_SERVO_ANGLE_RANGE, data, 5);
188 if (!WaitData(COMM_CMD::SET_SERVO_ANGLE_RANGE, 100)) {
189 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
191 }
192
193 uint8_t b[1];
194 if (!CommReadData(b, 1)) {
195 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
197 }
198
199 if (b[0] == 0x00) {
200 MR4_DEBUG_PRINT_TAIL(F("OK"));
201 return RESULT::OK;
202 }
203 if (b[0] == 0x02) {
204 MR4_DEBUG_PRINT_TAIL(F("ERROR_SERVO_MIN_ANGLE"));
206 }
207 if (b[0] == 0x03) {
208 MR4_DEBUG_PRINT_TAIL(F("ERROR_SERVO_MAX_ANGLE"));
210 }
211
212 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
213 return RESULT::ERROR;
214}
215
217{
218 MR4_DEBUG_PRINT_HEADER(F("[SetIMUEchoMode]"));
219
220 uint8_t data[3];
221 data[0] = (uint8_t)mode;
222 BitConverter::GetBytes(data + 1, echoIntervalMs);
223 CommSendData(COMM_CMD::SET_IMU_ECHO_MODE, data, 3);
224 if (!WaitData(COMM_CMD::SET_IMU_ECHO_MODE, 100)) {
225 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
227 }
228
229 uint8_t b[1];
230 if (!CommReadData(b, 1)) {
232 }
233
234 if (b[0] == 0x00) {
235 MR4_DEBUG_PRINT_TAIL(F("OK"));
236 return RESULT::OK;
237 }
238 if (b[0] == 0x02) {
239 MR4_DEBUG_PRINT_TAIL(F("ERROR_MODE"));
240 return RESULT::ERROR_MODE;
241 }
242 if (b[0] == 0x03) {
243 MR4_DEBUG_PRINT_TAIL(F("ERROR_INTERVAL"));
245 }
246
247 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
248 return RESULT::ERROR;
249}
250
252 IMU_ACC_FSR accFSR, IMU_GYRO_FSR gyroFSR, IMU_ODR odr, IMU_FIFO fifo)
253{
254 MR4_DEBUG_PRINT_HEADER(F("[SetIMUInit]"));
255
256 uint8_t data[4];
257 data[0] = (uint8_t)accFSR;
258 data[1] = (uint8_t)gyroFSR;
259 data[2] = (uint8_t)odr;
260 data[3] = (uint8_t)fifo;
261 CommSendData(COMM_CMD::SET_IMU_INIT, data, 4);
262 if (!WaitData(COMM_CMD::SET_IMU_INIT, 100)) {
263 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
265 }
266
267 uint8_t b[1];
268 if (!CommReadData(b, 1)) {
269 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
271 }
272
273 if (b[0] == 0x00) {
274 MR4_DEBUG_PRINT_TAIL(F("OK"));
275 return RESULT::OK;
276 }
277 if (b[0] == 0x02) {
278 MR4_DEBUG_PRINT_TAIL(F("ERROR_IMU_ACC_FSR"));
280 }
281 if (b[0] == 0x03) {
282 MR4_DEBUG_PRINT_TAIL(F("ERROR_IMU_GYRO_FSR"));
284 }
285 if (b[0] == 0x04) {
286 MR4_DEBUG_PRINT_TAIL(F("ERROR_IMU_ODR"));
288 }
289
290 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
291 return RESULT::ERROR;
292}
293
294MMLower::RESULT MMLower::SetPowerParam(float fullVolt, float cutOffVolt, float alarmVolt)
295{
296 MR4_DEBUG_PRINT_HEADER(F("[SetPowerParam]"));
297
298 uint8_t data[3];
299 data[0] = (uint8_t)(fullVolt * 10.0f);
300 data[1] = (uint8_t)(cutOffVolt * 10.0f);
301 data[2] = (uint8_t)(alarmVolt * 10.0f);
302 CommSendData(COMM_CMD::SET_POWER_PARAM, data, 3);
303 if (!WaitData(COMM_CMD::SET_POWER_PARAM, 100)) {
304 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
306 }
307
308 uint8_t b[1];
309 if (!CommReadData(b, 1, 5)) {
310 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
312 }
313 if (b[0] == 0x00) {
314 MR4_DEBUG_PRINT_TAIL(F("OK"));
315 return RESULT::OK;
316 }
317 if (b[0] == 0x02) {
318 MR4_DEBUG_PRINT_TAIL(F("ERROR_POWER_VOLT_RANGE"));
320 }
321
322 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
323 return RESULT::ERROR;
324}
325// Setting-Commonly used
326
327MMLower::RESULT MMLower::SetDCMotorPower(uint8_t num, int16_t power)
328{
329 MR4_DEBUG_PRINT_HEADER(F("[SetDCMotorPower]"));
330
331 uint8_t data[4];
332 data[0] = (1 << --num);
333 data[1] = 0; // Ma
334 BitConverter::GetBytes(data + 2, power);
335 CommSendData(COMM_CMD::SET_DC_MOTOR_POWER, data, 4);
336 if (!WaitData(COMM_CMD::SET_DC_MOTOR_POWER, 100)) {
337 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
339 }
340
341 uint8_t b[1];
342 if (!CommReadData(b, 1)) {
343 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
345 }
346
347 if (b[0] == 0x00) {
348 MR4_DEBUG_PRINT_TAIL(F("OK"));
349 return RESULT::OK;
350 }
351 if (b[0] == 0x02) {
352 MR4_DEBUG_PRINT_TAIL(F("ERROR_MOTOR_POWER"));
354 }
355
356 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
357 return RESULT::ERROR;
358}
359
360MMLower::RESULT MMLower::SetDCMotorSpeed(uint8_t num, int16_t speed)
361{
362 MR4_DEBUG_PRINT_HEADER(F("[SetDCMotorSpeed]"));
363
364 uint8_t data[4];
365 data[0] = (1 << --num);
366 data[1] = 0; // Ma
367 BitConverter::GetBytes(data + 2, speed);
368 CommSendData(COMM_CMD::SET_DC_MOTOR_SPEED, data, 4);
369 if (!WaitData(COMM_CMD::SET_DC_MOTOR_SPEED, 100)) {
370 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
372 }
373
374 uint8_t b[1];
375 if (!CommReadData(b, 1)) {
376 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
378 }
379
380 if (b[0] == 0x00) {
381 MR4_DEBUG_PRINT_TAIL(F("OK"));
382 return RESULT::OK;
383 }
384 if (b[0] == 0x02) {
385 MR4_DEBUG_PRINT_TAIL(F("ERROR_MOTOR_SPEED"));
387 }
388
389 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
390 return RESULT::ERROR;
391}
392
393MMLower::RESULT MMLower::SetDCMotorRotate(uint8_t num, int16_t maxSpeed, uint16_t degree)
394{
395 MR4_DEBUG_PRINT_HEADER(F("[SetDCMotorRotate]"));
396
397 uint8_t data[5];
398 data[0] = (1 << --num);
399 BitConverter::GetBytes(data + 1, maxSpeed);
400 BitConverter::GetBytes(data + 3, degree);
401 CommSendData(COMM_CMD::SET_DC_MOTOR_ROTATE, data, 5);
402 if (!WaitData(COMM_CMD::SET_DC_MOTOR_ROTATE, 100)) {
403 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
405 }
406
407 uint8_t b[1];
408 if (!CommReadData(b, 1)) {
409 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
411 }
412
413 if (b[0] == 0x00) {
414 MR4_DEBUG_PRINT_TAIL(F("OK"));
415 return RESULT::OK;
416 }
417
418 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
419 return RESULT::ERROR;
420}
421
423{
424 MR4_DEBUG_PRINT_HEADER(F("[SetAllDCMotorSpeed]"));
425
426 uint8_t data[9];
427 data[0] = (uint8_t)param.m1_dir;
428 data[0] |= ((uint8_t)param.m2_dir) << 1;
429 data[0] |= ((uint8_t)param.m3_dir) << 2;
430 data[0] |= ((uint8_t)param.m4_dir) << 3;
431 BitConverter::GetBytes(data + 1, param.m1_speed);
432 BitConverter::GetBytes(data + 3, param.m2_speed);
433 BitConverter::GetBytes(data + 5, param.m3_speed);
434 BitConverter::GetBytes(data + 7, param.m4_speed);
435 CommSendData(COMM_CMD::SET_ALL_DC_MOTOR_SPEED, data, 10);
436 if (!WaitData(COMM_CMD::SET_ALL_DC_MOTOR_SPEED, 100)) {
437 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
439 }
440
441 uint8_t b[1];
442 if (!CommReadData(b, 1)) {
443 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
445 }
446
447 if (b[0] == 0x00) {
448 MR4_DEBUG_PRINT_TAIL(F("OK"));
449 return RESULT::OK;
450 }
451 if (b[0] == 0x02) {
452 MR4_DEBUG_PRINT_TAIL(F("ERROR_MOTOR1_SPEED"));
454 }
455 if (b[0] == 0x03) {
456 MR4_DEBUG_PRINT_TAIL(F("ERROR_MOTOR2_SPEED"));
458 }
459 if (b[0] == 0x04) {
460 MR4_DEBUG_PRINT_TAIL(F("ERROR_MOTOR3_SPEED"));
462 }
463 if (b[0] == 0x05) {
464 MR4_DEBUG_PRINT_TAIL(F("ERROR_MOTOR4_SPEED"));
466 }
467
468 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
469 return RESULT::ERROR;
470}
471
472MMLower::RESULT MMLower::SetServoAngle(uint8_t num, uint16_t angle)
473{
474 MR4_DEBUG_PRINT_HEADER(F("[SetServoAngle]"));
475
476 uint8_t data[3];
477 data[0] = (1 << --num);
478 BitConverter::GetBytes(data + 1, angle);
479 CommSendData(COMM_CMD::SET_SERVO_ANGLE, data, 3);
480 if (!WaitData(COMM_CMD::SET_SERVO_ANGLE, 100)) {
481 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
483 }
484
485 uint8_t b[1];
486 if (!CommReadData(b, 1)) {
487 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
489 }
490
491 if (b[0] == 0x00) {
492 MR4_DEBUG_PRINT_TAIL(F("OK"));
493 return RESULT::OK;
494 }
495 if (b[0] == 0x02) {
496 MR4_DEBUG_PRINT_TAIL(F("ERROR_SERVO_ANGLE"));
498 }
499
500 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
501 return RESULT::ERROR;
502}
503
505 uint16_t angle1, uint16_t angle2, uint16_t angle3, uint16_t angle4)
506{
507 MR4_DEBUG_PRINT_HEADER(F("[SetAllServoAngle]"));
508
509 uint8_t data[8];
510 BitConverter::GetBytes(data + 0, angle1);
511 BitConverter::GetBytes(data + 2, angle2);
512 BitConverter::GetBytes(data + 4, angle3);
513 BitConverter::GetBytes(data + 6, angle4);
514 CommSendData(COMM_CMD::SET_ALL_SERVO_ANGLE, data, 8);
515 if (!WaitData(COMM_CMD::SET_ALL_SERVO_ANGLE, 100)) {
516 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
518 }
519
520 uint8_t b[1];
521 if (!CommReadData(b, 1)) {
522 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
524 }
525
526 if (b[0] == 0x00) {
527 MR4_DEBUG_PRINT_TAIL(F("OK"));
528 return RESULT::OK;
529 }
530 if (b[0] == 0x02) {
531 MR4_DEBUG_PRINT_TAIL(F("ERROR_SERVO1_ANGLE"));
533 }
534 if (b[0] == 0x03) {
535 MR4_DEBUG_PRINT_TAIL(F("ERROR_SERVO2_ANGLE"));
537 }
538 if (b[0] == 0x04) {
539 MR4_DEBUG_PRINT_TAIL(F("ERROR_SERVO3_ANGLE"));
541 }
542 if (b[0] == 0x05) {
543 MR4_DEBUG_PRINT_TAIL(F("ERROR_SERVO4_ANGLE"));
545 }
546
547 return RESULT::ERROR;
548}
549
551 MOVE_TYPE type, MOVE_ACTION action, uint16_t speed, uint16_t enCounter)
552{
553 MR4_DEBUG_PRINT_HEADER(F("[SetMoveDistance]"));
554
555 uint8_t data[6];
556 data[0] = (uint8_t)type;
557 data[1] = (uint8_t)action;
558 BitConverter::GetBytes(data + 2, speed);
560 CommSendData(COMM_CMD::SET_MOVE_DISTANCE, data, 6);
561 if (!WaitData(COMM_CMD::SET_MOVE_DISTANCE, 100)) {
562 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
564 }
565
566 uint8_t b[1];
567 if (!CommReadData(b, 1)) {
568 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
570 }
571
572 if (b[0] == 0x00) {
573 MR4_DEBUG_PRINT_TAIL(F("OK"));
574 return RESULT::OK;
575 }
576 if (b[0] == 0x02) {
577 MR4_DEBUG_PRINT_TAIL(F("ERROR_MOVE_ACTION"));
579 }
580 if (b[0] == 0x03) {
581 MR4_DEBUG_PRINT_TAIL(F("ERROR_MOVE_SPEED"));
583 }
584 if (b[0] == 0x04) {
585 MR4_DEBUG_PRINT_TAIL(F("ERROR_MOVE_ENCODER"));
587 }
588
589 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
590 return RESULT::ERROR;
591}
592
594{
595 MR4_DEBUG_PRINT_HEADER(F("[SetEncoderResetCounter]"));
596
597 uint8_t data[1] = {(1 << --num)};
598 CommSendData(COMM_CMD::SET_ENCODER_RESET_COUNTER, data, 1);
599 if (!WaitData(COMM_CMD::SET_ENCODER_RESET_COUNTER, 100)) {
600 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
602 }
603
604 uint8_t b[1];
605 if (!CommReadData(b, 1)) {
606 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
608 }
609 if (b[0] == 0x00) {
610 MR4_DEBUG_PRINT_TAIL(F("OK"));
611 return RESULT::OK;
612 }
613
614 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
615 return RESULT::ERROR;
616}
617
618MMLower::RESULT MMLower::SetPIDParam(uint8_t num, uint8_t pidNum, float kp, float ki, float kd)
619{
620 uint8_t data[8] = {(1 << --num), pidNum};
621 BitConverter::GetBytes(data + 2, (uint16_t)(kp * 100.0f));
622 BitConverter::GetBytes(data + 4, (uint16_t)(ki * 100.0f));
623 BitConverter::GetBytes(data + 6, (uint16_t)(kd * 100.0f));
624
625 CommSendData(COMM_CMD::SET_PID_PARAM, data, 8);
626 if (!WaitData(COMM_CMD::SET_PID_PARAM, 100)) {
627 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
629 }
630
631 uint8_t b[1];
632 if (!CommReadData(b, 1)) {
633 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
635 }
636 if (b[0] == 0x00) {
637 MR4_DEBUG_PRINT_TAIL(F("OK"));
638 return RESULT::OK;
639 }
640
641 return RESULT::ERROR;
642}
643
645{
646 MR4_DEBUG_PRINT_HEADER(F("[SetDCBrake]"));
647
648 uint8_t data[1] = {(1 << --num)};
649 CommSendData(COMM_CMD::SET_DC_BRAKE, data, 1);
650 if (!WaitData(COMM_CMD::SET_DC_BRAKE, 100)) {
651 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
653 }
654
655 uint8_t b[1];
656 if (!CommReadData(b, 1)) {
657 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
659 }
660 if (b[0] == 0x00) {
661 MR4_DEBUG_PRINT_TAIL(F("OK"));
662 return RESULT::OK;
663 }
664
665 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
666 return RESULT::ERROR;
667}
668
669MMLower::RESULT MMLower::SetStateLED(uint8_t brightness, uint32_t colorRGB)
670{
671 MR4_DEBUG_PRINT_HEADER(F("[SetStateLED]"));
672
673 uint8_t data[4];
674 data[0] = brightness;
675 data[1] = (uint8_t)(colorRGB >> 16);
676 data[2] = (uint8_t)(colorRGB >> 8);
677 data[3] = (uint8_t)(colorRGB);
678 CommSendData(COMM_CMD::SET_STATE_LED, data, 4);
679 if (!WaitData(COMM_CMD::SET_STATE_LED, 100)) {
680 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
682 }
683
684 uint8_t b[1];
685 if (!CommReadData(b, 1, 10)) {
686 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
688 }
689 if (b[0] == 0x00) {
690 MR4_DEBUG_PRINT_TAIL(F("OK"));
691 return RESULT::OK;
692 }
693
694 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
695 return RESULT::ERROR;
696}
697
699{
700 MR4_DEBUG_PRINT_HEADER(F("[SetIMUToZero]"));
701
702 CommSendData(COMM_CMD::SET_IMU_TO_ZERO);
703 if (!WaitData(COMM_CMD::SET_IMU_TO_ZERO, 1000)) {
704 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
706 }
707
708 uint8_t b[1];
709 if (!CommReadData(b, 1, 10)) {
710 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
712 }
713 if (b[0] == 0x00) {
714 MR4_DEBUG_PRINT_TAIL(F("OK"));
715 return RESULT::OK;
716 }
717
718 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
719 return RESULT::ERROR;
720}
721// Getting
722MMLower::RESULT MMLower::GetButtonState(uint8_t num, bool& btnState)
723{
724 MR4_DEBUG_PRINT_HEADER(F("[GetButtonState]"));
725
726 uint8_t data[1] = {--num};
727 CommSendData(COMM_CMD::GET_BUTTON_STATE, data, 1);
728 if (!WaitData(COMM_CMD::GET_BUTTON_STATE, 100)) {
729 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
731 }
732
733 uint8_t b[1];
734 if (!CommReadData(b, 1)) {
735 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
737 }
738 btnState = (bool)b[0];
739
740 MR4_DEBUG_PRINT_TAIL(F("OK"));
741 return RESULT::OK;
742}
743
745{
746 MR4_DEBUG_PRINT_HEADER(F("[GetButtonsState]"));
747
748 CommSendData(COMM_CMD::GET_BUTTONS_STATE);
749 if (!WaitData(COMM_CMD::GET_BUTTONS_STATE, 100)) {
750 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
752 }
753
754 uint8_t b[2];
755 if (!CommReadData(b, 2)) {
756 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
758 }
759 uint16_t flag = BitConverter::ToUInt16(b, 0);
760 btnsState[0] = (bool)(flag);
761 btnsState[1] = (bool)(flag >> 1);
762
763 MR4_DEBUG_PRINT_TAIL(F("OK"));
764 return RESULT::OK;
765}
766
767MMLower::RESULT MMLower::GetEncoderCounter(uint8_t num, int32_t& enCounter)
768{
769 MR4_DEBUG_PRINT_HEADER(F("[GetEncoderCounter]"));
770
771 uint8_t data[1] = {--num};
772 CommSendData(COMM_CMD::GET_ENCODER_COUNTER, data, 1);
773 if (!WaitData(COMM_CMD::GET_ENCODER_COUNTER, 100)) {
774 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
776 }
777
778 uint8_t b[4];
779 if (!CommReadData(b, 4)) {
780 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
782 }
784
785 MR4_DEBUG_PRINT_TAIL(F("OK"));
786 return RESULT::OK;
787}
788
790{
791 MR4_DEBUG_PRINT_HEADER(F("[GetAllEncoderCounter]"));
792
794 if (!WaitData(COMM_CMD::GET_ALL_ENCODER_COUNTER, 100)) {
795 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
797 }
798
799 uint8_t b[16];
800 if (!CommReadData(b, 16)) {
801 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
803 }
808
809 MR4_DEBUG_PRINT_TAIL(F("OK"));
810 return RESULT::OK;
811}
812
813MMLower::RESULT MMLower::GetIMUEuler(int16_t& roll, int16_t& pitch, int16_t& yaw)
814{
815 MR4_DEBUG_PRINT_HEADER(F("[GetIMUEuler]"));
816
817 CommSendData(COMM_CMD::GET_IMU_EULER);
818 if (!WaitData(COMM_CMD::GET_IMU_EULER, 100)) {
819 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
821 }
822
823 uint8_t b[6];
824 if (!CommReadData(b, 6)) {
825 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
827 }
828
829 roll = BitConverter::ToInt16(b, 0);
830 pitch = BitConverter::ToInt16(b, 2);
831 yaw = BitConverter::ToInt16(b, 4);
832
833 MR4_DEBUG_PRINT_TAIL(F("OK"));
834 return RESULT::OK;
835}
836
837MMLower::RESULT MMLower::GetIMUGyro(double& x, double& y, double& z)
838{
839 MR4_DEBUG_PRINT_HEADER(F("[GetIMUGyro]"));
840
841 CommSendData(COMM_CMD::GET_IMU_GYRO);
842 if (!WaitData(COMM_CMD::GET_IMU_GYRO, 100)) {
843 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
845 }
846
847 uint8_t b[6];
848 if (!CommReadData(b, 6)) {
849 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
851 }
852 x = BitConverter::ToInt16(b, 0) / 100.0f;
853 y = BitConverter::ToInt16(b, 2) / 100.0f;
854 z = BitConverter::ToInt16(b, 4) / 100.0f;
855
856 MR4_DEBUG_PRINT_TAIL(F("OK"));
857 return RESULT::OK;
858}
859
860MMLower::RESULT MMLower::GetIMUAcc(double& x, double& y, double& z)
861{
862 MR4_DEBUG_PRINT_HEADER(F("[GetIMUAcc]"));
863
864 CommSendData(COMM_CMD::GET_IMU_ACC);
865 if (!WaitData(COMM_CMD::GET_IMU_ACC, 100)) {
866 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
868 }
869
870 uint8_t b[6];
871 if (!CommReadData(b, 6)) {
872 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
874 }
875 x = BitConverter::ToInt16(b, 0) / 1000.0f;
876 y = BitConverter::ToInt16(b, 2) / 1000.0f;
877 z = BitConverter::ToInt16(b, 4) / 1000.0f;
878
879 MR4_DEBUG_PRINT_TAIL(F("OK"));
880 return RESULT::OK;
881}
882
883MMLower::RESULT MMLower::GetPowerInfo(float& curVolt, float& curVoltPerc)
884{
885 MR4_DEBUG_PRINT_HEADER(F("[GetPowerInfo]"));
886
887 CommSendData(COMM_CMD::GET_POWER_INFO);
888 if (!WaitData(COMM_CMD::GET_POWER_INFO, 100)) {
889 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
891 }
892
893 uint8_t b[3];
894 if (!CommReadData(b, 3)) {
895 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
897 }
898
899 uint16_t voltRaw = BitConverter::ToUInt16(b, 0);
900 curVolt = (float)voltRaw / 1000.0f;
901 curVoltPerc = (float)b[2];
902
903 MR4_DEBUG_PRINT_TAIL(F("OK"));
904 return RESULT::OK;
905}
906
908{
909 MR4_DEBUG_PRINT_HEADER(F("[GetRotateState]"));
910
911 uint8_t data[1] = {--num};
912 CommSendData(COMM_CMD::GET_ROTATE_STATE, data, 1);
913 if (!WaitData(COMM_CMD::GET_ROTATE_STATE, 100)) {
914 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
916 }
917
918 uint8_t b[1];
919 if (!CommReadData(b, 1)) {
920 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
922 }
923 isEnd = b[0];
924
925 MR4_DEBUG_PRINT_TAIL(F("OK"));
926 return RESULT::OK;
927}
928// Other-Info
930{
931 MR4_DEBUG_PRINT_HEADER(F("[EchoTest]"));
932
933 uint8_t data[1] = {0x55};
934 CommSendData(COMM_CMD::ECHO_TEST, data, 1);
935 if (!WaitData(COMM_CMD::ECHO_TEST, 100)) {
936 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
938 }
939
940 uint8_t b[1];
941 if (!CommReadData(b, 1)) {
942 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
944 }
945 if (b[0] == data[0]) {
946 MR4_DEBUG_PRINT_TAIL(F("OK"));
947 return RESULT::OK;
948 }
949 MR4_DEBUG_PRINT_TAIL(F("ERROR"));
950 return RESULT::ERROR;
951}
952
954{
955 MR4_DEBUG_PRINT_HEADER(F("[GetFWVersion]"));
956
957 CommSendData(COMM_CMD::F_VERSION);
958 if (!WaitData(COMM_CMD::F_VERSION, 100)) {
959 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
961 }
962
963 uint8_t b[1];
964 if (!CommReadData(b, 1)) {
965 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
967 }
968
969 version = String(b[0] / 10.0f);
970
971 MR4_DEBUG_PRINT_TAIL(F("OK"));
972 return RESULT::OK;
973}
974
976{
977 MR4_DEBUG_PRINT_HEADER(F("[GetFWBuildDay]"));
978
979 CommSendData(COMM_CMD::F_BUILD_DAY);
980 if (!WaitData(COMM_CMD::F_BUILD_DAY, 100)) {
981 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
983 }
984
985 uint8_t b[4];
986 if (!CommReadData(b, 4)) {
987 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
989 }
990
991 uint16_t year = BitConverter::ToUInt16(b, 0);
992 uint8_t month = b[2];
993 uint8_t day = b[3];
994
995 char str[10];
996 sprintf(str, "%04d-%02d-%02d", year, month, day);
997 date = String(str);
998
999 MR4_DEBUG_PRINT_TAIL(F("OK"));
1000 return RESULT::OK;
1001}
1002
1004{
1005 MR4_DEBUG_PRINT_HEADER(F("[GetFWDescriptor]"));
1006
1007 CommSendData(COMM_CMD::F_DESCRIPTOR);
1008 if (!WaitData(COMM_CMD::F_DESCRIPTOR, 100)) {
1009 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1011 }
1012
1013 uint8_t b[1];
1014 if (!CommReadData(b, 1)) {
1015 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1017 }
1018
1019 uint8_t len = b[0];
1020 uint8_t str[len + 1];
1021 if (!CommReadData(str, len)) {
1022 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1024 }
1025 str[len] = '\0';
1026 descriptor = String((char*)str);
1027 MR4_DEBUG_PRINT_TAIL(F("OK"));
1028 return RESULT::OK;
1029}
1030
1032{
1033 MR4_DEBUG_PRINT_HEADER(F("[GetModelIndex]"));
1034
1035 CommSendData(COMM_CMD::READ_MODEL_INDEX);
1036 if (!WaitData(COMM_CMD::READ_MODEL_INDEX, 100)) {
1037 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1039 }
1040
1041 uint8_t b[1];
1042 if (!CommReadData(b, 1)) {
1043 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1045 }
1046 index = b[0];
1047
1048 MR4_DEBUG_PRINT_TAIL(F("OK"));
1049 return RESULT::OK;
1050}
1051
1053{
1054 MR4_DEBUG_PRINT_HEADER(F("[GetAllInfo]"));
1055
1056 CommSendData(COMM_CMD::F_VERSION);
1057 if (!WaitData(COMM_CMD::F_VERSION, 100)) {
1058 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1060 }
1061
1062 uint8_t b[6];
1063 if (!CommReadData(b, 6)) {
1064 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1066 }
1067 uint16_t year = BitConverter::ToUInt16(b, 0);
1068 uint8_t month = b[2];
1069 uint8_t day = b[3];
1070
1071 char str[10];
1072 sprintf(str, "%04d-%02d-%02d", year, month, day);
1073
1074 info.fwVersion = String(b[0] / 10.0f);
1075 info.fwBuildDay = String(str);
1076 info.modelIndex = b[5];
1077
1078 MR4_DEBUG_PRINT_TAIL(F("OK"));
1079 return RESULT::OK;
1080}
1081
1083{
1084 MR4_DEBUG_PRINT_HEADER(F("[RunAutoQC]"));
1085
1086 CommSendData(COMM_CMD::RUN_AUTO_QC);
1087 if (!WaitData(COMM_CMD::RUN_AUTO_QC, 100)) {
1088 MR4_DEBUG_PRINT_TAIL(F("ERROR_WAIT_TIMEOUT"));
1090 }
1091
1092 uint8_t b[1];
1093 if (!CommReadData(b, 1)) {
1094 MR4_DEBUG_PRINT_TAIL(F("ERROR_READ_TIMEOUT"));
1096 }
1097
1098 if ((b[0] & 0x01) == 0x00) {
1099 MR4_DEBUG_PRINT_TAIL(F("ERROR_QC_IMU"));
1100 return RESULT::ERROR_QC_IMU;
1101 }
1102
1103 MR4_DEBUG_PRINT_TAIL(F("OK"));
1104 return RESULT::OK;
1105}
1106
1108{
1109 WaitData(COMM_CMD::NONE);
1110}
1111
1112void MMLower::onBtnChg(BtnChgCallback callback)
1113{
1114 callbackFunc = callback;
1115}
1116
1117void MMLower::CommSendData(COMM_CMD cmd, uint8_t* data, uint16_t size)
1118{
1119 uint8_t arr[3 + size];
1120 uint8_t* ptr = arr;
1121
1122 *ptr++ = MatrixR4_COMM_LEAD;
1123 *ptr++ = ((~MatrixR4_COMM_LEAD) & 0xFF);
1124 *ptr++ = (uint8_t)cmd;
1125
1126 for (uint16_t i = 0; i < size; i++) {
1127 *ptr++ = data[i];
1128 }
1129 commSerial->write(arr, 3 + size);
1130 commSerial->flush();
1131}
1132
1133void MMLower::CommSendData(COMM_CMD cmd, uint8_t data)
1134{
1135 uint8_t _data[1] = {data};
1136 CommSendData((COMM_CMD)cmd, _data, 1);
1137}
1138
1139bool MMLower::CommReadData(uint8_t* data, uint16_t size, uint32_t timeout_ms)
1140{
1141 uint32_t timeout = millis() + timeout_ms;
1142 while (millis() <= timeout) {
1143 if (commSerial->available() >= size) {
1144 for (uint16_t i = 0; i < size; i++) {
1145 data[i] = commSerial->read();
1146 }
1147 return true;
1148 }
1149 }
1150 // Timeout
1151 // Clear Buffer
1152 while (commSerial->available() > 0) {
1153 commSerial->read();
1154 }
1155 return false;
1156}
1157
1158bool MMLower::WaitData(COMM_CMD cmd, uint32_t timeout_ms)
1159{
1160 static COMM_STATE state = COMM_STATE::WAIT_LEAD;
1161
1162 uint32_t timeout = millis() + timeout_ms;
1163 while (millis() <= timeout) {
1164 if (commSerial->available() <= 0) {
1165 continue;
1166 }
1167 switch (state) {
1169 {
1170 uint8_t b = commSerial->read();
1171 if (b == MatrixR4_COMM_LEAD) {
1173 }
1174 } break;
1175
1177 {
1178 uint8_t b = commSerial->read();
1179 if (b == ((~MatrixR4_COMM_LEAD) & 0xFF))
1180 state = COMM_STATE::WAIT_CMD;
1181 else
1182 state = COMM_STATE::WAIT_LEAD;
1183 } break;
1184
1186 {
1187 uint8_t b = commSerial->read();
1188 if (b == (uint8_t)cmd) {
1189 state = COMM_STATE::WAIT_LEAD;
1190 return true;
1191 } else {
1192 state = COMM_STATE::WAIT_LEAD;
1193 HandleCommand(b);
1194 }
1195 } break;
1196
1197 case COMM_STATE::ERROR:
1198 {
1199 // TODO: Handle Error
1200 MR4_DEBUG_PRINTLN("COMM_STATE: ERROR");
1201 state = COMM_STATE::WAIT_LEAD;
1202 } break;
1203
1204 default: state = COMM_STATE::WAIT_LEAD; break;
1205 }
1206 }
1207 // Timeout
1208 state = COMM_STATE::WAIT_LEAD;
1209 return false;
1210}
1211
1212void MMLower::HandleCommand(uint8_t cmd)
1213{
1214 switch (cmd) {
1216 {
1217 uint8_t b[2];
1218 if (CommReadData(b, 2)) {
1219 if (callbackFunc == NULL) break;
1220 if (b[0] < MatrixR4_BUTTON_NUM) {
1221 callbackFunc(b[0] + 1, (BTN_STATE)b[1]);
1222 }
1223 }
1224 } break;
1226 {
1227 uint8_t b[8];
1228 if (CommReadData(b, 8)) {
1229 for (uint8_t i = 0; i < MatrixR4_ENCODER_NUM; i++) {
1230 enCounter[i] = BitConverter::ToInt16(b, i * 2);
1231 }
1232 }
1233 } break;
1234 case (uint8_t)COMM_CMD::AUTO_SEND_IMU_EULER:
1235 {
1236 uint8_t b[6];
1237 if (CommReadData(b, 6)) {}
1238 } break;
1239 case (uint8_t)COMM_CMD::AUTO_SEND_IMU_GYRO:
1240 {
1241 uint8_t b[6];
1242 if (CommReadData(b, 6)) {
1243 imuGyroX = BitConverter::ToInt16(b, 0) / 100.0f;
1244 imuGyroY = BitConverter::ToInt16(b, 2) / 100.0f;
1245 imuGyroZ = BitConverter::ToInt16(b, 4) / 100.0f;
1246 }
1247 } break;
1248 case (uint8_t)COMM_CMD::AUTO_SEND_IMU_ACC:
1249 {
1250 uint8_t b[6];
1251 if (CommReadData(b, 6)) {
1252 imuAccX = BitConverter::ToInt16(b, 0) / 1000.0f;
1253 imuAccY = BitConverter::ToInt16(b, 2) / 1000.0f;
1254 imuAccZ = BitConverter::ToInt16(b, 4) / 1000.0f;
1255 }
1256 } break;
1257 default: break;
1258 }
1259}
1260
1261MMLower 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 uint16_t ToUInt16(uint8_t *value, int startIdx)
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:504
IMU_GYRO_FSR
Definition MMLower.h:168
RESULT GetAllInfo(AllInfo_t &info)
Definition MMLower.cpp:1052
COMM_STATE
Definition MMLower.h:57
double imuGyroX
Definition MMLower.h:337
RESULT GetRotateState(uint8_t num, bool &isEnd)
Definition MMLower.cpp:907
RESULT SetEncoderDir(uint8_t num, DIR dir)
Definition MMLower.cpp:61
MOVE_ACTION
Definition MMLower.h:206
RESULT SetStateLED(uint8_t brightness, uint32_t colorRGB)
Definition MMLower.cpp:669
RESULT SetServoAngleRange(uint8_t num, uint16_t min, uint16_t max)
Definition MMLower.cpp:179
RESULT SetServoPulseRange(uint8_t num, uint16_t min, uint16_t max)
Definition MMLower.cpp:142
RESULT SetDCMotorPower(uint8_t num, int16_t power)
Definition MMLower.cpp:327
RESULT RunAutoQC(void)
Definition MMLower.cpp:1082
int32_t enCounter[MatrixR4_ENCODER_NUM]
Definition MMLower.h:335
RESULT SetDCMotorRotate(uint8_t num, int16_t maxSpeed, uint16_t degree)
Definition MMLower.cpp:393
RESULT GetIMUGyro(double &x, double &y, double &z)
Definition MMLower.cpp:837
RESULT SetServoAngle(uint8_t num, uint16_t angle)
Definition MMLower.cpp:472
double imuAccX
Definition MMLower.h:338
RESULT EchoTest(void)
Definition MMLower.cpp:929
RESULT GetFWVersion(String &version)
Definition MMLower.cpp:953
RESULT GetFWBuildDay(String &date)
Definition MMLower.cpp:975
void loop(void)
Definition MMLower.cpp:1107
IMU_ECHO_MODE
Definition MMLower.h:152
RESULT Init(uint32_t timeout_ms=1000)
Definition MMLower.cpp:15
RESULT GetFWDescriptor(String &descriptor)
Definition MMLower.cpp:1003
RESULT GetEncoderCounter(uint8_t num, int32_t &enCounter)
Definition MMLower.cpp:767
RESULT SetDCMotorSpeed(uint8_t num, int16_t speed)
Definition MMLower.cpp:360
RESULT GetPowerInfo(float &curVolt, float &curVoltPerc)
Definition MMLower.cpp:883
RESULT GetButtonState(uint8_t num, bool &btnState)
Definition MMLower.cpp:722
double imuGyroY
Definition MMLower.h:337
RESULT SetEncoderResetCounter(uint8_t num)
Definition MMLower.cpp:593
RESULT GetIMUAcc(double &x, double &y, double &z)
Definition MMLower.cpp:860
RESULT SetIMUEchoMode(IMU_ECHO_MODE mode, uint16_t echoIntervalMs)
Definition MMLower.cpp:216
double imuAccZ
Definition MMLower.h:338
RESULT GetModelIndex(uint8_t &index)
Definition MMLower.cpp:1031
RESULT SetAllDCMotorSpeed(Motors_Param_t param)
Definition MMLower.cpp:422
void onBtnChg(BtnChgCallback callback)
Definition MMLower.cpp:1112
RESULT SetServoDir(uint8_t num, DIR dir)
Definition MMLower.cpp:87
RESULT SetMoveDistance(MOVE_TYPE type, MOVE_ACTION action, uint16_t speed, uint16_t enCounter)
Definition MMLower.cpp:550
RESULT GetIMUEuler(int16_t &roll, int16_t &pitch, int16_t &yaw)
Definition MMLower.cpp:813
double imuGyroZ
Definition MMLower.h:337
RESULT GetAllEncoderCounter(int32_t *enCounter)
Definition MMLower.cpp:789
double imuAccY
Definition MMLower.h:338
IMU_ACC_FSR
Definition MMLower.h:160
RESULT SetPIDParam(uint8_t num, uint8_t pidNum, float kp, float ki, float kd)
Definition MMLower.cpp:618
RESULT SetIMUToZero(void)
Definition MMLower.cpp:698
MMLower(uint8_t rx, uint8_t tx, uint32_t baudrate)
Definition MMLower.cpp:9
RESULT SetDCMotorSpeedRange(uint8_t num, uint16_t min, uint16_t max)
Definition MMLower.cpp:113
RESULT GetButtonsState(bool *btnsState)
Definition MMLower.cpp:744
RESULT SetDCBrake(uint8_t num)
Definition MMLower.cpp:644
RESULT SetIMUInit(IMU_ACC_FSR accFSR, IMU_GYRO_FSR gyroFSR, IMU_ODR odr, IMU_FIFO fifo)
Definition MMLower.cpp:251
RESULT SetDCMotorDir(uint8_t num, DIR dir)
Definition MMLower.cpp:36
RESULT SetPowerParam(float fullVolt, float cutOffVolt, float alarmVolt)
Definition MMLower.cpp:294
uint8_t modelIndex
Definition MMLower.h:281