添加了pid以及gui

This commit is contained in:
2025-12-05 14:22:47 +08:00
parent 8f5ced6be3
commit ac566a0cf6
4 changed files with 230 additions and 7 deletions

46
inc/PidController.h Normal file
View File

@@ -0,0 +1,46 @@
#ifndef PID_CONTROLLER_H
#define PID_CONTROLLER_H
#include <opencv2/opencv.hpp>
class PidController {
public:
// 构造函数
PidController(float kp = 0.0f, float ki = 0.0f, float kd = 0.0f);
// 更新PID计算
float update(float setpoint, float measured_value, float dt);
// 重置PID控制器
void reset();
// 设置PID参数
void setKp(float kp);
void setKi(float ki);
void setKd(float kd);
void setParameters(float kp, float ki, float kd);
// 获取PID参数
float getKp() const;
float getKi() const;
float getKd() const;
// 设置输出限制
void setOutputLimits(float min, float max);
// 获取输出
float getOutput() const;
// 获取误差
float getError() const;
private:
float kp_, ki_, kd_; // PID参数
float last_error_; // 上一次误差
float integral_; // 积分项
float output_; // 输出值
float output_min_, output_max_; // 输出限制
bool first_iteration_; // 是否为第一次迭代
};
#endif // PID_CONTROLLER_H