]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim.cxx
Fix from Dave to get JSBSim engine startups working again.
[flightgear.git] / src / FDM / 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 #include <simgear/compiler.h>
25
26 #ifdef SG_MATH_EXCEPTION_CLASH
27 #  include <math.h>
28 #endif
29
30 #include STL_STRING
31
32 #include <simgear/constants.h>
33 #include <simgear/debug/logstream.hxx>
34 #include <simgear/math/sg_geodesy.hxx>
35 #include <simgear/misc/sg_path.hxx>
36
37 #include <Scenery/scenery.hxx>
38
39 #include <Aircraft/aircraft.hxx>
40 #include <Controls/controls.hxx>
41 #include <Main/globals.hxx>
42 #include <Main/fg_props.hxx>
43
44 #include <FDM/JSBSim/FGFDMExec.h>
45 #include <FDM/JSBSim/FGAircraft.h>
46 #include <FDM/JSBSim/FGFCS.h>
47 #include <FDM/JSBSim/FGPosition.h>
48 #include <FDM/JSBSim/FGRotation.h>
49 #include <FDM/JSBSim/FGState.h>
50 #include <FDM/JSBSim/FGTranslation.h>
51 #include <FDM/JSBSim/FGAuxiliary.h>
52 #include <FDM/JSBSim/FGDefs.h>
53 #include <FDM/JSBSim/FGInitialCondition.h>
54 #include <FDM/JSBSim/FGTrim.h>
55 #include <FDM/JSBSim/FGAtmosphere.h>
56 #include <FDM/JSBSim/FGMassBalance.h>
57 #include <FDM/JSBSim/FGAerodynamics.h>
58 #include "JSBSim.hxx"
59
60 /******************************************************************************/
61
62 FGJSBsim::FGJSBsim( double dt ) 
63   : FGInterface(dt)
64 {
65     bool result;
66    
67     fdmex = new FGFDMExec;
68     
69     State        = fdmex->GetState();
70     Atmosphere   = fdmex->GetAtmosphere();
71     FCS          = fdmex->GetFCS();
72     MassBalance  = fdmex->GetMassBalance();
73     Propulsion   = fdmex->GetPropulsion();
74     Aircraft     = fdmex->GetAircraft();
75     Translation  = fdmex->GetTranslation();
76     Rotation     = fdmex->GetRotation();
77     Position     = fdmex->GetPosition();
78     Auxiliary    = fdmex->GetAuxiliary();
79     Aerodynamics = fdmex->GetAerodynamics();
80     
81     Atmosphere->UseInternal();
82     
83     fgic=new FGInitialCondition(fdmex);
84     needTrim=true;
85   
86     SGPath aircraft_path( globals->get_fg_root() );
87     aircraft_path.append( "Aircraft" );
88
89     SGPath engine_path( globals->get_fg_root() );
90     engine_path.append( "Engine" );
91     set_delta_t( dt );
92     State->Setdt( dt );
93
94     result = fdmex->LoadModel( aircraft_path.str(),
95                                engine_path.str(),
96                                fgGetString("/sim/aircraft") );
97     
98     if (result) {
99       SG_LOG( SG_FLIGHT, SG_INFO, "  loaded aircraft.");
100     } else {
101       SG_LOG( SG_FLIGHT, SG_INFO,
102               "  aircraft does not exist (you may have mis-typed the name).");
103       throw(-1);
104     }
105
106     SG_LOG( SG_FLIGHT, SG_INFO, "" );
107     SG_LOG( SG_FLIGHT, SG_INFO, "" );
108     SG_LOG( SG_FLIGHT, SG_INFO, "After loading aircraft definition file ..." );
109
110     int Neng = Propulsion->GetNumEngines();
111     SG_LOG( SG_FLIGHT, SG_INFO, "num engines = " << Neng );
112     for(int i=0;i<Neng;i++) {
113         add_engine( FGEngInterface() );
114     }  
115     
116     if ( fdmex->GetGroundReactions()->GetNumGearUnits() <= 0 ) {
117         SG_LOG( SG_FLIGHT, SG_ALERT, "num gear units = "
118                 << fdmex->GetGroundReactions()->GetNumGearUnits() );
119         SG_LOG( SG_FLIGHT, SG_ALERT, "This is a very bad thing because with 0 gear units, the ground trimming");
120          SG_LOG( SG_FLIGHT, SG_ALERT, "routine (coming up later in the code) will core dump.");
121          SG_LOG( SG_FLIGHT, SG_ALERT, "Halting the sim now, and hoping a solution will present itself soon!");
122          exit(-1);
123     }
124         
125     
126     fgSetDouble("/fdm/trim/pitch-trim", FCS->GetPitchTrimCmd());
127     fgSetDouble("/fdm/trim/throttle",   FCS->GetThrottleCmd(0));
128     fgSetDouble("/fdm/trim/aileron",    FCS->GetDaCmd());
129     fgSetDouble("/fdm/trim/rudder",     FCS->GetDrCmd());
130
131     startup_trim = fgGetNode("/sim/startup/trim", true);
132
133     trimmed = fgGetNode("/fdm/trim/trimmed", true);
134     trimmed->setBoolValue(false);
135
136     pitch_trim = fgGetNode("/fdm/trim/pitch-trim", true );
137     throttle_trim = fgGetNode("/fdm/trim/throttle", true );
138     aileron_trim = fgGetNode("/fdm/trim/aileron", true );
139     rudder_trim = fgGetNode("/fdm/trim/rudder", true );
140 }
141
142 /******************************************************************************/
143 FGJSBsim::~FGJSBsim(void) {
144     if (fdmex != NULL) {
145         delete fdmex; fdmex=NULL;
146         delete fgic; fgic=NULL;
147     }  
148 }
149
150 /******************************************************************************/
151
152 // Initialize the JSBsim flight model, dt is the time increment for
153 // each subsequent iteration through the EOM
154
155 void FGJSBsim::init() {
156     
157     SG_LOG( SG_FLIGHT, SG_INFO, "Starting and initializing JSBsim" );
158    
159     // Explicitly call the superclass's
160     // init method first.
161     FGInterface::init();
162
163     fdmex->GetState()->Initialize(fgic);
164     fdmex->RunIC(fgic); //loop JSBSim once w/o integrating
165     // fdmex->Run();       //loop JSBSim once
166     copy_from_JSBsim(); //update the bus
167
168     SG_LOG( SG_FLIGHT, SG_INFO, "  Initialized JSBSim with:" );
169
170     switch(fgic->GetSpeedSet()) {
171     case setned:
172         SG_LOG(SG_FLIGHT,SG_INFO, "  Vn,Ve,Vd= "
173                << Position->GetVn() << ", "
174                << Position->GetVe() << ", "
175                << Position->GetVd() << " ft/s");
176     break;
177     case setuvw:
178         SG_LOG(SG_FLIGHT,SG_INFO, "  U,V,W= "
179                << Translation->GetUVW(1) << ", "
180                << Translation->GetUVW(2) << ", "
181                << Translation->GetUVW(3) << " ft/s");
182     break;
183     case setmach:
184         SG_LOG(SG_FLIGHT,SG_INFO, "  Mach: "
185                << Translation->GetMach() );
186     break;
187     case setvc:
188     default:
189         SG_LOG(SG_FLIGHT,SG_INFO, "  Indicated Airspeed: "
190                << Auxiliary->GetVcalibratedKTS() << " knots" );
191     break;
192     }
193
194     SG_LOG( SG_FLIGHT, SG_INFO, "  Bank Angle: "
195             <<  Rotation->Getphi()*RADTODEG << " deg" );
196     SG_LOG( SG_FLIGHT, SG_INFO, "  Pitch Angle: "
197             << Rotation->Gettht()*RADTODEG << " deg" );
198     SG_LOG( SG_FLIGHT, SG_INFO, "  True Heading: "
199             << Rotation->Getpsi()*RADTODEG << " deg" );
200     SG_LOG( SG_FLIGHT, SG_INFO, "  Latitude: "
201             << Position->GetLatitude() << " deg" );
202     SG_LOG( SG_FLIGHT, SG_INFO, "  Longitude: "
203             << Position->GetLongitude() << " deg" );
204     SG_LOG( SG_FLIGHT, SG_INFO, "  Altitude: "
205             << Position->Geth() << " feet" );
206     SG_LOG( SG_FLIGHT, SG_INFO, "  loaded initial conditions" );
207
208     SG_LOG( SG_FLIGHT, SG_INFO, "  set dt" );
209
210     SG_LOG( SG_FLIGHT, SG_INFO, "Finished initializing JSBSim" );
211 }
212
213 /******************************************************************************/
214
215 // Run an iteration of the EOM (equations of motion)
216
217 bool FGJSBsim::update( int multiloop ) {
218
219     int i;
220
221     double save_alt = 0.0;
222
223     copy_to_JSBsim();
224
225     trimmed->setBoolValue(false);
226
227     if ( needTrim && startup_trim->getBoolValue() ) {
228         cout << "num gear units = " << fdmex->GetGroundReactions()->GetNumGearUnits() << endl;
229         //fgic->SetSeaLevelRadiusFtIC( get_Sea_level_radius() );
230         //fgic->SetTerrainAltitudeFtIC( scenery.cur_elev * SG_METER_TO_FEET );
231
232         FGTrim *fgtrim;
233         if(fgic->GetVcalibratedKtsIC() < 10 ) {
234             fgic->SetVcalibratedKtsIC(0.0);
235             fgtrim=new FGTrim(fdmex,fgic,tGround);
236         } else {
237             fgtrim=new FGTrim(fdmex,fgic,tLongitudinal);
238         }
239         if(!fgtrim->DoTrim()) {
240             fgtrim->Report();
241             fgtrim->TrimStats();
242         } else {
243             trimmed->setBoolValue(true);
244         }
245         fgtrim->ReportState();
246         delete fgtrim;
247
248         needTrim=false;
249
250         pitch_trim->setDoubleValue( FCS->GetPitchTrimCmd() );
251         throttle_trim->setDoubleValue( FCS->GetThrottleCmd(0) );
252         aileron_trim->setDoubleValue( FCS->GetDaCmd() );
253         rudder_trim->setDoubleValue( FCS->GetDrCmd() );
254
255         globals->get_controls()->set_elevator_trim(FCS->GetPitchTrimCmd());
256         globals->get_controls()->set_elevator(FCS->GetDeCmd());
257         globals->get_controls()->set_throttle(FGControls::ALL_ENGINES,
258                                               FCS->GetThrottleCmd(0));
259
260         globals->get_controls()->set_aileron(FCS->GetDaCmd());
261         globals->get_controls()->set_rudder( FCS->GetDrCmd());
262     
263         SG_LOG( SG_FLIGHT, SG_INFO, "  Trim complete" );
264     }
265   
266     for( i=0; i<get_num_engines(); i++ ) {
267       FGEngInterface * e = get_engine(i);
268       FGEngine * eng = Propulsion->GetEngine(i);
269       FGThruster * thrust = Propulsion->GetThruster(i);
270       eng->SetMagnetos( globals->get_controls()->get_magnetos(i) );
271       eng->SetStarter( globals->get_controls()->get_starter(i) );
272       e->set_Manifold_Pressure( eng->getManifoldPressure_inHg() );
273       e->set_RPM( thrust->GetRPM() );
274       e->set_EGT( eng->getExhaustGasTemp_degF() );
275       e->set_CHT( eng->getCylinderHeadTemp_degF() );
276       e->set_Oil_Temp( eng->getOilTemp_degF() );
277       e->set_Running_Flag( eng->GetRunning() );
278       e->set_Cranking_Flag( eng->GetCranking() );
279       e->set_Throttle( globals->get_controls()->get_throttle(i) );
280     }
281
282     for ( i=0; i < multiloop; i++ ) {
283         fdmex->Run();
284     }
285
286     // printf("%d FG_Altitude = %.2f\n", i, FG_Altitude * 0.3048);
287     // printf("%d Altitude = %.2f\n", i, Altitude * 0.3048);
288
289     // translate JSBsim back to FG structure so that the
290     // autopilot (and the rest of the sim can use the updated values
291
292     copy_from_JSBsim();
293     return true;
294 }
295
296 /******************************************************************************/
297
298 // Convert from the FGInterface struct to the JSBsim generic_ struct
299
300 bool FGJSBsim::copy_to_JSBsim() {
301     // copy control positions into the JSBsim structure
302
303     FCS->SetDaCmd( globals->get_controls()->get_aileron());
304     FCS->SetDeCmd( globals->get_controls()->get_elevator());
305     FCS->SetPitchTrimCmd(globals->get_controls()->get_elevator_trim());
306     FCS->SetDrCmd( -globals->get_controls()->get_rudder());
307     FCS->SetDfCmd(  globals->get_controls()->get_flaps() );
308     FCS->SetDsbCmd( 0.0 ); //speedbrakes
309     FCS->SetDspCmd( 0.0 ); //spoilers
310     FCS->SetLBrake( globals->get_controls()->get_brake( 0 ) );
311     FCS->SetRBrake( globals->get_controls()->get_brake( 1 ) );
312     FCS->SetCBrake( globals->get_controls()->get_brake( 2 ) );
313     for (int i = 0; i < get_num_engines(); i++) {
314       FCS->SetThrottleCmd(i, globals->get_controls()->get_throttle(i));
315       FCS->SetMixtureCmd(i, globals->get_controls()->get_mixture(i));
316     }
317
318     Position->SetSeaLevelRadius( get_Sea_level_radius() );
319     Position->SetRunwayRadius( scenery.get_cur_elev()*SG_METER_TO_FEET
320                                + get_Sea_level_radius() );
321
322     Atmosphere->SetExTemperature(get_Static_temperature());
323     Atmosphere->SetExPressure(get_Static_pressure());
324     Atmosphere->SetExDensity(get_Density());
325     Atmosphere->SetWindNED(get_V_north_airmass(),
326                            get_V_east_airmass(),
327                            get_V_down_airmass());
328 //    SG_LOG(SG_FLIGHT,SG_INFO, "Wind NED: "
329 //                  << get_V_north_airmass() << ", "
330 //                  << get_V_east_airmass()  << ", "
331 //                  << get_V_down_airmass() );
332
333     return true;
334 }
335
336 /******************************************************************************/
337
338 // Convert from the JSBsim generic_ struct to the FGInterface struct
339
340 bool FGJSBsim::copy_from_JSBsim() {
341     unsigned int i, j;
342
343     _set_Inertias( MassBalance->GetMass(),
344                    MassBalance->GetIxx(),
345                    MassBalance->GetIyy(),
346                    MassBalance->GetIzz(),
347                    MassBalance->GetIxz() );
348
349     _set_CG_Position( MassBalance->GetXYZcg(1),
350                       MassBalance->GetXYZcg(2),
351                       MassBalance->GetXYZcg(3) );
352
353     _set_Accels_Body( Translation->GetUVWdot(1),
354                       Translation->GetUVWdot(2),
355                       Translation->GetUVWdot(3) );
356
357     _set_Accels_CG_Body( Translation->GetUVWdot(1),
358                          Translation->GetUVWdot(2),
359                          Translation->GetUVWdot(3) );
360
361     //_set_Accels_CG_Body_N ( Translation->GetNcg(1),
362     //                       Translation->GetNcg(2),
363     //                       Translation->GetNcg(3) );
364     //
365     _set_Accels_Pilot_Body( Auxiliary->GetPilotAccel(1),
366                             Auxiliary->GetPilotAccel(2),
367                             Auxiliary->GetPilotAccel(3) );
368
369     //_set_Accels_Pilot_Body_N( Auxiliary->GetNpilot(1),
370     //                         Auxiliary->GetNpilot(2),
371     //                         Auxiliary->GetNpilot(3) );
372
373     _set_Nlf( Aerodynamics->GetNlf() );
374
375     // Velocities
376
377     _set_Velocities_Local( Position->GetVn(),
378                            Position->GetVe(),
379                            Position->GetVd() );
380
381     _set_Velocities_Wind_Body( Translation->GetUVW(1),
382                                Translation->GetUVW(2),
383                                Translation->GetUVW(3) );
384
385     _set_V_rel_wind( Translation->GetVt() );
386
387     _set_V_equiv_kts( Auxiliary->GetVequivalentKTS() );
388
389     // _set_V_calibrated( Auxiliary->GetVcalibratedFPS() );
390
391     _set_V_calibrated_kts( Auxiliary->GetVcalibratedKTS() );
392
393     _set_V_ground_speed( Position->GetVground() );
394
395     _set_Omega_Body( Rotation->GetPQR(1),
396                      Rotation->GetPQR(2),
397                      Rotation->GetPQR(3) );
398
399     _set_Euler_Rates( Rotation->GetEulerRates(1),
400                       Rotation->GetEulerRates(2),
401                       Rotation->GetEulerRates(3) );
402
403     _set_Geocentric_Rates(Position->GetLatitudeDot(),
404                           Position->GetLongitudeDot(),
405                           Position->Gethdot() );
406
407     _set_Mach_number( Translation->GetMach() );
408
409     // Positions
410     _updatePosition( Position->GetLatitude(),
411                      Position->GetLongitude(),
412                      Position->Geth() );
413
414     _set_Altitude_AGL( Position->GetDistanceAGL() );
415
416     _set_Euler_Angles( Rotation->Getphi(),
417                        Rotation->Gettht(),
418                        Rotation->Getpsi() );
419
420     _set_Alpha( Translation->Getalpha() );
421     _set_Beta( Translation->Getbeta() );
422
423
424     _set_Gamma_vert_rad( Position->GetGamma() );
425     // set_Gamma_horiz_rad( Gamma_horiz_rad );
426
427     _set_Earth_position_angle( Auxiliary->GetEarthPositionAngle() );
428
429     _set_Climb_Rate( Position->Gethdot() );
430
431
432     for ( i = 1; i <= 3; i++ ) {
433         for ( j = 1; j <= 3; j++ ) {
434             _set_T_Local_to_Body( i, j, State->GetTl2b(i,j) );
435         }
436     }
437     return true;
438 }
439
440 void FGJSBsim::snap_shot(void) {
441     fgic->SetLatitudeRadIC(get_Lat_geocentric() );
442     fgic->SetLongitudeRadIC( get_Longitude() );
443     fgic->SetAltitudeFtIC( get_Altitude() );
444     fgic->SetTerrainAltitudeFtIC( get_Runway_altitude() );
445     fgic->SetVtrueFpsIC( get_V_rel_wind() );
446     fgic->SetPitchAngleRadIC( get_Theta() );
447     fgic->SetRollAngleRadIC( get_Phi() );
448     fgic->SetTrueHeadingRadIC( get_Psi() );
449     fgic->SetClimbRateFpsIC( get_Climb_Rate() );
450 }
451
452
453 bool FGJSBsim::ToggleDataLogging(void) {
454     return fdmex->GetOutput()->Toggle();
455 }
456
457
458 bool FGJSBsim::ToggleDataLogging(bool state) {
459     if (state) {
460       fdmex->GetOutput()->Enable();
461       return true;
462     } else {
463       fdmex->GetOutput()->Disable();
464       return false;
465     }
466 }
467
468
469 //Positions
470 void FGJSBsim::set_Latitude(double lat) {
471     static const SGPropertyNode *altitude
472         = fgGetNode("/position/altitude-ft");
473     double alt;
474     if ( altitude->getDoubleValue() > -9990 ) {
475         alt = altitude->getDoubleValue();
476     } else {
477         alt = 0.0;
478     }
479
480     double sea_level_radius_meters, lat_geoc;
481
482     SG_LOG(SG_FLIGHT,SG_INFO,"FGJSBsim::set_Latitude: " << lat );
483     SG_LOG(SG_FLIGHT,SG_INFO," cur alt (ft) =  " << alt );
484
485     sgGeodToGeoc( lat, alt * SG_FEET_TO_METER,
486                   &sea_level_radius_meters, &lat_geoc );
487     _set_Sea_level_radius( sea_level_radius_meters * SG_METER_TO_FEET  );
488     fgic->SetSeaLevelRadiusFtIC( sea_level_radius_meters * SG_METER_TO_FEET  );
489     fgic->SetLatitudeRadIC( lat_geoc );
490     needTrim=true;
491 }
492
493 void FGJSBsim::set_Longitude(double lon) {
494
495     SG_LOG(SG_FLIGHT,SG_INFO,"FGJSBsim::set_Longitude: " << lon );
496
497     fgic->SetLongitudeRadIC( lon );
498     needTrim=true;
499 }
500
501 void FGJSBsim::set_Altitude(double alt) {
502     static const SGPropertyNode *latitude
503         = fgGetNode("/position/latitude-deg");
504
505     double sea_level_radius_meters,lat_geoc;
506
507     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Altitude: " << alt );
508     SG_LOG(SG_FLIGHT,SG_INFO, "  lat (deg) = " << latitude->getDoubleValue() );
509
510     sgGeodToGeoc( latitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS, alt,
511                   &sea_level_radius_meters, &lat_geoc);
512     _set_Sea_level_radius( sea_level_radius_meters * SG_METER_TO_FEET  );
513     fgic->SetSeaLevelRadiusFtIC( sea_level_radius_meters * SG_METER_TO_FEET );
514     fgic->SetLatitudeRadIC( lat_geoc );
515     fgic->SetAltitudeFtIC(alt);
516     needTrim=true;
517 }
518
519 void FGJSBsim::set_V_calibrated_kts(double vc) {
520     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_V_calibrated_kts: " <<  vc );
521
522     fgic->SetVcalibratedKtsIC(vc);
523     needTrim=true;
524 }
525
526 void FGJSBsim::set_Mach_number(double mach) {
527     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Mach_number: " <<  mach );
528
529     fgic->SetMachIC(mach);
530     needTrim=true;
531 }
532
533 void FGJSBsim::set_Velocities_Local( double north, double east, double down ){
534     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Velocities_Local: "
535        << north << ", " <<  east << ", " << down );
536
537     fgic->SetVnorthFpsIC(north);
538     fgic->SetVeastFpsIC(east);
539     fgic->SetVdownFpsIC(down);
540     needTrim=true;
541 }
542
543 void FGJSBsim::set_Velocities_Wind_Body( double u, double v, double w){
544     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Velocities_Wind_Body: "
545        << u << ", " <<  v << ", " <<  w );
546
547     fgic->SetUBodyFpsIC(u);
548     fgic->SetVBodyFpsIC(v);
549     fgic->SetWBodyFpsIC(w);
550     needTrim=true;
551 }
552
553 //Euler angles
554 void FGJSBsim::set_Euler_Angles( double phi, double theta, double psi ) {
555     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Euler_Angles: "
556        << phi << ", " << theta << ", " << psi );
557
558     fgic->SetPitchAngleRadIC(theta);
559     fgic->SetRollAngleRadIC(phi);
560     fgic->SetTrueHeadingRadIC(psi);
561     needTrim=true;
562 }
563
564 //Flight Path
565 void FGJSBsim::set_Climb_Rate( double roc) {
566     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Climb_Rate: " << roc );
567
568     fgic->SetClimbRateFpsIC(roc);
569     needTrim=true;
570 }
571
572 void FGJSBsim::set_Gamma_vert_rad( double gamma) {
573     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Gamma_vert_rad: " << gamma );
574
575     fgic->SetFlightPathAngleRadIC(gamma);
576     needTrim=true;
577 }
578
579 //Earth
580 void FGJSBsim::set_Sea_level_radius(double slr) {
581     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Sea_level_radius: " << slr );
582
583     fgic->SetSeaLevelRadiusFtIC(slr);
584     needTrim=true;
585 }
586
587 void FGJSBsim::set_Runway_altitude(double ralt) {
588     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Runway_altitude: " << ralt );
589
590     _set_Runway_altitude( ralt );
591     fgic->SetTerrainAltitudeFtIC( ralt );
592     needTrim=true;
593 }
594
595 void FGJSBsim::set_Static_pressure(double p) {
596     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Static_pressure: " << p );
597
598     Atmosphere->SetExPressure(p);
599     if(Atmosphere->External() == true)
600     needTrim=true;
601 }
602
603 void FGJSBsim::set_Static_temperature(double T) {
604     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Static_temperature: " << T );
605     
606     Atmosphere->SetExTemperature(T);
607     if(Atmosphere->External() == true)
608     needTrim=true;
609 }
610  
611
612 void FGJSBsim::set_Density(double rho) {
613     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Density: " << rho );
614     
615     Atmosphere->SetExDensity(rho);
616     if(Atmosphere->External() == true)
617     needTrim=true;
618 }
619   
620
621 void FGJSBsim::set_Velocities_Local_Airmass (double wnorth, 
622                          double weast, 
623                          double wdown ) {
624     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Velocities_Local_Airmass: " 
625        << wnorth << ", " << weast << ", " << wdown );
626     
627     _set_Velocities_Local_Airmass( wnorth, weast, wdown );
628     Atmosphere->SetWindNED(wnorth, weast, wdown );
629     if(Atmosphere->External() == true)
630         needTrim=true;
631 }     
632
633
634 //Positions
635 void FGJSBsim::update_Latitude(double lat) {
636     double sea_level_radius_meters, lat_geoc;
637
638     SG_LOG(SG_FLIGHT,SG_INFO,"FGJSBsim::update_Latitude: " << lat );
639     SG_LOG(SG_FLIGHT,SG_INFO," cur alt =  " << get_Altitude() );
640
641     snap_shot();
642     sgGeodToGeoc( lat, get_Altitude(), &sea_level_radius_meters, &lat_geoc);
643     _set_Sea_level_radius( sea_level_radius_meters * SG_METER_TO_FEET  );
644     fgic->SetSeaLevelRadiusFtIC( sea_level_radius_meters * SG_METER_TO_FEET  );
645     fgic->SetLatitudeRadIC( lat_geoc );
646     fdmex->RunIC(fgic); //loop JSBSim once
647     copy_from_JSBsim(); //update the bus
648     needTrim=true;
649 }
650
651 void FGJSBsim::update_Longitude(double lon) {
652
653     SG_LOG(SG_FLIGHT,SG_INFO,"FGJSBsim::update_Longitude: " << lon );
654     SG_LOG(SG_FLIGHT,SG_INFO," cur alt =  " << get_Altitude() );
655
656     snap_shot();
657     fgic->SetLongitudeRadIC(lon);
658     fdmex->RunIC(fgic); //loop JSBSim once
659     copy_from_JSBsim(); //update the bus
660     needTrim=true;
661 }
662
663 void FGJSBsim::update_Altitude(double alt) {
664     double sea_level_radius_meters,lat_geoc;
665
666     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::update_Altitude: " << alt );
667
668     snap_shot();
669     sgGeodToGeoc( get_Latitude(), alt , &sea_level_radius_meters, &lat_geoc);
670     _set_Sea_level_radius( sea_level_radius_meters * SG_METER_TO_FEET  );
671     fgic->SetSeaLevelRadiusFtIC( sea_level_radius_meters * SG_METER_TO_FEET );
672     fgic->SetLatitudeRadIC( lat_geoc );
673     fgic->SetAltitudeFtIC(alt);
674     fdmex->RunIC(fgic); //loop JSBSim once
675     copy_from_JSBsim(); //update the bus
676     needTrim=true;
677 }
678
679 void FGJSBsim::update_V_calibrated_kts(double vc) {
680     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::update_V_calibrated_kts: " <<  vc );
681
682     snap_shot();
683     fgic->SetVcalibratedKtsIC(vc);
684     fdmex->RunIC(fgic); //loop JSBSim once
685     copy_from_JSBsim(); //update the bus
686     needTrim=true;
687 }
688
689 void FGJSBsim::update_Mach_number(double mach) {
690     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::update_Mach_number: " <<  mach );
691
692     snap_shot();
693     fgic->SetMachIC(mach);
694     fdmex->RunIC(fgic); //loop JSBSim once
695     copy_from_JSBsim(); //update the bus
696     needTrim=true;
697 }
698
699 void FGJSBsim::update_Velocities_Local( double north, double east, double down ){
700     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::update_Velocities_Local: "
701        << north << ", " <<  east << ", " << down );
702
703     snap_shot();
704     fgic->SetVnorthFpsIC(north);
705     fgic->SetVeastFpsIC(east);
706     fgic->SetVdownFpsIC(down);
707     fdmex->RunIC(fgic); //loop JSBSim once
708     copy_from_JSBsim(); //update the bus
709     needTrim=true;
710 }
711
712 void FGJSBsim::update_Velocities_Wind_Body( double u, double v, double w){
713     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::update_Velocities_Wind_Body: "
714        << u << ", " <<  v << ", " <<  w );
715
716     snap_shot();
717     fgic->SetUBodyFpsIC(u);
718     fgic->SetVBodyFpsIC(v);
719     fgic->SetWBodyFpsIC(w);
720     fdmex->RunIC(fgic); //loop JSBSim once
721     copy_from_JSBsim(); //update the bus
722     needTrim=true;
723 }
724
725 //Euler angles
726 void FGJSBsim::update_Euler_Angles( double phi, double theta, double psi ) {
727     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::update_Euler_Angles: "
728        << phi << ", " << theta << ", " << psi );
729
730     snap_shot();
731     fgic->SetPitchAngleRadIC(theta);
732     fgic->SetRollAngleRadIC(phi);
733     fgic->SetTrueHeadingRadIC(psi);
734     fdmex->RunIC(fgic); //loop JSBSim once
735     copy_from_JSBsim(); //update the bus
736     needTrim=true;
737 }
738
739 //Flight Path
740 void FGJSBsim::update_Climb_Rate( double roc) {
741     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::update_Climb_Rate: " << roc );
742
743     snap_shot();
744     fgic->SetClimbRateFpsIC(roc);
745     fdmex->RunIC(fgic); //loop JSBSim once
746     copy_from_JSBsim(); //update the bus
747     needTrim=true;
748 }
749
750 void FGJSBsim::update_Gamma_vert_rad( double gamma) {
751     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::update_Gamma_vert_rad: " << gamma );
752
753     snap_shot();
754     fgic->SetFlightPathAngleRadIC(gamma);
755     fdmex->RunIC(fgic); //loop JSBSim once
756     copy_from_JSBsim(); //update the bus
757     needTrim=true;
758 }
759
760 //Earth
761 void FGJSBsim::update_Sea_level_radius(double slr) {
762     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::update_Sea_level_radius: " << slr );
763
764     snap_shot();
765     fgic->SetSeaLevelRadiusFtIC(slr);
766     fdmex->RunIC(fgic); //loop JSBSim once
767     copy_from_JSBsim(); //update the bus
768     needTrim=true;
769 }
770
771 void FGJSBsim::update_Runway_altitude(double ralt) {
772     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::update_Runway_altitude: " << ralt );
773
774     snap_shot();
775     _set_Runway_altitude( ralt );
776     fgic->SetTerrainAltitudeFtIC( ralt );
777     fdmex->RunIC(fgic); //loop JSBSim once
778     copy_from_JSBsim(); //update the bus
779     needTrim=true;
780 }
781
782 void FGJSBsim::update_Static_pressure(double p) {
783     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::update_Static_pressure: " << p );
784
785     snap_shot();
786     Atmosphere->SetExPressure(p);
787     if(Atmosphere->External() == true)
788     needTrim=true;
789 }
790
791 void FGJSBsim::update_Static_temperature(double T) {
792     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::update_Static_temperature: " << T );
793     
794     snap_shot();
795     Atmosphere->SetExTemperature(T);
796     if(Atmosphere->External() == true)
797     needTrim=true;
798 }
799  
800
801 void FGJSBsim::update_Density(double rho) {
802     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::update_Density: " << rho );
803     
804     snap_shot();
805     Atmosphere->SetExDensity(rho);
806     if(Atmosphere->External() == true)
807     needTrim=true;
808 }
809   
810
811 void FGJSBsim::update_Velocities_Local_Airmass (double wnorth, 
812                          double weast, 
813                          double wdown ) {
814     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::update_Velocities_Local_Airmass: " 
815        << wnorth << ", " << weast << ", " << wdown );
816     
817     _set_Velocities_Local_Airmass( wnorth, weast, wdown );
818     snap_shot();
819     Atmosphere->SetWindNED(wnorth, weast, wdown );
820     if(Atmosphere->External() == true)
821         needTrim=true;
822 }     
823