Files
FDR-Core/Core/Inc/motor.h
2026-03-28 13:48:31 +08:00

33 lines
868 B
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#ifndef __MOTOR_H
#define __MOTOR_H
#include "main.h"
#define MAX_PWM_DUTY 1049
#define PWM_LIMIT 1000
#define ENCODER_RESOLUTION 11.0f
#define REDUCTION_RATIO 90.0f
#define PULSES_PER_REV (ENCODER_RESOLUTION * 4.0f * REDUCTION_RATIO)
/* 控制循环 5ms但速度估计窗口取 2 个采样点 => 10ms */
#define MOTOR_SPEED_WINDOW_SAMPLES 2U
typedef enum {
MOTOR_FL = 0,
MOTOR_RL,
MOTOR_FR,
MOTOR_RR
} Motor_ID_t;
void Motor_Init(void);
void Set_Motor_Output(Motor_ID_t id, int16_t control_out);
void Motor_Brake_All(void);
/* 外部仍按 5ms 调用;内部会按滚动窗口更新速度估计 */
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);
#endif /* __MOTOR_H */