In the source code of the libraries, there are two about the PID of the source file folder, one called Ac_pid, the other is the PID. Ac_pid is subdivided into ac_heli_pid, ac_p and Ac_pid, where we only discuss ac_pid. PID folder only a PID class, the following list the properties and methods in these two classes, and roughly describe its function and implementation details, the source code please download and read. Ac_pid
Constructor (slightly)
Float Get_pid (float error, float DT); The calculation of the output of the PID controller is actually called the following get_p, Get_i, Get_d function
Float Get_pi (float error, float DT); Calculate PI Controller Output
Float get_p (float error) const; Calculate P output
Float get_i (float error, float DT); Calculate I output, with integral limit, determined by _imax
Float Get_d (float error, float DT); Calculate the D output, first determine whether the last differential value is valid, avoid the last value is not determined to cause large output, and has a 20HZ low-pass filter
Reset the PID Integrator
///
void Reset_i (); Set the integral value to 0 and the last differential value to Nan
Load Gain Properties
///
void Load_gains ();
Save Gain Properties
///
void Save_gains ();
Sets filter Alpha for D-term LPF
void Set_d_lpf_alpha (int16_t cutoff_frequency, float time_step); Calculate filter coefficients
PID
Constructor (slightly)
float get_pid (float error, float scaler = 1.0); //Calculate the output of the PID controller, similar to the method used above, Different points 1. If two times the calculation time is greater than 1 seconds, then resets the integral value, avoids the big fluctuation; 2 There is a scaler that can perform a whole scale operation on the output value, instead of adjusting the PID three parameters, the default is 1.
//get_pid () constrained to +/-4500
int16_t get_pid_4500 (float error, float scaler = 1.0); //Limit the output of the PID between +/-4500
//Reset the PID Integrator
//
void reset_i ();
//Load Gain Properties
//
void Load_gains ();
//Save Gain Properties
//
void Save_gains ();
It can be seen that the two PID implementation is basically the same, in detail processing is not quite the same, the specific use of what is not clear, here is just a note, as the study deepened will be further improved.