1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 ------------- Copyright (C) 1998 by Jon S. Berndt, jsb@hal-pc.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 #include <input_output/FGXMLElement.h>
43 #include <math/FGTable.h>
47 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
51 #define ID_GAIN "$Id$"
53 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
61 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
65 /** Encapsulates a gain component for the flight control system.
66 The gain component merely multiplies the input by a gain. The <b>pure gain</b> form
67 of the component specification is:
70 <pure_gain name="name">
71 <input> {[-]property} </input>
72 <gain> {property name | value} </gain>
74 <min> {property name | value} </min>
75 <max> {property name | value} </max>
77 [<output> {property} </output>]
84 <pure_gain name="Roll AP Wing Leveler">
85 <input>fcs/attitude/sensor/phi-rad</input>
94 Note: the input property name may be immediately preceded by a minus sign to
97 The <b>scheduled gain</b> component multiplies the input by a variable gain that is
98 dependent on another property (such as qbar, altitude, etc.). The lookup
99 mapping is in the form of a table. This kind of component might be used, for
100 example, in a case where aerosurface deflection must only be commanded to
101 acceptable settings - i.e at higher qbar the commanded elevator setting might
102 be attenuated. The form of the scheduled gain component specification is:
105 <scheduled_gain name="name">
106 <input> {[-]property} </input>
113 <min> {[-]property name | value} </min>
114 <max> {[-]property name | value} </max>
116 [<gain> {property name | value} </gain>]
117 [<output> {property} </output>]
124 <scheduled_gain name="Scheduled Steer Pos Deg">
125 <input>fcs/steer-cmd-norm</input>
127 <independentVar>velocities/vg-fps</independentVar>
135 <output>fcs/steer-pos-rad</output>
139 An overall GAIN may be supplied that is multiplicative with the scheduled gain.
141 Note: the input property name may be immediately preceded by a minus sign to
144 In the example above, we see the utility of the overall gain value in
145 effecting a degrees-to-radians conversion.
147 The <b>aerosurface scale</b> component is a modified version of the simple gain
148 component. The purpose for this component is to take control inputs from the
149 domain minimum and maximum, as specified (or from -1 to +1 by default) and
150 scale them to map to a specified range. This can be done, for instance, to match
151 the component outputs to the expected inputs to a flight control system.
153 The zero_centered element dictates whether the domain-to-range mapping is linear
154 or centered about zero. For example, if zero_centered is false, and if the domain
155 or range is not symmetric about zero, and an input value is zero, the output
156 will not be zero. Let's say that the domain is min=-2 and max=+4, with a range
157 of -1 to +1. If the input is 0.0, then the "normalized" input is calculated to
158 be 33% of the way from the minimum to the maximum. That input would be mapped
159 to an output of -0.33, which is 33% of the way from the range minimum to maximum.
160 If zero_centered is set to true (or 1) then an input of 0.0 will be mapped to an
161 output of 0.0, although if either the domain or range are unsymmetric about
162 0.0, then the scales for the positive and negative portions of the input domain
163 (above and below 0.0) will be different. The zero_centered element is true by
164 default. Note that this feature may be important for some control surface mappings,
165 where the maximum upper and lower deflections may be different, but where a zero
166 setting is desired to be the "undeflected" value, and where full travel of the
167 stick is desired to cause a full deflection of the control surface.
169 The form of the aerosurface scaling component specification is:
172 <aerosurface_scale name="name">
173 <input> {[-]property name} </input>
175 <min> {value} </min> <!-- If omitted, default is -1.0 ->
176 <max> {value} </max> <!-- If omitted, default is 1.0 ->
179 <min> {value} </min> <!-- If omitted, default is 0 ->
180 <max> {value} </max> <!-- If omitted, default is 0 ->
182 <zero_centered< value </zero_centered>
184 <min> {[-]property name | value} </min>
185 <max> {[-]property name | value} </max>
187 [<gain> {property name | value} </gain>]
188 [<output> {property} </output>]
192 Note: the input property name may be immediately preceded by a minus sign to
195 For instance, the normal and expected ability of a
196 pilot to push or pull on a control stick is about 50 pounds. The input to the
197 pitch channel block diagram of a flight control system is often in units of pounds.
198 Yet, the joystick control input usually defines a span from -1 to +1. The aerosurface_scale
199 form of the gain component maps the inputs to the desired output range. The example
200 below shoes a simple aerosurface_scale component that maps the joystick
201 input to a range of +/- 50, which represents pilot stick force in pounds for the F-16.
204 <aerosurface_scale name="Pilot input">
205 <input>fcs/elevator-cmd-norm</input>
207 <min> -50 </min> <!-- If omitted, default is 0 ->
208 <max> 50 </max> <!-- If omitted, default is 0 ->
213 @author Jon S. Berndt
217 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
219 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
221 class FGGain : public FGFCSComponent
224 FGGain(FGFCS* fcs, Element* element);
231 FGPropertyManager* GainPropertyNode;
232 double GainPropertySign;
234 double InMin, InMax, OutMin, OutMax;
238 void Debug(int from);