]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/JSBSim.cxx
Fix stall widths for the "auxilliary" (reverse flow) stalls so they
[flightgear.git] / src / FDM / JSBSim / JSBSim.cxx
1 // JSBsim.cxx -- interface to the JSBsim flight model
2 //
3 // Written by Curtis Olson, started February 1999.
4 //
5 // Copyright (C) 1999  Curtis L. Olson  - curt@flightgear.org
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23
24 #ifdef HAVE_CONFIG_H
25 #  include <config.h>
26 #endif
27
28 #include <simgear/compiler.h>
29
30 #include <stdio.h>      //      size_t
31 #ifdef SG_MATH_EXCEPTION_CLASH
32 #  include <math.h>
33 #endif
34
35 #include STL_STRING
36
37 #include <simgear/constants.h>
38 #include <simgear/debug/logstream.hxx>
39 #include <simgear/math/sg_geodesy.hxx>
40 #include <simgear/misc/sg_path.hxx>
41 #include <simgear/structure/commands.hxx>
42
43 #include <FDM/flight.hxx>
44
45 #include <Aircraft/aircraft.hxx>
46 #include <Aircraft/controls.hxx>
47 #include <Main/globals.hxx>
48 #include <Main/fg_props.hxx>
49
50 #include <FDM/JSBSim/FGFDMExec.h>
51 #include <FDM/JSBSim/FGAircraft.h>
52 #include <FDM/JSBSim/FGFCS.h>
53 #include <FDM/JSBSim/FGPropagate.h>
54 #include <FDM/JSBSim/FGState.h>
55 #include <FDM/JSBSim/FGAuxiliary.h>
56 #include <FDM/JSBSim/FGInitialCondition.h>
57 #include <FDM/JSBSim/FGTrim.h>
58 #include <FDM/JSBSim/FGAtmosphere.h>
59 #include <FDM/JSBSim/FGMassBalance.h>
60 #include <FDM/JSBSim/FGAerodynamics.h>
61 #include <FDM/JSBSim/FGLGear.h>
62 #include <FDM/JSBSim/FGPropertyManager.h>
63 #include <FDM/JSBSim/FGEngine.h>
64 #include <FDM/JSBSim/FGPiston.h>
65 #include <FDM/JSBSim/FGGroundCallback.h>
66 #include <FDM/JSBSim/FGTurbine.h>
67 #include <FDM/JSBSim/FGRocket.h>
68 #include <FDM/JSBSim/FGElectric.h>
69 #include <FDM/JSBSim/FGNozzle.h>
70 #include <FDM/JSBSim/FGPropeller.h>
71 #include <FDM/JSBSim/FGRotor.h>
72 #include <FDM/JSBSim/FGTank.h>
73 #include "JSBSim.hxx"
74
75 static inline double
76 FMAX (double a, double b)
77 {
78   return a > b ? a : b;
79 }
80
81 class FGFSGroundCallback : public FGGroundCallback {
82 public:
83   FGFSGroundCallback(FGInterface* ifc) : mInterface(ifc) {}
84   virtual ~FGFSGroundCallback() {}
85
86   /** Get the altitude above sea level depenent on the location. */
87   virtual double GetAltitude(const FGLocation& l) const {
88     double pt[3] = { SG_FEET_TO_METER*l(eX),
89                      SG_FEET_TO_METER*l(eY),
90                      SG_FEET_TO_METER*l(eZ) };
91     double lat, lon, alt;
92     sgCartToGeod( pt, &lat, &lon, &alt);
93     return alt * SG_METER_TO_FEET;
94   }
95
96   /** Compute the altitude above ground. */
97   virtual double GetAGLevel(double t, const FGLocation& l,
98                             FGLocation& cont,
99                             FGColumnVector3& n, FGColumnVector3& v) const {
100     double loc_cart[3] = { l(eX), l(eY), l(eZ) };
101     double contact[3], normal[3], vel[3], lc, ff, agl;
102     int groundtype;
103     mInterface->get_agl_ft(t, loc_cart, contact, normal, vel,
104                            &groundtype, &lc, &ff, &agl);
105     n = l.GetTec2l()*FGColumnVector3( normal[0], normal[1], normal[2] );
106     v = l.GetTec2l()*FGColumnVector3( vel[0], vel[1], vel[2] );
107     cont = FGColumnVector3( contact[0], contact[1], contact[2] );
108     return agl;
109   }
110 private:
111   FGInterface* mInterface;
112 };
113
114 /******************************************************************************/
115
116 FGJSBsim::FGJSBsim( double dt )
117   : FGInterface(dt)
118 {
119     bool result;
120                                 // Set up the debugging level
121                                 // FIXME: this will not respond to
122                                 // runtime changes
123
124                                 // if flight is excluded, don't bother
125     if ((logbuf::get_log_classes() & SG_FLIGHT) != 0) {
126
127                                 // do a rough-and-ready mapping to
128                                 // the levels documented in FGFDMExec.h
129         switch (logbuf::get_log_priority()) {
130         case SG_BULK:
131             FGJSBBase::debug_lvl = 0x1f;
132             break;
133         case SG_DEBUG:
134             FGJSBBase::debug_lvl = 0x0f;
135         case SG_INFO:
136             FGJSBBase::debug_lvl = 0x01;
137             break;
138         case SG_WARN:
139         case SG_ALERT:
140             FGJSBBase::debug_lvl = 0x00;
141             break;
142         }
143     }
144
145     reset_on_crash = fgGetBool("/sim/reset-on-crash", false);
146     crashed = false;
147     fgSetBool("/sim/crashed", false);
148
149     fdmex = new FGFDMExec( (FGPropertyManager*)globals->get_props() );
150
151     // Register ground callback.
152     fdmex->SetGroundCallback( new FGFSGroundCallback(this) );
153
154     State           = fdmex->GetState();
155     Atmosphere      = fdmex->GetAtmosphere();
156     FCS             = fdmex->GetFCS();
157     MassBalance     = fdmex->GetMassBalance();
158     Propulsion      = fdmex->GetPropulsion();
159     Aircraft        = fdmex->GetAircraft();
160     Propagate        = fdmex->GetPropagate();
161     Auxiliary       = fdmex->GetAuxiliary();
162     Aerodynamics    = fdmex->GetAerodynamics();
163     GroundReactions = fdmex->GetGroundReactions();
164
165     fgic=fdmex->GetIC();
166     needTrim=true;
167
168     SGPath aircraft_path( fgGetString("/sim/aircraft-dir") );
169
170     SGPath engine_path( fgGetString("/sim/aircraft-dir") );
171     engine_path.append( "Engine" );
172     State->Setdt( dt );
173
174     result = fdmex->LoadModel( aircraft_path.str(),
175                                engine_path.str(),
176                                fgGetString("/sim/aero"), false );
177
178     if (result) {
179       SG_LOG( SG_FLIGHT, SG_INFO, "  loaded aero.");
180     } else {
181       SG_LOG( SG_FLIGHT, SG_INFO,
182               "  aero does not exist (you may have mis-typed the name).");
183       throw(-1);
184     }
185
186     SG_LOG( SG_FLIGHT, SG_INFO, "" );
187     SG_LOG( SG_FLIGHT, SG_INFO, "" );
188     SG_LOG( SG_FLIGHT, SG_INFO, "After loading aero definition file ..." );
189
190     int Neng = Propulsion->GetNumEngines();
191     SG_LOG( SG_FLIGHT, SG_INFO, "num engines = " << Neng );
192
193     if ( GroundReactions->GetNumGearUnits() <= 0 ) {
194         SG_LOG( SG_FLIGHT, SG_ALERT, "num gear units = "
195                 << GroundReactions->GetNumGearUnits() );
196         SG_LOG( SG_FLIGHT, SG_ALERT, "This is a very bad thing because with 0 gear units, the ground trimming");
197         SG_LOG( SG_FLIGHT, SG_ALERT, "routine (coming up later in the code) will core dump.");
198         SG_LOG( SG_FLIGHT, SG_ALERT, "Halting the sim now, and hoping a solution will present itself soon!");
199         exit(-1);
200     }
201
202     init_gear();
203
204     // Set initial fuel levels if provided.
205     for (unsigned int i = 0; i < Propulsion->GetNumTanks(); i++) {
206       SGPropertyNode * node = fgGetNode("/consumables/fuel/tank", i, true);
207       if (node->getChild("level-gal_us", 0, false) != 0) {
208         Propulsion->GetTank(i)->SetContents(node->getDoubleValue("level-gal_us") * 6.6);
209       } else {
210         node->setDoubleValue("level-lb", Propulsion->GetTank(i)->GetContents());
211         node->setDoubleValue("level-gal_us", Propulsion->GetTank(i)->GetContents() / 6.6);
212       }
213     }
214     Propulsion->SetFuelFreeze((fgGetNode("/sim/freeze/fuel",true))->getBoolValue());
215
216     fgSetDouble("/fdm/trim/pitch-trim", FCS->GetPitchTrimCmd());
217     fgSetDouble("/fdm/trim/throttle",   FCS->GetThrottleCmd(0));
218     fgSetDouble("/fdm/trim/aileron",    FCS->GetDaCmd());
219     fgSetDouble("/fdm/trim/rudder",     FCS->GetDrCmd());
220
221     startup_trim = fgGetNode("/sim/presets/trim", true);
222
223     trimmed = fgGetNode("/fdm/trim/trimmed", true);
224     trimmed->setBoolValue(false);
225
226     pitch_trim = fgGetNode("/fdm/trim/pitch-trim", true );
227     throttle_trim = fgGetNode("/fdm/trim/throttle", true );
228     aileron_trim = fgGetNode("/fdm/trim/aileron", true );
229     rudder_trim = fgGetNode("/fdm/trim/rudder", true );
230
231     stall_warning = fgGetNode("/sim/alarms/stall-warning",true);
232     stall_warning->setDoubleValue(0);
233
234
235     flap_pos_pct=fgGetNode("/surface-positions/flap-pos-norm",true);
236     elevator_pos_pct=fgGetNode("/surface-positions/elevator-pos-norm",true);
237     left_aileron_pos_pct
238         =fgGetNode("/surface-positions/left-aileron-pos-norm",true);
239     right_aileron_pos_pct
240         =fgGetNode("/surface-positions/right-aileron-pos-norm",true);
241     rudder_pos_pct=fgGetNode("/surface-positions/rudder-pos-norm",true);
242     speedbrake_pos_pct
243         =fgGetNode("/surface-positions/speedbrake-pos-norm",true);
244     spoilers_pos_pct=fgGetNode("/surface-positions/spoilers-pos-norm",true);
245
246     elevator_pos_pct->setDoubleValue(0);
247     left_aileron_pos_pct->setDoubleValue(0);
248     right_aileron_pos_pct->setDoubleValue(0);
249     rudder_pos_pct->setDoubleValue(0);
250     flap_pos_pct->setDoubleValue(0);
251     speedbrake_pos_pct->setDoubleValue(0);
252     spoilers_pos_pct->setDoubleValue(0);
253
254     temperature = fgGetNode("/environment/temperature-degc",true);
255     pressure = fgGetNode("/environment/pressure-inhg",true);
256     density = fgGetNode("/environment/density-slugft3",true);
257     turbulence_gain = fgGetNode("/environment/turbulence/magnitude-norm",true);
258     turbulence_rate = fgGetNode("/environment/turbulence/rate-hz",true);
259
260     wind_from_north= fgGetNode("/environment/wind-from-north-fps",true);
261     wind_from_east = fgGetNode("/environment/wind-from-east-fps" ,true);
262     wind_from_down = fgGetNode("/environment/wind-from-down-fps" ,true);
263
264     for (unsigned int i = 0; i < Propulsion->GetNumEngines(); i++) {
265       SGPropertyNode * node = fgGetNode("engines/engine", i, true);
266       Propulsion->GetEngine(i)->GetThruster()->SetRPM(node->getDoubleValue("rpm") /
267                      Propulsion->GetEngine(i)->GetThruster()->GetGearRatio());
268     }
269 }
270
271 /******************************************************************************/
272 FGJSBsim::~FGJSBsim(void)
273 {
274   delete fdmex;
275 }
276
277 /******************************************************************************/
278
279 // Initialize the JSBsim flight model, dt is the time increment for
280 // each subsequent iteration through the EOM
281
282 void FGJSBsim::init()
283 {
284     double tmp;
285
286     SG_LOG( SG_FLIGHT, SG_INFO, "Starting and initializing JSBsim" );
287
288     // Explicitly call the superclass's
289     // init method first.
290
291 #ifdef FG_WEATHERCM
292     Atmosphere->UseInternal();
293 #else
294     if (fgGetBool("/environment/params/control-fdm-atmosphere")) {
295       Atmosphere->UseExternal();
296       Atmosphere->SetExTemperature(
297                   9.0/5.0*(temperature->getDoubleValue()+273.15) );
298       Atmosphere->SetExPressure(pressure->getDoubleValue()*70.726566);
299       Atmosphere->SetExDensity(density->getDoubleValue());
300
301       tmp = turbulence_gain->getDoubleValue();
302       Atmosphere->SetTurbGain(tmp * tmp * 100.0);
303
304       tmp = turbulence_rate->getDoubleValue();
305       Atmosphere->SetTurbRate(tmp);
306
307     } else {
308       Atmosphere->UseInternal();
309     }
310 #endif
311
312     fgic->SetVnorthFpsIC( wind_from_north->getDoubleValue() );
313     fgic->SetVeastFpsIC( wind_from_east->getDoubleValue() );
314     fgic->SetVdownFpsIC( wind_from_down->getDoubleValue() );
315
316     //Atmosphere->SetExTemperature(get_Static_temperature());
317     //Atmosphere->SetExPressure(get_Static_pressure());
318     //Atmosphere->SetExDensity(get_Density());
319     SG_LOG(SG_FLIGHT,SG_INFO,"T,p,rho: " << fdmex->GetAtmosphere()->GetTemperature()
320      << ", " << fdmex->GetAtmosphere()->GetPressure()
321      << ", " << fdmex->GetAtmosphere()->GetDensity() );
322
323     if (fgGetBool("/sim/presets/running")) {
324           for (int i=0; i < Propulsion->GetNumEngines(); i++) {
325             SGPropertyNode * node = fgGetNode("engines/engine", i, true);
326             node->setBoolValue("running", true);
327             Propulsion->GetEngine(i)->SetRunning(true);
328           }
329     }
330
331     common_init();
332
333     copy_to_JSBsim();
334     fdmex->RunIC();     //loop JSBSim once w/o integrating
335     copy_from_JSBsim(); //update the bus
336
337     SG_LOG( SG_FLIGHT, SG_INFO, "  Initialized JSBSim with:" );
338
339     switch(fgic->GetSpeedSet()) {
340     case setned:
341         SG_LOG(SG_FLIGHT,SG_INFO, "  Vn,Ve,Vd= "
342                << Propagate->GetVel(eNorth) << ", "
343                << Propagate->GetVel(eEast) << ", "
344                << Propagate->GetVel(eDown) << " ft/s");
345     break;
346     case setuvw:
347         SG_LOG(SG_FLIGHT,SG_INFO, "  U,V,W= "
348                << Propagate->GetUVW(1) << ", "
349                << Propagate->GetUVW(2) << ", "
350                << Propagate->GetUVW(3) << " ft/s");
351     break;
352     case setmach:
353         SG_LOG(SG_FLIGHT,SG_INFO, "  Mach: "
354                << Auxiliary->GetMach() );
355     break;
356     case setvc:
357     default:
358         SG_LOG(SG_FLIGHT,SG_INFO, "  Indicated Airspeed: "
359                << Auxiliary->GetVcalibratedKTS() << " knots" );
360     break;
361     }
362
363     stall_warning->setDoubleValue(0);
364
365     SG_LOG( SG_FLIGHT, SG_INFO, "  Bank Angle: "
366             << Propagate->GetEuler(ePhi)*RADTODEG << " deg" );
367     SG_LOG( SG_FLIGHT, SG_INFO, "  Pitch Angle: "
368             << Propagate->GetEuler(eTht)*RADTODEG << " deg" );
369     SG_LOG( SG_FLIGHT, SG_INFO, "  True Heading: "
370             << Propagate->GetEuler(ePsi)*RADTODEG << " deg" );
371     SG_LOG( SG_FLIGHT, SG_INFO, "  Latitude: "
372             << Propagate->GetLocation().GetLatitudeDeg() << " deg" );
373     SG_LOG( SG_FLIGHT, SG_INFO, "  Longitude: "
374             << Propagate->GetLocation().GetLongitudeDeg() << " deg" );
375     SG_LOG( SG_FLIGHT, SG_INFO, "  Altitude: "
376             << Propagate->Geth() << " feet" );
377     SG_LOG( SG_FLIGHT, SG_INFO, "  loaded initial conditions" );
378
379     SG_LOG( SG_FLIGHT, SG_INFO, "  set dt" );
380
381     SG_LOG( SG_FLIGHT, SG_INFO, "Finished initializing JSBSim" );
382
383     SG_LOG( SG_FLIGHT, SG_INFO, "FGControls::get_gear_down()= " <<
384                                   globals->get_controls()->get_gear_down() );
385 }
386
387 /******************************************************************************/
388
389 // Run an iteration of the EOM (equations of motion)
390
391 void FGJSBsim::update( double dt )
392 {
393     if (is_suspended())
394       return;
395
396     int multiloop = _calc_multiloop(dt);
397
398     int i;
399
400     // Compute the radius of the aircraft. That is the radius of a ball
401     // where all gear units are in. At the moment it is at least 10ft ...
402     double acrad = 10.0;
403     int n_gears = GroundReactions->GetNumGearUnits();
404     for (i=0; i<n_gears; ++i) {
405       FGColumnVector3 bl = GroundReactions->GetGearUnit(i)->GetBodyLocation();
406       double r = bl.Magnitude();
407       if (acrad < r)
408         acrad = r;
409     }
410
411     // Compute the potential movement of this aircraft and query for the
412     // ground in this area.
413     double groundCacheRadius = acrad + 2*dt*Propagate->GetUVW().Magnitude();
414     double alt, slr, lat, lon;
415     FGColumnVector3 cart = Auxiliary->GetLocationVRP();
416     if ( needTrim && startup_trim->getBoolValue() ) {
417       alt = fgic->GetAltitudeFtIC();
418       slr = fgic->GetSeaLevelRadiusFtIC();
419       lat = fgic->GetLatitudeDegIC() * SGD_DEGREES_TO_RADIANS;
420       lon = fgic->GetLongitudeDegIC() * SGD_DEGREES_TO_RADIANS;
421       cart = FGLocation(lon, lat, alt+slr);
422     }
423     double cart_pos[3] = { cart(1), cart(2), cart(3) };
424     bool cache_ok = prepare_ground_cache_ft( State->Getsim_time(), cart_pos,
425                                              groundCacheRadius );
426     if (!cache_ok) {
427       SG_LOG(SG_FLIGHT, SG_WARN,
428              "FGInterface is being called without scenery below the aircraft!");
429       cout << "altitude         = " << alt << endl;
430       cout << "sea level radius = " << slr << endl;
431       cout << "latitude         = " << lat << endl;
432       cout << "longitude        = " << lon << endl;
433       //return;
434     }
435
436     copy_to_JSBsim();
437
438     trimmed->setBoolValue(false);
439
440     if ( needTrim ) {
441       if ( startup_trim->getBoolValue() ) {
442         double contact[3], dummy[3], lc, ff, agl;
443         int groundtype;
444         get_agl_ft(State->Getsim_time(), cart_pos, contact,
445                    dummy, dummy, &groundtype, &lc, &ff, &agl);
446         double terrain_alt = sqrt(contact[0]*contact[0] + contact[1]*contact[1]
447              + contact[2]*contact[2]) - fgic->GetSeaLevelRadiusFtIC();
448
449         SG_LOG(SG_FLIGHT, SG_INFO,
450           "Ready to trim, terrain altitude is: "
451             << terrain_alt * SG_METER_TO_FEET );
452
453         fgic->SetTerrainAltitudeFtIC( terrain_alt );
454         do_trim();
455       } else {
456         fdmex->RunIC();  //apply any changes made through the set_ functions
457       }
458       needTrim = false;
459     }
460
461     for ( i=0; i < multiloop; i++ ) {
462       fdmex->Run();
463     }
464
465     FGJSBBase::Message* msg;
466     while (fdmex->ReadMessage()) {
467       msg = fdmex->ProcessMessage();
468       switch (msg->type) {
469       case FGJSBBase::Message::eText:
470         SG_LOG( SG_FLIGHT, SG_INFO, msg->messageId << ": " << msg->text );
471         break;
472       case FGJSBBase::Message::eBool:
473         SG_LOG( SG_FLIGHT, SG_INFO, msg->messageId << ": " << msg->text << " " << msg->bVal );
474         break;
475       case FGJSBBase::Message::eInteger:
476         SG_LOG( SG_FLIGHT, SG_INFO, msg->messageId << ": " << msg->text << " " << msg->iVal );
477         break;
478       case FGJSBBase::Message::eDouble:
479         SG_LOG( SG_FLIGHT, SG_INFO, msg->messageId << ": " << msg->text << " " << msg->dVal );
480         break;
481       default:
482         SG_LOG( SG_FLIGHT, SG_INFO, "Unrecognized message type." );
483         break;
484       }
485     }
486
487     // translate JSBsim back to FG structure so that the
488     // autopilot (and the rest of the sim can use the updated values
489     copy_from_JSBsim();
490
491     // crashed (altitude AGL < 0)
492     if (get_Altitude_AGL() < 0.0) {
493       crash_message = "Attempted to fly under ground.";
494       crash_handler();
495     }
496 }
497
498 /******************************************************************************/
499
500 // Convert from the FGInterface struct to the JSBsim generic_ struct
501
502 bool FGJSBsim::copy_to_JSBsim()
503 {
504     double tmp;
505     unsigned int i;
506
507     // copy control positions into the JSBsim structure
508
509     FCS->SetDaCmd( globals->get_controls()->get_aileron());
510     FCS->SetRollTrimCmd( globals->get_controls()->get_aileron_trim() );
511     FCS->SetDeCmd( globals->get_controls()->get_elevator());
512     FCS->SetPitchTrimCmd( globals->get_controls()->get_elevator_trim() );
513     FCS->SetDrCmd( -globals->get_controls()->get_rudder() );
514     FCS->SetYawTrimCmd( -globals->get_controls()->get_rudder_trim() );
515     // FIXME: make that get_steering work
516 //     FCS->SetDsCmd( globals->get_controls()->get_steering()/80.0 );
517     FCS->SetDsCmd( globals->get_controls()->get_rudder() );
518     FCS->SetDfCmd( globals->get_controls()->get_flaps() );
519     FCS->SetDsbCmd( globals->get_controls()->get_speedbrake() );
520     FCS->SetDspCmd( globals->get_controls()->get_spoilers() );
521
522         // Parking brake sets minimum braking
523         // level for mains.
524     double parking_brake = globals->get_controls()->get_brake_parking();
525     FCS->SetLBrake(FMAX(globals->get_controls()->get_brake_left(), parking_brake));
526     FCS->SetRBrake(FMAX(globals->get_controls()->get_brake_right(), parking_brake));
527     FCS->SetCBrake( 0.0 );
528     // FCS->SetCBrake( globals->get_controls()->get_brake(2) );
529
530     FCS->SetGearCmd( globals->get_controls()->get_gear_down());
531     for (i = 0; i < Propulsion->GetNumEngines(); i++) {
532       SGPropertyNode * node = fgGetNode("engines/engine", i, true);
533
534       FCS->SetThrottleCmd(i, globals->get_controls()->get_throttle(i));
535       FCS->SetMixtureCmd(i, globals->get_controls()->get_mixture(i));
536       FCS->SetPropAdvanceCmd(i, globals->get_controls()->get_prop_advance(i));
537
538       switch (Propulsion->GetEngine(i)->GetType()) {
539       case FGEngine::etPiston:
540         { // FGPiston code block
541         FGPiston* eng = (FGPiston*)Propulsion->GetEngine(i);
542         eng->SetMagnetos( globals->get_controls()->get_magnetos(i) );
543         break;
544         } // end FGPiston code block
545       case FGEngine::etTurbine:
546         { // FGTurbine code block
547         FGTurbine* eng = (FGTurbine*)Propulsion->GetEngine(i);
548         eng->SetAugmentation( globals->get_controls()->get_augmentation(i) );
549         eng->SetReverse( globals->get_controls()->get_reverser(i) );
550         eng->SetInjection( globals->get_controls()->get_water_injection(i) );
551         eng->SetCutoff( globals->get_controls()->get_cutoff(i) );
552         eng->SetIgnition( globals->get_controls()->get_ignition(i) );
553         break;
554         } // end FGTurbine code block
555       case FGEngine::etRocket:
556         { // FGRocket code block
557         FGRocket* eng = (FGRocket*)Propulsion->GetEngine(i);
558         break;
559         } // end FGRocket code block
560       }
561
562       { // FGEngine code block
563       FGEngine* eng = Propulsion->GetEngine(i);
564
565       eng->SetStarter( globals->get_controls()->get_starter(i) );
566       eng->SetRunning( node->getBoolValue("running") );
567       } // end FGEngine code block
568     }
569
570
571     Propagate->SetSeaLevelRadius( get_Sea_level_radius() );
572
573     Atmosphere->SetExTemperature(
574                   9.0/5.0*(temperature->getDoubleValue()+273.15) );
575     Atmosphere->SetExPressure(pressure->getDoubleValue()*70.726566);
576     Atmosphere->SetExDensity(density->getDoubleValue());
577
578     tmp = turbulence_gain->getDoubleValue();
579     Atmosphere->SetTurbGain(tmp * tmp * 100.0);
580
581     tmp = turbulence_rate->getDoubleValue();
582     Atmosphere->SetTurbRate(tmp);
583
584     Atmosphere->SetWindNED( wind_from_north->getDoubleValue(),
585                             wind_from_east->getDoubleValue(),
586                             wind_from_down->getDoubleValue() );
587 //    SG_LOG(SG_FLIGHT,SG_INFO, "Wind NED: "
588 //                  << get_V_north_airmass() << ", "
589 //                  << get_V_east_airmass()  << ", "
590 //                  << get_V_down_airmass() );
591
592     for (i = 0; i < Propulsion->GetNumTanks(); i++) {
593       SGPropertyNode * node = fgGetNode("/consumables/fuel/tank", i, true);
594       FGTank * tank = Propulsion->GetTank(i);
595       tank->SetContents(node->getDoubleValue("level-gal_us") * 6.6);
596 //       tank->SetContents(node->getDoubleValue("level-lb"));
597     }
598     SGPropertyNode* node = fgGetNode("/systems/refuel", true);
599     Propulsion->SetRefuel(node->getDoubleValue("contact"));
600     Propulsion->SetFuelFreeze((fgGetNode("/sim/freeze/fuel",true))->getBoolValue());
601
602     return true;
603 }
604
605 /******************************************************************************/
606
607 // Convert from the JSBsim generic_ struct to the FGInterface struct
608
609 bool FGJSBsim::copy_from_JSBsim()
610 {
611     unsigned int i, j;
612 /*
613     _set_Inertias( MassBalance->GetMass(),
614                    MassBalance->GetIxx(),
615                    MassBalance->GetIyy(),
616                    MassBalance->GetIzz(),
617                    MassBalance->GetIxz() );
618 */
619     _set_CG_Position( MassBalance->GetXYZcg(1),
620                       MassBalance->GetXYZcg(2),
621                       MassBalance->GetXYZcg(3) );
622
623     _set_Accels_Body( Aircraft->GetBodyAccel(1),
624                       Aircraft->GetBodyAccel(2),
625                       Aircraft->GetBodyAccel(3) );
626
627     _set_Accels_CG_Body_N ( Aircraft->GetNcg(1),
628                             Aircraft->GetNcg(2),
629                             Aircraft->GetNcg(3) );
630
631     _set_Accels_Pilot_Body( Auxiliary->GetPilotAccel(1),
632                             Auxiliary->GetPilotAccel(2),
633                             Auxiliary->GetPilotAccel(3) );
634
635     _set_Nlf( Aircraft->GetNlf() );
636
637     // Velocities
638
639     _set_Velocities_Local( Propagate->GetVel(eNorth),
640                            Propagate->GetVel(eEast),
641                            Propagate->GetVel(eDown) );
642
643     _set_Velocities_Wind_Body( Propagate->GetUVW(1),
644                                Propagate->GetUVW(2),
645                                Propagate->GetUVW(3) );
646
647     // Make the HUD work ...
648     _set_Velocities_Ground( Propagate->GetVel(eNorth),
649                             Propagate->GetVel(eEast),
650                             -Propagate->GetVel(eDown) );
651
652     _set_V_rel_wind( Auxiliary->GetVt() );
653
654     _set_V_equiv_kts( Auxiliary->GetVequivalentKTS() );
655
656     _set_V_calibrated_kts( Auxiliary->GetVcalibratedKTS() );
657
658     _set_V_ground_speed( Auxiliary->GetVground() );
659
660     _set_Omega_Body( Propagate->GetPQR(eP),
661                      Propagate->GetPQR(eQ),
662                      Propagate->GetPQR(eR) );
663
664     _set_Euler_Rates( Auxiliary->GetEulerRates(ePhi),
665                       Auxiliary->GetEulerRates(eTht),
666                       Auxiliary->GetEulerRates(ePsi) );
667
668     _set_Mach_number( Auxiliary->GetMach() );
669
670     // Positions of Visual Reference Point
671     FGLocation l = Auxiliary->GetLocationVRP();
672     _updateGeocentricPosition( l.GetLatitude(), l.GetLongitude(),
673                                l.GetRadius() - get_Sea_level_radius() );
674
675     _set_Altitude_AGL( Propagate->GetDistanceAGL() );
676     {
677       double loc_cart[3] = { l(eX), l(eY), l(eZ) };
678       double contact[3], d[3], sd, t;
679       int id;
680       is_valid_m(&t, d, &sd);
681       get_agl_ft(t, loc_cart, contact, d, d, &id, &sd, &sd, &sd);
682       double rwrad
683         = FGColumnVector3( contact[0], contact[1], contact[2] ).Magnitude();
684       _set_Runway_altitude( rwrad - get_Sea_level_radius() );
685     }
686
687     _set_Euler_Angles( Propagate->GetEuler(ePhi),
688                        Propagate->GetEuler(eTht),
689                        Propagate->GetEuler(ePsi) );
690
691     _set_Alpha( Auxiliary->Getalpha() );
692     _set_Beta( Auxiliary->Getbeta() );
693
694
695     _set_Gamma_vert_rad( Auxiliary->GetGamma() );
696
697     _set_Earth_position_angle( Auxiliary->GetEarthPositionAngle() );
698
699     _set_Climb_Rate( Propagate->Gethdot() );
700
701     const FGMatrix33& Tl2b = Propagate->GetTl2b();
702     for ( i = 1; i <= 3; i++ ) {
703         for ( j = 1; j <= 3; j++ ) {
704             _set_T_Local_to_Body( i, j, Tl2b(i,j) );
705         }
706     }
707
708     // Copy the engine values from JSBSim.
709     for ( i=0; i < Propulsion->GetNumEngines(); i++ ) {
710       SGPropertyNode * node = fgGetNode("engines/engine", i, true);
711       char buf[30];
712       sprintf(buf, "engines/engine[%d]/thruster", i);
713       SGPropertyNode * tnode = fgGetNode(buf, true);
714       FGThruster * thruster = Propulsion->GetEngine(i)->GetThruster();
715
716       switch (Propulsion->GetEngine(i)->GetType()) {
717       case FGEngine::etPiston:
718         { // FGPiston code block
719         FGPiston* eng = (FGPiston*)Propulsion->GetEngine(i);
720         node->setDoubleValue("egt-degf", eng->getExhaustGasTemp_degF());
721         node->setDoubleValue("oil-temperature-degf", eng->getOilTemp_degF());
722         node->setDoubleValue("oil-pressure-psi", eng->getOilPressure_psi());
723         node->setDoubleValue("mp-osi", eng->getManifoldPressure_inHg());
724         node->setDoubleValue("cht-degf", eng->getCylinderHeadTemp_degF());
725         node->setDoubleValue("rpm", eng->getRPM());
726         } // end FGPiston code block
727         break;
728       case FGEngine::etRocket:
729         { // FGRocket code block
730         FGRocket* eng = (FGRocket*)Propulsion->GetEngine(i);
731         } // end FGRocket code block
732         break;
733       case FGEngine::etTurbine:
734         { // FGTurbine code block
735         FGTurbine* eng = (FGTurbine*)Propulsion->GetEngine(i);
736         node->setDoubleValue("n1", eng->GetN1());
737         node->setDoubleValue("n2", eng->GetN2());
738         node->setDoubleValue("egt_degf", 32 + eng->GetEGT()*9/5);
739         node->setBoolValue("augmentation", eng->GetAugmentation());
740         node->setBoolValue("water-injection", eng->GetInjection());
741         node->setBoolValue("ignition", eng->GetIgnition());
742         node->setDoubleValue("nozzle-pos-norm", eng->GetNozzle());
743         node->setDoubleValue("inlet-pos-norm", eng->GetInlet());
744         node->setDoubleValue("oil-pressure-psi", eng->getOilPressure_psi());
745         node->setBoolValue("reversed", eng->GetReversed());
746         node->setBoolValue("cutoff", eng->GetCutoff());
747         node->setDoubleValue("epr", eng->GetEPR());
748         globals->get_controls()->set_reverser(i, eng->GetReversed() );
749         globals->get_controls()->set_cutoff(i, eng->GetCutoff() );
750         globals->get_controls()->set_water_injection(i, eng->GetInjection() );
751         globals->get_controls()->set_augmentation(i, eng->GetAugmentation() );
752         } // end FGTurbine code block
753         break;
754       case FGEngine::etElectric:
755         { // FGElectric code block
756         FGElectric* eng = (FGElectric*)Propulsion->GetEngine(i);
757         node->setDoubleValue("rpm", eng->getRPM());
758         } // end FGElectric code block
759         break;
760       }
761
762       { // FGEngine code block
763       FGEngine* eng = Propulsion->GetEngine(i);
764       node->setDoubleValue("fuel-flow-gph", eng->getFuelFlow_gph());
765       node->setDoubleValue("thrust_lb", thruster->GetThrust());
766       node->setDoubleValue("fuel-flow_pph", eng->getFuelFlow_pph());
767       node->setBoolValue("running", eng->GetRunning());
768       node->setBoolValue("starter", eng->GetStarter());
769       node->setBoolValue("cranking", eng->GetCranking());
770       globals->get_controls()->set_starter(i, eng->GetStarter() );
771       } // end FGEngine code block
772
773       switch (thruster->GetType()) {
774       case FGThruster::ttNozzle:
775         { // FGNozzle code block
776         FGNozzle* noz = (FGNozzle*)thruster;
777         } // end FGNozzle code block
778         break;
779       case FGThruster::ttPropeller:
780         { // FGPropeller code block
781         FGPropeller* prop = (FGPropeller*)thruster;
782         tnode->setDoubleValue("rpm", thruster->GetRPM());
783         tnode->setDoubleValue("pitch", prop->GetPitch());
784         tnode->setDoubleValue("torque", prop->GetTorque());
785         } // end FGPropeller code block
786         break;
787       case FGThruster::ttRotor:
788         { // FGRotor code block
789         FGRotor* rotor = (FGRotor*)thruster;
790         } // end FGRotor code block
791         break;
792       case FGThruster::ttDirect:
793         { // Direct code block
794         } // end Direct code block
795         break;
796       }
797
798     }
799
800     // Copy the fuel levels from JSBSim if fuel
801     // freeze not enabled.
802     if ( ! Propulsion->GetFuelFreeze() ) {
803       for (i = 0; i < Propulsion->GetNumTanks(); i++) {
804         SGPropertyNode * node = fgGetNode("/consumables/fuel/tank", i, true);
805         FGTank* tank = Propulsion->GetTank(i);
806         double contents = tank->GetContents();
807         double temp = tank->GetTemperature_degC();
808         node->setDoubleValue("level-gal_us", contents/6.6);
809         node->setDoubleValue("level-lb", contents);
810         if (temp != -9999.0) node->setDoubleValue("temperature_degC", temp);
811       }
812     }
813
814     update_gear();
815
816     stall_warning->setDoubleValue( Aerodynamics->GetStallWarn() );
817
818     elevator_pos_pct->setDoubleValue( FCS->GetDePos(ofNorm) );
819     left_aileron_pos_pct->setDoubleValue( FCS->GetDaLPos(ofNorm) );
820     right_aileron_pos_pct->setDoubleValue( FCS->GetDaRPos(ofNorm) );
821     rudder_pos_pct->setDoubleValue( -1*FCS->GetDrPos(ofNorm) );
822     flap_pos_pct->setDoubleValue( FCS->GetDfPos(ofNorm) );
823     speedbrake_pos_pct->setDoubleValue( FCS->GetDsbPos(ofNorm) );
824     spoilers_pos_pct->setDoubleValue( FCS->GetDspPos(ofNorm) );
825
826     return true;
827 }
828
829
830 bool FGJSBsim::ToggleDataLogging(void)
831 {
832     return fdmex->GetOutput()->Toggle();
833 }
834
835
836 bool FGJSBsim::ToggleDataLogging(bool state)
837 {
838     if (state) {
839       fdmex->GetOutput()->Enable();
840       return true;
841     } else {
842       fdmex->GetOutput()->Disable();
843       return false;
844     }
845 }
846
847
848 //Positions
849 void FGJSBsim::set_Latitude(double lat)
850 {
851     static const SGPropertyNode *altitude = fgGetNode("/position/altitude-ft");
852     double alt;
853     double sea_level_radius_meters, lat_geoc;
854
855     // In case we're not trimming
856     FGInterface::set_Latitude(lat);
857
858     if ( altitude->getDoubleValue() > -9990 ) {
859       alt = altitude->getDoubleValue();
860     } else {
861       alt = 0.0;
862     }
863
864     update_ic();
865     SG_LOG(SG_FLIGHT,SG_INFO,"FGJSBsim::set_Latitude: " << lat );
866     SG_LOG(SG_FLIGHT,SG_INFO," cur alt (ft) =  " << alt );
867
868     sgGeodToGeoc( lat, alt * SG_FEET_TO_METER,
869                       &sea_level_radius_meters, &lat_geoc );
870     _set_Sea_level_radius( sea_level_radius_meters * SG_METER_TO_FEET  );
871     fgic->SetSeaLevelRadiusFtIC( sea_level_radius_meters * SG_METER_TO_FEET  );
872     fgic->SetLatitudeRadIC( lat_geoc );
873     needTrim=true;
874 }
875
876
877 void FGJSBsim::set_Longitude(double lon)
878 {
879     SG_LOG(SG_FLIGHT,SG_INFO,"FGJSBsim::set_Longitude: " << lon );
880
881     // In case we're not trimming
882     FGInterface::set_Longitude(lon);
883
884     update_ic();
885     fgic->SetLongitudeRadIC( lon );
886     needTrim=true;
887 }
888
889 void FGJSBsim::set_Altitude(double alt)
890 {
891     static const SGPropertyNode *latitude = fgGetNode("/position/latitude-deg");
892
893     double sea_level_radius_meters,lat_geoc;
894
895     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Altitude: " << alt );
896     SG_LOG(SG_FLIGHT,SG_INFO, "  lat (deg) = " << latitude->getDoubleValue() );
897
898     // In case we're not trimming
899     FGInterface::set_Altitude(alt);
900
901     update_ic();
902     sgGeodToGeoc( latitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS, alt,
903                   &sea_level_radius_meters, &lat_geoc);
904     _set_Sea_level_radius( sea_level_radius_meters * SG_METER_TO_FEET  );
905     fgic->SetSeaLevelRadiusFtIC( sea_level_radius_meters * SG_METER_TO_FEET );
906     SG_LOG(SG_FLIGHT, SG_INFO,
907           "Terrain altitude: " << cur_fdm_state->get_Runway_altitude() * SG_METER_TO_FEET );
908     fgic->SetLatitudeRadIC( lat_geoc );
909     fgic->SetAltitudeFtIC(alt);
910     needTrim=true;
911 }
912
913 void FGJSBsim::set_V_calibrated_kts(double vc)
914 {
915     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_V_calibrated_kts: " <<  vc );
916
917     // In case we're not trimming
918     FGInterface::set_V_calibrated_kts(vc);
919
920     update_ic();
921     fgic->SetVcalibratedKtsIC(vc);
922     needTrim=true;
923 }
924
925 void FGJSBsim::set_Mach_number(double mach)
926 {
927     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Mach_number: " <<  mach );
928
929     // In case we're not trimming
930     FGInterface::set_Mach_number(mach);
931
932     update_ic();
933     fgic->SetMachIC(mach);
934     needTrim=true;
935 }
936
937 void FGJSBsim::set_Velocities_Local( double north, double east, double down )
938 {
939     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Velocities_Local: "
940        << north << ", " <<  east << ", " << down );
941
942     // In case we're not trimming
943     FGInterface::set_Velocities_Local(north, east, down);
944
945     update_ic();
946     fgic->SetVnorthFpsIC(north);
947     fgic->SetVeastFpsIC(east);
948     fgic->SetVdownFpsIC(down);
949     needTrim=true;
950 }
951
952 void FGJSBsim::set_Velocities_Wind_Body( double u, double v, double w)
953 {
954     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Velocities_Wind_Body: "
955        << u << ", " <<  v << ", " <<  w );
956
957     // In case we're not trimming
958     FGInterface::set_Velocities_Wind_Body(u, v, w);
959
960     update_ic();
961     fgic->SetUBodyFpsIC(u);
962     fgic->SetVBodyFpsIC(v);
963     fgic->SetWBodyFpsIC(w);
964     needTrim=true;
965 }
966
967 //Euler angles
968 void FGJSBsim::set_Euler_Angles( double phi, double theta, double psi )
969 {
970     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Euler_Angles: "
971        << phi << ", " << theta << ", " << psi );
972
973     // In case we're not trimming
974     FGInterface::set_Euler_Angles(phi, theta, psi);
975
976     update_ic();
977     fgic->SetPitchAngleRadIC(theta);
978     fgic->SetRollAngleRadIC(phi);
979     fgic->SetTrueHeadingRadIC(psi);
980     needTrim=true;
981 }
982
983 //Flight Path
984 void FGJSBsim::set_Climb_Rate( double roc)
985 {
986     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Climb_Rate: " << roc );
987
988     // In case we're not trimming
989     FGInterface::set_Climb_Rate(roc);
990
991     update_ic();
992     //since both climb rate and flight path angle are set in the FG
993     //startup sequence, something is needed to keep one from cancelling
994     //out the other.
995     if( !(fabs(roc) > 1 && fabs(fgic->GetFlightPathAngleRadIC()) < 0.01) ) {
996       fgic->SetClimbRateFpsIC(roc);
997     }
998     needTrim=true;
999 }
1000
1001 void FGJSBsim::set_Gamma_vert_rad( double gamma)
1002 {
1003     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Gamma_vert_rad: " << gamma );
1004
1005     update_ic();
1006     if( !(fabs(gamma) < 0.01 && fabs(fgic->GetClimbRateFpsIC()) > 1) ) {
1007       fgic->SetFlightPathAngleRadIC(gamma);
1008     }
1009     needTrim=true;
1010 }
1011
1012 void FGJSBsim::init_gear(void )
1013 {
1014     FGGroundReactions* gr=fdmex->GetGroundReactions();
1015     int Ngear=GroundReactions->GetNumGearUnits();
1016     for (int i=0;i<Ngear;i++) {
1017       FGLGear *gear = gr->GetGearUnit(i);
1018       SGPropertyNode * node = fgGetNode("gear/gear", i, true);
1019       node->setDoubleValue("xoffset-in", gear->GetBodyLocation()(1));
1020       node->setDoubleValue("yoffset-in", gear->GetBodyLocation()(2));
1021       node->setDoubleValue("zoffset-in", gear->GetBodyLocation()(3));
1022       node->setBoolValue("wow", gear->GetWOW());
1023       node->setBoolValue("has-brake", gear->GetBrakeGroup() > 0);
1024       node->setDoubleValue("position-norm", FCS->GetGearPos());
1025       node->setDoubleValue("tire-pressure-norm", gear->GetTirePressure());
1026       node->setDoubleValue("compression-norm", gear->GetCompLen());
1027       if ( gear->GetSteerable() )
1028         node->setDoubleValue("steering-norm", gear->GetSteerNorm());
1029     }
1030 }
1031
1032 void FGJSBsim::update_gear(void)
1033 {
1034     FGGroundReactions* gr=fdmex->GetGroundReactions();
1035     int Ngear=GroundReactions->GetNumGearUnits();
1036     for (int i=0;i<Ngear;i++) {
1037       FGLGear *gear = gr->GetGearUnit(i);
1038       SGPropertyNode * node = fgGetNode("gear/gear", i, true);
1039       node->getChild("wow", 0, true)->setBoolValue( gear->GetWOW());
1040       node->getChild("position-norm", 0, true)->setDoubleValue(FCS->GetGearPos());
1041       gear->SetTirePressure(node->getDoubleValue("tire-pressure-norm"));
1042       node->setDoubleValue("compression-norm", gear->GetCompLen());
1043       if ( gear->GetSteerable() )
1044         node->setDoubleValue("steering-norm", gear->GetSteerNorm());
1045     }
1046 }
1047
1048 void FGJSBsim::do_trim(void)
1049 {
1050   FGTrim *fgtrim;
1051
1052   if ( fgGetBool("/sim/presets/onground") )
1053   {
1054     fgic->SetVcalibratedKtsIC(0.0);
1055     fgtrim = new FGTrim(fdmex,tGround);
1056   } else {
1057     fgtrim = new FGTrim(fdmex,tLongitudinal);
1058   }
1059
1060   if ( !fgtrim->DoTrim() ) {
1061     fgtrim->Report();
1062     fgtrim->TrimStats();
1063   } else {
1064     trimmed->setBoolValue(true);
1065   }
1066   if (FGJSBBase::debug_lvl > 0)
1067       State->ReportState();
1068
1069   delete fgtrim;
1070
1071   pitch_trim->setDoubleValue( FCS->GetPitchTrimCmd() );
1072   throttle_trim->setDoubleValue( FCS->GetThrottleCmd(0) );
1073   aileron_trim->setDoubleValue( FCS->GetDaCmd() );
1074   rudder_trim->setDoubleValue( FCS->GetDrCmd() );
1075
1076   globals->get_controls()->set_elevator_trim(FCS->GetPitchTrimCmd());
1077   globals->get_controls()->set_elevator(FCS->GetDeCmd());
1078   globals->get_controls()->set_throttle(FGControls::ALL_ENGINES,
1079   FCS->GetThrottleCmd(0));
1080
1081   globals->get_controls()->set_aileron(FCS->GetDaCmd());
1082   globals->get_controls()->set_rudder( FCS->GetDrCmd());
1083
1084   SG_LOG( SG_FLIGHT, SG_INFO, "  Trim complete" );
1085 }
1086
1087 void FGJSBsim::update_ic(void)
1088 {
1089    if ( !needTrim ) {
1090      fgic->SetLatitudeRadIC(get_Lat_geocentric() );
1091      fgic->SetLongitudeRadIC( get_Longitude() );
1092      fgic->SetAltitudeFtIC( get_Altitude() );
1093      fgic->SetVcalibratedKtsIC( get_V_calibrated_kts() );
1094      fgic->SetPitchAngleRadIC( get_Theta() );
1095      fgic->SetRollAngleRadIC( get_Phi() );
1096      fgic->SetTrueHeadingRadIC( get_Psi() );
1097      fgic->SetClimbRateFpsIC( get_Climb_Rate() );
1098    }
1099 }
1100
1101 void FGJSBsim::crash_handler(void)
1102 {
1103    if (crashed) return;  // we already crashed
1104    crashed = true;
1105    fgSetBool("/sim/crashed", true);
1106    SG_LOG( SG_FLIGHT, SG_WARN, "  Crash: " << crash_message );
1107    if (reset_on_crash) {
1108      SGPropertyNode* node = fgGetNode("/sim/presets", true);
1109      globals->get_commands()->execute("old-reinit-dialog", node);   
1110    } else {
1111      fgSetBool("/sim/freeze/master", true);
1112      fgSetBool("/sim/freeze/clock", true);
1113    }
1114 }