1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 ------------- Copyright (C) 2000 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 --------------------------------------------------------------------------------
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
36 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40 #include "FGFCSComponent.h"
42 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
46 #define ID_FILTER "$Id$"
48 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
55 class FGPropertyManager;
58 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
62 /** Encapsulates a filter for the flight control system.
63 The filter component can simulate any first or second order filter. The
64 Tustin substitution is used to take filter definitions from LaPlace space to the
65 time domain. The general format for a filter specification is:
68 <typename name="name">
69 <input> property </input>
70 <c1> value|property </c1>
71 [<c2> value|property </c2>]
72 [<c3> value|property </c3>]
73 [<c4> value|property </c4>]
74 [<c5> value|property </c5>]
75 [<c6> value|property </c6>]
77 <min> {[-]property name | value} </min>
78 <max> {[-]property name | value} </max>
80 [<output> property </output>]
84 For a lag filter of the form,
92 the corresponding filter definition is:
95 <lag_filter name="name">
96 <input> property </input>
97 <c1> value|property </c1>
99 <min> {[-]property name | value} </min>
100 <max> {[-]property name | value} </max>
102 [<output> property <output>]
106 As an example, for the specific filter:
114 the corresponding filter definition could be:
117 <lag_filter name="Heading Roll Error Lag">
118 <input> fcs/heading-command </input>
123 For a lead-lag filter of the form:
131 The corresponding filter definition is:
134 <lead_lag_filter name="name">
135 <input> property </input>
136 <c1> value|property <c/1>
137 <c2> value|property <c/2>
138 <c3> value|property <c/3>
139 <c4> value|property <c/4>
141 <min> {[-]property name | value} </min>
142 <max> {[-]property name | value} </max>
144 [<output> property </output>]
148 For a washout filter of the form:
156 The corresponding filter definition is:
159 <washout_filter name="name">
160 <input> property </input>
163 <min> {[-]property name | value} </min>
164 <max> {[-]property name | value} </max>
166 [<output> property </output>]
170 For a second order filter of the form:
178 The corresponding filter definition is:
181 <second_order_filter name="name">
182 <input> property </input>
183 <c1> value|property </c1>
184 <c2> value|property </c2>
185 <c3> value|property </c3>
186 <c4> value|property </c4>
187 <c5> value|property </c5>
188 <c6> value|property </c6>
190 <min> {[-]property name | value} </min>
191 <max> {[-]property name | value} </max>
193 [<output> property </output>]
194 </second_order_filter>
197 For an integrator of the form:
205 The corresponding filter definition is:
208 <integrator name="name">
209 <input> property </input>
210 <c1> value|property </c1>
211 [<trigger> property </trigger>]
213 <min> {[-]property name | value} </min>
214 <max> {[-]property name | value} </max>
216 [<output> property </output>]
220 For the integrator, the trigger features the following behavior. If the trigger
222 - 0: no action is taken - the output is calculated normally
223 - not 0: (or simply greater than zero), all current and previous inputs will
226 In all the filter specifications above, an \<output> element is also seen. This
227 is so that the last component in a "string" can copy its value to the appropriate
228 output, such as the elevator, or speedbrake, etc.
230 @author Jon S. Berndt
235 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
237 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
239 class FGFilter : public FGFCSComponent
242 FGFilter(FGFCS* fcs, Element* element);
247 /** When true, causes previous values to be set to current values. This
248 is particularly useful for first pass. */
250 void ResetPastStates(void) {Input = 0.0; Initialize = true;}
252 enum {eLag, eLeadLag, eOrder2, eWashout, eIntegrator, eUnknown} FilterType;
260 double C[7]; // There are 6 coefficients, indexing is "1" based.
261 double PropertySign[7];
262 double PreviousInput1;
263 double PreviousInput2;
264 double PreviousOutput1;
265 double PreviousOutput2;
266 FGPropertyManager* Trigger;
267 FGPropertyManager* PropertyNode[7];
268 void CalculateDynamicFilters(void);
269 void ReadFilterCoefficients(Element* el, int index);
271 void Debug(int from);