2024-12-27 09:47:56 +08:00
|
|
|
#ifndef MOTOR_H
|
|
|
|
#define MOTOR_H
|
|
|
|
|
|
|
|
#include <Arduino.h>
|
|
|
|
|
|
|
|
struct MotorPin
|
|
|
|
{
|
|
|
|
int pwm;
|
|
|
|
int in1;
|
|
|
|
int in2;
|
|
|
|
};
|
|
|
|
|
|
|
|
// 电机状态结构体
|
|
|
|
struct MotorStatus
|
|
|
|
{
|
|
|
|
MotorPin pin;
|
|
|
|
bool in1;
|
|
|
|
bool in2;
|
|
|
|
unsigned char pwm;
|
|
|
|
};
|
|
|
|
|
2025-01-01 17:53:59 +08:00
|
|
|
typedef enum {
|
|
|
|
ROTATE_CLOCKWISE = 1,
|
|
|
|
ROTATE_ANTICLOCKWISE = -1,
|
|
|
|
} RotateDirection;
|
|
|
|
|
2024-12-27 09:47:56 +08:00
|
|
|
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);
|
2025-01-01 17:53:59 +08:00
|
|
|
static void rotate(RotateDirection direction, uint8_t speed);
|
2024-12-27 09:47:56 +08:00
|
|
|
|
|
|
|
// 获取电机状态
|
|
|
|
static MotorStatus getMotorStatus(char motor);
|
|
|
|
|
|
|
|
private:
|
|
|
|
static MotorStatus motorA;
|
|
|
|
static MotorStatus motorB;
|
|
|
|
static MotorStatus motorC;
|
|
|
|
static MotorStatus motorD;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|