WSF
P6DofPID.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2003-2015 The Boeing Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11
12#ifndef P6DOFPID_H
13#define P6DOFPID_H
14
15#include <vector>
16
17#include "P6DofVehicleData.hpp"
18
19// P6DofPID defines a Proportional, Integral, Derivative (PID) controller
20// class that is used by other autopilot classes. The PID includes the standard
21// Kp, Ki, and Kd parameters as well as five additional attributes:
22//
23// * MaxErrorAccum, limits accumulation to a max (absolute) value
24// * DerivativeLowpassAlpha, uses a low-pass filter on the derivative
25// * MaxErrorAntiWindup, halts accumulation if error is > value
26// * MinErrorAntiWindup, halts accumulation if error is < value
27// * Kt, which is an anti-windup to help address saturation
28//
29// It is also possible to use tabular gain data, if desired, based on a
30// controlling parameter (such as dynamic pressure).
31
33{
34public:
35 P6DofPID();
36 ~P6DofPID();
37
38 P6DofPID& operator=(const P6DofPID& other) = delete;
39
40 P6DofPID* Clone() const;
41
42 P6DofPID(const P6DofPID& aSrc);
43
44 // This is the main method is used to update the PID. It uses
45 // the set point and current value to determine the error.
46 double CalcOutputFromTargetAndCurrent(double aSetPoint, double aCurValue, double aDt_sec);
47
48 // This method includes output limits.
49 double CalcOutputFromTargetAndCurrentWithLimits(double aSetPoint,
50 double aCurValue,
51 double aDt_sec,
52 double aMinOutput,
53 double aMaxOutput);
54
55 // This method is used when the error needs to be calculated outside
56 // of the method, such as when dealing with circular values such
57 // as angles.
58 double CalcOutputFromError(double aError, double aDt_sec);
59
60 // This method includes output limits.
61 double CalcOutputFromErrorWithLimits(double aError, double aDt_sec, double aMinOutput, double aMaxOutput);
62
63 // This sets the current value of the plant
64 void SetCurrentValue(double aCurrentValue);
65
66 // This sets the target value (set point) for the plant
67 void SetTargetValue(double aTargetValue);
68
69 // This sets the controlling value (such as dynamic pressure). This only has
70 // an effect if the controlling value is enabled
71 void SetControllingValue(double aControllingValue);
72
73 // This zeroes out calculated state data, useful when resetting parent vehicle state
74 void ResetPidState();
75
76 // This gets the current gains of the PID
77 std::vector<P6DOF::PidGainData>* GetPidGainTableData(unsigned char& aPackedFlags);
78
79 // This sets the gains of the PID
80 void SetPidGainTableData(std::vector<P6DOF::PidGainData>& aDataTables, unsigned char& aPackedFlags);
81
82 // This gets the current values of the PID
84
85 // This sets a bias (also know as "feed forward") for the proportional channel.
86 // This bias will remain in effect until "cleared" by a value of zero.
87 void SetBias(double aBias);
88 void SetFeedForward(double aFeedForward);
89
90 // This returns true if feed forward is active, and returns the
91 // feed forward (bias) value by reference. Otherwise it returns
92 // false and the reference value is undefined.
93 bool GetFeedForward(double& aFeedForward);
94
95 // This should be used to setup items in the gain table before calling the
96 // various "set" functions such as SetKpTable, SetKtAntiWindupTable, etc. to
97 // avoid an error in the set function due to insufficient elements in the table.
98 void AddElementsToGainTable(size_t aTotalElementsInTable);
99
100private:
101 double GetOutputWithLimits(double aDt_sec, double aMinOutput, double aMaxOutput, bool aUseLimits);
102
103 void CalcPidGainsData(std::vector<P6DOF::PidGainData>& aTables,
104 double aControllingValue,
105 double& aKpGain,
106 double& aKiGain,
107 double& aKdGain,
108 double& aLowpassAlpha,
109 double& aMaxAccum,
110 double& aMaxErrorZero,
111 double& aMinErrorZero,
112 double& aKtAntiWindup);
113
114 static void CopyPidGainsData(std::vector<P6DOF::PidGainData>& aTargetTables,
115 const std::vector<P6DOF::PidGainData>& aSourceTables);
116
117 double mSetPoint; // PID set point (target setting)
118 double mCurrentValue; // Current value of PID
119 double mCurrentError; // Current error of PID
120 double mCurrentDeriv; // Current derivative of PID
121 double mLastError; // Previous error
122 double mLastDerivative; // Previous derivative
123 double mErrorAccum; // Accumulated error
124 double mPrelimitedOutput; // Output value before any limiting
125 double mOutput; // Output value
126 double mKpOutputContrib; // Most recent contribution to output by Kp
127 double mKiOutputContrib; // Most recent contribution to output by Ki
128 double mKdOutputContrib; // Most recent contribution to output by Kd
129
130 // The flags are used by both single data (above) and tabular data (below)
131
132 bool mUseAlpha; // Use low-pass (alpha) filter on derivative
133 bool mLimitMax; // Limit accum to max accum value (mMaxErrorAccum)
134 bool mZeroGtMax; // Do not accumulate when error > max value (mMaxErrorAntiWindup)
135 bool mZeroLtMin; // Do not accumulate when error < min value (mMinErrorAntiWindup)
136 bool mUseKt; // Use Kt windup technique -- This is an anti-windup technique
137 // for the integral component that involves feeding back the
138 // error between the unlimited pid output and a limited pid
139 // output with a gain of Kt into the integral.
140
141 // These tables provide PID gain data when mEnableControllingValue is true
142 std::vector<P6DOF::PidGainData> mGainTables;
143
144 bool mProportionalBiasActive;
145 double mProportionalBiasValue; // This is a bias that is added to the proportional channel
146
147 // Controlling Value -- This allows tabular PID gain data, often using
148 // dynamic pressure as the "controlling value". For example, Kp can use
149 // a table of values and interpolate based on the current controlling
150 // value. This allows Kp to be a function of dynamic pressure, for instance.
151 double mControllingValue;
152};
153
154#endif // P6DOFPID_H
void GetPidValueData(P6DOF::SinglePidValueData &aData) const
Definition P6DofPID.cpp:376
double CalcOutputFromTargetAndCurrent(double aSetPoint, double aCurValue, double aDt_sec)
Definition P6DofPID.cpp:98
void AddElementsToGainTable(size_t aTotalElementsInTable)
Definition P6DofPID.cpp:269
void SetCurrentValue(double aCurrentValue)
Definition P6DofPID.cpp:259
P6DofPID & operator=(const P6DofPID &other)=delete
double CalcOutputFromError(double aError, double aDt_sec)
Definition P6DofPID.cpp:107
std::vector< P6DOF::PidGainData > * GetPidGainTableData(unsigned char &aPackedFlags)
Definition P6DofPID.cpp:286
void SetControllingValue(double aControllingValue)
Definition P6DofPID.cpp:413
void SetFeedForward(double aFeedForward)
Definition P6DofPID.cpp:396
~P6DofPID()
Definition P6DofPID.cpp:40
bool GetFeedForward(double &aFeedForward)
Definition P6DofPID.cpp:402
void SetBias(double aBias)
Definition P6DofPID.cpp:390
double CalcOutputFromErrorWithLimits(double aError, double aDt_sec, double aMinOutput, double aMaxOutput)
Definition P6DofPID.cpp:90
double CalcOutputFromTargetAndCurrentWithLimits(double aSetPoint, double aCurValue, double aDt_sec, double aMinOutput, double aMaxOutput)
Definition P6DofPID.cpp:77
void ResetPidState()
Definition P6DofPID.cpp:418
P6DofPID * Clone() const
Definition P6DofPID.cpp:46
void SetPidGainTableData(std::vector< P6DOF::PidGainData > &aDataTables, unsigned char &aPackedFlags)
Definition P6DofPID.cpp:314
P6DofPID()
Definition P6DofPID.cpp:16
void SetTargetValue(double aTargetValue)
Definition P6DofPID.cpp:264
Definition P6DofVehicleData.hpp:152
Copyrights Multiple, All Rights Reserved