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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
42 #include "FGFDMExec.h"
43 #include "FGAtmosphere.h"
44 #include "FGAircraft.h"
45 #include "FGTranslation.h"
46 #include "FGRotation.h"
47 #include "FGPosition.h"
48 #include "FGAuxiliary.h"
51 #include "filtersjb/FGFilter.h"
52 #include "filtersjb/FGDeadBand.h"
53 #include "filtersjb/FGGain.h"
54 #include "filtersjb/FGGradient.h"
55 #include "filtersjb/FGSwitch.h"
56 #include "filtersjb/FGSummer.h"
57 #include "filtersjb/FGKinemat.h"
59 static const char *IdSrc = "$Id$";
60 static const char *IdHdr = ID_FCS;
62 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
66 FGFCS::FGFCS(FGFDMExec* fdmex) : FGModel(fdmex)
70 DaCmd = DeCmd = DrCmd = DfCmd = DsbCmd = DspCmd = PTrimCmd = 0.0;
71 DaPos = DePos = DrPos = DfPos = DsbPos = DspPos = 0.0;
72 GearCmd = GearPos = 1; // default to gear down
73 LeftBrake = RightBrake = CenterBrake = 0.0;
75 if (debug_lvl & 2) cout << "Instantiated: " << Name << endl;
78 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91 for (i=0;i<Components.size();i++) delete Components[i];
92 if (debug_lvl & 2) cout << "Destroyed: FGFCS" << endl;
95 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101 if (!FGModel::Run()) {
102 for (i=0; i<ThrottlePos.size(); i++) ThrottlePos[i] = ThrottleCmd[i];
103 for (i=0; i<MixturePos.size(); i++) MixturePos[i] = MixtureCmd[i];
104 for (i=0; i<PropPitchPos.size(); i++) PropPitchPos[i] = PropPitchCmd[i];
105 for (i=0; i<Components.size(); i++) Components[i]->Run();
112 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
114 void FGFCS::SetThrottleCmd(int engineNum, double setting)
118 if (engineNum < (int)ThrottlePos.size()) {
120 for (ctr=0;ctr<ThrottleCmd.size();ctr++) ThrottleCmd[ctr] = setting;
122 ThrottleCmd[engineNum] = setting;
125 cerr << "Throttle " << engineNum << " does not exist! " << ThrottleCmd.size()
126 << " engines exist, but attempted throttle command is for engine "
127 << engineNum << endl;
131 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133 void FGFCS::SetThrottlePos(int engineNum, double setting)
137 if (engineNum < (int)ThrottlePos.size()) {
139 for (ctr=0;ctr<ThrottlePos.size();ctr++) ThrottlePos[ctr] = setting;
141 ThrottlePos[engineNum] = setting;
144 cerr << "Throttle " << engineNum << " does not exist! " << ThrottlePos.size()
145 << " engines exist, but attempted throttle position setting is for engine "
146 << engineNum << endl;
150 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
152 double FGFCS::GetThrottleCmd(int engineNum)
154 if (engineNum < (int)ThrottlePos.size()) {
156 cerr << "Cannot get throttle value for ALL engines" << endl;
158 return ThrottleCmd[engineNum];
161 cerr << "Throttle " << engineNum << " does not exist! " << ThrottleCmd.size()
162 << " engines exist, but throttle setting for engine " << engineNum
163 << " is selected" << endl;
168 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
170 double FGFCS::GetThrottlePos(int engineNum)
172 if (engineNum < (int)ThrottlePos.size()) {
174 cerr << "Cannot get throttle value for ALL engines" << endl;
176 return ThrottlePos[engineNum];
179 cerr << "Throttle " << engineNum << " does not exist! " << ThrottlePos.size()
180 << " engines exist, but attempted throttle position setting is for engine "
181 << engineNum << endl;
186 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
188 void FGFCS::SetMixtureCmd(int engineNum, double setting)
192 if (engineNum < (int)ThrottlePos.size()) {
194 for (ctr=0;ctr<MixtureCmd.size();ctr++) MixtureCmd[ctr] = setting;
196 MixtureCmd[engineNum] = setting;
201 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
203 void FGFCS::SetMixturePos(int engineNum, double setting)
207 if (engineNum < (int)ThrottlePos.size()) {
209 for (ctr=0;ctr<=MixtureCmd.size();ctr++) MixturePos[ctr] = MixtureCmd[ctr];
211 MixturePos[engineNum] = setting;
216 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
218 void FGFCS::SetPropPitchCmd(int engineNum, double setting)
222 if (engineNum < (int)ThrottlePos.size()) {
224 for (ctr=0;ctr<PropPitchCmd.size();ctr++) PropPitchCmd[ctr] = setting;
226 PropPitchCmd[engineNum] = setting;
231 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
233 void FGFCS::SetPropPitchPos(int engineNum, double setting)
237 if (engineNum < (int)ThrottlePos.size()) {
239 for (ctr=0;ctr<=PropPitchCmd.size();ctr++) PropPitchPos[ctr] = PropPitchCmd[ctr];
241 PropPitchPos[engineNum] = setting;
246 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
248 bool FGFCS::Load(FGConfigFile* AC_cfg)
252 Name = Name + ":" + AC_cfg->GetValue("NAME");
253 if (debug_lvl > 0) cout << " Control System Name: " << Name << endl;
254 AC_cfg->GetNextConfigLine();
255 while ((token = AC_cfg->GetValue()) != string("/FLIGHT_CONTROL")) {
256 if (token == "COMPONENT") {
257 token = AC_cfg->GetValue("TYPE");
258 if (debug_lvl > 0) cout << " Loading Component \""
259 << AC_cfg->GetValue("NAME")
260 << "\" of type: " << token << endl;
261 if ((token == "LAG_FILTER") ||
262 (token == "LEAD_LAG_FILTER") ||
263 (token == "SECOND_ORDER_FILTER") ||
264 (token == "WASHOUT_FILTER") ||
265 (token == "INTEGRATOR") ) {
266 Components.push_back(new FGFilter(this, AC_cfg));
267 } else if ((token == "PURE_GAIN") ||
268 (token == "SCHEDULED_GAIN") ||
269 (token == "AEROSURFACE_SCALE") ) {
271 Components.push_back(new FGGain(this, AC_cfg));
273 } else if (token == "SUMMER") {
274 Components.push_back(new FGSummer(this, AC_cfg));
275 } else if (token == "DEADBAND") {
276 Components.push_back(new FGDeadBand(this, AC_cfg));
277 } else if (token == "GRADIENT") {
278 Components.push_back(new FGGradient(this, AC_cfg));
279 } else if (token == "SWITCH") {
280 Components.push_back(new FGSwitch(this, AC_cfg));
281 } else if (token == "KINEMAT") {
282 Components.push_back(new FGKinemat(this, AC_cfg));
284 cerr << "Unknown token [" << token << "] in FCS portion of config file" << endl;
287 AC_cfg->GetNextConfigLine();
293 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
295 double FGFCS::GetComponentOutput(eParam idx) {
296 return Components[idx]->GetOutput();
299 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
301 string FGFCS::GetComponentName(int idx) {
302 return Components[idx]->GetName();
305 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
307 double FGFCS::GetBrake(FGLGear::BrakeGroup bg) {
309 case FGLGear::bgLeft:
311 case FGLGear::bgRight:
313 case FGLGear::bgCenter:
316 cerr << "GetBrake asked to return a bogus brake value" << endl;
321 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
323 string FGFCS::GetComponentStrings(void)
327 string CompStrings = "";
328 bool firstime = true;
330 for (comp = 0; comp < Components.size(); comp++) {
331 if (firstime) firstime = false;
332 else CompStrings += ", ";
334 CompStrings += Components[comp]->GetName();
340 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
342 string FGFCS::GetComponentValues(void)
346 string CompValues = "";
348 bool firstime = true;
350 for (comp = 0; comp < Components.size(); comp++) {
351 if (firstime) firstime = false;
352 else CompValues += ", ";
354 sprintf(buffer, "%9.6f", Components[comp]->GetOutput());
355 CompValues += string(buffer);
361 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
363 void FGFCS::AddThrottle(void)
365 ThrottleCmd.push_back(0.0);
366 ThrottlePos.push_back(0.0);
367 MixtureCmd.push_back(0.0); // assume throttle and mixture are coupled
368 MixturePos.push_back(0.0);
369 PropPitchCmd.push_back(0.0); // assume throttle and prop pitch are coupled
370 PropPitchPos.push_back(0.0);
373 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
375 void FGFCS::Debug(void)
377 //TODO: Add your source code here