2 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 Purpose: Schedules and runs the model routines.
9 ------------- Copyright (C) 1999 Jon S. Berndt (jon@jsbsim.org) -------------
11 This program is free software; you can redistribute it and/or modify it under
12 the terms of the GNU Lesser 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 Lesser General Public License for more
21 You should have received a copy of the GNU Lesser 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 Lesser General Public License can also be found on
26 the world wide web at http://www.gnu.org.
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
31 This class wraps up the simulation scheduling routines.
34 --------------------------------------------------------------------------------
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 COMMENTS, REFERENCES, and NOTES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
49 #include "FGFDMExec.h"
50 #include "models/atmosphere/FGStandardAtmosphere.h"
51 #include "models/atmosphere/FGWinds.h"
52 #include "models/FGFCS.h"
53 #include "models/FGPropulsion.h"
54 #include "models/FGMassBalance.h"
55 #include "models/FGGroundReactions.h"
56 #include "models/FGExternalReactions.h"
57 #include "models/FGBuoyantForces.h"
58 #include "models/FGAerodynamics.h"
59 #include "models/FGInertial.h"
60 #include "models/FGAircraft.h"
61 #include "models/FGAccelerations.h"
62 #include "models/FGPropagate.h"
63 #include "models/FGAuxiliary.h"
64 #include "models/FGInput.h"
65 #include "models/FGOutput.h"
66 #include "initialization/FGInitialCondition.h"
67 #include "initialization/FGSimplexTrim.h"
68 #include "input_output/FGPropertyManager.h"
69 #include "input_output/FGScript.h"
75 static const char *IdSrc = "$Id: FGFDMExec.cpp,v 1.145 2012/11/11 18:43:07 bcoconni Exp $";
76 static const char *IdHdr = ID_FDMEXEC;
78 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
82 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85 FGFDMExec::FGFDMExec(FGPropertyManager* root, unsigned int* fdmctr) : Root(root), FDMctr(fdmctr)
89 SetGroundCallback(new FGDefaultGroundCallback());
102 IncrementThenHolding = false; // increment then hold is off by default
103 TimeStepsUntilHold = -1;
106 dT = 1.0/120.0; // a default timestep size. This is needed for when JSBSim is
107 // run in standalone mode with no initialization file.
109 AircraftPath = "aircraft";
110 EnginePath = "engine";
111 SystemsPath = "systems";
114 char* num = getenv("JSBSIM_DEBUG");
115 if (num) debug_lvl = atoi(num); // set debug level
116 } catch (...) { // if error set to 1
120 if (Root == 0) { // Then this is the root FDM
121 Root = new FGPropertyManager; // Create the property manager
126 FDMctr = new unsigned int; // Create and initialize the child FDM counter
130 // Store this FDM's ID
131 IdFDM = (*FDMctr); // The main (parent) JSBSim instance is always the "zeroth"
133 // Prepare FDMctr for the next child FDM id
134 (*FDMctr)++; // instance. "child" instances are loaded last.
136 instance = Root->GetNode("/fdm/jsbsim",IdFDM,true);
138 // this is to catch errors in binding member functions to the property tree.
141 } catch ( string msg ) {
142 cout << "Caught error: " << msg << endl;
150 typedef int (FGFDMExec::*iPMF)(void) const;
151 typedef double (FGFDMExec::*dPMF)(void) const;
152 // typedef unsigned int (FGFDMExec::*uiPMF)(void) const;
153 // instance->Tie("simulation/do_trim_analysis", this, (iPMF)0, &FGFDMExec::DoTrimAnalysis, false);
154 instance->Tie("simulation/do_simple_trim", this, (iPMF)0, &FGFDMExec::DoTrim, false);
155 instance->Tie("simulation/do_simplex_trim", this, (iPMF)0, &FGFDMExec::DoSimplexTrim);
156 instance->Tie("simulation/reset", this, (iPMF)0, &FGFDMExec::ResetToInitialConditions, false);
157 instance->Tie("simulation/randomseed", this, (iPMF)0, &FGFDMExec::SRand, false);
158 instance->Tie("simulation/terminate", (int *)&Terminate);
159 instance->Tie("simulation/sim-time-sec", this, &FGFDMExec::GetSimTime);
160 instance->Tie("simulation/jsbsim-debug", this, &FGFDMExec::GetDebugLevel, &FGFDMExec::SetDebugLevel);
161 instance->Tie("simulation/frame", (int *)&Frame, false);
163 // simplex trim properties
164 instance->SetDouble("trim/solver/rtol",0.0001);
165 instance->SetDouble("trim/solver/speed",2);
166 instance->SetDouble("trim/solver/abstol",0.001);
167 instance->SetDouble("trim/solver/iterMax",2000);
168 instance->SetInt("trim/solver/debugLevel",0);
169 instance->SetDouble("trim/solver/random",0);
170 instance->SetBool("trim/solver/showSimplex",false);
171 // instance->SetBool("trim/solver/showConvergence",true);
172 instance->SetBool("trim/solver/pause",false);
174 instance->SetDouble("trim/solver/throttleGuess",0.50);
175 instance->SetDouble("trim/solver/throttleMin",0.0);
176 instance->SetDouble("trim/solver/throttleMax",1.0);
177 // instance->SetDouble("trim/solver/throttleInitialStepSize",0.1);
178 instance->SetDouble("trim/solver/throttleStep",0.1);
180 instance->SetDouble("trim/solver/aileronGuess",0);
181 instance->SetDouble("trim/solver/aileronMin",-1.00);
182 instance->SetDouble("trim/solver/aileronMax",1.00);
183 // instance->SetDouble("trim/solver/aileronInitialStepSize",0.1);
184 instance->SetDouble("trim/solver/aileronStep",0.1);
186 instance->SetDouble("trim/solver/rudderGuess",0);
187 instance->SetDouble("trim/solver/rudderMin",-1.00);
188 instance->SetDouble("trim/solver/rudderMax",1.00);
189 // instance->SetDouble("trim/solver/rudderInitialStepSize",0.1);
190 instance->SetDouble("trim/solver/rudderStep",0.1);
192 instance->SetDouble("trim/solver/elevatorGuess",-0.1);
193 instance->SetDouble("trim/solver/elevatorMin",-1.0);
194 instance->SetDouble("trim/solver/elevatorMax",1.0);
195 // instance->SetDouble("trim/solver/elevatorInitialStepSize",0.1);
196 instance->SetDouble("trim/solver/elevatorStep",0.1);
198 instance->SetDouble("trim/solver/alphaGuess",0.05);
199 instance->SetDouble("trim/solver/alphaMin",-0.1);
200 instance->SetDouble("trim/solver/alphaMax",.18);
201 // instance->SetDouble("trim/solver/alphaInitialStepSize",0.1);
202 instance->SetDouble("trim/solver/alphaStep",0.05);
204 instance->SetDouble("trim/solver/betaGuess",0);
205 instance->SetDouble("trim/solver/betaMin",-0.05);
206 instance->SetDouble("trim/solver/betaMax",0.05);
207 // instance->SetDouble("trim/solver/betaInitialStepSize",0.1);
208 instance->SetDouble("trim/solver/betaStep",0.05);
210 instance->SetBool("trim/solver/showConvergeStatus",true);
211 // instance->SetBool("trim/solver/pause",true);
212 instance->SetBool("trim/solver/variablePropPitch",false);
213 // instance->SetBool("trim/solver/debugLevel",0);
215 Constructing = false;
218 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
220 FGFDMExec::~FGFDMExec()
226 if (IdFDM == 0) { // Meaning this is no child FDM
237 } catch ( string msg ) {
238 cout << "Caught error: " << msg << endl;
241 for (unsigned int i=1; i<ChildFDMList.size(); i++) delete ChildFDMList[i]->exec;
242 ChildFDMList.clear();
244 PropertyCatalog.clear();
246 if (FDMctr > 0) (*FDMctr)--;
251 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
253 bool FGFDMExec::Allocate(void)
257 Models.resize(eNumStandardModels);
259 // See the eModels enum specification in the header file. The order of the enums
260 // specifies the order of execution. The Models[] vector is the primary
261 // storage array for the list of models.
262 Models[ePropagate] = new FGPropagate(this);
263 Models[eInput] = new FGInput(this);
264 Models[eInertial] = new FGInertial(this);
265 Models[eAtmosphere] = new FGStandardAtmosphere(this);
266 Models[eWinds] = new FGWinds(this);
267 Models[eAuxiliary] = new FGAuxiliary(this);
268 Models[eSystems] = new FGFCS(this);
269 Models[ePropulsion] = new FGPropulsion(this);
270 Models[eAerodynamics] = new FGAerodynamics (this);
271 Models[eGroundReactions] = new FGGroundReactions(this);
272 Models[eExternalReactions] = new FGExternalReactions(this);
273 Models[eBuoyantForces] = new FGBuoyantForces(this);
274 Models[eMassBalance] = new FGMassBalance(this);
275 Models[eAircraft] = new FGAircraft(this);
276 Models[eAccelerations] = new FGAccelerations(this);
277 Models[eOutput] = new FGOutput(this);
279 // Assign the Model shortcuts for internal executive use only.
280 Propagate = (FGPropagate*)Models[ePropagate];
281 Inertial = (FGInertial*)Models[eInertial];
282 Atmosphere = (FGAtmosphere*)Models[eAtmosphere];
283 Winds = (FGWinds*)Models[eWinds];
284 Auxiliary = (FGAuxiliary*)Models[eAuxiliary];
285 FCS = (FGFCS*)Models[eSystems];
286 Propulsion = (FGPropulsion*)Models[ePropulsion];
287 Aerodynamics = (FGAerodynamics*)Models[eAerodynamics];
288 GroundReactions = (FGGroundReactions*)Models[eGroundReactions];
289 ExternalReactions = (FGExternalReactions*)Models[eExternalReactions];
290 BuoyantForces = (FGBuoyantForces*)Models[eBuoyantForces];
291 MassBalance = (FGMassBalance*)Models[eMassBalance];
292 Aircraft = (FGAircraft*)Models[eAircraft];
293 Accelerations = (FGAccelerations*)Models[eAccelerations];
294 Output = (FGOutput*)Models[eOutput];
296 // Initialize planet (environment) constants
297 LoadPlanetConstants();
298 GetGroundCallback()->SetSeaLevelRadius(Inertial->GetRefRadius());
301 for (unsigned int i = 0; i < Models.size(); i++) {
302 // The Output model must not be initialized prior to IC loading
303 if (i == eOutput) continue;
306 Models[i]->InitModel();
309 IC = new FGInitialCondition(this);
316 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
318 bool FGFDMExec::DeAllocate(void)
321 for (unsigned int i=0; i<eNumStandardModels; i++) delete Models[i];
334 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
336 void FGFDMExec::Schedule(FGModel* model, int rate)
338 model->SetRate(rate);
339 Models.push_back(model);
342 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
344 bool FGFDMExec::Run(void)
350 for (unsigned int i=1; i<ChildFDMList.size(); i++) {
351 ChildFDMList[i]->AssignState( (FGPropagate*)Models[ePropagate] ); // Transfer state to the child FDM
352 ChildFDMList[i]->Run();
357 // returns true if success, false if complete
358 if (Script != 0 && !IntegrationSuspended()) success = Script->RunScript();
360 for (unsigned int i = 0; i < Models.size(); i++) {
362 Models[i]->Run(holding);
365 if (Terminate) success = false;
370 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
372 void FGFDMExec::LoadInputs(unsigned int idx)
376 Propagate->in.vPQRidot = Accelerations->GetPQRidot();
377 Propagate->in.vQtrndot = Accelerations->GetQuaterniondot();
378 Propagate->in.vUVWidot = Accelerations->GetUVWidot();
379 Propagate->in.DeltaT = dT;
384 Inertial->in.Radius = Propagate->GetRadius();
385 Inertial->in.Latitude = Propagate->GetLatitude();
388 Atmosphere->in.altitudeASL = Propagate->GetAltitudeASL();
391 Winds->in.AltitudeASL = Propagate->GetAltitudeASL();
392 Winds->in.DistanceAGL = Propagate->GetDistanceAGL();
393 Winds->in.Tl2b = Propagate->GetTl2b();
394 Winds->in.Tw2b = Auxiliary->GetTw2b();
395 Winds->in.V = Auxiliary->GetVt();
396 Winds->in.totalDeltaT = dT * Winds->GetRate();
399 Auxiliary->in.Pressure = Atmosphere->GetPressure();
400 Auxiliary->in.Density = Atmosphere->GetDensity();
401 Auxiliary->in.DensitySL = Atmosphere->GetDensitySL();
402 Auxiliary->in.PressureSL = Atmosphere->GetPressureSL();
403 Auxiliary->in.Temperature = Atmosphere->GetTemperature();
404 Auxiliary->in.SoundSpeed = Atmosphere->GetSoundSpeed();
405 Auxiliary->in.KinematicViscosity = Atmosphere->GetKinematicViscosity();
406 Auxiliary->in.DistanceAGL = Propagate->GetDistanceAGL();
407 Auxiliary->in.Mass = MassBalance->GetMass();
408 Auxiliary->in.Tl2b = Propagate->GetTl2b();
409 Auxiliary->in.Tb2l = Propagate->GetTb2l();
410 Auxiliary->in.vPQR = Propagate->GetPQR();
411 Auxiliary->in.vPQRdot = Accelerations->GetPQRdot();
412 Auxiliary->in.vUVW = Propagate->GetUVW();
413 Auxiliary->in.vUVWdot = Accelerations->GetUVWdot();
414 Auxiliary->in.vVel = Propagate->GetVel();
415 Auxiliary->in.vBodyAccel = Accelerations->GetBodyAccel();
416 Auxiliary->in.ToEyePt = MassBalance->StructuralToBody(Aircraft->GetXYZep());
417 Auxiliary->in.VRPBody = MassBalance->StructuralToBody(Aircraft->GetXYZvrp());
418 Auxiliary->in.RPBody = MassBalance->StructuralToBody(Aircraft->GetXYZrp());
419 Auxiliary->in.vFw = Aerodynamics->GetvFw();
420 Auxiliary->in.vLocation = Propagate->GetLocation();
421 Auxiliary->in.CosTht = Propagate->GetCosEuler(eTht);
422 Auxiliary->in.SinTht = Propagate->GetSinEuler(eTht);
423 Auxiliary->in.CosPhi = Propagate->GetCosEuler(ePhi);
424 Auxiliary->in.SinPhi = Propagate->GetSinEuler(ePhi);
425 Auxiliary->in.Psi = Propagate->GetEuler(ePsi);
426 Auxiliary->in.TotalWindNED = Winds->GetTotalWindNED();
427 Auxiliary->in.TurbPQR = Winds->GetTurbPQR();
428 Auxiliary->in.WindPsi = Winds->GetWindPsi();
429 Auxiliary->in.Vwind = Winds->GetTotalWindNED().Magnitude();
432 // Dynamic inputs come into the components that FCS manages through properties
435 Propulsion->in.SLPressure = Atmosphere->GetPressureSL();
436 Propulsion->in.Pressure = Atmosphere->GetPressure();
437 Propulsion->in.PressureRatio = Atmosphere->GetPressureRatio();
438 Propulsion->in.Temperature = Atmosphere->GetTemperature();
439 Propulsion->in.DensityRatio = Atmosphere->GetDensityRatio();
440 Propulsion->in.Density = Atmosphere->GetDensity();
441 Propulsion->in.Soundspeed = Atmosphere->GetSoundSpeed();
442 Propulsion->in.TotalPressure = Auxiliary->GetTotalPressure();
443 Propulsion->in.TotalTempearture = Auxiliary->GetTotalTemperature();
444 Propulsion->in.Vc = Auxiliary->GetVcalibratedKTS();
445 Propulsion->in.Vt = Auxiliary->GetVt();
446 Propulsion->in.qbar = Auxiliary->Getqbar();
447 Propulsion->in.TAT_c = Auxiliary->GetTAT_C();
448 Propulsion->in.AeroUVW = Auxiliary->GetAeroUVW();
449 Propulsion->in.AeroPQR = Auxiliary->GetAeroPQR();
450 Propulsion->in.alpha = Auxiliary->Getalpha();
451 Propulsion->in.beta = Auxiliary->Getbeta();
452 Propulsion->in.TotalDeltaT = dT * Propulsion->GetRate();
453 Propulsion->in.ThrottlePos = FCS->GetThrottlePos();
454 Propulsion->in.MixturePos = FCS->GetMixturePos();
455 Propulsion->in.ThrottleCmd = FCS->GetThrottleCmd();
456 Propulsion->in.MixtureCmd = FCS->GetMixtureCmd();
457 Propulsion->in.PropAdvance = FCS->GetPropAdvance();
458 Propulsion->in.PropFeather = FCS->GetPropFeather();
459 Propulsion->in.H_agl = Propagate->GetDistanceAGL();
460 Propulsion->in.PQR = Propagate->GetPQR();
464 Aerodynamics->in.Alpha = Auxiliary->Getalpha();
465 Aerodynamics->in.Beta = Auxiliary->Getbeta();
466 Aerodynamics->in.Qbar = Auxiliary->Getqbar();
467 Aerodynamics->in.Vt = Auxiliary->GetVt();
468 Aerodynamics->in.Tb2w = Auxiliary->GetTb2w();
469 Aerodynamics->in.Tw2b = Auxiliary->GetTw2b();
470 Aerodynamics->in.RPBody = MassBalance->StructuralToBody(Aircraft->GetXYZrp());
472 case eGroundReactions:
473 // There are no external inputs to this model.
474 GroundReactions->in.Vground = Auxiliary->GetVground();
475 GroundReactions->in.VcalibratedKts = Auxiliary->GetVcalibratedKTS();
476 GroundReactions->in.Temperature = Atmosphere->GetTemperature();
477 GroundReactions->in.TakeoffThrottle = (FCS->GetThrottlePos().size() > 0) ? (FCS->GetThrottlePos(0) > 0.90) : false;
478 GroundReactions->in.SteerPosDeg = FCS->GetSteerPosDeg();
479 GroundReactions->in.BrakePos = FCS->GetBrakePos();
480 GroundReactions->in.FCSGearPos = FCS->GetGearPos();
481 GroundReactions->in.EmptyWeight = MassBalance->GetEmptyWeight();
482 GroundReactions->in.Tb2l = Propagate->GetTb2l();
483 GroundReactions->in.Tec2l = Propagate->GetTec2l();
484 GroundReactions->in.Tec2b = Propagate->GetTec2b();
485 GroundReactions->in.PQR = Propagate->GetPQR();
486 GroundReactions->in.UVW = Propagate->GetUVW();
487 GroundReactions->in.DistanceAGL = Propagate->GetDistanceAGL();
488 GroundReactions->in.DistanceASL = Propagate->GetAltitudeASL();
489 GroundReactions->in.TotalDeltaT = dT * GroundReactions->GetRate();
490 GroundReactions->in.WOW = GroundReactions->GetWOW();
491 GroundReactions->in.Location = Propagate->GetLocation();
492 GroundReactions->in.vXYZcg = MassBalance->GetXYZcg();
494 case eExternalReactions:
495 // There are no external inputs to this model.
498 BuoyantForces->in.Density = Atmosphere->GetDensity();
499 BuoyantForces->in.Pressure = Atmosphere->GetPressure();
500 BuoyantForces->in.Temperature = Atmosphere->GetTemperature();
501 BuoyantForces->in.gravity = Inertial->gravity();
504 MassBalance->in.GasInertia = BuoyantForces->GetGasMassInertia();
505 MassBalance->in.GasMass = BuoyantForces->GetGasMass();
506 MassBalance->in.GasMoment = BuoyantForces->GetGasMassMoment();
507 MassBalance->in.TanksWeight = Propulsion->GetTanksWeight();
508 MassBalance->in.TanksMoment = Propulsion->GetTanksMoment();
509 MassBalance->in.TankInertia = Propulsion->CalculateTankInertias();
512 Aircraft->in.AeroForce = Aerodynamics->GetForces();
513 Aircraft->in.PropForce = Propulsion->GetForces();
514 Aircraft->in.GroundForce = GroundReactions->GetForces();
515 Aircraft->in.ExternalForce = ExternalReactions->GetForces();
516 Aircraft->in.BuoyantForce = BuoyantForces->GetForces();
517 Aircraft->in.AeroMoment = Aerodynamics->GetMoments();
518 Aircraft->in.PropMoment = Propulsion->GetMoments();
519 Aircraft->in.GroundMoment = GroundReactions->GetMoments();
520 Aircraft->in.ExternalMoment = ExternalReactions->GetMoments();
521 Aircraft->in.BuoyantMoment = BuoyantForces->GetMoments();
524 Accelerations->in.J = MassBalance->GetJ();
525 Accelerations->in.Jinv = MassBalance->GetJinv();
526 Accelerations->in.Ti2b = Propagate->GetTi2b();
527 Accelerations->in.Tb2i = Propagate->GetTb2i();
528 Accelerations->in.Tec2b = Propagate->GetTec2b();
529 Accelerations->in.Tec2i = Propagate->GetTec2i();
530 Accelerations->in.qAttitudeECI = Propagate->GetQuaternionECI();
531 Accelerations->in.Moment = Aircraft->GetMoments();
532 Accelerations->in.GroundMoment = GroundReactions->GetMoments();
533 Accelerations->in.Force = Aircraft->GetForces();
534 Accelerations->in.GroundForce = GroundReactions->GetForces();
535 Accelerations->in.GAccel = Inertial->GetGAccel(Propagate->GetRadius());
536 Accelerations->in.J2Grav = Inertial->GetGravityJ2(Propagate->GetLocation());
537 Accelerations->in.vPQRi = Propagate->GetPQRi();
538 Accelerations->in.vPQR = Propagate->GetPQR();
539 Accelerations->in.vUVW = Propagate->GetUVW();
540 Accelerations->in.vInertialPosition = Propagate->GetInertialPosition();
541 Accelerations->in.DeltaT = dT;
542 Accelerations->in.Mass = MassBalance->GetMass();
543 Accelerations->in.MultipliersList = GroundReactions->GetMultipliersList();
544 Accelerations->in.TerrainVelocity = Propagate->GetTerrainVelocity();
545 Accelerations->in.TerrainAngularVel = Propagate->GetTerrainAngularVelocity();
552 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
554 void FGFDMExec::LoadPlanetConstants(void)
556 Propagate->in.vOmegaPlanet = Inertial->GetOmegaPlanet();
557 Accelerations->in.vOmegaPlanet = Inertial->GetOmegaPlanet();
558 Propagate->in.SemiMajor = Inertial->GetSemimajor();
559 Propagate->in.SemiMinor = Inertial->GetSemiminor();
560 Auxiliary->in.SLGravity = Inertial->SLgravity();
561 Auxiliary->in.ReferenceRadius = Inertial->GetRefRadius();
564 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
566 void FGFDMExec::LoadModelConstants(void)
568 Winds->in.wingspan = Aircraft->GetWingSpan();
569 FCS->in.NumGear = GroundReactions->GetNumGearUnits();
570 Aerodynamics->in.Wingarea = Aircraft->GetWingArea();
571 Aerodynamics->in.Wingchord = Aircraft->Getcbar();
572 Aerodynamics->in.Wingincidence = Aircraft->GetWingIncidence();
573 Aerodynamics->in.Wingspan = Aircraft->GetWingSpan();
574 Auxiliary->in.Wingspan = Aircraft->GetWingSpan();
575 Auxiliary->in.Wingchord = Aircraft->Getcbar();
576 GroundReactions->in.vXYZcg = MassBalance->GetXYZcg();
578 LoadPlanetConstants();
581 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
582 // This call will cause the sim time to reset to 0.0
584 bool FGFDMExec::RunIC(void)
586 FGPropulsion* propulsion = (FGPropulsion*)Models[ePropulsion];
588 Models[eOutput]->InitModel();
590 SuspendIntegration(); // saves the integration rate, dt, then sets it to 0.0.
593 ResumeIntegration(); // Restores the integration rate to what it was.
595 for (unsigned int i=0; i<IC->GetNumEnginesRunning(); i++)
596 propulsion->InitRunning(IC->GetEngineRunning(i));
601 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
603 void FGFDMExec::Initialize(FGInitialCondition *FGIC)
607 Propagate->SetInitialState( FGIC );
608 LoadInputs(eAccelerations);
609 Accelerations->Run(false);
610 LoadInputs(ePropagate);
611 Propagate->InitializeDerivatives();
612 LoadInputs(eAtmosphere);
613 Atmosphere->Run(false);
614 Winds->SetWindNED(FGIC->GetWindNEDFpsIC());
615 Auxiliary->Run(false);
618 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
620 // A private, internal function call for Tie-ing to a property, so it needs an
623 void FGFDMExec::ResetToInitialConditions(int mode)
625 if (mode == 1) Output->SetStartNewOutput();
627 ResetToInitialConditions();
630 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
632 void FGFDMExec::ResetToInitialConditions(void)
634 if (Constructing) return;
636 for (unsigned int i = 0; i < Models.size(); i++) {
637 // The Output model will be initialized during the RunIC() execution
638 if (i == eOutput) continue;
641 Models[i]->InitModel();
646 if (Script) Script->ResetEvents();
649 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
651 vector <string> FGFDMExec::EnumerateFDMs(void)
653 vector <string> FDMList;
654 FGAircraft* Aircraft = (FGAircraft*)Models[eAircraft];
656 FDMList.push_back(Aircraft->GetAircraftName());
658 for (unsigned int i=1; i<ChildFDMList.size(); i++) {
659 FDMList.push_back(ChildFDMList[i]->exec->GetAircraft()->GetAircraftName());
665 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
667 bool FGFDMExec::LoadScript(const string& script, double deltaT, const string initfile)
671 Script = new FGScript(this);
672 result = Script->LoadScript(RootDir + script, deltaT, initfile);
677 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
679 bool FGFDMExec::LoadModel(const string& AircraftPath, const string& EnginePath, const string& SystemsPath,
680 const string& model, bool addModelToPath)
682 FGFDMExec::AircraftPath = RootDir + AircraftPath;
683 FGFDMExec::EnginePath = RootDir + EnginePath;
684 FGFDMExec::SystemsPath = RootDir + SystemsPath;
686 return LoadModel(model, addModelToPath);
689 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
691 bool FGFDMExec::LoadModel(const string& model, bool addModelToPath)
694 string aircraftCfgFileName;
695 Element* element = 0L;
696 bool result = false; // initialize result to false, indicating input file not yet read
698 modelName = model; // Set the class modelName attribute
700 if( AircraftPath.empty() || EnginePath.empty() || SystemsPath.empty()) {
701 cerr << "Error: attempted to load aircraft with undefined ";
702 cerr << "aircraft, engine, and system paths" << endl;
706 FullAircraftPath = AircraftPath;
707 if (addModelToPath) FullAircraftPath += "/" + model;
708 aircraftCfgFileName = FullAircraftPath + "/" + model + ".xml";
715 int saved_debug_lvl = debug_lvl;
717 document = LoadXMLDocument(aircraftCfgFileName); // "document" is a class member
719 if (IsChild) debug_lvl = 0;
721 ReadPrologue(document);
723 if (IsChild) debug_lvl = saved_debug_lvl;
725 // Process the fileheader element in the aircraft config file. This element is OPTIONAL.
726 element = document->FindElement("fileheader");
728 result = ReadFileHeader(element);
730 cerr << endl << "Aircraft fileheader element has problems in file " << aircraftCfgFileName << endl;
735 if (IsChild) debug_lvl = 0;
737 // Process the metrics element. This element is REQUIRED.
738 element = document->FindElement("metrics");
740 result = ((FGAircraft*)Models[eAircraft])->Load(element);
742 cerr << endl << "Aircraft metrics element has problems in file " << aircraftCfgFileName << endl;
746 cerr << endl << "No metrics element was found in the aircraft config file." << endl;
750 // Process the mass_balance element. This element is REQUIRED.
751 element = document->FindElement("mass_balance");
753 result = ((FGMassBalance*)Models[eMassBalance])->Load(element);
755 cerr << endl << "Aircraft mass_balance element has problems in file " << aircraftCfgFileName << endl;
759 cerr << endl << "No mass_balance element was found in the aircraft config file." << endl;
763 // Process the ground_reactions element. This element is REQUIRED.
764 element = document->FindElement("ground_reactions");
766 result = ((FGGroundReactions*)Models[eGroundReactions])->Load(element);
768 cerr << endl << "Aircraft ground_reactions element has problems in file " << aircraftCfgFileName << endl;
771 ((FGFCS*)Models[eSystems])->AddGear(((FGGroundReactions*)Models[eGroundReactions])->GetNumGearUnits());
773 cerr << endl << "No ground_reactions element was found in the aircraft config file." << endl;
777 // Process the external_reactions element. This element is OPTIONAL.
778 element = document->FindElement("external_reactions");
780 result = ((FGExternalReactions*)Models[eExternalReactions])->Load(element);
782 cerr << endl << "Aircraft external_reactions element has problems in file " << aircraftCfgFileName << endl;
787 // Process the buoyant_forces element. This element is OPTIONAL.
788 element = document->FindElement("buoyant_forces");
790 result = ((FGBuoyantForces*)Models[eBuoyantForces])->Load(element);
792 cerr << endl << "Aircraft buoyant_forces element has problems in file " << aircraftCfgFileName << endl;
797 // Process the propulsion element. This element is OPTIONAL.
798 element = document->FindElement("propulsion");
800 result = ((FGPropulsion*)Models[ePropulsion])->Load(element);
802 cerr << endl << "Aircraft propulsion element has problems in file " << aircraftCfgFileName << endl;
805 for (unsigned int i=0; i<((FGPropulsion*)Models[ePropulsion])->GetNumEngines(); i++)
806 ((FGFCS*)Models[eSystems])->AddThrottle();
809 // Process the system element[s]. This element is OPTIONAL, and there may be more than one.
810 element = document->FindElement("system");
812 result = ((FGFCS*)Models[eSystems])->Load(element, FGFCS::stSystem);
814 cerr << endl << "Aircraft system element has problems in file " << aircraftCfgFileName << endl;
817 element = document->FindNextElement("system");
820 // Process the autopilot element. This element is OPTIONAL.
821 element = document->FindElement("autopilot");
823 result = ((FGFCS*)Models[eSystems])->Load(element, FGFCS::stAutoPilot);
825 cerr << endl << "Aircraft autopilot element has problems in file " << aircraftCfgFileName << endl;
830 // Process the flight_control element. This element is OPTIONAL.
831 element = document->FindElement("flight_control");
833 result = ((FGFCS*)Models[eSystems])->Load(element, FGFCS::stFCS);
835 cerr << endl << "Aircraft flight_control element has problems in file " << aircraftCfgFileName << endl;
840 // Process the aerodynamics element. This element is OPTIONAL, but almost always expected.
841 element = document->FindElement("aerodynamics");
843 result = ((FGAerodynamics*)Models[eAerodynamics])->Load(element);
845 cerr << endl << "Aircraft aerodynamics element has problems in file " << aircraftCfgFileName << endl;
849 cerr << endl << "No expected aerodynamics element was found in the aircraft config file." << endl;
852 // Process the input element. This element is OPTIONAL.
853 element = document->FindElement("input");
855 result = ((FGInput*)Models[eInput])->Load(element);
857 cerr << endl << "Aircraft input element has problems in file " << aircraftCfgFileName << endl;
862 // Process the output element[s]. This element is OPTIONAL, and there may be more than one.
863 element = document->FindElement("output");
865 string output_file_name = aircraftCfgFileName;
867 if (!element->GetAttributeValue("file").empty()) {
868 output_file_name = RootDir + element->GetAttributeValue("file");
869 result = ((FGOutput*)Models[eOutput])->SetDirectivesFile(output_file_name);
872 result = ((FGOutput*)Models[eOutput])->Load(element);
875 cerr << endl << "Aircraft output element has problems in file " << output_file_name << endl;
878 element = document->FindNextElement("output");
881 // Lastly, process the child element. This element is OPTIONAL - and NOT YET SUPPORTED.
882 element = document->FindElement("child");
884 result = ReadChild(element);
886 cerr << endl << "Aircraft child element has problems in file " << aircraftCfgFileName << endl;
891 // Since all vehicle characteristics have been loaded, place the values in the Inputs
892 // structure for the FGModel-derived classes.
893 LoadModelConstants();
898 LoadInputs(eMassBalance); // Update all input mass properties for the report.
899 Models[eMassBalance]->Run(false); // Update all mass properties for the report.
900 LoadInputs(ePropulsion); // Update propulsion properties for the report.
901 Models[ePropulsion]->Run(false); // Update propulsion properties for the report.
902 LoadInputs(eMassBalance); // Update all (one more time) input mass properties for the report.
903 Models[eMassBalance]->Run(false); // Update all (one more time) mass properties for the report.
904 ((FGMassBalance*)Models[eMassBalance])->GetMassPropertiesReport();
906 cout << endl << fgblue << highint
907 << "End of vehicle configuration loading." << endl
908 << "-------------------------------------------------------------------------------"
912 if (IsChild) debug_lvl = saved_debug_lvl;
916 << " JSBSim failed to open the configuration file: " << aircraftCfgFileName
920 for (unsigned int i=0; i< Models.size(); i++) LoadInputs(i);
923 struct PropertyCatalogStructure masterPCS;
924 masterPCS.base_string = "";
925 masterPCS.node = (FGPropertyManager*)Root;
926 BuildPropertyCatalog(&masterPCS);
932 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
934 string FGFDMExec::GetPropulsionTankReport()
936 return ((FGPropulsion*)Models[ePropulsion])->GetPropulsionTankReport();
939 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
941 void FGFDMExec::BuildPropertyCatalog(struct PropertyCatalogStructure* pcs)
943 struct PropertyCatalogStructure* pcsNew = new struct PropertyCatalogStructure;
946 for (int i=0; i<pcs->node->nChildren(); i++) {
947 pcsNew->base_string = pcs->base_string + "/" + pcs->node->getChild(i)->getName();
948 node_idx = pcs->node->getChild(i)->getIndex();
950 pcsNew->base_string = CreateIndexedPropertyName(pcsNew->base_string, node_idx);
952 if (pcs->node->getChild(i)->nChildren() == 0) {
953 if (pcsNew->base_string.substr(0,12) == string("/fdm/jsbsim/")) {
954 pcsNew->base_string = pcsNew->base_string.erase(0,12);
956 PropertyCatalog.push_back(pcsNew->base_string);
958 pcsNew->node = (FGPropertyManager*)pcs->node->getChild(i);
959 BuildPropertyCatalog(pcsNew);
965 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
967 string FGFDMExec::QueryPropertyCatalog(const string& in)
970 for (unsigned i=0; i<PropertyCatalog.size(); i++) {
971 if (PropertyCatalog[i].find(in) != string::npos) results += PropertyCatalog[i] + "\n";
973 if (results.empty()) return "No matches found\n";
977 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
979 void FGFDMExec::PrintPropertyCatalog(void)
982 cout << " " << fgblue << highint << underon << "Property Catalog for "
983 << modelName << reset << endl << endl;
984 for (unsigned i=0; i<PropertyCatalog.size(); i++) {
985 cout << " " << PropertyCatalog[i] << endl;
989 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
991 bool FGFDMExec::ReadFileHeader(Element* el)
993 bool result = true; // true for success
995 if (debug_lvl == 0) return result;
998 cout << endl <<highint << fgblue << "Reading child model: " << IdFDM << reset << endl << endl;
1001 if (el->FindElement("description"))
1002 cout << " Description: " << el->FindElement("description")->GetDataLine() << endl;
1003 if (el->FindElement("author"))
1004 cout << " Model Author: " << el->FindElement("author")->GetDataLine() << endl;
1005 if (el->FindElement("filecreationdate"))
1006 cout << " Creation Date: " << el->FindElement("filecreationdate")->GetDataLine() << endl;
1007 if (el->FindElement("version"))
1008 cout << " Version: " << el->FindElement("version")->GetDataLine() << endl;
1013 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1015 bool FGFDMExec::ReadPrologue(Element* el) // el for ReadPrologue is the document element
1017 bool result = true; // true for success
1019 if (!el) return false;
1021 string AircraftName = el->GetAttributeValue("name");
1022 ((FGAircraft*)Models[eAircraft])->SetAircraftName(AircraftName);
1024 if (debug_lvl & 1) cout << underon << "Reading Aircraft Configuration File"
1025 << underoff << ": " << highint << AircraftName << normint << endl;
1027 CFGVersion = el->GetAttributeValue("version");
1028 Release = el->GetAttributeValue("release");
1031 cout << " Version: " << highint << CFGVersion
1033 if (CFGVersion != needed_cfg_version) {
1034 cerr << endl << fgred << "YOU HAVE AN INCOMPATIBLE CFG FILE FOR THIS AIRCRAFT."
1035 " RESULTS WILL BE UNPREDICTABLE !!" << endl;
1036 cerr << "Current version needed is: " << needed_cfg_version << endl;
1037 cerr << " You have version: " << CFGVersion << endl << fgdef << endl;
1041 if (Release == "ALPHA" && (debug_lvl & 1)) {
1042 cout << endl << endl
1043 << highint << "This aircraft model is an " << fgred << Release
1044 << reset << highint << " release!!!" << endl << endl << reset
1045 << "This aircraft model may not even properly load, and probably"
1046 << " will not fly as expected." << endl << endl
1047 << fgred << highint << "Use this model for development purposes ONLY!!!"
1048 << normint << reset << endl << endl;
1049 } else if (Release == "BETA" && (debug_lvl & 1)) {
1050 cout << endl << endl
1051 << highint << "This aircraft model is a " << fgred << Release
1052 << reset << highint << " release!!!" << endl << endl << reset
1053 << "This aircraft model probably will not fly as expected." << endl << endl
1054 << fgblue << highint << "Use this model for development purposes ONLY!!!"
1055 << normint << reset << endl << endl;
1056 } else if (Release == "PRODUCTION" && (debug_lvl & 1)) {
1057 cout << endl << endl
1058 << highint << "This aircraft model is a " << fgblue << Release
1059 << reset << highint << " release." << endl << endl << reset;
1060 } else if (debug_lvl & 1) {
1061 cout << endl << endl
1062 << highint << "This aircraft model is an " << fgred << Release
1063 << reset << highint << " release!!!" << endl << endl << reset
1064 << "This aircraft model may not even properly load, and probably"
1065 << " will not fly as expected." << endl << endl
1066 << fgred << highint << "Use this model for development purposes ONLY!!!"
1067 << normint << reset << endl << endl;
1073 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1075 bool FGFDMExec::ReadChild(Element* el)
1077 // Add a new childData object to the child FDM list
1078 // Populate that childData element with a new FDMExec object
1079 // Set the IsChild flag for that FDMExec object
1080 // Get the aircraft name
1081 // set debug level to print out no additional data for child objects
1082 // Load the model given the aircraft name
1083 // reset debug level to prior setting
1087 struct childData* child = new childData;
1089 child->exec = new FGFDMExec(Root, FDMctr);
1090 child->exec->SetChild(true);
1092 string childAircraft = el->GetAttributeValue("name");
1093 string sMated = el->GetAttributeValue("mated");
1094 if (sMated == "false") child->mated = false; // child objects are mated by default.
1095 string sInternal = el->GetAttributeValue("internal");
1096 if (sInternal == "true") child->internal = true; // child objects are external by default.
1098 child->exec->SetAircraftPath( AircraftPath );
1099 child->exec->SetEnginePath( EnginePath );
1100 child->exec->SetSystemsPath( SystemsPath );
1101 child->exec->LoadModel(childAircraft);
1103 Element* location = el->FindElement("location");
1105 child->Loc = location->FindElementTripletConvertTo("IN");
1107 cerr << endl << highint << fgred << " No location was found for this child object!" << reset << endl;
1111 Element* orientation = el->FindElement("orient");
1113 child->Orient = orientation->FindElementTripletConvertTo("RAD");
1114 } else if (debug_lvl > 0) {
1115 cerr << endl << highint << " No orientation was found for this child object! Assuming 0,0,0." << reset << endl;
1118 ChildFDMList.push_back(child);
1123 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1125 FGPropertyManager* FGFDMExec::GetPropertyManager(void)
1130 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1132 FGTrim* FGFDMExec::GetTrim(void)
1135 Trim = new FGTrim(this,tNone);
1139 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1141 void FGFDMExec::CheckIncrementalHold(void)
1143 // Only check if increment then hold is on
1144 if( IncrementThenHolding ) {
1146 if (TimeStepsUntilHold == 0) {
1148 // Should hold simulation if TimeStepsUntilHold has reached zero
1151 // Still need to decrement TimeStepsUntilHold as value of -1
1152 // indicates that incremental then hold is turned off
1153 IncrementThenHolding = false;
1154 TimeStepsUntilHold--;
1156 } else if ( TimeStepsUntilHold > 0 ) {
1157 // Keep decrementing until 0 is reached
1158 TimeStepsUntilHold--;
1163 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1165 void FGFDMExec::DoTrim(int mode)
1169 if (Constructing) return;
1171 if (mode < 0 || mode > JSBSim::tNone) {
1172 cerr << endl << "Illegal trimming mode!" << endl << endl;
1175 saved_time = sim_time;
1176 FGTrim trim(this, (JSBSim::TrimMode)mode);
1177 if ( !trim.DoTrim() ) cerr << endl << "Trim Failed" << endl << endl;
1179 sim_time = saved_time;
1182 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1184 void FGFDMExec::DoSimplexTrim(int mode)
1187 if (Constructing) return;
1188 if (mode < 0 || mode > JSBSim::tNone) {
1189 cerr << endl << "Illegal trimming mode!" << endl << endl;
1192 saved_time = sim_time;
1193 FGSimplexTrim trim(this, (JSBSim::TrimMode)mode);
1194 sim_time = saved_time;
1195 Setsim_time(saved_time);
1199 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1201 void FGFDMExec::SRand(int sr)
1206 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1207 // The bitmasked value choices are as follows:
1208 // unset: In this case (the default) JSBSim would only print
1209 // out the normally expected messages, essentially echoing
1210 // the config files as they are read. If the environment
1211 // variable is not set, debug_lvl is set to 1 internally
1212 // 0: This requests JSBSim not to output any messages
1214 // 1: This value explicity requests the normal JSBSim
1216 // 2: This value asks for a message to be printed out when
1217 // a class is instantiated
1218 // 4: When this value is set, a message is displayed when a
1219 // FGModel object executes its Run() method
1220 // 8: When this value is set, various runtime state variables
1221 // are printed out periodically
1222 // 16: When set various parameters are sanity checked and
1223 // a message is printed out when they go out of bounds
1225 void FGFDMExec::Debug(int from)
1227 if (debug_lvl <= 0) return;
1229 if (debug_lvl & 1 && IdFDM == 0) { // Standard console startup message output
1230 if (from == 0) { // Constructor
1232 << "JSBSim Flight Dynamics Model v" << JSBSim_version << endl;
1233 cout << " [JSBSim-ML v" << needed_cfg_version << "]\n\n";
1234 cout << "JSBSim startup beginning ...\n\n";
1235 } else if (from == 3) {
1236 cout << "\n\nJSBSim startup complete\n\n";
1239 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
1240 if (from == 0) cout << "Instantiated: FGFDMExec" << endl;
1241 if (from == 1) cout << "Destroyed: FGFDMExec" << endl;
1243 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
1245 cout << "================== Frame: " << Frame << " Time: "
1246 << sim_time << " dt: " << dT << endl;
1249 if (debug_lvl & 8 ) { // Runtime state variables
1251 if (debug_lvl & 16) { // Sanity checking
1253 if (debug_lvl & 64) {
1254 if (from == 0) { // Constructor
1255 cout << IdSrc << endl;
1256 cout << IdHdr << endl;