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 clipmin = clipmax = 0.0;
70 Type = AC_cfg->GetValue("TYPE");
71 Name = AC_cfg->GetValue("NAME");
72 AC_cfg->GetNextConfigLine();
74 while ((token = AC_cfg->GetValue()) != string("/COMPONENT")) {
76 if (token == "INPUT") {
79 if (token[0] == '-') {
84 if (InputNodes.size() > 0) {
85 cerr << "Gains can only accept one input" << endl;
87 InputNodes.push_back( resolveSymbol(token) );
90 } else if (token == "GAIN") {
92 } else if (token == "MIN") {
94 } else if (token == "MAX") {
96 } else if (token == "CLIPTO") {
97 *AC_cfg >> clipmin >> clipmax;
98 if (clipmax > clipmin) {
101 } else if (token == "INVERT") {
103 cerr << endl << "The INVERT keyword is being deprecated and will not be "
104 "supported in the future. Please use a minus sign in front "
105 "of an input property in the future." << endl << endl;
106 } else if (token == "ROWS") {
108 Table = new FGTable(Rows);
109 } else if (token == "SCHEDULED_BY") {
110 token = AC_cfg->GetValue("SCHEDULED_BY");
111 *AC_cfg >> strScheduledBy;
112 ScheduledBy = PropertyManager->GetNode( strScheduledBy );
113 } else if (token == "OUTPUT") {
115 *AC_cfg >> sOutputIdx;
116 OutputNode = PropertyManager->GetNode( sOutputIdx, true );
118 AC_cfg->ResetLineIndexToZero();
123 FGFCSComponent::bind();
124 if (Type == "AEROSURFACE_SCALE")
125 treenode->Tie( "output-norm", this, &FGGain::GetOutputPct );
130 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
137 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
139 bool FGGain::Run(void )
141 double SchedGain = 1.0;
142 double LookupVal = 0;
144 FGFCSComponent::Run(); // call the base class for initialization of Input
145 Input = InputNodes[0]->getDoubleValue();
147 if (invert) Input = -Input;
149 if (Type == "PURE_GAIN") { // PURE_GAIN
151 Output = Gain * Input;
153 } else if (Type == "SCHEDULED_GAIN") { // SCHEDULED_GAIN
155 LookupVal = ScheduledBy->getDoubleValue();
156 SchedGain = Table->GetValue(LookupVal);
157 Output = Gain * SchedGain * Input;
159 } else if (Type == "AEROSURFACE_SCALE") { // AEROSURFACE_SCALE
162 if (Input >= 0.0) Output = Input * Max;
163 else Output = Input * -Min;
169 if (Output > clipmax) Output = clipmax;
170 else if (Output < clipmin) Output = clipmin;
173 if (IsOutput) SetOutput();
178 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
179 // The bitmasked value choices are as follows:
180 // unset: In this case (the default) JSBSim would only print
181 // out the normally expected messages, essentially echoing
182 // the config files as they are read. If the environment
183 // variable is not set, debug_lvl is set to 1 internally
184 // 0: This requests JSBSim not to output any messages
186 // 1: This value explicity requests the normal JSBSim
188 // 2: This value asks for a message to be printed out when
189 // a class is instantiated
190 // 4: When this value is set, a message is displayed when a
191 // FGModel object executes its Run() method
192 // 8: When this value is set, various runtime state variables
193 // are printed out periodically
194 // 16: When set various parameters are sanity checked and
195 // a message is printed out when they go out of bounds
197 void FGGain::Debug(int from)
199 if (debug_lvl <= 0) return;
201 if (debug_lvl & 1) { // Standard console startup message output
202 if (from == 0) { // Constructor
204 cout << " INPUT: -" << InputNodes[0]->getName() << endl;
206 cout << " INPUT: " << InputNodes[0]->getName() << endl;
208 cout << " GAIN: " << Gain << endl;
209 if (IsOutput) cout << " OUTPUT: " << OutputNode->getName() << endl;
210 cout << " MIN: " << Min << endl;
211 cout << " MAX: " << Max << endl;
212 if (ScheduledBy != 0) {
213 cout << " Scheduled by parameter: " << ScheduledBy->getName() << endl;
218 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
219 if (from == 0) cout << "Instantiated: FGGain" << endl;
220 if (from == 1) cout << "Destroyed: FGGain" << endl;
222 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
224 if (debug_lvl & 8 ) { // Runtime state variables
226 if (debug_lvl & 16) { // Sanity checking
228 if (debug_lvl & 64) {
229 if (from == 0) { // Constructor
230 cout << IdSrc << endl;
231 cout << IdHdr << endl;