1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-26 15:54:15 +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 * @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 * @brief Executes PID control for down direction
* *
* @see The GNU Public License (GPL) Version 3 * @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) void PIDControlDown::UpdateParameters(float kp, float ki, float kd, float beta, float dT, float velocityMax)
{ {
// pid_configure(&PID, kp, ki, kd, ilimit); float Td; // Derivative time constant
float Td; float Ti; // Integral time constant
float Ti; float kt; // Feedback gain for integral windup avoidance
float Tt; float N = 10.0f; // N is the factor used to determine the
float kt; // time constant for derivative filtering
float N = 10.0f; // Why 10? Maybe should be configurable?
float Tf; float Tf; // Low pass filter time constant for derivative filtering
// Define Td, handling zero kp term (for I or ID controller) // Define Td, handling zero kp term (for I or ID controller)
if (kp < 1e-6f) { 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) // Define Ti, Tt and kt, handling zero ki term (for P or PD controller)
if (ki < 1e-6f) { // Avoid Ti being infinite 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; kt = 0.0f;
} else { } else {
Ti = kp / ki; Ti = kp / ki;
Tt = (Ti + Td) / 2.0f; kt = 1.0f / Ti;
kt = 1.0f / Tt;
} }
// Define Tf, according to controller type // Define Tf, according to controller type
if (kd < 1e-6f) { if (kd < 1e-6f) {
// PI Controller or P Controller // 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 { } else {
Tf = Td / N; Tf = Td / N;
} }