#ifndef _PID_H_ #define _PID_H_ #include #include "consts.h" struct PIDConfig { float Kp; float Ki; float Kd; float outputMax; // 输出限幅 float outputMin; // 输出限幅 float integralMax; // 积分限幅 }; struct PID { float error; float last_error; float integral; float derivative; unsigned long lastTime; // 上次更新时间 }; class PIDController { public: static PID pid; static PIDConfig pidConfig; static void reset(); // 重置PID状态 static void setConfig(float Kp, float Ki, float Kd, float outputMax = 255, float outputMin = -255, float integralMax = 1000); static float update(float target, float current); }; #endif