10#include <SoftwareSerial.h>
12#define MR4_DEBUG_ENABLE false
13#define MR4_DEBUG_SERIAL Serial
15# define MR4_DEBUG_HEADER() MR4_DEBUG_SERIAL.println(F("\nBMR4\n"))
16# define MR4_DEBUG_TAIL() MR4_DEBUG_SERIAL.println(F("\nEMR4\n"))
17# define MR4_DEBUG_PRINT(...) MR4_DEBUG_SERIAL.print(__VA_ARGS__)
18# define MR4_DEBUG_PRINTLN(...) MR4_DEBUG_SERIAL.println(__VA_ARGS__)
19# define MR4_DEBUG_PRINT_HEADER(...) \
22 MR4_DEBUG_SERIAL.println(__VA_ARGS__); \
24# define MR4_DEBUG_PRINT_TAIL(...) \
26 MR4_DEBUG_SERIAL.println(__VA_ARGS__); \
30# define MR4_DEBUG_HEADER()
31# define MR4_DEBUG_TAIL()
32# define MR4_DEBUG_PRINT_HEADER(...)
33# define MR4_DEBUG_PRINT_TAIL(...)
34# define MR4_DEBUG_PRINT(...)
35# define MR4_DEBUG_PRINTLN(...)
38#define MatrixR4_COMM_LEAD 0x7B
40#define MatrixR4_SERVO_NUM 4
41#define MatrixR4_DC_MOTOR_NUM 4
42#define MatrixR4_ENCODER_NUM 4
43#define MatrixR4_BUTTON_NUM 2
45#define DIR_REVERSE (MatrixMiniR4::DIR::REVERSE)
46#define DIR_FORWARD (MatrixMiniR4::DIR::FORWARD)
54 MMLower(uint8_t rx, uint8_t tx, uint32_t baudrate);
445 SoftwareSerial* commSerial;
448 void CommSendData(
COMM_CMD cmd, uint8_t* data = NULL, uint16_t size = 0);
449 void CommSendData(
COMM_CMD cmd, uint8_t data);
450 bool CommReadData(uint8_t* data, uint16_t size = 1, uint32_t timeout_ms = 10);
452 void HandleCommand(uint8_t cmd);
#define MatrixR4_ENCODER_NUM
Handling the Lower MCU (STM32) communication.
RESULT SetAllServoAngle(uint16_t angle1, uint16_t angle2, uint16_t angle3, uint16_t angle4)
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)
RESULT Set_Drive_MoveGyro_PID(float Kp, float Ki, float Kd, uint8_t num)
Drive_RESULT Set_Drive_Motor_Type(uint8_t num, uint8_t type)
RESULT GetAllInfo(AllInfo_t &info)
RESULT SetALLDCBrake(void)
RESULT GetRotateState(uint8_t num, bool &isEnd)
RESULT SetEncoderDir(uint8_t num, DIR dir)
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)
RESULT SetStateLED(uint8_t brightness, uint32_t colorRGB)
RESULT SetServoAngleRange(uint8_t num, uint16_t min, uint16_t max)
RESULT SetServoPulseRange(uint8_t num, uint16_t min, uint16_t max)
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)
Drive_RESULT Set_Drive_MoveSync_Func(int16_t power_left, int16_t power_right, uint8_t num)
RESULT GetIMUEuler(double &roll, double &pitch, double &yaw)
Drive_RESULT Set_Drive_MoveGyro_Time(int16_t power, int16_t Target_dri, uint32_t Time_mS, bool brake, bool async, uint8_t num)
RESULT Set_Drive_MoveSync_PID(float Kp, float Ki, float Kd, uint8_t num)
RESULT SetDCMotorPower(uint8_t num, int16_t power)
@ SET_ENCODER_RESET_COUNTER
@ SET_DC_TWO_MOTOR_Reset_count
@ SET_DC_TWO_TurnGyro_PID
@ AUTO_SEND_ENCODER_COUNTER
@ GET_ALL_ENCODER_COUNTER
@ SET_DC_TWO_MoveSync_PID
@ SET_ENCODER_PPR_MAXSPEED
@ SET_DC_MOTOR_SPEED_RANGE
@ SET_Drive_MoveSyncDegsACC
@ SET_DC_TWO_MoveGyro_PID
RESULT SetALL_Encode_PPR(uint16_t *ppr)
Drive_RESULT Get_Drive_isTaskDone(uint8_t num, bool *isEnd)
int32_t enCounter[MatrixR4_ENCODER_NUM]
Drive_RESULT Set_Drive_Brake(bool brake, uint8_t num)
RESULT SetDCMotorRotate(uint8_t num, int16_t maxSpeed, uint16_t degree)
RESULT SetIMU_Calib_data(float *bufdata)
RESULT GetIMUGyro(double &x, double &y, double &z)
RESULT SetServoAngle(uint8_t num, uint16_t angle)
RESULT GetFWVersion(String &version)
RESULT GetFWBuildDay(String &date)
RESULT Init(uint32_t timeout_ms=1000)
RESULT GetFWDescriptor(String &descriptor)
RESULT GetEncoderCounter(uint8_t num, int32_t &enCounter)
RESULT SetDCMotorSpeed(uint8_t num, int16_t speed)
RESULT GetPowerInfo(float &curVolt, float &curVoltPerc)
RESULT GetButtonState(uint8_t num, bool &btnState)
Drive_RESULT Set_Drive_Reset_Count(uint8_t num, bool reset)
RESULT SetEncoderResetCounter(uint8_t num)
RESULT GetIMUAcc(double &x, double &y, double &z)
RESULT SetIMUEchoMode(IMU_ECHO_MODE mode, uint16_t echoIntervalMs)
Drive_RESULT Get_Drive_Degrees(uint8_t num, int32_t &Degs)
RESULT GetModelIndex(uint8_t &index)
RESULT Get_IMU_nancalib_acc(float *accdata)
RESULT SetAllDCMotorSpeed(Motors_Param_t param)
void onBtnChg(BtnChgCallback callback)
RESULT SetServoDir(uint8_t num, DIR dir)
Drive_RESULT Set_Drive_MoveGyro_Func(int16_t power, int16_t Target_dri, uint8_t num)
RESULT SetMoveDistance(MOVE_TYPE type, MOVE_ACTION action, uint16_t speed, uint16_t enCounter)
RESULT GetALLEncoderSpeed(int32_t *enSpeed)
RESULT Set_Drive_MoveTurn_PID(float Kp, float Ki, float Kd, uint8_t num)
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)
Drive_RESULT Set_Drive_Move_Func(int16_t power_left, int16_t power_right, uint8_t num)
RESULT SetAllDCMotorPower(Motors_Param_t param)
Drive_RESULT Get_Drive_EncoderCounter(uint8_t num, int32_t &enCounter)
Drive_RESULT Set_Drive2Motor_PARAM(uint8_t m1_num, uint8_t m2_num, DIR m1_dir, DIR m2_dir, uint8_t num)
RESULT GetAllEncoderCounter(int32_t *enCounter)
RESULT SetPIDParam(uint8_t num, uint8_t pidNum, float kp, float ki, float kd)
RESULT SetIMUToZero(void)
MMLower(uint8_t rx, uint8_t tx, uint32_t baudrate)
RESULT SetALLDC_Type_Brake(uint8_t *type)
RESULT SetDCMotorSpeedRange(uint8_t num, uint16_t min, uint16_t max)
RESULT GetButtonsState(bool *btnsState)
RESULT SetDCBrake(uint8_t num)
RESULT SetIMUInit(IMU_ACC_FSR accFSR, IMU_GYRO_FSR gyroFSR, IMU_ODR odr, IMU_FIFO fifo)
void(* BtnChgCallback)(uint8_t num, BTN_STATE newState)
Drive_RESULT Set_Drive_MoveGyro_Degs(int16_t power, int16_t Target_dri, uint16_t Degree_c, bool brake, bool async, uint8_t num)
RESULT SetDC_Type_Brake(uint8_t num, uint8_t type)
Drive_RESULT Set_Drive_TurnGyro(int16_t power, int16_t Target_dri, uint8_t mode, bool brake, bool async, uint8_t num)
Drive_RESULT Set_Drive_Encode_PPR(uint8_t num, uint16_t *ppr)
RESULT SetEncode_PPR_MaxRPM(uint8_t num, uint16_t ppr, uint16_t Maxspeed)
RESULT SetDCMotorDir(uint8_t num, DIR dir)
RESULT GetEncoderDegrees(uint8_t num, int32_t &enDeges)
RESULT SetPowerParam(float fullVolt, float cutOffVolt, float alarmVolt)