1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5 Date started: 6/17/2006
7 ------------- Copyright (C) 2006 by Jon S. Berndt, jon@jsbsim.org -------------
9 This program is free software; you can redistribute it and/or modify it under
10 the terms of the GNU Lesser General Public License as published by the Free Software
11 Foundation; either version 2 of the License, or (at your option) any later
14 This program is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
19 You should have received a copy of the GNU Lesser General Public License along with
20 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21 Place - Suite 330, Boston, MA 02111-1307, USA.
23 Further information about the GNU Lesser General Public License can also be found on
24 the world wide web at http://www.gnu.org.
27 --------------------------------------------------------------------------------
28 Initial Code 6/17/2006 JSB
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
41 #include "FGFCSComponent.h"
43 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
47 #define ID_PID "$Id: FGPID.h,v 1.13 2012/05/10 12:10:48 jberndt Exp $"
49 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
58 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
62 /** Encapsulates a PID control component for the flight control system.
64 <h3>Configuration Format:</h3>
67 <pid name="{string}" [type="standard"]>
68 <kp> {number|property} </kp>
69 <ki> {number|property} </ki>
70 <kd> {number|property} </kd>
71 <trigger> {property} </trigger>
75 For the integration constant element, one can also supply the type attribute for
76 what kind of integrator to be used, one of:
78 - rect, for a rectangular integrator
79 - trap, for a trapezoidal integrator
80 - ab2, for a second order Adams Bashforth integrator
81 - ab3, for a third order Adams Bashforth integrator
86 <pid name="fcs/heading-control">
88 <ki type="ab3"> 1 </ki>
95 <h3>Configuration Parameters:</h3>
98 The values of kp, ki, and kd have slightly different interpretations depending on
99 whether the PID controller is a standard one, or an ideal/parallel one - with the latter
102 kp - Proportional constant, default value 0.
103 ki - Integrative constant, default value 0.
104 kd - Derivative constant, default value 0.
105 trigger - Property which is used to sense wind-up, optional. Most often, the trigger
106 will be driven by the "saturated" property of a particular actuator. When
107 the relevant actuator has reached it's limits (if there are any, specified
108 by the <clipto> element) the automatically generated saturated property will
109 be greater than zero (true). If this property is used as the trigger for the
110 integrator, the integrator will not continue to integrate while the property
111 is still true (> 1), preventing wind-up.
112 pvdot - The property to be used as the process variable time derivative.
118 @author Jon S. Berndt
119 @version $Revision: 1.13 $
122 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
124 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
126 class FGPID : public FGFCSComponent
129 FGPID(FGFCS* fcs, Element* element);
133 void ResetPastStates(void) {Input_prev = Input_prev2 = Output = I_out_total = 0.0;}
135 /// These define the indices use to select the various integrators.
136 enum eIntegrateType {eNone = 0, eRectEuler, eTrapezoidal, eAdamsBashforth2, eAdamsBashforth3};
141 double Input_prev, Input_prev2;
142 double KpPropertySign;
143 double KiPropertySign;
144 double KdPropertySign;
148 eIntegrateType IntType;
150 FGPropertyManager *Trigger;
151 FGPropertyManager* KpPropertyNode;
152 FGPropertyManager* KiPropertyNode;
153 FGPropertyManager* KdPropertyNode;
154 FGPropertyManager* ProcessVariableDot;
156 void Debug(int from);