Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/libraries/AC_PID/AC_HELI_PID.cpp
Views: 1798
/// @file AC_HELI_PID.cpp1/// @brief Generic PID algorithm23#include <AP_Math/AP_Math.h>4#include "AC_HELI_PID.h"56const AP_Param::GroupInfo AC_HELI_PID::var_info[] = {7// @Param: P8// @DisplayName: PID Proportional Gain9// @Description: P Gain which produces an output value that is proportional to the current error value10AP_GROUPINFO("P", 0, AC_HELI_PID, _kp, 0),1112// @Param: I13// @DisplayName: PID Integral Gain14// @Description: I Gain which produces an output that is proportional to both the magnitude and the duration of the error15AP_GROUPINFO("I", 1, AC_HELI_PID, _ki, 0),1617// @Param: D18// @DisplayName: PID Derivative Gain19// @Description: D Gain which produces an output that is proportional to the rate of change of the error20AP_GROUPINFO("D", 2, AC_HELI_PID, _kd, 0),2122// 3 was for uint16 IMAX2324// @Param: FF25// @DisplayName: FF FeedForward Gain26// @Description: FF Gain which produces an output value that is proportional to the demanded input27AP_GROUPINFO("FF", 4, AC_HELI_PID, _kff, 0),2829// @Param: IMAX30// @DisplayName: PID Integral Maximum31// @Description: The maximum/minimum value that the I term can output32AP_GROUPINFO("IMAX", 5, AC_HELI_PID, _kimax, 0),3334// 6 was for float FILT3536// @Param: ILMI37// @DisplayName: I-term Leak Minimum38// @Description: Point below which I-term will not leak down39// @Range: 0 140// @User: Advanced41AP_GROUPINFO("ILMI", 7, AC_HELI_PID, _leak_min, AC_PID_LEAK_MIN),4243// 8 was for float AFF4445// @Param: FLTT46// @DisplayName: PID Target filter frequency in Hz47// @Description: Target filter frequency in Hz48// @Units: Hz49AP_GROUPINFO("FLTT", 9, AC_HELI_PID, _filt_T_hz, AC_PID_TFILT_HZ_DEFAULT),5051// @Param: FLTE52// @DisplayName: PID Error filter frequency in Hz53// @Description: Error filter frequency in Hz54// @Units: Hz55AP_GROUPINFO("FLTE", 10, AC_HELI_PID, _filt_E_hz, AC_PID_EFILT_HZ_DEFAULT),5657// @Param: FLTD58// @DisplayName: PID D term filter frequency in Hz59// @Description: Derivative filter frequency in Hz60// @Units: Hz61AP_GROUPINFO("FLTD", 11, AC_HELI_PID, _filt_D_hz, AC_PID_DFILT_HZ_DEFAULT),6263// @Param: SMAX64// @DisplayName: Slew rate limit65// @Description: Sets an upper limit on the slew rate produced by the combined P and D gains. If the amplitude of the control action produced by the rate feedback exceeds this value, then the D+P gain is reduced to respect the limit. This limits the amplitude of high frequency oscillations caused by an excessive gain. The limit should be set to no more than 25% of the actuators maximum slew rate to allow for load effects. Note: The gain will not be reduced to less than 10% of the nominal value. A value of zero will disable this feature.66// @Range: 0 20067// @Increment: 0.568// @User: Advanced69AP_GROUPINFO("SMAX", 12, AC_HELI_PID, _slew_rate_max, 0),7071// @Param: PDMX72// @DisplayName: PD sum maximum73// @Description: The maximum/minimum value that the sum of the P and D term can output74// @User: Advanced75AP_GROUPINFO("PDMX", 13, AC_HELI_PID, _kpdmax, 0),7677// @Param: D_FF78// @DisplayName: PID Derivative FeedForward Gain79// @Description: FF D Gain which produces an output that is proportional to the rate of change of the target80// @Range: 0 0.0281// @Increment: 0.000182// @User: Advanced83AP_GROUPINFO("D_FF", 14, AC_HELI_PID, _kdff, 0),8485#if AP_FILTER_ENABLED86// @Param: NTF87// @DisplayName: PID Target notch filter index88// @Description: PID Target notch filter index89// @Range: 1 890// @User: Advanced91AP_GROUPINFO("NTF", 15, AC_HELI_PID, _notch_T_filter, 0),9293// @Param: NEF94// @DisplayName: PID Error notch filter index95// @Description: PID Error notch filter index96// @Range: 1 897// @User: Advanced98AP_GROUPINFO("NEF", 16, AC_HELI_PID, _notch_E_filter, 0),99#endif100101AP_GROUPEND102};103104// This is an integrator which tends to decay to zero naturally105// if the error is zero.106107void AC_HELI_PID::update_leaky_i(float leak_rate)108{109if (!is_zero(_ki)){110111// integrator does not leak down below Leak Min112if (_integrator > _leak_min){113_integrator -= (float)(_integrator - _leak_min) * leak_rate;114} else if (_integrator < -_leak_min) {115_integrator -= (float)(_integrator + _leak_min) * leak_rate;116}117118}119}120121122