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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
42 static const char *IdSrc = "$Id$";
43 static const char *IdHdr = ID_GAIN;
45 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
50 FGGain::FGGain(FGFCS* fcs, FGConfigFile* AC_cfg) : FGFCSComponent(fcs),
54 string strScheduledBy;
56 State = fcs->GetState();
61 ScheduledBy = FG_UNDEF;
63 Type = AC_cfg->GetValue("TYPE");
64 Name = AC_cfg->GetValue("NAME");
65 AC_cfg->GetNextConfigLine();
67 while ((token = AC_cfg->GetValue()) != string("/COMPONENT")) {
71 } else if (token == "INPUT") {
72 token = AC_cfg->GetValue("INPUT");
73 if (token.find("FG_") != token.npos) {
75 InputIdx = State->GetParameterIndex(token);
76 InputType = itPilotAC;
81 } else if (token == "GAIN") {
83 } else if (token == "MIN") {
85 } else if (token == "MAX") {
87 } else if (token == "ROWS") {
89 Table = new FGTable(Rows);
90 } else if (token == "SCHEDULED_BY") {
91 token = AC_cfg->GetValue("SCHEDULED_BY");
92 if (token.find("FG_") != token.npos) {
93 *AC_cfg >> strScheduledBy;
94 ScheduledBy = State->GetParameterIndex(strScheduledBy);
96 *AC_cfg >> ScheduledBy;
98 } else if (token == "OUTPUT") {
100 *AC_cfg >> sOutputIdx;
101 OutputIdx = State->GetParameterIndex(sOutputIdx);
103 AC_cfg->ResetLineIndexToZero();
109 cout << " ID: " << ID << endl;
110 cout << " INPUT: " << InputIdx << endl;
111 cout << " GAIN: " << Gain << endl;
112 if (IsOutput) cout << " OUTPUT: " << sOutputIdx << endl;
113 cout << " MIN: " << Min << endl;
114 cout << " MAX: " << Max << endl;
115 if (ScheduledBy != FG_UNDEF) {
116 cout << " Scheduled by parameter: " << ScheduledBy << endl;
121 if (debug_lvl & 2) cout << "Instantiated: FGGain" << endl;
124 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128 if (debug_lvl & 2) cout << "Destroyed: FGGain" << endl;
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
140 if (Type == "PURE_GAIN") {
141 Output = Gain * Input;
142 } else if (Type == "SCHEDULED_GAIN") {
143 LookupVal = State->GetParameter(ScheduledBy);
144 SchedGain = Table->GetValue(LookupVal);
145 Output = Gain * SchedGain * Input;
146 } else if (Type == "AEROSURFACE_SCALE") {
147 if (Output >= 0.0) Output = Input * Max;
148 else Output = Input * (-Min);
152 if (IsOutput) SetOutput();
157 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
159 void FGGain::Debug(void)
161 //TODO: Add your source code here