esp32-car/include/motor.h

40 lines
712 B
C
Raw Normal View History

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;
};
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 MotorStatus getMotorStatus(char motor);
private:
static MotorStatus motorA;
static MotorStatus motorB;
static MotorStatus motorC;
static MotorStatus motorD;
};
#endif