Files
FDR-Core/Core/Inc/motor.h

33 lines
868 B
C
Raw Normal View History

2026-03-08 18:17:14 +08:00
#ifndef __MOTOR_H
#define __MOTOR_H
#include "main.h"
2026-03-28 13:48:31 +08:00
#define MAX_PWM_DUTY 1049
#define PWM_LIMIT 1000
2026-03-08 18:17:14 +08:00
2026-03-28 13:48:31 +08:00
#define ENCODER_RESOLUTION 11.0f
#define REDUCTION_RATIO 90.0f
#define PULSES_PER_REV (ENCODER_RESOLUTION * 4.0f * REDUCTION_RATIO)
2026-03-08 18:17:14 +08:00
2026-03-28 13:48:31 +08:00
/* 控制循环 5ms但速度估计窗口取 2 个采样点 => 10ms */
#define MOTOR_SPEED_WINDOW_SAMPLES 2U
2026-03-08 18:17:14 +08:00
typedef enum {
2026-03-28 13:48:31 +08:00
MOTOR_FL = 0,
MOTOR_RL,
MOTOR_FR,
MOTOR_RR
2026-03-08 18:17:14 +08:00
} Motor_ID_t;
void Motor_Init(void);
void Set_Motor_Output(Motor_ID_t id, int16_t control_out);
void Motor_Brake_All(void);
2026-03-28 13:48:31 +08:00
/* 外部仍按 5ms 调用;内部会按滚动窗口更新速度估计 */
2026-03-08 18:17:14 +08:00
void Motor_Update_RPM(float dt_s);
float Get_Motor_RPM(Motor_ID_t id);
void Motor_Get_And_Clear_Delta_Ticks(int16_t* d_fl, int16_t* d_rl, int16_t* d_fr, int16_t* d_rr);
2026-03-28 13:48:31 +08:00
#endif /* __MOTOR_H */