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;
78 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86 PropAdvanceCmd.clear();
91 for (i=0;i<Components.size();i++) delete Components[i];
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<PropAdvance.size(); i++) PropAdvance[i] = PropAdvanceCmd[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::SetPropAdvanceCmd(int engineNum, double setting)
222 if (engineNum < (int)ThrottlePos.size()) {
224 for (ctr=0;ctr<PropAdvanceCmd.size();ctr++) PropAdvanceCmd[ctr] = setting;
226 PropAdvanceCmd[engineNum] = setting;
231 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
233 void FGFCS::SetPropAdvance(int engineNum, double setting)
237 if (engineNum < (int)ThrottlePos.size()) {
239 for (ctr=0;ctr<=PropAdvanceCmd.size();ctr++) PropAdvance[ctr] = PropAdvanceCmd[ctr];
241 PropAdvance[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)
310 case FGLGear::bgLeft:
312 case FGLGear::bgRight:
314 case FGLGear::bgCenter:
317 cerr << "GetBrake asked to return a bogus brake value" << endl;
322 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
324 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)
345 string CompValues = "";
347 bool firstime = true;
349 for (comp = 0; comp < Components.size(); comp++) {
350 if (firstime) firstime = false;
351 else CompValues += ", ";
353 sprintf(buffer, "%9.6f", Components[comp]->GetOutput());
354 CompValues += string(buffer);
360 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
362 void FGFCS::AddThrottle(void)
364 ThrottleCmd.push_back(0.0);
365 ThrottlePos.push_back(0.0);
366 MixtureCmd.push_back(0.0); // assume throttle and mixture are coupled
367 MixturePos.push_back(0.0);
368 PropAdvanceCmd.push_back(0.0); // assume throttle and prop pitch are coupled
369 PropAdvance.push_back(0.0);
372 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
373 // The bitmasked value choices are as follows:
374 // unset: In this case (the default) JSBSim would only print
375 // out the normally expected messages, essentially echoing
376 // the config files as they are read. If the environment
377 // variable is not set, debug_lvl is set to 1 internally
378 // 0: This requests JSBSim not to output any messages
380 // 1: This value explicity requests the normal JSBSim
382 // 2: This value asks for a message to be printed out when
383 // a class is instantiated
384 // 4: When this value is set, a message is displayed when a
385 // FGModel object executes its Run() method
386 // 8: When this value is set, various runtime state variables
387 // are printed out periodically
388 // 16: When set various parameters are sanity checked and
389 // a message is printed out when they go out of bounds
391 void FGFCS::Debug(int from)
393 if (debug_lvl <= 0) return;
395 if (debug_lvl & 1) { // Standard console startup message output
396 if (from == 0) { // Constructor
400 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
401 if (from == 0) cout << "Instantiated: FGFCS" << endl;
402 if (from == 1) cout << "Destroyed: FGFCS" << endl;
404 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
406 if (debug_lvl & 8 ) { // Runtime state variables
408 if (debug_lvl & 16) { // Sanity checking