feat: 添加 PID 控制器及霍尔传感器转速获取功能
This commit is contained in:
30
Core/Bsp/bsp_pid.h
Normal file
30
Core/Bsp/bsp_pid.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef __BSP_PID_H
|
||||
#define __BSP_PID_H
|
||||
|
||||
#include "main.h"
|
||||
|
||||
/**
|
||||
* @brief PID 参数结构体定义
|
||||
*/
|
||||
typedef struct {
|
||||
float target; // 目标值 (目标 RPM)
|
||||
float actual; // 实际值 (反馈 RPM)
|
||||
float err; // 当前误差
|
||||
float err_last; // 上次误差
|
||||
float Kp, Ki, Kd; // PID 增益
|
||||
float integral; // 误差积分累加器
|
||||
float integral_max; // 积分限幅 (防止积分饱和)
|
||||
float output; // PID 计算输出值 (PWM)
|
||||
float output_max; // 输出限幅 (如 3599)
|
||||
} PID_TypeDef;
|
||||
|
||||
/* 初始化 PID 控制器 */
|
||||
void pid_init(PID_TypeDef *pid, float kp, float ki, float kd, float out_max, float int_max);
|
||||
|
||||
/* 计算 PID 输出 */
|
||||
float pid_calculate(PID_TypeDef *pid, float target, float actual);
|
||||
|
||||
/* 重置 PID 内部状态 */
|
||||
void pid_reset(PID_TypeDef *pid);
|
||||
|
||||
#endif /* __BSP_PID_H */
|
||||
Reference in New Issue
Block a user