41 #include "input_output/FGXMLElement.h" 50 IDENT(IdSrc,
"$Id: FGGain.cpp,v 1.25 2014/01/13 10:46:09 ehofman Exp $");
57 FGGain::FGGain(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element)
59 Element *scale_element, *zero_centered;
60 string strScheduledBy, gain_string, sZeroCentered;
63 GainPropertySign = 1.0;
69 OutMin = OutMax = 0.0;
71 if (Type ==
"PURE_GAIN") {
72 if ( !element->FindElement(
"gain") ) {
73 cerr <<
highint <<
" No GAIN specified (default: 1.0)" <<
normint << endl;
77 if ( element->FindElement(
"gain") ) {
78 gain_string = element->FindElementValue(
"gain");
79 if (!is_number(gain_string)) {
80 if (gain_string[0] ==
'-') {
81 GainPropertySign = -1.0;
82 gain_string.erase(0,1);
84 GainPropertyNode = PropertyManager->GetNode(gain_string);
86 Gain = element->FindElementValueAsNumber(
"gain");
90 if (Type ==
"AEROSURFACE_SCALE") {
91 scale_element = element->FindElement(
"domain");
93 if (scale_element->FindElement(
"max") && scale_element->FindElement(
"min") )
95 InMax = scale_element->FindElementValueAsNumber(
"max");
96 InMin = scale_element->FindElementValueAsNumber(
"min");
99 scale_element = element->FindElement(
"range");
100 if (!scale_element)
throw(
string(
"No range supplied for aerosurface scale component"));
101 if (scale_element->FindElement(
"max") && scale_element->FindElement(
"min") )
103 OutMax = scale_element->FindElementValueAsNumber(
"max");
104 OutMin = scale_element->FindElementValueAsNumber(
"min");
106 cerr <<
"Maximum and minimum output values must be supplied for the " 107 "aerosurface scale component" << endl;
111 zero_centered = element->FindElement(
"zero_centered");
114 sZeroCentered = element->FindElementValue(
"zero_centered");
115 if (sZeroCentered ==
string(
"0") || sZeroCentered ==
string(
"false")) {
116 ZeroCentered =
false;
121 if (Type ==
"SCHEDULED_GAIN") {
122 if (element->FindElement(
"table")) {
123 Table =
new FGTable(PropertyManager, element->FindElement(
"table"));
125 cerr <<
"A table must be provided for the scheduled gain component" << endl;
130 FGFCSComponent::bind();
146 bool FGGain::Run(
void )
148 double SchedGain = 1.0;
150 Input = InputNodes[0]->getDoubleValue() * InputSigns[0];
152 if (GainPropertyNode != 0) Gain = GainPropertyNode->getDoubleValue() * GainPropertySign;
154 if (Type ==
"PURE_GAIN") {
156 Output = Gain * Input;
158 }
else if (Type ==
"SCHEDULED_GAIN") {
160 SchedGain = Table->GetValue();
161 Output = Gain * SchedGain * Input;
163 }
else if (Type ==
"AEROSURFACE_SCALE") {
168 }
else if (Input > 0) {
169 Output = (Input / InMax) * OutMax;
171 Output = (Input / InMin) * OutMin;
174 Output = OutMin + ((Input - InMin) / (InMax - InMin)) * (OutMax - OutMin);
181 if (IsOutput) SetOutput();
205 void FGGain::Debug(
int from)
207 if (debug_lvl <= 0)
return;
211 if (InputSigns[0] < 0)
212 cout <<
" INPUT: -" << InputNodes[0]->GetName() << endl;
214 cout <<
" INPUT: " << InputNodes[0]->GetName() << endl;
216 if (GainPropertyNode != 0) {
217 cout <<
" GAIN: " << GainPropertyNode->GetName() << endl;
219 cout <<
" GAIN: " << Gain << endl;
222 for (
unsigned int i=0; i<OutputNodes.size(); i++)
223 cout <<
" OUTPUT: " << OutputNodes[i]->getName() << endl;
225 if (Type ==
"AEROSURFACE_SCALE") {
226 cout <<
" In/Out Mapping:" << endl;
227 cout <<
" Input MIN: " << InMin << endl;
228 cout <<
" Input MAX: " << InMax << endl;
229 cout <<
" Output MIN: " << OutMin << endl;
230 cout <<
" Output MAX: " << OutMax << endl;
233 cout <<
" Scheduled by table: " << endl;
238 if (debug_lvl & 2 ) {
239 if (from == 0) cout <<
"Instantiated: FGGain" << endl;
240 if (from == 1) cout <<
"Destroyed: FGGain" << endl;
242 if (debug_lvl & 4 ) {
244 if (debug_lvl & 8 ) {
246 if (debug_lvl & 16) {
248 if (debug_lvl & 64) {
250 cout << IdSrc << endl;
251 cout << IdHdr << endl;
static char normint[6]
normal intensity text
static char highint[5]
highlights text