1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-01 09:24:10 +01:00

LP-289 Further clean up of PIDControlDown::UpdateParameters()

This commit is contained in:
paul Jewell 2016-12-10 12:43:50 +01:00
parent 814a882a1d
commit edd3b8689b

View File

@ -7,7 +7,8 @@
* @{
*
* @file pidcontroldown.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2015.
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016.
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2015.
* @brief Executes PID control for down direction
*
* @see The GNU Public License (GPL) Version 3
@ -90,13 +91,13 @@ void PIDControlDown::Activate()
void PIDControlDown::UpdateParameters(float kp, float ki, float kd, float beta, float dT, float velocityMax)
{
// pid_configure(&PID, kp, ki, kd, ilimit);
float Td;
float Ti;
float Tt;
float kt;
float N = 10.0f;
float Tf;
float Td; // Derivative time constant
float Ti; // Integral time constant
float kt; // Feedback gain for integral windup avoidance
float N = 10.0f; // N is the factor used to determine the
// time constant for derivative filtering
// Why 10? Maybe should be configurable?
float Tf; // Low pass filter time constant for derivative filtering
// Define Td, handling zero kp term (for I or ID controller)
if (kp < 1e-6f) {
@ -107,19 +108,17 @@ void PIDControlDown::UpdateParameters(float kp, float ki, float kd, float beta,
// Define Ti, Tt and kt, handling zero ki term (for P or PD controller)
if (ki < 1e-6f) { // Avoid Ti being infinite
Ti = 1e6f;
// Tt antiwindup time constant - we don't need antiwindup with no I term
Tt = 1e6f;
kt = 0.0f;
} else {
Ti = kp / ki;
Tt = (Ti + Td) / 2.0f;
kt = 1.0f / Tt;
kt = 1.0f / Ti;
}
// Define Tf, according to controller type
if (kd < 1e-6f) {
// PI Controller or P Controller
Tf = Ti / N;
Tf = 0; // Originally this: (Ti / N) - which creates a D term from
// the integral time constant!
} else {
Tf = Td / N;
}