]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/flight_control/FGPID.h
sync with JSB JSBSim CVS
[flightgear.git] / src / FDM / JSBSim / models / flight_control / FGPID.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Header:       FGPID.h
4  Author:       Jon Berndt
5  Date started: 6/17/2006
6
7  ------------- Copyright (C) 2006 by Jon S. Berndt, jon@jsbsim.org -------------
8
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
12  version.
13
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
17  details.
18
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.
22
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.
25
26 HISTORY
27 --------------------------------------------------------------------------------
28 Initial Code 6/17/2006 JSB
29
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 SENTRY
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
33
34 #ifndef FGPID_H
35 #define FGPID_H
36
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 INCLUDES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40
41 #include "FGFCSComponent.h"
42
43 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44 DEFINITIONS
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
46
47 #define ID_PID "$Id: FGPID.h,v 1.13 2012/05/10 12:10:48 jberndt Exp $"
48
49 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 FORWARD DECLARATIONS
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
52
53 namespace JSBSim {
54
55 class FGFCS;
56 class Element;
57
58 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59 CLASS DOCUMENTATION
60 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
61
62 /** Encapsulates a PID control component for the flight control system.
63
64 <h3>Configuration Format:</h3>
65
66 @code
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>
72 </pid>
73 @endcode
74
75 For the integration constant element, one can also supply the type attribute for
76 what kind of integrator to be used, one of:
77
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
82
83 For example,
84
85 @code
86 <pid name="fcs/heading-control">
87   <kp> 3 </kp>
88   <ki type="ab3"> 1 </ki>
89   <kd> 1 </kd>
90 </pid>
91 @endcode
92
93
94
95 <h3>Configuration Parameters:</h3>
96 <pre>
97
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
100   being the default.
101   
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. 
113
114
115
116 </pre>
117
118     @author Jon S. Berndt
119     @version $Revision: 1.13 $
120 */
121
122 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
123 CLASS DECLARATION
124 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
125
126 class FGPID  : public FGFCSComponent
127 {
128 public:
129   FGPID(FGFCS* fcs, Element* element);
130   ~FGPID();
131
132   bool Run (void);
133   void ResetPastStates(void) {Input_prev = Input_prev2 = Output = I_out_total = 0.0;}
134
135     /// These define the indices use to select the various integrators.
136   enum eIntegrateType {eNone = 0, eRectEuler, eTrapezoidal, eAdamsBashforth2, eAdamsBashforth3};
137
138 private:
139   double Kp, Ki, Kd;
140   double I_out_total;
141   double Input_prev, Input_prev2;
142   double KpPropertySign;
143   double KiPropertySign;
144   double KdPropertySign;
145
146   bool IsStandard;
147
148   eIntegrateType IntType;
149
150   FGPropertyManager *Trigger;
151   FGPropertyManager* KpPropertyNode;
152   FGPropertyManager* KiPropertyNode;
153   FGPropertyManager* KdPropertyNode;
154   FGPropertyManager* ProcessVariableDot;
155
156   void Debug(int from);
157 };
158 }
159 #endif