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 /*******************************************************************************
43 ************************************ CODE **************************************
44 *******************************************************************************/
46 // *****************************************************************************
47 // Function: Constructor
48 // Purpose: Builds a Gain-type of FCS component.
50 // Comments: Types are PURE_GAIN, SCHEDULED_GAIN, and AEROSURFACE_SCALE
52 FGGain::FGGain(FGFCS* fcs, FGConfigFile* AC_cfg) : FGFCSComponent(fcs),
63 Type = AC_cfg->GetValue("TYPE");
64 Name = AC_cfg->GetValue("NAME");
65 AC_cfg->GetNextConfigLine();
67 while ((token = AC_cfg->GetValue()) != "/COMPONENT") {
71 cout << " ID: " << ID << endl;
72 } else if (token == "INPUT") {
73 token = AC_cfg->GetValue("INPUT");
74 cout << " INPUT: " << token << endl;
75 if (token.find("FG_") != token.npos) {
77 InputIdx = fcs->GetState()->GetParameterIndex(token);
78 InputType = itPilotAC;
83 } else if (token == "GAIN") {
85 cout << " GAIN: " << Gain << endl;
86 } else if (token == "MIN") {
88 cout << " MIN: " << Min << endl;
89 } else if (token == "MAX") {
91 cout << " MAX: " << Max << endl;
92 } else if (token == "SCHEDULED_BY") {
93 *AC_cfg >> ScheduledBy;
94 } else if (token == "OUTPUT") {
96 *AC_cfg >> sOutputIdx;
97 OutputIdx = fcs->GetState()->GetParameterIndex(sOutputIdx);
98 cout << " OUTPUT: " << sOutputIdx << endl;
100 AC_cfg->ResetLineIndexToZero();
101 lookup = new float[2];
102 *AC_cfg >> lookup[0] >> lookup[1];
103 Schedule.push_back(lookup);
108 // *****************************************************************************
114 bool FGGain::Run(void )
116 float SchedGain = 1.0;
118 FGFCSComponent::Run(); // call the base class for initialization of Input
120 if (Type == "PURE_GAIN") {
122 Output = Gain * Input;
124 } else if (Type == "SCHEDULED_GAIN") {
126 float LookupVal = fcs->GetState()->GetParameter(ScheduledBy);
127 unsigned int last = Schedule.size()-1;
128 float lowVal = Schedule[0][0], hiVal = Schedule[last][0];
131 if (LookupVal <= lowVal) Output = Gain * Schedule[0][1];
132 else if (LookupVal >= hiVal) Output = Gain * Schedule[last][1];
134 for (unsigned int ctr = 1; ctr < last; ctr++) {
135 if (LookupVal < Schedule[ctr][0]) {
136 hiVal = Schedule[ctr][0];
137 lowVal = Schedule[ctr-1][0];
138 factor = (LookupVal - lowVal) / (hiVal - lowVal);
139 SchedGain = Schedule[ctr-1][1] + factor*(Schedule[ctr][1] - Schedule[ctr-1][1]);
140 Output = Gain * SchedGain * Input;
146 } else if (Type == "AEROSURFACE_SCALE") {
148 if (Output >= 0.0) Output = Input * Max;
149 else Output = Input * (-Min);
154 if (IsOutput) SetOutput();