1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 Purpose: Model the flight controls
9 ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
11 This program is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free Software
13 Foundation; either version 2 of the License, or (at your option) any later
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23 Place - Suite 330, Boston, MA 02111-1307, USA.
25 Further information about the GNU General Public License can also be found on
26 the world wide web at http://www.gnu.org.
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
30 This class models the flight controls for a specific airplane
33 --------------------------------------------------------------------------------
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
44 #include "FGFDMExec.h"
45 #include "FGAtmosphere.h"
46 #include "FGAircraft.h"
47 #include "FGTranslation.h"
48 #include "FGRotation.h"
49 #include "FGPosition.h"
50 #include "FGAuxiliary.h"
53 #include "filtersjb/FGFilter.h"
54 #include "filtersjb/FGDeadBand.h"
55 #include "filtersjb/FGGain.h"
56 #include "filtersjb/FGGradient.h"
57 #include "filtersjb/FGSwitch.h"
58 #include "filtersjb/FGSummer.h"
59 #include "filtersjb/FGFlaps.h"
61 static const char *IdSrc = "$Id$";
62 static const char *IdHdr = ID_FCS;
64 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
68 FGFCS::FGFCS(FGFDMExec* fdmex) : FGModel(fdmex)
72 DaCmd = DeCmd = DrCmd = DfCmd = DsbCmd = DspCmd = PTrimCmd = 0.0;
73 DaPos = DePos = DrPos = DfPos = DsbPos = DspPos = 0.0;
74 LeftBrake = RightBrake = CenterBrake = 0.0;
76 if (debug_lvl & 2) cout << "Instantiated: " << Name << endl;
79 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
90 for(i=0;i<Components.size();i++) delete Components[i];
91 if (debug_lvl & 2) cout << "Destroyed: FGFCS" << endl;
94 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100 if (!FGModel::Run()) {
101 for (i=0; i<ThrottlePos.size(); i++) ThrottlePos[i] = ThrottleCmd[i];
102 for (i=0; i<MixturePos.size(); i++) MixturePos[i] = MixtureCmd[i];
103 for (i=0; i<Components.size(); i++) Components[i]->Run();
110 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
112 void FGFCS::SetThrottleCmd(int engineNum, float setting)
116 if ((int)ThrottleCmd.size() > engineNum) {
118 for (ctr=0;ctr<=ThrottleCmd.size();ctr++) ThrottleCmd[ctr] = setting;
120 ThrottleCmd[engineNum] = setting;
123 cerr << "Throttle " << engineNum << " does not exist! " << ThrottleCmd.size()
124 << " engines exist, but attempted throttle command is for engine "
125 << engineNum << endl;
129 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131 void FGFCS::SetThrottlePos(int engineNum, float setting)
135 if ((int)ThrottlePos.size() > engineNum) {
137 for (ctr=0;ctr<=ThrottlePos.size();ctr++) ThrottlePos[ctr] = setting;
139 ThrottlePos[engineNum] = setting;
142 cerr << "Throttle " << engineNum << " does not exist! " << ThrottlePos.size()
143 << " engines exist, but attempted throttle position setting is for engine "
144 << engineNum << endl;
148 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
150 float FGFCS::GetThrottleCmd(int engineNum)
152 if ((int)ThrottleCmd.size() > engineNum) {
154 cerr << "Cannot get throttle value for ALL engines" << endl;
156 return ThrottleCmd[engineNum];
159 cerr << "Throttle " << engineNum << " does not exist! " << ThrottleCmd.size()
160 << " engines exist, but throttle setting for engine " << engineNum
161 << " is selected" << endl;
165 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
167 float FGFCS::GetThrottlePos(int engineNum)
169 if ((int)ThrottlePos.size() > engineNum) {
171 cerr << "Cannot get throttle value for ALL engines" << endl;
173 return ThrottlePos[engineNum];
176 cerr << "Throttle " << engineNum << " does not exist! " << ThrottlePos.size()
177 << " engines exist, but attempted throttle position setting is for engine "
178 << engineNum << endl;
182 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
184 void FGFCS::SetMixtureCmd(int engineNum, float setting)
189 for (ctr=0;ctr<MixtureCmd.size();ctr++) MixtureCmd[ctr] = setting;
191 MixtureCmd[engineNum] = setting;
195 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
197 void FGFCS::SetMixturePos(int engineNum, float setting)
202 for (ctr=0;ctr<=MixtureCmd.size();ctr++) MixturePos[ctr] = MixtureCmd[ctr];
204 MixturePos[engineNum] = setting;
208 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
210 bool FGFCS::Load(FGConfigFile* AC_cfg)
214 Name = Name + ":" + AC_cfg->GetValue("NAME");
215 if (debug_lvl > 0) cout << " Control System Name: " << Name << endl;
216 AC_cfg->GetNextConfigLine();
217 while ((token = AC_cfg->GetValue()) != "/FLIGHT_CONTROL") {
218 if (token == "COMPONENT") {
219 token = AC_cfg->GetValue("TYPE");
220 if (debug_lvl > 0) cout << " Loading Component \""
221 << AC_cfg->GetValue("NAME")
222 << "\" of type: " << token << endl;
223 if ((token == "LAG_FILTER") ||
224 (token == "LEAD_LAG_FILTER") ||
225 (token == "SECOND_ORDER_FILTER") ||
226 (token == "WASHOUT_FILTER") ||
227 (token == "INTEGRATOR") ) {
228 Components.push_back(new FGFilter(this, AC_cfg));
229 } else if ((token == "PURE_GAIN") ||
230 (token == "SCHEDULED_GAIN") ||
231 (token == "AEROSURFACE_SCALE") ) {
233 Components.push_back(new FGGain(this, AC_cfg));
235 } else if (token == "SUMMER") {
236 Components.push_back(new FGSummer(this, AC_cfg));
237 } else if (token == "DEADBAND") {
238 Components.push_back(new FGDeadBand(this, AC_cfg));
239 } else if (token == "GRADIENT") {
240 Components.push_back(new FGGradient(this, AC_cfg));
241 } else if (token == "SWITCH") {
242 Components.push_back(new FGSwitch(this, AC_cfg));
243 } else if (token == "FLAPS") {
244 Components.push_back(new FGFlaps(this, AC_cfg));
246 cerr << "Unknown token [" << token << "] in FCS portion of config file" << endl;
249 AC_cfg->GetNextConfigLine();
255 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
257 float FGFCS::GetComponentOutput(eParam idx) {
258 return Components[idx]->GetOutput();
261 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
263 string FGFCS::GetComponentName(int idx) {
264 return Components[idx]->GetName();
267 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
269 float FGFCS::GetBrake(FGLGear::BrakeGroup bg) {
271 case FGLGear::bgLeft:
273 case FGLGear::bgRight:
275 case FGLGear::bgCenter:
278 cerr << "GetBrake asked to return a bogus brake value" << endl;
283 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
285 string FGFCS::GetComponentStrings(void)
289 string CompStrings = "";
290 bool firstime = true;
292 for (comp = 0; comp < Components.size(); comp++) {
293 if (firstime) firstime = false;
294 else CompStrings += ", ";
296 CompStrings += Components[comp]->GetName();
302 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
304 string FGFCS::GetComponentValues(void)
308 string CompValues = "";
310 bool firstime = true;
312 for (comp = 0; comp < Components.size(); comp++) {
313 if (firstime) firstime = false;
314 else CompValues += ", ";
316 sprintf(buffer, "%9.6f", Components[comp]->GetOutput());
317 CompValues += string(buffer);
323 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
325 void FGFCS::AddThrottle(void)
327 ThrottleCmd.push_back(0.0);
328 ThrottlePos.push_back(0.0);
329 MixtureCmd.push_back(0.0); // assume throttle and mixture are coupled
330 MixturePos.push_back(0.0);
333 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
335 void FGFCS::Debug(void)
337 //TODO: Add your source code here