#ifndef MOTOR_H #define MOTOR_H #include struct MotorPin { int pwm; int in1; int in2; }; // 电机状态结构体 struct MotorStatus { MotorPin pin; bool in1; bool in2; unsigned char pwm; }; typedef enum { ROTATE_CLOCKWISE = 1, ROTATE_ANTICLOCKWISE = -1, } RotateDirection; class MotorController { public: static void init(MotorPin aPin, MotorPin bPin, MotorPin cPin, MotorPin dPin); static void pwmControl(char motor, unsigned char pwm); static void motorControl(char motor, int speed); static void motorXYRControl(int8_t x, int8_t y, int8_t r); static void rotate(RotateDirection direction, uint8_t speed); // 获取电机状态 static MotorStatus getMotorStatus(char motor); private: static MotorStatus motorA; static MotorStatus motorB; static MotorStatus motorC; static MotorStatus motorD; }; #endif