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 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 General Public License for more
19 You should have received a copy of the GNU 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 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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
52 FGGain::FGGain(FGFCS* fcs, FGConfigFile* AC_cfg) : FGFCSComponent(fcs),
56 string strScheduledBy;
59 State = fcs->GetState();
68 Type = AC_cfg->GetValue("TYPE");
69 Name = AC_cfg->GetValue("NAME");
70 AC_cfg->GetNextConfigLine();
72 while ((token = AC_cfg->GetValue()) != string("/COMPONENT")) {
74 if (token == "INPUT") {
75 token = AC_cfg->GetValue("INPUT");
76 if (InputNodes.size() > 0) {
77 cerr << "Gains can only accept one input" << endl;
80 InputNodes.push_back( resolveSymbol(token) );
82 } else if (token == "GAIN") {
84 } else if (token == "MIN") {
86 } else if (token == "MAX") {
88 } else if (token == "INVERT") {
90 } else if (token == "ROWS") {
92 Table = new FGTable(Rows);
93 } else if (token == "SCHEDULED_BY") {
94 token = AC_cfg->GetValue("SCHEDULED_BY");
95 *AC_cfg >> strScheduledBy;
96 ScheduledBy = PropertyManager->GetNode( strScheduledBy );
97 } else if (token == "OUTPUT") {
99 *AC_cfg >> sOutputIdx;
100 OutputNode = PropertyManager->GetNode( sOutputIdx );
103 AC_cfg->ResetLineIndexToZero();
108 FGFCSComponent::bind();
109 if (Type == "AEROSURFACE_SCALE")
110 treenode->Tie( "output-norm", this, &FGGain::GetOutputPct );
115 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
122 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
124 bool FGGain::Run(void )
126 double SchedGain = 1.0;
127 double LookupVal = 0;
129 FGFCSComponent::Run(); // call the base class for initialization of Input
130 Input = InputNodes[0]->getDoubleValue();
131 if (Type == "PURE_GAIN") {
132 Output = Gain * Input;
133 } else if (Type == "SCHEDULED_GAIN") {
134 LookupVal = ScheduledBy->getDoubleValue();
135 SchedGain = Table->GetValue(LookupVal);
136 Output = Gain * SchedGain * Input;
137 } else if (Type == "AEROSURFACE_SCALE") {
140 if (Input >= 0.0) Output = Input * Max;
141 else Output = Input * -Min;
144 if (Input <= 0.0) Output = Input * -Max;
145 else Output = Input * Min;
150 if (IsOutput) SetOutput();
155 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
156 // The bitmasked value choices are as follows:
157 // unset: In this case (the default) JSBSim would only print
158 // out the normally expected messages, essentially echoing
159 // the config files as they are read. If the environment
160 // variable is not set, debug_lvl is set to 1 internally
161 // 0: This requests JSBSim not to output any messages
163 // 1: This value explicity requests the normal JSBSim
165 // 2: This value asks for a message to be printed out when
166 // a class is instantiated
167 // 4: When this value is set, a message is displayed when a
168 // FGModel object executes its Run() method
169 // 8: When this value is set, various runtime state variables
170 // are printed out periodically
171 // 16: When set various parameters are sanity checked and
172 // a message is printed out when they go out of bounds
174 void FGGain::Debug(int from)
176 if (debug_lvl <= 0) return;
178 if (debug_lvl & 1) { // Standard console startup message output
179 if (from == 0) { // Constructor
180 cout << " INPUT: " << InputNodes[0]->getName() << endl;
181 cout << " GAIN: " << Gain << endl;
182 if (IsOutput) cout << " OUTPUT: " << OutputNode->getName() << endl;
183 cout << " MIN: " << Min << endl;
184 cout << " MAX: " << Max << endl;
185 if(invert) cout << " Invert mapping" << endl;
186 if (ScheduledBy != 0) {
187 cout << " Scheduled by parameter: " << ScheduledBy->getName() << endl;
192 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
193 if (from == 0) cout << "Instantiated: FGGain" << endl;
194 if (from == 1) cout << "Destroyed: FGGain" << endl;
196 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
198 if (debug_lvl & 8 ) { // Runtime state variables
200 if (debug_lvl & 16) { // Sanity checking
202 if (debug_lvl & 64) {
203 if (from == 0) { // Constructor
204 cout << IdSrc << endl;
205 cout << IdHdr << endl;