]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/filtersjb/FGGain.cpp
-Removed .cvsignore from itself, since .cvsignore is now in the CVS
[flightgear.git] / src / FDM / JSBSim / filtersjb / FGGain.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Module:       FGGain.cpp
4  Author:       Jon S. Berndt
5  Date started: 4/2000
6  
7  ------------- Copyright (C) 2000 -------------
8
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
12  version.
13
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
17  details.
18
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.
22
23  Further information about the GNU General Public License can also be found on
24  the world wide web at http://www.gnu.org.
25
26 FUNCTIONAL DESCRIPTION
27 --------------------------------------------------------------------------------
28
29 HISTORY
30 --------------------------------------------------------------------------------
31
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33 COMMENTS, REFERENCES,  and NOTES
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 INCLUDES
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
39
40 #include "FGGain.h"            
41
42 static const char *IdSrc = "$Id$";
43 static const char *IdHdr = ID_GAIN;
44
45 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46 CLASS IMPLEMENTATION
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
48
49
50 FGGain::FGGain(FGFCS* fcs, FGConfigFile* AC_cfg) : FGFCSComponent(fcs),
51                                                    AC_cfg(AC_cfg)
52 {
53   string token;
54   string strScheduledBy;
55
56   State = fcs->GetState();
57
58   Gain = 1.000;
59   Rows = 0;
60   Min = Max = 0.0;
61   ScheduledBy = FG_UNDEF;
62
63   Type = AC_cfg->GetValue("TYPE");
64   Name = AC_cfg->GetValue("NAME");
65   AC_cfg->GetNextConfigLine();
66
67   while ((token = AC_cfg->GetValue()) != string("/COMPONENT")) {
68     *AC_cfg >> token;
69     if (token == "ID") {
70       *AC_cfg >> ID;
71     } else if (token == "INPUT") {
72       token = AC_cfg->GetValue("INPUT");
73       if (token.find("FG_") != token.npos) {
74         *AC_cfg >> token;
75         InputIdx = State->GetParameterIndex(token);
76         InputType = itPilotAC;
77       } else {
78         *AC_cfg >> InputIdx;
79         InputType = itFCS;
80       }
81     } else if (token == "GAIN") {
82       *AC_cfg >> Gain;
83     } else if (token == "MIN") {
84       *AC_cfg >> Min;
85     } else if (token == "MAX") {
86       *AC_cfg >> Max;
87     } else if (token == "ROWS") {
88       *AC_cfg >> 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);
95       } else {
96         *AC_cfg >> ScheduledBy;
97       }
98     } else if (token == "OUTPUT") {
99       IsOutput = true;
100       *AC_cfg >> sOutputIdx;
101       OutputIdx = State->GetParameterIndex(sOutputIdx);
102     } else {
103       AC_cfg->ResetLineIndexToZero();
104       *Table << *AC_cfg;
105     }
106   }
107
108   if (debug_lvl > 0) {
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;
117       Table->Print();
118     }
119   }
120
121   if (debug_lvl & 2) cout << "Instantiated: FGGain" << endl;
122 }
123
124 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
125
126 FGGain::~FGGain()
127 {
128   if (debug_lvl & 2) cout << "Destroyed:    FGGain" << endl;
129 }
130
131 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
132
133 bool FGGain::Run(void )
134 {
135   double SchedGain = 1.0;
136   double LookupVal = 0;
137
138   FGFCSComponent::Run(); // call the base class for initialization of Input
139
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);
149     Output *= Gain;
150   }
151
152   if (IsOutput) SetOutput();
153
154   return true;
155 }
156
157 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
158
159 void FGGain::Debug(void)
160 {
161     //TODO: Add your source code here
162 }
163