41 #include "math/FGParameterValue.h"
42 #include "math/FGTable.h"
52 FGGain::FGGain(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element)
58 OutMin = OutMax = 0.0;
60 CheckInputNodes(1, 1, element);
62 if (Type ==
"PURE_GAIN") {
63 if ( !element->FindElement(
"gain") ) {
64 cerr << element->ReadFrom()
65 << highint <<
" No GAIN specified (default: 1.0)" << normint
70 Element* gain_element = element->FindElement(
"gain");
72 Gain =
new FGParameterValue(gain_element, PropertyManager);
74 Gain =
new FGRealValue(1.0);
76 if (Type ==
"AEROSURFACE_SCALE") {
77 Element* scale_element = element->FindElement(
"domain");
79 if (scale_element->FindElement(
"max") && scale_element->FindElement(
"min") )
81 InMax = scale_element->FindElementValueAsNumber(
"max");
82 InMin = scale_element->FindElementValueAsNumber(
"min");
85 scale_element = element->FindElement(
"range");
87 throw(
string(
"No range supplied for aerosurface scale component"));
88 if (scale_element->FindElement(
"max") && scale_element->FindElement(
"min") )
90 OutMax = scale_element->FindElementValueAsNumber(
"max");
91 OutMin = scale_element->FindElementValueAsNumber(
"min");
93 cerr << scale_element->ReadFrom()
94 <<
"Maximum and minimum output values must be supplied for the "
95 "aerosurface scale component" << endl;
96 throw(
"Some inputs are missing.");
99 Element* zero_centered = element->FindElement(
"zero_centered");
102 string sZeroCentered = element->FindElementValue(
"zero_centered");
103 if (sZeroCentered ==
string(
"0") || sZeroCentered ==
string(
"false")) {
104 ZeroCentered =
false;
109 if (Type ==
"SCHEDULED_GAIN") {
110 if (element->FindElement(
"table")) {
111 Table =
new FGTable(PropertyManager, element->FindElement(
"table"));
113 cerr << element->ReadFrom()
114 <<
"A table must be provided for the scheduled gain component"
116 throw(
"Some inputs are missing.");
136 bool FGGain::Run(
void )
138 Input = InputNodes[0]->getDoubleValue();
140 if (Type ==
"PURE_GAIN") {
142 Output = Gain * Input;
144 }
else if (Type ==
"SCHEDULED_GAIN") {
146 double SchedGain = Table->GetValue();
147 Output = Gain * SchedGain * Input;
149 }
else if (Type ==
"AEROSURFACE_SCALE") {
154 }
else if (Input > 0) {
155 Output = (Input / InMax) * OutMax;
157 Output = (Input / InMin) * OutMin;
160 Output = OutMin + ((Input - InMin) / (InMax - InMin)) * (OutMax - OutMin);
163 Output *= Gain->GetValue();
191 void FGGain::Debug(
int from)
193 if (debug_lvl <= 0)
return;
197 cout <<
" INPUT: " << InputNodes[0]->GetNameWithSign() << endl;
198 cout <<
" GAIN: " << Gain->GetName() << endl;
200 for (
auto node: OutputNodes)
201 cout <<
" OUTPUT: " << node->getNameString() << endl;
203 if (Type ==
"AEROSURFACE_SCALE") {
204 cout <<
" In/Out Mapping:" << endl;
205 cout <<
" Input MIN: " << InMin << endl;
206 cout <<
" Input MAX: " << InMax << endl;
207 cout <<
" Output MIN: " << OutMin << endl;
208 cout <<
" Output MAX: " << OutMax << endl;
211 cout <<
" Scheduled by table: " << endl;
216 if (debug_lvl & 2 ) {
217 if (from == 0) cout <<
"Instantiated: FGGain" << endl;
218 if (from == 1) cout <<
"Destroyed: FGGain" << endl;
220 if (debug_lvl & 4 ) {
222 if (debug_lvl & 8 ) {
224 if (debug_lvl & 16) {
226 if (debug_lvl & 64) {