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 "initialization/FGLinearization.h"
69 #include "input_output/FGPropertyManager.h"
70 #include "input_output/FGScript.h"
76 static const char *IdSrc = "$Id: FGFDMExec.cpp,v 1.148 2013/06/10 01:46:27 jberndt Exp $";
77 static const char *IdHdr = ID_FDMEXEC;
79 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
83 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86 FGFDMExec::FGFDMExec(FGPropertyManager* root, unsigned int* fdmctr) : Root(root), FDMctr(fdmctr)
90 SetGroundCallback(new FGDefaultGroundCallback());
103 IncrementThenHolding = false; // increment then hold is off by default
104 TimeStepsUntilHold = -1;
107 dT = 1.0/120.0; // a default timestep size. This is needed for when JSBSim is
108 // run in standalone mode with no initialization file.
110 AircraftPath = "aircraft";
111 EnginePath = "engine";
112 SystemsPath = "systems";
115 char* num = getenv("JSBSIM_DEBUG");
116 if (num) debug_lvl = atoi(num); // set debug level
117 } catch (...) { // if error set to 1
121 if (Root == 0) { // Then this is the root FDM
122 Root = new FGPropertyManager; // Create the property manager
127 FDMctr = new unsigned int; // Create and initialize the child FDM counter
131 // Store this FDM's ID
132 IdFDM = (*FDMctr); // The main (parent) JSBSim instance is always the "zeroth"
134 // Prepare FDMctr for the next child FDM id
135 (*FDMctr)++; // instance. "child" instances are loaded last.
137 FGPropertyNode* instanceRoot = Root->GetNode("/fdm/jsbsim",IdFDM,true);
138 instance = new FGPropertyManager(instanceRoot);
140 // this is to catch errors in binding member functions to the property tree.
143 } catch ( string msg ) {
144 cout << "Caught error: " << msg << endl;
152 typedef int (FGFDMExec::*iPMF)(void) const;
153 typedef double (FGFDMExec::*dPMF)(void) const;
154 // typedef unsigned int (FGFDMExec::*uiPMF)(void) const;
155 // instance->Tie("simulation/do_trim_analysis", this, (iPMF)0, &FGFDMExec::DoTrimAnalysis, false);
156 instance->Tie("simulation/do_simple_trim", this, (iPMF)0, &FGFDMExec::DoTrim, false);
157 instance->Tie("simulation/do_simplex_trim", this, (iPMF)0, &FGFDMExec::DoSimplexTrim);
158 instance->Tie("simulation/do_linearization", this, (iPMF)0, &FGFDMExec::DoLinearization);
159 instance->Tie("simulation/reset", this, (iPMF)0, &FGFDMExec::ResetToInitialConditions, false);
160 instance->Tie("simulation/randomseed", this, (iPMF)0, &FGFDMExec::SRand, false);
161 instance->Tie("simulation/terminate", (int *)&Terminate);
162 instance->Tie("simulation/sim-time-sec", this, &FGFDMExec::GetSimTime);
163 instance->Tie("simulation/jsbsim-debug", this, &FGFDMExec::GetDebugLevel, &FGFDMExec::SetDebugLevel);
164 instance->Tie("simulation/frame", (int *)&Frame, false);
166 // simplex trim properties
167 instanceRoot->SetDouble("trim/solver/rtol",0.0001);
168 instanceRoot->SetDouble("trim/solver/speed",2);
169 instanceRoot->SetDouble("trim/solver/abstol",0.001);
170 instanceRoot->SetDouble("trim/solver/iterMax",2000);
171 instanceRoot->SetInt("trim/solver/debugLevel",0);
172 instanceRoot->SetDouble("trim/solver/random",0);
173 instanceRoot->SetBool("trim/solver/showSimplex",false);
174 instanceRoot->SetBool("trim/solver/showConvergence",false);
175 instanceRoot->SetBool("trim/solver/pause",false);
176 instanceRoot->SetBool("trim/solver/variablePropPitch",false);
178 instanceRoot->SetDouble("trim/solver/throttleGuess",0.50);
179 instanceRoot->SetDouble("trim/solver/throttleMin",0.0);
180 instanceRoot->SetDouble("trim/solver/throttleMax",1.0);
181 instanceRoot->SetDouble("trim/solver/throttleStep",0.1);
183 instanceRoot->SetDouble("trim/solver/aileronGuess",0);
184 instanceRoot->SetDouble("trim/solver/aileronMin",-1.00);
185 instanceRoot->SetDouble("trim/solver/aileronMax",1.00);
186 instanceRoot->SetDouble("trim/solver/aileronStep",0.1);
188 instanceRoot->SetDouble("trim/solver/rudderGuess",0);
189 instanceRoot->SetDouble("trim/solver/rudderMin",-1.00);
190 instanceRoot->SetDouble("trim/solver/rudderMax",1.00);
191 instanceRoot->SetDouble("trim/solver/rudderStep",0.1);
193 instanceRoot->SetDouble("trim/solver/elevatorGuess",-0.1);
194 instanceRoot->SetDouble("trim/solver/elevatorMin",-1.0);
195 instanceRoot->SetDouble("trim/solver/elevatorMax",1.0);
196 instanceRoot->SetDouble("trim/solver/elevatorStep",0.1);
198 instanceRoot->SetDouble("trim/solver/alphaGuess",0.05);
199 instanceRoot->SetDouble("trim/solver/alphaMin",-0.1);
200 instanceRoot->SetDouble("trim/solver/alphaMax",.18);
201 instanceRoot->SetDouble("trim/solver/alphaStep",0.05);
203 instanceRoot->SetDouble("trim/solver/betaGuess",0);
204 instanceRoot->SetDouble("trim/solver/betaMin",-0.1);
205 instanceRoot->SetDouble("trim/solver/betaMax",0.1);
206 instanceRoot->SetDouble("trim/solver/betaStep",0.0001);
208 Constructing = false;
211 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
213 FGFDMExec::~FGFDMExec()
221 if (IdFDM == 0) { // Meaning this is no child FDM
232 } catch ( string msg ) {
233 cout << "Caught error: " << msg << endl;
236 for (unsigned int i=1; i<ChildFDMList.size(); i++) delete ChildFDMList[i]->exec;
237 ChildFDMList.clear();
239 PropertyCatalog.clear();
241 if (FDMctr > 0) (*FDMctr)--;
246 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
248 bool FGFDMExec::Allocate(void)
252 Models.resize(eNumStandardModels);
254 // See the eModels enum specification in the header file. The order of the enums
255 // specifies the order of execution. The Models[] vector is the primary
256 // storage array for the list of models.
257 Models[ePropagate] = new FGPropagate(this);
258 Models[eInput] = new FGInput(this);
259 Models[eInertial] = new FGInertial(this);
260 Models[eAtmosphere] = new FGStandardAtmosphere(this);
261 Models[eWinds] = new FGWinds(this);
262 Models[eAuxiliary] = new FGAuxiliary(this);
263 Models[eSystems] = new FGFCS(this);
264 Models[ePropulsion] = new FGPropulsion(this);
265 Models[eAerodynamics] = new FGAerodynamics (this);
266 Models[eGroundReactions] = new FGGroundReactions(this);
267 Models[eExternalReactions] = new FGExternalReactions(this);
268 Models[eBuoyantForces] = new FGBuoyantForces(this);
269 Models[eMassBalance] = new FGMassBalance(this);
270 Models[eAircraft] = new FGAircraft(this);
271 Models[eAccelerations] = new FGAccelerations(this);
272 Models[eOutput] = new FGOutput(this);
274 // Assign the Model shortcuts for internal executive use only.
275 Propagate = (FGPropagate*)Models[ePropagate];
276 Inertial = (FGInertial*)Models[eInertial];
277 Atmosphere = (FGAtmosphere*)Models[eAtmosphere];
278 Winds = (FGWinds*)Models[eWinds];
279 Auxiliary = (FGAuxiliary*)Models[eAuxiliary];
280 FCS = (FGFCS*)Models[eSystems];
281 Propulsion = (FGPropulsion*)Models[ePropulsion];
282 Aerodynamics = (FGAerodynamics*)Models[eAerodynamics];
283 GroundReactions = (FGGroundReactions*)Models[eGroundReactions];
284 ExternalReactions = (FGExternalReactions*)Models[eExternalReactions];
285 BuoyantForces = (FGBuoyantForces*)Models[eBuoyantForces];
286 MassBalance = (FGMassBalance*)Models[eMassBalance];
287 Aircraft = (FGAircraft*)Models[eAircraft];
288 Accelerations = (FGAccelerations*)Models[eAccelerations];
289 Output = (FGOutput*)Models[eOutput];
291 // Initialize planet (environment) constants
292 LoadPlanetConstants();
293 GetGroundCallback()->SetSeaLevelRadius(Inertial->GetRefRadius());
296 for (unsigned int i = 0; i < Models.size(); i++) {
297 // The Output model must not be initialized prior to IC loading
298 if (i == eOutput) continue;
301 Models[i]->InitModel();
304 IC = new FGInitialCondition(this);
311 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
313 bool FGFDMExec::DeAllocate(void)
316 for (unsigned int i=0; i<eNumStandardModels; i++) delete Models[i];
329 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
331 void FGFDMExec::Schedule(FGModel* model, int rate)
333 model->SetRate(rate);
334 Models.push_back(model);
337 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
339 bool FGFDMExec::Run(void)
345 for (unsigned int i=1; i<ChildFDMList.size(); i++) {
346 ChildFDMList[i]->AssignState( (FGPropagate*)Models[ePropagate] ); // Transfer state to the child FDM
347 ChildFDMList[i]->Run();
352 // returns true if success, false if complete
353 if (Script != 0 && !IntegrationSuspended()) success = Script->RunScript();
355 for (unsigned int i = 0; i < Models.size(); i++) {
357 Models[i]->Run(holding);
360 if (Terminate) success = false;
365 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
367 void FGFDMExec::LoadInputs(unsigned int idx)
371 Propagate->in.vPQRidot = Accelerations->GetPQRidot();
372 Propagate->in.vQtrndot = Accelerations->GetQuaterniondot();
373 Propagate->in.vUVWidot = Accelerations->GetUVWidot();
374 Propagate->in.DeltaT = dT;
379 Inertial->in.Radius = Propagate->GetRadius();
380 Inertial->in.Latitude = Propagate->GetLatitude();
383 Atmosphere->in.altitudeASL = Propagate->GetAltitudeASL();
386 Winds->in.AltitudeASL = Propagate->GetAltitudeASL();
387 Winds->in.DistanceAGL = Propagate->GetDistanceAGL();
388 Winds->in.Tl2b = Propagate->GetTl2b();
389 Winds->in.Tw2b = Auxiliary->GetTw2b();
390 Winds->in.V = Auxiliary->GetVt();
391 Winds->in.totalDeltaT = dT * Winds->GetRate();
394 Auxiliary->in.Pressure = Atmosphere->GetPressure();
395 Auxiliary->in.Density = Atmosphere->GetDensity();
396 Auxiliary->in.DensitySL = Atmosphere->GetDensitySL();
397 Auxiliary->in.PressureSL = Atmosphere->GetPressureSL();
398 Auxiliary->in.Temperature = Atmosphere->GetTemperature();
399 Auxiliary->in.SoundSpeed = Atmosphere->GetSoundSpeed();
400 Auxiliary->in.KinematicViscosity = Atmosphere->GetKinematicViscosity();
401 Auxiliary->in.DistanceAGL = Propagate->GetDistanceAGL();
402 Auxiliary->in.Mass = MassBalance->GetMass();
403 Auxiliary->in.Tl2b = Propagate->GetTl2b();
404 Auxiliary->in.Tb2l = Propagate->GetTb2l();
405 Auxiliary->in.vPQR = Propagate->GetPQR();
406 Auxiliary->in.vPQRdot = Accelerations->GetPQRdot();
407 Auxiliary->in.vUVW = Propagate->GetUVW();
408 Auxiliary->in.vUVWdot = Accelerations->GetUVWdot();
409 Auxiliary->in.vVel = Propagate->GetVel();
410 Auxiliary->in.vBodyAccel = Accelerations->GetBodyAccel();
411 Auxiliary->in.ToEyePt = MassBalance->StructuralToBody(Aircraft->GetXYZep());
412 Auxiliary->in.VRPBody = MassBalance->StructuralToBody(Aircraft->GetXYZvrp());
413 Auxiliary->in.RPBody = MassBalance->StructuralToBody(Aircraft->GetXYZrp());
414 Auxiliary->in.vFw = Aerodynamics->GetvFw();
415 Auxiliary->in.vLocation = Propagate->GetLocation();
416 Auxiliary->in.CosTht = Propagate->GetCosEuler(eTht);
417 Auxiliary->in.SinTht = Propagate->GetSinEuler(eTht);
418 Auxiliary->in.CosPhi = Propagate->GetCosEuler(ePhi);
419 Auxiliary->in.SinPhi = Propagate->GetSinEuler(ePhi);
420 Auxiliary->in.Psi = Propagate->GetEuler(ePsi);
421 Auxiliary->in.TotalWindNED = Winds->GetTotalWindNED();
422 Auxiliary->in.TurbPQR = Winds->GetTurbPQR();
423 Auxiliary->in.WindPsi = Winds->GetWindPsi();
424 Auxiliary->in.Vwind = Winds->GetTotalWindNED().Magnitude();
427 // Dynamic inputs come into the components that FCS manages through properties
430 Propulsion->in.SLPressure = Atmosphere->GetPressureSL();
431 Propulsion->in.Pressure = Atmosphere->GetPressure();
432 Propulsion->in.PressureRatio = Atmosphere->GetPressureRatio();
433 Propulsion->in.Temperature = Atmosphere->GetTemperature();
434 Propulsion->in.DensityRatio = Atmosphere->GetDensityRatio();
435 Propulsion->in.Density = Atmosphere->GetDensity();
436 Propulsion->in.Soundspeed = Atmosphere->GetSoundSpeed();
437 Propulsion->in.TotalPressure = Auxiliary->GetTotalPressure();
438 Propulsion->in.TotalTempearture = Auxiliary->GetTotalTemperature();
439 Propulsion->in.Vc = Auxiliary->GetVcalibratedKTS();
440 Propulsion->in.Vt = Auxiliary->GetVt();
441 Propulsion->in.qbar = Auxiliary->Getqbar();
442 Propulsion->in.TAT_c = Auxiliary->GetTAT_C();
443 Propulsion->in.AeroUVW = Auxiliary->GetAeroUVW();
444 Propulsion->in.AeroPQR = Auxiliary->GetAeroPQR();
445 Propulsion->in.alpha = Auxiliary->Getalpha();
446 Propulsion->in.beta = Auxiliary->Getbeta();
447 Propulsion->in.TotalDeltaT = dT * Propulsion->GetRate();
448 Propulsion->in.ThrottlePos = FCS->GetThrottlePos();
449 Propulsion->in.MixturePos = FCS->GetMixturePos();
450 Propulsion->in.ThrottleCmd = FCS->GetThrottleCmd();
451 Propulsion->in.MixtureCmd = FCS->GetMixtureCmd();
452 Propulsion->in.PropAdvance = FCS->GetPropAdvance();
453 Propulsion->in.PropFeather = FCS->GetPropFeather();
454 Propulsion->in.H_agl = Propagate->GetDistanceAGL();
455 Propulsion->in.PQR = Propagate->GetPQR();
459 Aerodynamics->in.Alpha = Auxiliary->Getalpha();
460 Aerodynamics->in.Beta = Auxiliary->Getbeta();
461 Aerodynamics->in.Qbar = Auxiliary->Getqbar();
462 Aerodynamics->in.Vt = Auxiliary->GetVt();
463 Aerodynamics->in.Tb2w = Auxiliary->GetTb2w();
464 Aerodynamics->in.Tw2b = Auxiliary->GetTw2b();
465 Aerodynamics->in.RPBody = MassBalance->StructuralToBody(Aircraft->GetXYZrp());
467 case eGroundReactions:
468 // There are no external inputs to this model.
469 GroundReactions->in.Vground = Auxiliary->GetVground();
470 GroundReactions->in.VcalibratedKts = Auxiliary->GetVcalibratedKTS();
471 GroundReactions->in.Temperature = Atmosphere->GetTemperature();
472 GroundReactions->in.TakeoffThrottle = (FCS->GetThrottlePos().size() > 0) ? (FCS->GetThrottlePos(0) > 0.90) : false;
473 GroundReactions->in.SteerPosDeg = FCS->GetSteerPosDeg();
474 GroundReactions->in.BrakePos = FCS->GetBrakePos();
475 GroundReactions->in.FCSGearPos = FCS->GetGearPos();
476 GroundReactions->in.EmptyWeight = MassBalance->GetEmptyWeight();
477 GroundReactions->in.Tb2l = Propagate->GetTb2l();
478 GroundReactions->in.Tec2l = Propagate->GetTec2l();
479 GroundReactions->in.Tec2b = Propagate->GetTec2b();
480 GroundReactions->in.PQR = Propagate->GetPQR();
481 GroundReactions->in.UVW = Propagate->GetUVW();
482 GroundReactions->in.DistanceAGL = Propagate->GetDistanceAGL();
483 GroundReactions->in.DistanceASL = Propagate->GetAltitudeASL();
484 GroundReactions->in.TotalDeltaT = dT * GroundReactions->GetRate();
485 GroundReactions->in.WOW = GroundReactions->GetWOW();
486 GroundReactions->in.Location = Propagate->GetLocation();
487 GroundReactions->in.vXYZcg = MassBalance->GetXYZcg();
489 case eExternalReactions:
490 // There are no external inputs to this model.
493 BuoyantForces->in.Density = Atmosphere->GetDensity();
494 BuoyantForces->in.Pressure = Atmosphere->GetPressure();
495 BuoyantForces->in.Temperature = Atmosphere->GetTemperature();
496 BuoyantForces->in.gravity = Inertial->gravity();
499 MassBalance->in.GasInertia = BuoyantForces->GetGasMassInertia();
500 MassBalance->in.GasMass = BuoyantForces->GetGasMass();
501 MassBalance->in.GasMoment = BuoyantForces->GetGasMassMoment();
502 MassBalance->in.TanksWeight = Propulsion->GetTanksWeight();
503 MassBalance->in.TanksMoment = Propulsion->GetTanksMoment();
504 MassBalance->in.TankInertia = Propulsion->CalculateTankInertias();
507 Aircraft->in.AeroForce = Aerodynamics->GetForces();
508 Aircraft->in.PropForce = Propulsion->GetForces();
509 Aircraft->in.GroundForce = GroundReactions->GetForces();
510 Aircraft->in.ExternalForce = ExternalReactions->GetForces();
511 Aircraft->in.BuoyantForce = BuoyantForces->GetForces();
512 Aircraft->in.AeroMoment = Aerodynamics->GetMoments();
513 Aircraft->in.PropMoment = Propulsion->GetMoments();
514 Aircraft->in.GroundMoment = GroundReactions->GetMoments();
515 Aircraft->in.ExternalMoment = ExternalReactions->GetMoments();
516 Aircraft->in.BuoyantMoment = BuoyantForces->GetMoments();
519 Accelerations->in.J = MassBalance->GetJ();
520 Accelerations->in.Jinv = MassBalance->GetJinv();
521 Accelerations->in.Ti2b = Propagate->GetTi2b();
522 Accelerations->in.Tb2i = Propagate->GetTb2i();
523 Accelerations->in.Tec2b = Propagate->GetTec2b();
524 Accelerations->in.Tec2i = Propagate->GetTec2i();
525 Accelerations->in.qAttitudeECI = Propagate->GetQuaternionECI();
526 Accelerations->in.Moment = Aircraft->GetMoments();
527 Accelerations->in.GroundMoment = GroundReactions->GetMoments();
528 Accelerations->in.Force = Aircraft->GetForces();
529 Accelerations->in.GroundForce = GroundReactions->GetForces();
530 Accelerations->in.GAccel = Inertial->GetGAccel(Propagate->GetRadius());
531 Accelerations->in.J2Grav = Inertial->GetGravityJ2(Propagate->GetLocation());
532 Accelerations->in.vPQRi = Propagate->GetPQRi();
533 Accelerations->in.vPQR = Propagate->GetPQR();
534 Accelerations->in.vUVW = Propagate->GetUVW();
535 Accelerations->in.vInertialPosition = Propagate->GetInertialPosition();
536 Accelerations->in.DeltaT = dT;
537 Accelerations->in.Mass = MassBalance->GetMass();
538 Accelerations->in.MultipliersList = GroundReactions->GetMultipliersList();
539 Accelerations->in.TerrainVelocity = Propagate->GetTerrainVelocity();
540 Accelerations->in.TerrainAngularVel = Propagate->GetTerrainAngularVelocity();
547 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
549 void FGFDMExec::LoadPlanetConstants(void)
551 Propagate->in.vOmegaPlanet = Inertial->GetOmegaPlanet();
552 Accelerations->in.vOmegaPlanet = Inertial->GetOmegaPlanet();
553 Propagate->in.SemiMajor = Inertial->GetSemimajor();
554 Propagate->in.SemiMinor = Inertial->GetSemiminor();
555 Auxiliary->in.SLGravity = Inertial->SLgravity();
556 Auxiliary->in.ReferenceRadius = Inertial->GetRefRadius();
559 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
561 void FGFDMExec::LoadModelConstants(void)
563 Winds->in.wingspan = Aircraft->GetWingSpan();
564 FCS->in.NumGear = GroundReactions->GetNumGearUnits();
565 Aerodynamics->in.Wingarea = Aircraft->GetWingArea();
566 Aerodynamics->in.Wingchord = Aircraft->Getcbar();
567 Aerodynamics->in.Wingincidence = Aircraft->GetWingIncidence();
568 Aerodynamics->in.Wingspan = Aircraft->GetWingSpan();
569 Auxiliary->in.Wingspan = Aircraft->GetWingSpan();
570 Auxiliary->in.Wingchord = Aircraft->Getcbar();
571 GroundReactions->in.vXYZcg = MassBalance->GetXYZcg();
573 LoadPlanetConstants();
576 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
577 // This call will cause the sim time to reset to 0.0
579 bool FGFDMExec::RunIC(void)
581 FGPropulsion* propulsion = (FGPropulsion*)Models[ePropulsion];
583 Models[eOutput]->InitModel();
585 SuspendIntegration(); // saves the integration rate, dt, then sets it to 0.0.
588 ResumeIntegration(); // Restores the integration rate to what it was.
590 for (unsigned int i=0; i<IC->GetNumEnginesRunning(); i++)
591 propulsion->InitRunning(IC->GetEngineRunning(i));
596 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
598 void FGFDMExec::Initialize(FGInitialCondition *FGIC)
602 Propagate->SetInitialState( FGIC );
603 LoadInputs(eAccelerations);
604 Accelerations->Run(false);
605 LoadInputs(ePropagate);
606 Propagate->InitializeDerivatives();
607 LoadInputs(eAtmosphere);
608 Atmosphere->Run(false);
609 Winds->SetWindNED(FGIC->GetWindNEDFpsIC());
610 Auxiliary->Run(false);
613 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
615 // A private, internal function call for Tie-ing to a property, so it needs an
618 void FGFDMExec::ResetToInitialConditions(int mode)
620 if (mode == 1) Output->SetStartNewOutput();
622 ResetToInitialConditions();
625 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
627 void FGFDMExec::ResetToInitialConditions(void)
629 if (Constructing) return;
631 for (unsigned int i = 0; i < Models.size(); i++) {
632 // The Output model will be initialized during the RunIC() execution
633 if (i == eOutput) continue;
636 Models[i]->InitModel();
641 if (Script) Script->ResetEvents();
644 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
646 vector <string> FGFDMExec::EnumerateFDMs(void)
648 vector <string> FDMList;
649 FGAircraft* Aircraft = (FGAircraft*)Models[eAircraft];
651 FDMList.push_back(Aircraft->GetAircraftName());
653 for (unsigned int i=1; i<ChildFDMList.size(); i++) {
654 FDMList.push_back(ChildFDMList[i]->exec->GetAircraft()->GetAircraftName());
660 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
662 bool FGFDMExec::LoadScript(const string& script, double deltaT, const string initfile)
666 Script = new FGScript(this);
667 result = Script->LoadScript(RootDir + script, deltaT, initfile);
672 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
674 bool FGFDMExec::LoadModel(const string& AircraftPath, const string& EnginePath, const string& SystemsPath,
675 const string& model, bool addModelToPath)
677 FGFDMExec::AircraftPath = RootDir + AircraftPath;
678 FGFDMExec::EnginePath = RootDir + EnginePath;
679 FGFDMExec::SystemsPath = RootDir + SystemsPath;
681 return LoadModel(model, addModelToPath);
684 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
686 bool FGFDMExec::LoadModel(const string& model, bool addModelToPath)
689 string aircraftCfgFileName;
690 Element* element = 0L;
691 bool result = false; // initialize result to false, indicating input file not yet read
693 modelName = model; // Set the class modelName attribute
695 if( AircraftPath.empty() || EnginePath.empty() || SystemsPath.empty()) {
696 cerr << "Error: attempted to load aircraft with undefined ";
697 cerr << "aircraft, engine, and system paths" << endl;
701 FullAircraftPath = AircraftPath;
702 if (addModelToPath) FullAircraftPath += "/" + model;
703 aircraftCfgFileName = FullAircraftPath + "/" + model + ".xml";
710 int saved_debug_lvl = debug_lvl;
712 document = LoadXMLDocument(aircraftCfgFileName); // "document" is a class member
714 if (IsChild) debug_lvl = 0;
716 ReadPrologue(document);
718 if (IsChild) debug_lvl = saved_debug_lvl;
720 // Process the fileheader element in the aircraft config file. This element is OPTIONAL.
721 element = document->FindElement("fileheader");
723 result = ReadFileHeader(element);
725 cerr << endl << "Aircraft fileheader element has problems in file " << aircraftCfgFileName << endl;
730 if (IsChild) debug_lvl = 0;
732 // Process the metrics element. This element is REQUIRED.
733 element = document->FindElement("metrics");
735 result = ((FGAircraft*)Models[eAircraft])->Load(element);
737 cerr << endl << "Aircraft metrics element has problems in file " << aircraftCfgFileName << endl;
741 cerr << endl << "No metrics element was found in the aircraft config file." << endl;
745 // Process the mass_balance element. This element is REQUIRED.
746 element = document->FindElement("mass_balance");
748 result = ((FGMassBalance*)Models[eMassBalance])->Load(element);
750 cerr << endl << "Aircraft mass_balance element has problems in file " << aircraftCfgFileName << endl;
754 cerr << endl << "No mass_balance element was found in the aircraft config file." << endl;
758 // Process the ground_reactions element. This element is REQUIRED.
759 element = document->FindElement("ground_reactions");
761 result = ((FGGroundReactions*)Models[eGroundReactions])->Load(element);
763 cerr << endl << "Aircraft ground_reactions element has problems in file " << aircraftCfgFileName << endl;
766 ((FGFCS*)Models[eSystems])->AddGear(((FGGroundReactions*)Models[eGroundReactions])->GetNumGearUnits());
768 cerr << endl << "No ground_reactions element was found in the aircraft config file." << endl;
772 // Process the external_reactions element. This element is OPTIONAL.
773 element = document->FindElement("external_reactions");
775 result = ((FGExternalReactions*)Models[eExternalReactions])->Load(element);
777 cerr << endl << "Aircraft external_reactions element has problems in file " << aircraftCfgFileName << endl;
782 // Process the buoyant_forces element. This element is OPTIONAL.
783 element = document->FindElement("buoyant_forces");
785 result = ((FGBuoyantForces*)Models[eBuoyantForces])->Load(element);
787 cerr << endl << "Aircraft buoyant_forces element has problems in file " << aircraftCfgFileName << endl;
792 // Process the propulsion element. This element is OPTIONAL.
793 element = document->FindElement("propulsion");
795 result = ((FGPropulsion*)Models[ePropulsion])->Load(element);
797 cerr << endl << "Aircraft propulsion element has problems in file " << aircraftCfgFileName << endl;
800 for (unsigned int i=0; i<((FGPropulsion*)Models[ePropulsion])->GetNumEngines(); i++)
801 ((FGFCS*)Models[eSystems])->AddThrottle();
804 // Process the system element[s]. This element is OPTIONAL, and there may be more than one.
805 element = document->FindElement("system");
807 result = ((FGFCS*)Models[eSystems])->Load(element, FGFCS::stSystem);
809 cerr << endl << "Aircraft system element has problems in file " << aircraftCfgFileName << endl;
812 element = document->FindNextElement("system");
815 // Process the autopilot element. This element is OPTIONAL.
816 element = document->FindElement("autopilot");
818 result = ((FGFCS*)Models[eSystems])->Load(element, FGFCS::stAutoPilot);
820 cerr << endl << "Aircraft autopilot element has problems in file " << aircraftCfgFileName << endl;
825 // Process the flight_control element. This element is OPTIONAL.
826 element = document->FindElement("flight_control");
828 result = ((FGFCS*)Models[eSystems])->Load(element, FGFCS::stFCS);
830 cerr << endl << "Aircraft flight_control element has problems in file " << aircraftCfgFileName << endl;
835 // Process the aerodynamics element. This element is OPTIONAL, but almost always expected.
836 element = document->FindElement("aerodynamics");
838 result = ((FGAerodynamics*)Models[eAerodynamics])->Load(element);
840 cerr << endl << "Aircraft aerodynamics element has problems in file " << aircraftCfgFileName << endl;
844 cerr << endl << "No expected aerodynamics element was found in the aircraft config file." << endl;
847 // Process the input element. This element is OPTIONAL.
848 element = document->FindElement("input");
850 result = ((FGInput*)Models[eInput])->Load(element);
852 cerr << endl << "Aircraft input element has problems in file " << aircraftCfgFileName << endl;
857 // Process the output element[s]. This element is OPTIONAL, and there may be more than one.
858 element = document->FindElement("output");
860 string output_file_name = aircraftCfgFileName;
862 if (!element->GetAttributeValue("file").empty()) {
863 output_file_name = RootDir + element->GetAttributeValue("file");
864 result = ((FGOutput*)Models[eOutput])->SetDirectivesFile(output_file_name);
867 result = ((FGOutput*)Models[eOutput])->Load(element);
870 cerr << endl << "Aircraft output element has problems in file " << output_file_name << endl;
873 element = document->FindNextElement("output");
876 // Lastly, process the child element. This element is OPTIONAL - and NOT YET SUPPORTED.
877 element = document->FindElement("child");
879 result = ReadChild(element);
881 cerr << endl << "Aircraft child element has problems in file " << aircraftCfgFileName << endl;
886 // Since all vehicle characteristics have been loaded, place the values in the Inputs
887 // structure for the FGModel-derived classes.
888 LoadModelConstants();
893 LoadInputs(eMassBalance); // Update all input mass properties for the report.
894 Models[eMassBalance]->Run(false); // Update all mass properties for the report.
895 LoadInputs(ePropulsion); // Update propulsion properties for the report.
896 Models[ePropulsion]->Run(false); // Update propulsion properties for the report.
897 LoadInputs(eMassBalance); // Update all (one more time) input mass properties for the report.
898 Models[eMassBalance]->Run(false); // Update all (one more time) mass properties for the report.
899 ((FGMassBalance*)Models[eMassBalance])->GetMassPropertiesReport();
901 cout << endl << fgblue << highint
902 << "End of vehicle configuration loading." << endl
903 << "-------------------------------------------------------------------------------"
907 if (IsChild) debug_lvl = saved_debug_lvl;
911 << " JSBSim failed to open the configuration file: " << aircraftCfgFileName
915 for (unsigned int i=0; i< Models.size(); i++) LoadInputs(i);
918 struct PropertyCatalogStructure masterPCS;
919 masterPCS.base_string = "";
920 masterPCS.node = Root->GetNode();
921 BuildPropertyCatalog(&masterPCS);
927 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
929 string FGFDMExec::GetPropulsionTankReport()
931 return ((FGPropulsion*)Models[ePropulsion])->GetPropulsionTankReport();
934 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
936 void FGFDMExec::BuildPropertyCatalog(struct PropertyCatalogStructure* pcs)
938 struct PropertyCatalogStructure* pcsNew = new struct PropertyCatalogStructure;
941 for (int i=0; i<pcs->node->nChildren(); i++) {
943 pcsNew->base_string = pcs->base_string + "/" + pcs->node->getChild(i)->getName();
944 node_idx = pcs->node->getChild(i)->getIndex();
946 pcsNew->base_string = CreateIndexedPropertyName(pcsNew->base_string, node_idx);
948 if (pcs->node->getChild(i)->nChildren() == 0) {
949 if (pcsNew->base_string.substr(0,12) == string("/fdm/jsbsim/")) {
950 pcsNew->base_string = pcsNew->base_string.erase(0,12);
952 if (pcs->node->getChild(i)->getAttribute(SGPropertyNode::READ)) access="R";
953 if (pcs->node->getChild(i)->getAttribute(SGPropertyNode::WRITE)) access+="W";
954 PropertyCatalog.push_back(pcsNew->base_string+" ("+access+")");
956 pcsNew->node = (FGPropertyNode*)pcs->node->getChild(i);
957 BuildPropertyCatalog(pcsNew);
963 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
965 string FGFDMExec::QueryPropertyCatalog(const string& in)
968 for (unsigned i=0; i<PropertyCatalog.size(); i++) {
969 if (PropertyCatalog[i].find(in) != string::npos) results += PropertyCatalog[i] + "\n";
971 if (results.empty()) return "No matches found\n";
975 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
977 void FGFDMExec::PrintPropertyCatalog(void)
980 cout << " " << fgblue << highint << underon << "Property Catalog for "
981 << modelName << reset << endl << endl;
982 for (unsigned i=0; i<PropertyCatalog.size(); i++) {
983 cout << " " << PropertyCatalog[i] << endl;
987 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
989 bool FGFDMExec::ReadFileHeader(Element* el)
991 bool result = true; // true for success
993 if (debug_lvl == 0) return result;
996 cout << endl <<highint << fgblue << "Reading child model: " << IdFDM << reset << endl << endl;
999 if (el->FindElement("description"))
1000 cout << " Description: " << el->FindElement("description")->GetDataLine() << endl;
1001 if (el->FindElement("author"))
1002 cout << " Model Author: " << el->FindElement("author")->GetDataLine() << endl;
1003 if (el->FindElement("filecreationdate"))
1004 cout << " Creation Date: " << el->FindElement("filecreationdate")->GetDataLine() << endl;
1005 if (el->FindElement("version"))
1006 cout << " Version: " << el->FindElement("version")->GetDataLine() << endl;
1011 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1013 bool FGFDMExec::ReadPrologue(Element* el) // el for ReadPrologue is the document element
1015 bool result = true; // true for success
1017 if (!el) return false;
1019 string AircraftName = el->GetAttributeValue("name");
1020 ((FGAircraft*)Models[eAircraft])->SetAircraftName(AircraftName);
1022 if (debug_lvl & 1) cout << underon << "Reading Aircraft Configuration File"
1023 << underoff << ": " << highint << AircraftName << normint << endl;
1025 CFGVersion = el->GetAttributeValue("version");
1026 Release = el->GetAttributeValue("release");
1029 cout << " Version: " << highint << CFGVersion
1031 if (CFGVersion != needed_cfg_version) {
1032 cerr << endl << fgred << "YOU HAVE AN INCOMPATIBLE CFG FILE FOR THIS AIRCRAFT."
1033 " RESULTS WILL BE UNPREDICTABLE !!" << endl;
1034 cerr << "Current version needed is: " << needed_cfg_version << endl;
1035 cerr << " You have version: " << CFGVersion << endl << fgdef << endl;
1039 if (Release == "ALPHA" && (debug_lvl & 1)) {
1040 cout << endl << endl
1041 << highint << "This aircraft model is an " << fgred << Release
1042 << reset << highint << " release!!!" << endl << endl << reset
1043 << "This aircraft model may not even properly load, and probably"
1044 << " will not fly as expected." << endl << endl
1045 << fgred << highint << "Use this model for development purposes ONLY!!!"
1046 << normint << reset << endl << endl;
1047 } else if (Release == "BETA" && (debug_lvl & 1)) {
1048 cout << endl << endl
1049 << highint << "This aircraft model is a " << fgred << Release
1050 << reset << highint << " release!!!" << endl << endl << reset
1051 << "This aircraft model probably will not fly as expected." << endl << endl
1052 << fgblue << highint << "Use this model for development purposes ONLY!!!"
1053 << normint << reset << endl << endl;
1054 } else if (Release == "PRODUCTION" && (debug_lvl & 1)) {
1055 cout << endl << endl
1056 << highint << "This aircraft model is a " << fgblue << Release
1057 << reset << highint << " release." << endl << endl << reset;
1058 } else if (debug_lvl & 1) {
1059 cout << endl << endl
1060 << highint << "This aircraft model is an " << fgred << Release
1061 << reset << highint << " release!!!" << endl << endl << reset
1062 << "This aircraft model may not even properly load, and probably"
1063 << " will not fly as expected." << endl << endl
1064 << fgred << highint << "Use this model for development purposes ONLY!!!"
1065 << normint << reset << endl << endl;
1071 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1073 bool FGFDMExec::ReadChild(Element* el)
1075 // Add a new childData object to the child FDM list
1076 // Populate that childData element with a new FDMExec object
1077 // Set the IsChild flag for that FDMExec object
1078 // Get the aircraft name
1079 // set debug level to print out no additional data for child objects
1080 // Load the model given the aircraft name
1081 // reset debug level to prior setting
1085 struct childData* child = new childData;
1087 child->exec = new FGFDMExec(Root, FDMctr);
1088 child->exec->SetChild(true);
1090 string childAircraft = el->GetAttributeValue("name");
1091 string sMated = el->GetAttributeValue("mated");
1092 if (sMated == "false") child->mated = false; // child objects are mated by default.
1093 string sInternal = el->GetAttributeValue("internal");
1094 if (sInternal == "true") child->internal = true; // child objects are external by default.
1096 child->exec->SetAircraftPath( AircraftPath );
1097 child->exec->SetEnginePath( EnginePath );
1098 child->exec->SetSystemsPath( SystemsPath );
1099 child->exec->LoadModel(childAircraft);
1101 Element* location = el->FindElement("location");
1103 child->Loc = location->FindElementTripletConvertTo("IN");
1105 cerr << endl << highint << fgred << " No location was found for this child object!" << reset << endl;
1109 Element* orientation = el->FindElement("orient");
1111 child->Orient = orientation->FindElementTripletConvertTo("RAD");
1112 } else if (debug_lvl > 0) {
1113 cerr << endl << highint << " No orientation was found for this child object! Assuming 0,0,0." << reset << endl;
1116 ChildFDMList.push_back(child);
1121 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1123 FGPropertyManager* FGFDMExec::GetPropertyManager(void)
1128 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1130 FGTrim* FGFDMExec::GetTrim(void)
1133 Trim = new FGTrim(this,tNone);
1137 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1139 void FGFDMExec::CheckIncrementalHold(void)
1141 // Only check if increment then hold is on
1142 if( IncrementThenHolding ) {
1144 if (TimeStepsUntilHold == 0) {
1146 // Should hold simulation if TimeStepsUntilHold has reached zero
1149 // Still need to decrement TimeStepsUntilHold as value of -1
1150 // indicates that incremental then hold is turned off
1151 IncrementThenHolding = false;
1152 TimeStepsUntilHold--;
1154 } else if ( TimeStepsUntilHold > 0 ) {
1155 // Keep decrementing until 0 is reached
1156 TimeStepsUntilHold--;
1161 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1163 void FGFDMExec::DoTrim(int mode)
1167 if (Constructing) return;
1169 if (mode < 0 || mode > JSBSim::tNone) {
1170 cerr << endl << "Illegal trimming mode!" << endl << endl;
1173 saved_time = sim_time;
1174 FGTrim trim(this, (JSBSim::TrimMode)mode);
1175 if ( !trim.DoTrim() ) cerr << endl << "Trim Failed" << endl << endl;
1177 sim_time = saved_time;
1180 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1182 void FGFDMExec::DoSimplexTrim(int mode)
1185 if (Constructing) return;
1186 if (mode < 0 || mode > JSBSim::tNone) {
1187 cerr << endl << "Illegal trimming mode!" << endl << endl;
1190 saved_time = sim_time;
1191 FGSimplexTrim trim(this, (JSBSim::TrimMode)mode);
1192 sim_time = saved_time;
1193 Setsim_time(saved_time);
1194 std::cout << "dT: " << dT << std::endl;
1197 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1199 void FGFDMExec::DoLinearization(int mode)
1202 if (Constructing) return;
1203 saved_time = sim_time;
1204 FGLinearization lin(this,mode);
1205 sim_time = saved_time;
1206 Setsim_time(saved_time);
1209 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1211 void FGFDMExec::SRand(int sr)
1216 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1217 // The bitmasked value choices are as follows:
1218 // unset: In this case (the default) JSBSim would only print
1219 // out the normally expected messages, essentially echoing
1220 // the config files as they are read. If the environment
1221 // variable is not set, debug_lvl is set to 1 internally
1222 // 0: This requests JSBSim not to output any messages
1224 // 1: This value explicity requests the normal JSBSim
1226 // 2: This value asks for a message to be printed out when
1227 // a class is instantiated
1228 // 4: When this value is set, a message is displayed when a
1229 // FGModel object executes its Run() method
1230 // 8: When this value is set, various runtime state variables
1231 // are printed out periodically
1232 // 16: When set various parameters are sanity checked and
1233 // a message is printed out when they go out of bounds
1235 void FGFDMExec::Debug(int from)
1237 if (debug_lvl <= 0) return;
1239 if (debug_lvl & 1 && IdFDM == 0) { // Standard console startup message output
1240 if (from == 0) { // Constructor
1242 << "JSBSim Flight Dynamics Model v" << JSBSim_version << endl;
1243 cout << " [JSBSim-ML v" << needed_cfg_version << "]\n\n";
1244 cout << "JSBSim startup beginning ...\n\n";
1245 } else if (from == 3) {
1246 cout << "\n\nJSBSim startup complete\n\n";
1249 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
1250 if (from == 0) cout << "Instantiated: FGFDMExec" << endl;
1251 if (from == 1) cout << "Destroyed: FGFDMExec" << endl;
1253 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
1255 cout << "================== Frame: " << Frame << " Time: "
1256 << sim_time << " dt: " << dT << endl;
1259 if (debug_lvl & 8 ) { // Runtime state variables
1261 if (debug_lvl & 16) { // Sanity checking
1263 if (debug_lvl & 64) {
1264 if (from == 0) { // Constructor
1265 cout << IdSrc << endl;
1266 cout << IdHdr << endl;