RobotHardware-UESTC/Hardware/银星机器人底盘/PiRobot-YH_Firmware v1.0/STM32/Lib/PID/pid.h

38 lines
894 B
C
Raw Normal View History

2024-01-24 22:08:32 +08:00
#ifndef __GEBOT_PID_H__
#define __GEBOT_PID_H__
2024-01-20 13:19:09 +08:00
//pid接口
class PID
{
public:
/* pid构造函数
2024-01-24 22:08:32 +08:00
* @param input pid
* @param output pid
* @param kp,ki,kd pid
2024-01-20 13:19:09 +08:00
* @param max_output
*/
PID(float* input, float* feedback, float kp, float ki, float kd, unsigned short max_output);
// pid计算
2024-01-24 22:08:32 +08:00
short Compute(float interval);
2024-01-20 13:19:09 +08:00
// 重置pid的值
2024-01-24 22:08:32 +08:00
void Clear();
2024-01-20 13:19:09 +08:00
2024-01-24 22:08:32 +08:00
// 更新pid参数
void Update(float kp, float ki, float kd, unsigned short _maxOutput);
2024-01-20 13:19:09 +08:00
private:
float kp;
float ki;
float kd;
float max_output;
float* input;
float* feedback;
2024-01-24 22:08:32 +08:00
float err; // 比例值
float integra; // 积分值
float derivative; // 微分值
float preErr; // 上一次的输入反馈差值
2024-01-20 13:19:09 +08:00
};
#endif