]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/filtersjb/FGFilter.h
Rob Deters: UIUC updates from March 1, 2004.
[flightgear.git] / src / FDM / JSBSim / filtersjb / FGFilter.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Header:       FGFilter.h
4  Author:       Jon S. Berndt
5  Date started: 4/2000
6
7  ------------- Copyright (C)  -------------
8
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU 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 General Public License for more
17  details.
18
19  You should have received a copy of the GNU 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 General Public License can also be found on
24  the world wide web at http://www.gnu.org.
25
26 HISTORY
27 --------------------------------------------------------------------------------
28
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30 SENTRY
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
32
33 #ifndef FGFILTER_H
34 #define FGFILTER_H
35
36 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 INCLUDES
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
39
40 #include "FGFCSComponent.h"
41 #include "../FGConfigFile.h"
42
43 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44 DEFINITIONS
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
46
47 #define ID_FILTER "$Id$"
48
49 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 FORWARD DECLARATIONS
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
52
53 namespace JSBSim {
54
55 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56 CLASS DOCUMENTATION
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
58
59 /** Encapsulates a filter for the flight control system.
60 The filter component can simulate any filter up to second order. The
61 Tustin substitution is used to take filter definitions from LaPlace space to the
62 time domain. The general format for a filter specification is:
63
64 <pre>
65 \<COMPONENT NAME="name" TYPE="type">
66   INPUT \<property>
67   C1  \<value>
68   [C2 \<value>]
69   [C3 \<value>]
70   [C4 \<value>]
71   [C5 \<value>]
72   [C6 \<value>]
73   [OUTPUT \<property>]
74 \</COMPONENT>
75 </pre>
76
77 For a lag filter of the form,
78 <pre>
79   C1
80 ------
81 s + C1 
82 </pre>
83 the corresponding filter definition is:
84 <pre>
85 \<COMPONENT NAME="name" TYPE="LAG_FILTER">
86   INPUT \<property>
87   C1 \<value>
88   [OUTPUT \<property>]
89 \</COMPONENT>
90 </pre>
91 As an example, for the specific filter:
92 <pre>
93   600
94 ------
95 s + 600 
96 </pre>
97 the corresponding filter definition could be:
98 <pre>
99 \<COMPONENT NAME="LAG_1" TYPE="LAG_FILTER">
100   INPUT aileron_cmd
101   C1 600
102 \</COMPONENT>
103 </pre>
104 For a lead-lag filter of the form:
105 <pre>
106 C1*s + C2
107 ---------
108 C3*s + C4 
109 </pre>
110 The corresponding filter definition is:
111 <pre>
112 \<COMPONENT NAME="name" TYPE="LEAD_LAG_FILTER">
113   INPUT \<property>
114   C1 \<value>
115   C2 \<value>
116   C3 \<value>
117   C4 \<value>
118   [OUTPUT \<property>]
119 \</COMPONENT>
120 </pre>
121 For a washout filter of the form:
122 <pre>
123   s
124 ------
125 s + C1 
126 </pre>
127 The corresponding filter definition is:
128 <pre>
129 \<COMPONENT NAME="name" TYPE="WASHOUT_FILTER">
130   INPUT \<property>
131   C1 \<value>
132   [OUTPUT \<property>]
133 \</COMPONENT>
134 </pre>
135 For a second order filter of the form:
136 <pre>
137 C1*s^2 + C2*s + C3
138 ------------------
139 C4*s^2 + C5*s + C6
140 </pre>
141 The corresponding filter definition is:
142 <pre>
143 \<COMPONENT NAME="name" TYPE="SECOND_ORDER_FILTER">
144   INPUT \<property>
145   C1 \<value>
146   C2 \<value>
147   C3 \<value>
148   C4 \<value>
149   C5 \<value>
150   C6 \<value>
151   [OUTPUT \<property>]
152 \</COMPONENT>
153 </pre>
154 For an integrator of the form:
155 <pre>
156  C1
157  ---
158   s
159 </pre>
160 The corresponding filter definition is:
161 <pre>
162 \<COMPONENT NAME="name" TYPE="INTEGRATOR">
163   INPUT \<property>
164   C1 \<value>
165   [OUTPUT \<property>]
166   [TRIGGER \<property>]
167 \</COMPONENT>
168 </pre>
169 For the integrator, the TRIGGER features the following behavior, if the TRIGGER
170 property value is:
171   - -1 (or simply less than zero), all previous inputs and outputs are set to 0.0
172   - 0, no action is taken - the output is calculated normally
173   - +1 (or simply greater than zero), all previous outputs (only) will be set to 0.0
174
175 In all the filter specifications above, an [OUTPUT] keyword is also seen.  This
176 is so that the last component in a "string" can copy its value to the appropriate
177 output, such as the elevator, or speedbrake, etc.
178
179 @author Jon S. Berndt
180 @version $Id$
181 */
182    
183 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
184 CLASS DECLARATION
185 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
186
187 class FGFilter  : public FGFCSComponent         
188 {
189 public:
190   FGFilter(FGFCS* fcs, FGConfigFile* AC_cfg);
191   ~FGFilter();
192
193   bool Run (void);
194
195   /** When true, causes previous values to be set to current values. This
196       is particularly useful for first pass. */
197   bool Initialize;
198
199   enum {eLag, eLeadLag, eOrder2, eWashout, eIntegrator, eUnknown} FilterType;
200
201 private:
202   double dt;
203   double ca;
204   double cb;
205   double cc;
206   double cd;
207   double ce;
208   double C1;
209   double C2;
210   double C3;
211   double C4;
212   double C5;
213   double C6;
214   double PreviousInput1;
215   double PreviousInput2;
216   double PreviousOutput1;
217   double PreviousOutput2;
218   FGConfigFile* AC_cfg;
219   FGPropertyManager* Trigger;
220   void Debug(int from);
221 };
222 }
223 #endif
224