1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 ------------- Copyright (C) 2000 -------------
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.
26 FUNCTIONAL DESCRIPTION
27 --------------------------------------------------------------------------------
30 --------------------------------------------------------------------------------
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33 COMMENTS, REFERENCES, and NOTES
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
44 static const char *IdSrc = "$Id$";
45 static const char *IdHdr = ID_GAIN;
47 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
51 FGGain::FGGain(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element)
53 Element *scale_element, *zero_centered;
54 string strScheduledBy, gain_string, sZeroCentered;
57 GainPropertySign = 1.0;
63 OutMin = OutMax = 0.0;
65 if (Type == "PURE_GAIN") {
66 if ( !element->FindElement("gain") ) {
67 cout << highint << " No GAIN specified (default: 1.0)" << normint << endl;
71 if ( element->FindElement("gain") ) {
72 gain_string = element->FindElementValue("gain");
73 if (!is_number(gain_string)) { // property
74 if (gain_string[0] == '-') {
75 GainPropertySign = -1.0;
76 gain_string.erase(0,1);
78 GainPropertyNode = PropertyManager->GetNode(gain_string);
80 Gain = element->FindElementValueAsNumber("gain");
84 if (Type == "AEROSURFACE_SCALE") {
85 scale_element = element->FindElement("domain");
87 if (scale_element->FindElement("max") && scale_element->FindElement("min") )
89 InMax = scale_element->FindElementValueAsNumber("max");
90 InMin = scale_element->FindElementValueAsNumber("min");
93 scale_element = element->FindElement("range");
94 if (!scale_element) throw(string("No range supplied for aerosurface scale component"));
95 if (scale_element->FindElement("max") && scale_element->FindElement("min") )
97 OutMax = scale_element->FindElementValueAsNumber("max");
98 OutMin = scale_element->FindElementValueAsNumber("min");
100 cerr << "Maximum and minimum output values must be supplied for the "
101 "aerosurface scale component" << endl;
105 zero_centered = element->FindElement("zero_centered");
106 //ToDo if zero centered, then mins must be <0 and max's must be >0
108 sZeroCentered = element->FindElementValue("zero_centered");
109 if (sZeroCentered == string("0") || sZeroCentered == string("false")) {
110 ZeroCentered = false;
115 if (Type == "SCHEDULED_GAIN") {
116 if (element->FindElement("table")) {
117 Table = new FGTable(PropertyManager, element->FindElement("table"));
119 cerr << "A table must be provided for the scheduled gain component" << endl;
124 FGFCSComponent::bind();
129 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
138 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
140 bool FGGain::Run(void )
142 double SchedGain = 1.0;
144 Input = InputNodes[0]->getDoubleValue() * InputSigns[0];
146 if (GainPropertyNode != 0) Gain = GainPropertyNode->getDoubleValue() * GainPropertySign;
148 if (Type == "PURE_GAIN") { // PURE_GAIN
150 Output = Gain * Input;
152 } else if (Type == "SCHEDULED_GAIN") { // SCHEDULED_GAIN
154 SchedGain = Table->GetValue();
155 Output = Gain * SchedGain * Input;
157 } else if (Type == "AEROSURFACE_SCALE") { // AEROSURFACE_SCALE
162 } else if (Input > 0) {
163 Output = (Input / InMax) * OutMax;
165 Output = (Input / InMin) * OutMin;
168 Output = OutMin + ((Input - InMin) / (InMax - InMin)) * (OutMax - OutMin);
175 if (IsOutput) SetOutput();
180 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181 // The bitmasked value choices are as follows:
182 // unset: In this case (the default) JSBSim would only print
183 // out the normally expected messages, essentially echoing
184 // the config files as they are read. If the environment
185 // variable is not set, debug_lvl is set to 1 internally
186 // 0: This requests JSBSim not to output any messages
188 // 1: This value explicity requests the normal JSBSim
190 // 2: This value asks for a message to be printed out when
191 // a class is instantiated
192 // 4: When this value is set, a message is displayed when a
193 // FGModel object executes its Run() method
194 // 8: When this value is set, various runtime state variables
195 // are printed out periodically
196 // 16: When set various parameters are sanity checked and
197 // a message is printed out when they go out of bounds
199 void FGGain::Debug(int from)
201 if (debug_lvl <= 0) return;
203 if (debug_lvl & 1) { // Standard console startup message output
204 if (from == 0) { // Constructor
205 if (InputSigns[0] < 0)
206 cout << " INPUT: -" << InputNodes[0]->getName() << endl;
208 cout << " INPUT: " << InputNodes[0]->getName() << endl;
210 if (GainPropertyNode != 0) {
211 cout << " GAIN: " << GainPropertyNode->GetName() << endl;
213 cout << " GAIN: " << Gain << endl;
215 if (IsOutput) cout << " OUTPUT: " << OutputNode->getName() << endl;
216 if (Type == "AEROSURFACE_SCALE") {
217 cout << " In/Out Mapping:" << endl;
218 cout << " Input MIN: " << InMin << endl;
219 cout << " Input MAX: " << InMax << endl;
220 cout << " Output MIN: " << OutMin << endl;
221 cout << " Output MAX: " << OutMax << endl;
224 cout << " Scheduled by table: " << endl;
229 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
230 if (from == 0) cout << "Instantiated: FGGain" << endl;
231 if (from == 1) cout << "Destroyed: FGGain" << endl;
233 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
235 if (debug_lvl & 8 ) { // Runtime state variables
237 if (debug_lvl & 16) { // Sanity checking
239 if (debug_lvl & 64) {
240 if (from == 0) { // Constructor
241 cout << IdSrc << endl;
242 cout << IdHdr << endl;