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 = 0.0;
71 PTrimCmd = YTrimCmd = RTrimCmd = 0.0;
72 DaPos = DePos = DrPos = DfPos = DsbPos = DspPos = 0.0;
73 GearCmd = GearPos = 1; // default to gear down
74 LeftBrake = RightBrake = CenterBrake = 0.0;
79 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87 PropAdvanceCmd.clear();
92 for (i=0;i<Components.size();i++) delete Components[i];
96 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102 if (!FGModel::Run()) {
103 for (i=0; i<ThrottlePos.size(); i++) ThrottlePos[i] = ThrottleCmd[i];
104 for (i=0; i<MixturePos.size(); i++) MixturePos[i] = MixtureCmd[i];
105 for (i=0; i<PropAdvance.size(); i++) PropAdvance[i] = PropAdvanceCmd[i];
106 for (i=0; i<Components.size(); i++) Components[i]->Run();
113 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115 void FGFCS::SetThrottleCmd(int engineNum, double setting)
119 if (engineNum < (int)ThrottlePos.size()) {
121 for (ctr=0;ctr<ThrottleCmd.size();ctr++) ThrottleCmd[ctr] = setting;
123 ThrottleCmd[engineNum] = setting;
126 cerr << "Throttle " << engineNum << " does not exist! " << ThrottleCmd.size()
127 << " engines exist, but attempted throttle command is for engine "
128 << engineNum << endl;
132 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134 void FGFCS::SetThrottlePos(int engineNum, double setting)
138 if (engineNum < (int)ThrottlePos.size()) {
140 for (ctr=0;ctr<ThrottlePos.size();ctr++) ThrottlePos[ctr] = setting;
142 ThrottlePos[engineNum] = setting;
145 cerr << "Throttle " << engineNum << " does not exist! " << ThrottlePos.size()
146 << " engines exist, but attempted throttle position setting is for engine "
147 << engineNum << endl;
151 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
153 double FGFCS::GetThrottleCmd(int engineNum)
155 if (engineNum < (int)ThrottlePos.size()) {
157 cerr << "Cannot get throttle value for ALL engines" << endl;
159 return ThrottleCmd[engineNum];
162 cerr << "Throttle " << engineNum << " does not exist! " << ThrottleCmd.size()
163 << " engines exist, but throttle setting for engine " << engineNum
164 << " is selected" << endl;
169 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
171 double FGFCS::GetThrottlePos(int engineNum)
173 if (engineNum < (int)ThrottlePos.size()) {
175 cerr << "Cannot get throttle value for ALL engines" << endl;
177 return ThrottlePos[engineNum];
180 cerr << "Throttle " << engineNum << " does not exist! " << ThrottlePos.size()
181 << " engines exist, but attempted throttle position setting is for engine "
182 << engineNum << endl;
187 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
189 void FGFCS::SetMixtureCmd(int engineNum, double setting)
193 if (engineNum < (int)ThrottlePos.size()) {
195 for (ctr=0;ctr<MixtureCmd.size();ctr++) MixtureCmd[ctr] = setting;
197 MixtureCmd[engineNum] = setting;
202 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
204 void FGFCS::SetMixturePos(int engineNum, double setting)
208 if (engineNum < (int)ThrottlePos.size()) {
210 for (ctr=0;ctr<=MixtureCmd.size();ctr++) MixturePos[ctr] = MixtureCmd[ctr];
212 MixturePos[engineNum] = setting;
217 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
219 void FGFCS::SetPropAdvanceCmd(int engineNum, double setting)
223 if (engineNum < (int)ThrottlePos.size()) {
225 for (ctr=0;ctr<PropAdvanceCmd.size();ctr++) PropAdvanceCmd[ctr] = setting;
227 PropAdvanceCmd[engineNum] = setting;
232 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
234 void FGFCS::SetPropAdvance(int engineNum, double setting)
238 if (engineNum < (int)ThrottlePos.size()) {
240 for (ctr=0;ctr<=PropAdvanceCmd.size();ctr++) PropAdvance[ctr] = PropAdvanceCmd[ctr];
242 PropAdvance[engineNum] = setting;
247 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
249 bool FGFCS::Load(FGConfigFile* AC_cfg)
253 Name = Name + ":" + AC_cfg->GetValue("NAME");
254 if (debug_lvl > 0) cout << " Control System Name: " << Name << endl;
255 AC_cfg->GetNextConfigLine();
256 while ((token = AC_cfg->GetValue()) != string("/FLIGHT_CONTROL")) {
257 if (token == "COMPONENT") {
258 token = AC_cfg->GetValue("TYPE");
259 if (debug_lvl > 0) cout << " Loading Component \""
260 << AC_cfg->GetValue("NAME")
261 << "\" of type: " << token << endl;
262 if ((token == "LAG_FILTER") ||
263 (token == "LEAD_LAG_FILTER") ||
264 (token == "SECOND_ORDER_FILTER") ||
265 (token == "WASHOUT_FILTER") ||
266 (token == "INTEGRATOR") ) {
267 Components.push_back(new FGFilter(this, AC_cfg));
268 } else if ((token == "PURE_GAIN") ||
269 (token == "SCHEDULED_GAIN") ||
270 (token == "AEROSURFACE_SCALE") ) {
272 Components.push_back(new FGGain(this, AC_cfg));
274 } else if (token == "SUMMER") {
275 Components.push_back(new FGSummer(this, AC_cfg));
276 } else if (token == "DEADBAND") {
277 Components.push_back(new FGDeadBand(this, AC_cfg));
278 } else if (token == "GRADIENT") {
279 Components.push_back(new FGGradient(this, AC_cfg));
280 } else if (token == "SWITCH") {
281 Components.push_back(new FGSwitch(this, AC_cfg));
282 } else if (token == "KINEMAT") {
283 Components.push_back(new FGKinemat(this, AC_cfg));
285 cerr << "Unknown token [" << token << "] in FCS portion of config file" << endl;
288 AC_cfg->GetNextConfigLine();
294 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
296 double FGFCS::GetComponentOutput(eParam idx) {
297 return Components[idx]->GetOutput();
300 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
302 string FGFCS::GetComponentName(int idx) {
303 return Components[idx]->GetName();
306 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
308 double FGFCS::GetBrake(FGLGear::BrakeGroup bg)
311 case FGLGear::bgLeft:
313 case FGLGear::bgRight:
315 case FGLGear::bgCenter:
318 cerr << "GetBrake asked to return a bogus brake value" << endl;
323 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
325 string FGFCS::GetComponentStrings(void)
328 string CompStrings = "";
329 bool firstime = true;
331 for (comp = 0; comp < Components.size(); comp++) {
332 if (firstime) firstime = false;
333 else CompStrings += ", ";
335 CompStrings += Components[comp]->GetName();
341 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
343 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 PropAdvanceCmd.push_back(0.0); // assume throttle and prop pitch are coupled
370 PropAdvance.push_back(0.0);
373 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
374 // The bitmasked value choices are as follows:
375 // unset: In this case (the default) JSBSim would only print
376 // out the normally expected messages, essentially echoing
377 // the config files as they are read. If the environment
378 // variable is not set, debug_lvl is set to 1 internally
379 // 0: This requests JSBSim not to output any messages
381 // 1: This value explicity requests the normal JSBSim
383 // 2: This value asks for a message to be printed out when
384 // a class is instantiated
385 // 4: When this value is set, a message is displayed when a
386 // FGModel object executes its Run() method
387 // 8: When this value is set, various runtime state variables
388 // are printed out periodically
389 // 16: When set various parameters are sanity checked and
390 // a message is printed out when they go out of bounds
392 void FGFCS::Debug(int from)
394 if (debug_lvl <= 0) return;
396 if (debug_lvl & 1) { // Standard console startup message output
397 if (from == 0) { // Constructor
401 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
402 if (from == 0) cout << "Instantiated: FGFCS" << endl;
403 if (from == 1) cout << "Destroyed: FGFCS" << endl;
405 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
407 if (debug_lvl & 8 ) { // Runtime state variables
409 if (debug_lvl & 16) { // Sanity checking
411 if (debug_lvl & 64) {
412 if (from == 0) { // Constructor
413 cout << IdSrc << endl;
414 cout << IdHdr << endl;