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") {
77 if (token[0] == '-') {
82 if (InputNodes.size() > 0) {
83 cerr << "Gains can only accept one input" << endl;
85 InputNodes.push_back( resolveSymbol(token) );
88 } else if (token == "GAIN") {
90 } else if (token == "MIN") {
92 } else if (token == "MAX") {
94 } else if (token == "INVERT") {
96 cerr << endl << "The INVERT keyword is being deprecated and will not be "
97 "supported in the future. Please use a minus sign in front "
98 "of an input property in the future." << endl << endl;
99 } else if (token == "ROWS") {
101 Table = new FGTable(Rows);
102 } else if (token == "SCHEDULED_BY") {
103 token = AC_cfg->GetValue("SCHEDULED_BY");
104 *AC_cfg >> strScheduledBy;
105 ScheduledBy = PropertyManager->GetNode( strScheduledBy );
106 } else if (token == "OUTPUT") {
108 *AC_cfg >> sOutputIdx;
109 OutputNode = PropertyManager->GetNode( sOutputIdx );
112 AC_cfg->ResetLineIndexToZero();
117 FGFCSComponent::bind();
118 if (Type == "AEROSURFACE_SCALE")
119 treenode->Tie( "output-norm", this, &FGGain::GetOutputPct );
124 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133 bool FGGain::Run(void )
135 double SchedGain = 1.0;
136 double LookupVal = 0;
138 FGFCSComponent::Run(); // call the base class for initialization of Input
139 Input = InputNodes[0]->getDoubleValue();
141 if (invert) Input = -Input;
143 if (Type == "PURE_GAIN") { // PURE_GAIN
145 Output = Gain * Input;
147 } else if (Type == "SCHEDULED_GAIN") { // SCHEDULED_GAIN
149 LookupVal = ScheduledBy->getDoubleValue();
150 SchedGain = Table->GetValue(LookupVal);
151 Output = Gain * SchedGain * Input;
153 } else if (Type == "AEROSURFACE_SCALE") { // AEROSURFACE_SCALE
156 if (Input >= 0.0) Output = Input * Max;
157 else Output = Input * -Min;
162 if (IsOutput) SetOutput();
167 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
168 // The bitmasked value choices are as follows:
169 // unset: In this case (the default) JSBSim would only print
170 // out the normally expected messages, essentially echoing
171 // the config files as they are read. If the environment
172 // variable is not set, debug_lvl is set to 1 internally
173 // 0: This requests JSBSim not to output any messages
175 // 1: This value explicity requests the normal JSBSim
177 // 2: This value asks for a message to be printed out when
178 // a class is instantiated
179 // 4: When this value is set, a message is displayed when a
180 // FGModel object executes its Run() method
181 // 8: When this value is set, various runtime state variables
182 // are printed out periodically
183 // 16: When set various parameters are sanity checked and
184 // a message is printed out when they go out of bounds
186 void FGGain::Debug(int from)
188 if (debug_lvl <= 0) return;
190 if (debug_lvl & 1) { // Standard console startup message output
191 if (from == 0) { // Constructor
193 cout << " INPUT: -" << InputNodes[0]->getName() << endl;
195 cout << " INPUT: " << InputNodes[0]->getName() << endl;
197 cout << " GAIN: " << Gain << endl;
198 if (IsOutput) cout << " OUTPUT: " << OutputNode->getName() << endl;
199 cout << " MIN: " << Min << endl;
200 cout << " MAX: " << Max << endl;
201 if (ScheduledBy != 0) {
202 cout << " Scheduled by parameter: " << ScheduledBy->getName() << endl;
207 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
208 if (from == 0) cout << "Instantiated: FGGain" << endl;
209 if (from == 1) cout << "Destroyed: FGGain" << endl;
211 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
213 if (debug_lvl & 8 ) { // Runtime state variables
215 if (debug_lvl & 16) { // Sanity checking
217 if (debug_lvl & 64) {
218 if (from == 0) { // Constructor
219 cout << IdSrc << endl;
220 cout << IdHdr << endl;