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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
41 # include <simgear/compiler.h>
48 #include "FGFCSComponent.h"
49 #include <input_output/FGXMLElement.h>
50 #include <math/FGTable.h>
52 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
56 #define ID_GAIN "$Id$"
58 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
66 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
70 /** Encapsulates a gain component for the flight control system.
71 The gain component merely multiplies the input by a gain. The <b>pure gain</b> form
72 of the component specification is:
75 <pure_gain name="name">
76 <input> {[-]property} </input>
77 <gain> {property name | value} </gain>
79 <min> {property name | value} </min>
80 <max> {property name | value} </max>
82 [<output> {property} </output>]
89 <pure_gain name="Roll AP Wing Leveler">
90 <input>fcs/attitude/sensor/phi-rad</input>
99 Note: the input property name may be immediately preceded by a minus sign to
102 The <b>scheduled gain</b> component multiplies the input by a variable gain that is
103 dependent on another property (such as qbar, altitude, etc.). The lookup
104 mapping is in the form of a table. This kind of component might be used, for
105 example, in a case where aerosurface deflection must only be commanded to
106 acceptable settings - i.e at higher qbar the commanded elevator setting might
107 be attenuated. The form of the scheduled gain component specification is:
110 <scheduled_gain name="name">
111 <input> {[-]property} </input>
118 <min> {[-]property name | value} </min>
119 <max> {[-]property name | value} </max>
121 [<gain> {property name | value} </gain>]
122 [<output> {property} </output>]
129 <scheduled_gain name="Scheduled Steer Pos Deg">
130 <input>fcs/steer-cmd-norm</input>
132 <independentVar>velocities/vg-fps</independentVar>
140 <output>fcs/steer-pos-rad</output>
144 An overall GAIN may be supplied that is multiplicative with the scheduled gain.
146 Note: the input property name may be immediately preceded by a minus sign to
149 In the example above, we see the utility of the overall gain value in
150 effecting a degrees-to-radians conversion.
152 The <b>aerosurface scale</b> component is a modified version of the simple gain
153 component. The purpose for this component is to take control inputs from the
154 domain minimum and maximum, as specified (or from -1 to +1 by default) and
155 scale them to map to a specified range. This can be done, for instance, to match
156 the component outputs to the expected inputs to a flight control system.
158 The zero_centered element dictates whether the domain-to-range mapping is linear
159 or centered about zero. For example, if zero_centered is false, and if the domain
160 or range is not symmetric about zero, and an input value is zero, the output
161 will not be zero. Let's say that the domain is min=-2 and max=+4, with a range
162 of -1 to +1. If the input is 0.0, then the "normalized" input is calculated to
163 be 33% of the way from the minimum to the maximum. That input would be mapped
164 to an output of -0.33, which is 33% of the way from the range minimum to maximum.
165 If zero_centered is set to true (or 1) then an input of 0.0 will be mapped to an
166 output of 0.0, although if either the domain or range are unsymmetric about
167 0.0, then the scales for the positive and negative portions of the input domain
168 (above and below 0.0) will be different. The zero_centered element is true by
169 default. Note that this feature may be important for some control surface mappings,
170 where the maximum upper and lower deflections may be different, but where a zero
171 setting is desired to be the "undeflected" value, and where full travel of the
172 stick is desired to cause a full deflection of the control surface.
174 The form of the aerosurface scaling component specification is:
177 <aerosurface_scale name="name">
178 <input> {[-]property name} </input>
180 <min> {value} </min> <!-- If omitted, default is -1.0 ->
181 <max> {value} </max> <!-- If omitted, default is 1.0 ->
184 <min> {value} </min> <!-- If omitted, default is 0 ->
185 <max> {value} </max> <!-- If omitted, default is 0 ->
187 <zero_centered< value </zero_centered>
189 <min> {[-]property name | value} </min>
190 <max> {[-]property name | value} </max>
192 [<gain> {property name | value} </gain>]
193 [<output> {property} </output>]
197 Note: the input property name may be immediately preceded by a minus sign to
200 For instance, the normal and expected ability of a
201 pilot to push or pull on a control stick is about 50 pounds. The input to the
202 pitch channel block diagram of a flight control system is often in units of pounds.
203 Yet, the joystick control input usually defines a span from -1 to +1. The aerosurface_scale
204 form of the gain component maps the inputs to the desired output range. The example
205 below shoes a simple aerosurface_scale component that maps the joystick
206 input to a range of +/- 50, which represents pilot stick force in pounds for the F-16.
209 <aerosurface_scale name="Pilot input">
210 <input>fcs/elevator-cmd-norm</input>
212 <min> -50 </min> <!-- If omitted, default is 0 ->
213 <max> 50 </max> <!-- If omitted, default is 0 ->
218 @author Jon S. Berndt
222 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
224 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
226 class FGGain : public FGFCSComponent
229 FGGain(FGFCS* fcs, Element* element);
236 FGPropertyManager* GainPropertyNode;
237 double GainPropertySign;
239 double InMin, InMax, OutMin, OutMax;
243 void Debug(int from);