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"
41 #include "input_output/FGXMLElement.h"
43 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
47 #define ID_FILTER "$Id$"
49 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
55 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
59 /** Encapsulates a filter for the flight control system.
60 The filter component can simulate any first or second order filter. 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:
65 <typename name="name">
66 <input> property </input>
67 <c1> value|property </c1>
68 [<c2> value|property </c2>]
69 [<c3> value|property </c3>]
70 [<c4> value|property </c4>]
71 [<c5> value|property </c5>]
72 [<c6> value|property </c6>]
74 <min> {[-]property name | value} </min>
75 <max> {[-]property name | value} </max>
77 [<output> property </output>]
81 For a lag filter of the form,
89 the corresponding filter definition is:
92 <lag_filter name="name">
93 <input> property </input>
94 <c1> value|property </c1>
96 <min> {[-]property name | value} </min>
97 <max> {[-]property name | value} </max>
99 [<output> property <output>]
103 As an example, for the specific filter:
111 the corresponding filter definition could be:
114 <lag_filter name="Heading Roll Error Lag">
115 <input> fcs/heading-command </input>
120 For a lead-lag filter of the form:
128 The corresponding filter definition is:
131 <lead_lag_filter name="name">
132 <input> property </input>
133 <c1> value|property <c/1>
134 <c2> value|property <c/2>
135 <c3> value|property <c/3>
136 <c4> value|property <c/4>
138 <min> {[-]property name | value} </min>
139 <max> {[-]property name | value} </max>
141 [<output> property </output>]
145 For a washout filter of the form:
153 The corresponding filter definition is:
156 <washout_filter name="name">
157 <input> property </input>
160 <min> {[-]property name | value} </min>
161 <max> {[-]property name | value} </max>
163 [<output> property </output>]
167 For a second order filter of the form:
175 The corresponding filter definition is:
178 <second_order_filter name="name">
179 <input> property </input>
180 <c1> value|property </c1>
181 <c2> value|property </c2>
182 <c3> value|property </c3>
183 <c4> value|property </c4>
184 <c5> value|property </c5>
185 <c6> value|property </c6>
187 <min> {[-]property name | value} </min>
188 <max> {[-]property name | value} </max>
190 [<output> property </output>]
191 </second_order_filter>
194 For an integrator of the form:
202 The corresponding filter definition is:
205 <integrator name="name">
206 <input> property </input>
207 <c1> value|property </c1>
208 [<trigger> property </trigger>]
210 <min> {[-]property name | value} </min>
211 <max> {[-]property name | value} </max>
213 [<output> property </output>]
217 For the integrator, the trigger features the following behavior. If the trigger
219 - 0: no action is taken - the output is calculated normally
220 - not 0: (or simply greater than zero), all current and previous inputs will
223 In all the filter specifications above, an \<output> element is also seen. This
224 is so that the last component in a "string" can copy its value to the appropriate
225 output, such as the elevator, or speedbrake, etc.
227 @author Jon S. Berndt
232 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
234 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
236 class FGFilter : public FGFCSComponent
239 FGFilter(FGFCS* fcs, Element* element);
244 /** When true, causes previous values to be set to current values. This
245 is particularly useful for first pass. */
247 void ResetPastStates(void) {Input = 0.0; Initialize = true;}
249 enum {eLag, eLeadLag, eOrder2, eWashout, eIntegrator, eUnknown} FilterType;
257 double C[7]; // There are 6 coefficients, indexing is "1" based.
258 double PropertySign[7];
259 double PreviousInput1;
260 double PreviousInput2;
261 double PreviousOutput1;
262 double PreviousOutput2;
263 FGPropertyManager* Trigger;
264 FGPropertyManager* PropertyNode[7];
265 void CalculateDynamicFilters(void);
266 void ReadFilterCoefficients(Element* el, int index);
268 void Debug(int from);