这个是参考Pixhawk库文件pid文件夹下的程序
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
/// @file PID.cpp
/// @brief Generic PID algorithm
#include <math.h>
#include "PID.h"
#include <AP_HAL/AP_HAL.h>
#include <AP_Math/AP_Math.h>
extern const AP_HAL::HAL& hal;
const AP_Param::GroupInfo PID::var_info[] = {
// @Param: P
// @DisplayName: PID Proportional Gain
// @Description: P Gain which produces an output value that is proportional to the current error value
AP_GROUPINFO("P", 0, PID, _kp, 0),
// @Param: I
// @DisplayName: PID Integral Gain
// @Description: I Gain which produces an output that is proportional to both the magnitude and the duration of the error
AP_GROUPINFO("I", 1, PID, _ki, 0),
// @Param: D
// @DisplayName: PID Derivative Gain
// @Description: D Gain which produces an output that is proportional to the rate of change of the error
AP_GROUPINFO

这是一个简单的PID控制器的C++代码实现,包含了比例、积分、微分三个部分,并且进行了低通滤波处理以减少噪声影响。代码中还提供了积分最大值限制、重置积分项的功能,以及读写参数到存储器的接口。
最低0.47元/天 解锁文章
2万+

被折叠的 条评论
为什么被折叠?



