]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim.cxx
Additional changes including updates to JSBSim to try to get interface and
[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       e->set_Manifold_Pressure( eng->getManifoldPressure_inHg() );
271       e->set_RPM( thrust->GetRPM() );
272       e->set_EGT( eng->getExhaustGasTemp_degF() );
273       e->set_CHT( eng->getCylinderHeadTemp_degF() );
274       e->set_Oil_Temp( eng->getOilTemp_degF() );
275       e->set_Throttle( globals->get_controls()->get_throttle(i) );
276     }
277
278     for ( i=0; i < multiloop; i++ ) {
279         fdmex->Run();
280     }
281
282     // printf("%d FG_Altitude = %.2f\n", i, FG_Altitude * 0.3048);
283     // printf("%d Altitude = %.2f\n", i, Altitude * 0.3048);
284
285     // translate JSBsim back to FG structure so that the
286     // autopilot (and the rest of the sim can use the updated values
287
288     copy_from_JSBsim();
289     return true;
290 }
291
292 /******************************************************************************/
293
294 // Convert from the FGInterface struct to the JSBsim generic_ struct
295
296 bool FGJSBsim::copy_to_JSBsim() {
297     // copy control positions into the JSBsim structure
298
299     FCS->SetDaCmd( globals->get_controls()->get_aileron());
300     FCS->SetDeCmd( globals->get_controls()->get_elevator());
301     FCS->SetPitchTrimCmd(globals->get_controls()->get_elevator_trim());
302     FCS->SetDrCmd( -globals->get_controls()->get_rudder());
303     FCS->SetDfCmd(  globals->get_controls()->get_flaps() );
304     FCS->SetDsbCmd( 0.0 ); //speedbrakes
305     FCS->SetDspCmd( 0.0 ); //spoilers
306     FCS->SetLBrake( globals->get_controls()->get_brake( 0 ) );
307     FCS->SetRBrake( globals->get_controls()->get_brake( 1 ) );
308     FCS->SetCBrake( globals->get_controls()->get_brake( 2 ) );
309     for (int i = 0; i < get_num_engines(); i++) {
310       FCS->SetThrottleCmd(i, globals->get_controls()->get_throttle(i));
311       FCS->SetMixtureCmd(i, globals->get_controls()->get_mixture(i));
312     }
313
314     Position->SetSeaLevelRadius( get_Sea_level_radius() );
315     Position->SetRunwayRadius( scenery.get_cur_elev()*SG_METER_TO_FEET
316                                + get_Sea_level_radius() );
317
318     Atmosphere->SetExTemperature(get_Static_temperature());
319     Atmosphere->SetExPressure(get_Static_pressure());
320     Atmosphere->SetExDensity(get_Density());
321     Atmosphere->SetWindNED(get_V_north_airmass(),
322                            get_V_east_airmass(),
323                            get_V_down_airmass());
324 //    SG_LOG(SG_FLIGHT,SG_INFO, "Wind NED: "
325 //                  << get_V_north_airmass() << ", "
326 //                  << get_V_east_airmass()  << ", "
327 //                  << get_V_down_airmass() );
328
329     return true;
330 }
331
332 /******************************************************************************/
333
334 // Convert from the JSBsim generic_ struct to the FGInterface struct
335
336 bool FGJSBsim::copy_from_JSBsim() {
337     unsigned int i, j;
338
339     _set_Inertias( MassBalance->GetMass(),
340                    MassBalance->GetIxx(),
341                    MassBalance->GetIyy(),
342                    MassBalance->GetIzz(),
343                    MassBalance->GetIxz() );
344
345     _set_CG_Position( MassBalance->GetXYZcg(1),
346                       MassBalance->GetXYZcg(2),
347                       MassBalance->GetXYZcg(3) );
348
349     _set_Accels_Body( Translation->GetUVWdot(1),
350                       Translation->GetUVWdot(2),
351                       Translation->GetUVWdot(3) );
352
353     _set_Accels_CG_Body( Translation->GetUVWdot(1),
354                          Translation->GetUVWdot(2),
355                          Translation->GetUVWdot(3) );
356
357     //_set_Accels_CG_Body_N ( Translation->GetNcg(1),
358     //                       Translation->GetNcg(2),
359     //                       Translation->GetNcg(3) );
360     //
361     _set_Accels_Pilot_Body( Auxiliary->GetPilotAccel(1),
362                             Auxiliary->GetPilotAccel(2),
363                             Auxiliary->GetPilotAccel(3) );
364
365     //_set_Accels_Pilot_Body_N( Auxiliary->GetNpilot(1),
366     //                         Auxiliary->GetNpilot(2),
367     //                         Auxiliary->GetNpilot(3) );
368
369     _set_Nlf( Aerodynamics->GetNlf() );
370
371     // Velocities
372
373     _set_Velocities_Local( Position->GetVn(),
374                            Position->GetVe(),
375                            Position->GetVd() );
376
377     _set_Velocities_Wind_Body( Translation->GetUVW(1),
378                                Translation->GetUVW(2),
379                                Translation->GetUVW(3) );
380
381     _set_V_rel_wind( Translation->GetVt() );
382
383     _set_V_equiv_kts( Auxiliary->GetVequivalentKTS() );
384
385     // _set_V_calibrated( Auxiliary->GetVcalibratedFPS() );
386
387     _set_V_calibrated_kts( Auxiliary->GetVcalibratedKTS() );
388
389     _set_V_ground_speed( Position->GetVground() );
390
391     _set_Omega_Body( Rotation->GetPQR(1),
392                      Rotation->GetPQR(2),
393                      Rotation->GetPQR(3) );
394
395     _set_Euler_Rates( Rotation->GetEulerRates(1),
396                       Rotation->GetEulerRates(2),
397                       Rotation->GetEulerRates(3) );
398
399     _set_Geocentric_Rates(Position->GetLatitudeDot(),
400                           Position->GetLongitudeDot(),
401                           Position->Gethdot() );
402
403     _set_Mach_number( Translation->GetMach() );
404
405     // Positions
406     _updatePosition( Position->GetLatitude(),
407                      Position->GetLongitude(),
408                      Position->Geth() );
409
410     _set_Altitude_AGL( Position->GetDistanceAGL() );
411
412     _set_Euler_Angles( Rotation->Getphi(),
413                        Rotation->Gettht(),
414                        Rotation->Getpsi() );
415
416     _set_Alpha( Translation->Getalpha() );
417     _set_Beta( Translation->Getbeta() );
418
419
420     _set_Gamma_vert_rad( Position->GetGamma() );
421     // set_Gamma_horiz_rad( Gamma_horiz_rad );
422
423     _set_Earth_position_angle( Auxiliary->GetEarthPositionAngle() );
424
425     _set_Climb_Rate( Position->Gethdot() );
426
427
428     for ( i = 1; i <= 3; i++ ) {
429         for ( j = 1; j <= 3; j++ ) {
430             _set_T_Local_to_Body( i, j, State->GetTl2b(i,j) );
431         }
432     }
433     return true;
434 }
435
436 void FGJSBsim::snap_shot(void) {
437     fgic->SetLatitudeRadIC(get_Lat_geocentric() );
438     fgic->SetLongitudeRadIC( get_Longitude() );
439     fgic->SetAltitudeFtIC( get_Altitude() );
440     fgic->SetTerrainAltitudeFtIC( get_Runway_altitude() );
441     fgic->SetVtrueFpsIC( get_V_rel_wind() );
442     fgic->SetPitchAngleRadIC( get_Theta() );
443     fgic->SetRollAngleRadIC( get_Phi() );
444     fgic->SetTrueHeadingRadIC( get_Psi() );
445     fgic->SetClimbRateFpsIC( get_Climb_Rate() );
446 }
447
448
449 bool FGJSBsim::ToggleDataLogging(void) {
450     return fdmex->GetOutput()->Toggle();
451 }
452
453
454 bool FGJSBsim::ToggleDataLogging(bool state) {
455     if (state) {
456       fdmex->GetOutput()->Enable();
457       return true;
458     } else {
459       fdmex->GetOutput()->Disable();
460       return false;
461     }
462 }
463
464
465 //Positions
466 void FGJSBsim::set_Latitude(double lat) {
467     static const SGPropertyNode *altitude
468         = fgGetNode("/position/altitude-ft");
469     double alt;
470     if ( altitude->getDoubleValue() > -9990 ) {
471         alt = altitude->getDoubleValue();
472     } else {
473         alt = 0.0;
474     }
475
476     double sea_level_radius_meters, lat_geoc;
477
478     SG_LOG(SG_FLIGHT,SG_INFO,"FGJSBsim::set_Latitude: " << lat );
479     SG_LOG(SG_FLIGHT,SG_INFO," cur alt (ft) =  " << alt );
480
481     sgGeodToGeoc( lat, alt * SG_FEET_TO_METER,
482                   &sea_level_radius_meters, &lat_geoc );
483     _set_Sea_level_radius( sea_level_radius_meters * SG_METER_TO_FEET  );
484     fgic->SetSeaLevelRadiusFtIC( sea_level_radius_meters * SG_METER_TO_FEET  );
485     fgic->SetLatitudeRadIC( lat_geoc );
486     needTrim=true;
487 }
488
489 void FGJSBsim::set_Longitude(double lon) {
490
491     SG_LOG(SG_FLIGHT,SG_INFO,"FGJSBsim::set_Longitude: " << lon );
492
493     fgic->SetLongitudeRadIC( lon );
494     needTrim=true;
495 }
496
497 void FGJSBsim::set_Altitude(double alt) {
498     static const SGPropertyNode *latitude
499         = fgGetNode("/position/latitude-deg");
500
501     double sea_level_radius_meters,lat_geoc;
502
503     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Altitude: " << alt );
504     SG_LOG(SG_FLIGHT,SG_INFO, "  lat (deg) = " << latitude->getDoubleValue() );
505
506     sgGeodToGeoc( latitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS, alt,
507                   &sea_level_radius_meters, &lat_geoc);
508     _set_Sea_level_radius( sea_level_radius_meters * SG_METER_TO_FEET  );
509     fgic->SetSeaLevelRadiusFtIC( sea_level_radius_meters * SG_METER_TO_FEET );
510     fgic->SetLatitudeRadIC( lat_geoc );
511     fgic->SetAltitudeFtIC(alt);
512     needTrim=true;
513 }
514
515 void FGJSBsim::set_V_calibrated_kts(double vc) {
516     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_V_calibrated_kts: " <<  vc );
517
518     fgic->SetVcalibratedKtsIC(vc);
519     needTrim=true;
520 }
521
522 void FGJSBsim::set_Mach_number(double mach) {
523     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Mach_number: " <<  mach );
524
525     fgic->SetMachIC(mach);
526     needTrim=true;
527 }
528
529 void FGJSBsim::set_Velocities_Local( double north, double east, double down ){
530     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Velocities_Local: "
531        << north << ", " <<  east << ", " << down );
532
533     fgic->SetVnorthFpsIC(north);
534     fgic->SetVeastFpsIC(east);
535     fgic->SetVdownFpsIC(down);
536     needTrim=true;
537 }
538
539 void FGJSBsim::set_Velocities_Wind_Body( double u, double v, double w){
540     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Velocities_Wind_Body: "
541        << u << ", " <<  v << ", " <<  w );
542
543     fgic->SetUBodyFpsIC(u);
544     fgic->SetVBodyFpsIC(v);
545     fgic->SetWBodyFpsIC(w);
546     needTrim=true;
547 }
548
549 //Euler angles
550 void FGJSBsim::set_Euler_Angles( double phi, double theta, double psi ) {
551     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Euler_Angles: "
552        << phi << ", " << theta << ", " << psi );
553
554     fgic->SetPitchAngleRadIC(theta);
555     fgic->SetRollAngleRadIC(phi);
556     fgic->SetTrueHeadingRadIC(psi);
557     needTrim=true;
558 }
559
560 //Flight Path
561 void FGJSBsim::set_Climb_Rate( double roc) {
562     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Climb_Rate: " << roc );
563
564     fgic->SetClimbRateFpsIC(roc);
565     needTrim=true;
566 }
567
568 void FGJSBsim::set_Gamma_vert_rad( double gamma) {
569     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Gamma_vert_rad: " << gamma );
570
571     fgic->SetFlightPathAngleRadIC(gamma);
572     needTrim=true;
573 }
574
575 //Earth
576 void FGJSBsim::set_Sea_level_radius(double slr) {
577     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Sea_level_radius: " << slr );
578
579     fgic->SetSeaLevelRadiusFtIC(slr);
580     needTrim=true;
581 }
582
583 void FGJSBsim::set_Runway_altitude(double ralt) {
584     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Runway_altitude: " << ralt );
585
586     _set_Runway_altitude( ralt );
587     fgic->SetTerrainAltitudeFtIC( ralt );
588     needTrim=true;
589 }
590
591 void FGJSBsim::set_Static_pressure(double p) {
592     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Static_pressure: " << p );
593
594     Atmosphere->SetExPressure(p);
595     if(Atmosphere->External() == true)
596     needTrim=true;
597 }
598
599 void FGJSBsim::set_Static_temperature(double T) {
600     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Static_temperature: " << T );
601     
602     Atmosphere->SetExTemperature(T);
603     if(Atmosphere->External() == true)
604     needTrim=true;
605 }
606  
607
608 void FGJSBsim::set_Density(double rho) {
609     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Density: " << rho );
610     
611     Atmosphere->SetExDensity(rho);
612     if(Atmosphere->External() == true)
613     needTrim=true;
614 }
615   
616
617 void FGJSBsim::set_Velocities_Local_Airmass (double wnorth, 
618                          double weast, 
619                          double wdown ) {
620     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Velocities_Local_Airmass: " 
621        << wnorth << ", " << weast << ", " << wdown );
622     
623     _set_Velocities_Local_Airmass( wnorth, weast, wdown );
624     Atmosphere->SetWindNED(wnorth, weast, wdown );
625     if(Atmosphere->External() == true)
626         needTrim=true;
627 }     
628
629
630 //Positions
631 void FGJSBsim::update_Latitude(double lat) {
632     double sea_level_radius_meters, lat_geoc;
633
634     SG_LOG(SG_FLIGHT,SG_INFO,"FGJSBsim::update_Latitude: " << lat );
635     SG_LOG(SG_FLIGHT,SG_INFO," cur alt =  " << get_Altitude() );
636
637     snap_shot();
638     sgGeodToGeoc( lat, get_Altitude(), &sea_level_radius_meters, &lat_geoc);
639     _set_Sea_level_radius( sea_level_radius_meters * SG_METER_TO_FEET  );
640     fgic->SetSeaLevelRadiusFtIC( sea_level_radius_meters * SG_METER_TO_FEET  );
641     fgic->SetLatitudeRadIC( lat_geoc );
642     fdmex->RunIC(fgic); //loop JSBSim once
643     copy_from_JSBsim(); //update the bus
644     needTrim=true;
645 }
646
647 void FGJSBsim::update_Longitude(double lon) {
648
649     SG_LOG(SG_FLIGHT,SG_INFO,"FGJSBsim::update_Longitude: " << lon );
650     SG_LOG(SG_FLIGHT,SG_INFO," cur alt =  " << get_Altitude() );
651
652     snap_shot();
653     fgic->SetLongitudeRadIC(lon);
654     fdmex->RunIC(fgic); //loop JSBSim once
655     copy_from_JSBsim(); //update the bus
656     needTrim=true;
657 }
658
659 void FGJSBsim::update_Altitude(double alt) {
660     double sea_level_radius_meters,lat_geoc;
661
662     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::update_Altitude: " << alt );
663
664     snap_shot();
665     sgGeodToGeoc( get_Latitude(), alt , &sea_level_radius_meters, &lat_geoc);
666     _set_Sea_level_radius( sea_level_radius_meters * SG_METER_TO_FEET  );
667     fgic->SetSeaLevelRadiusFtIC( sea_level_radius_meters * SG_METER_TO_FEET );
668     fgic->SetLatitudeRadIC( lat_geoc );
669     fgic->SetAltitudeFtIC(alt);
670     fdmex->RunIC(fgic); //loop JSBSim once
671     copy_from_JSBsim(); //update the bus
672     needTrim=true;
673 }
674
675 void FGJSBsim::update_V_calibrated_kts(double vc) {
676     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::update_V_calibrated_kts: " <<  vc );
677
678     snap_shot();
679     fgic->SetVcalibratedKtsIC(vc);
680     fdmex->RunIC(fgic); //loop JSBSim once
681     copy_from_JSBsim(); //update the bus
682     needTrim=true;
683 }
684
685 void FGJSBsim::update_Mach_number(double mach) {
686     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::update_Mach_number: " <<  mach );
687
688     snap_shot();
689     fgic->SetMachIC(mach);
690     fdmex->RunIC(fgic); //loop JSBSim once
691     copy_from_JSBsim(); //update the bus
692     needTrim=true;
693 }
694
695 void FGJSBsim::update_Velocities_Local( double north, double east, double down ){
696     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::update_Velocities_Local: "
697        << north << ", " <<  east << ", " << down );
698
699     snap_shot();
700     fgic->SetVnorthFpsIC(north);
701     fgic->SetVeastFpsIC(east);
702     fgic->SetVdownFpsIC(down);
703     fdmex->RunIC(fgic); //loop JSBSim once
704     copy_from_JSBsim(); //update the bus
705     needTrim=true;
706 }
707
708 void FGJSBsim::update_Velocities_Wind_Body( double u, double v, double w){
709     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::update_Velocities_Wind_Body: "
710        << u << ", " <<  v << ", " <<  w );
711
712     snap_shot();
713     fgic->SetUBodyFpsIC(u);
714     fgic->SetVBodyFpsIC(v);
715     fgic->SetWBodyFpsIC(w);
716     fdmex->RunIC(fgic); //loop JSBSim once
717     copy_from_JSBsim(); //update the bus
718     needTrim=true;
719 }
720
721 //Euler angles
722 void FGJSBsim::update_Euler_Angles( double phi, double theta, double psi ) {
723     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::update_Euler_Angles: "
724        << phi << ", " << theta << ", " << psi );
725
726     snap_shot();
727     fgic->SetPitchAngleRadIC(theta);
728     fgic->SetRollAngleRadIC(phi);
729     fgic->SetTrueHeadingRadIC(psi);
730     fdmex->RunIC(fgic); //loop JSBSim once
731     copy_from_JSBsim(); //update the bus
732     needTrim=true;
733 }
734
735 //Flight Path
736 void FGJSBsim::update_Climb_Rate( double roc) {
737     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::update_Climb_Rate: " << roc );
738
739     snap_shot();
740     fgic->SetClimbRateFpsIC(roc);
741     fdmex->RunIC(fgic); //loop JSBSim once
742     copy_from_JSBsim(); //update the bus
743     needTrim=true;
744 }
745
746 void FGJSBsim::update_Gamma_vert_rad( double gamma) {
747     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::update_Gamma_vert_rad: " << gamma );
748
749     snap_shot();
750     fgic->SetFlightPathAngleRadIC(gamma);
751     fdmex->RunIC(fgic); //loop JSBSim once
752     copy_from_JSBsim(); //update the bus
753     needTrim=true;
754 }
755
756 //Earth
757 void FGJSBsim::update_Sea_level_radius(double slr) {
758     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::update_Sea_level_radius: " << slr );
759
760     snap_shot();
761     fgic->SetSeaLevelRadiusFtIC(slr);
762     fdmex->RunIC(fgic); //loop JSBSim once
763     copy_from_JSBsim(); //update the bus
764     needTrim=true;
765 }
766
767 void FGJSBsim::update_Runway_altitude(double ralt) {
768     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::update_Runway_altitude: " << ralt );
769
770     snap_shot();
771     _set_Runway_altitude( ralt );
772     fgic->SetTerrainAltitudeFtIC( ralt );
773     fdmex->RunIC(fgic); //loop JSBSim once
774     copy_from_JSBsim(); //update the bus
775     needTrim=true;
776 }
777
778 void FGJSBsim::update_Static_pressure(double p) {
779     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::update_Static_pressure: " << p );
780
781     snap_shot();
782     Atmosphere->SetExPressure(p);
783     if(Atmosphere->External() == true)
784     needTrim=true;
785 }
786
787 void FGJSBsim::update_Static_temperature(double T) {
788     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::update_Static_temperature: " << T );
789     
790     snap_shot();
791     Atmosphere->SetExTemperature(T);
792     if(Atmosphere->External() == true)
793     needTrim=true;
794 }
795  
796
797 void FGJSBsim::update_Density(double rho) {
798     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::update_Density: " << rho );
799     
800     snap_shot();
801     Atmosphere->SetExDensity(rho);
802     if(Atmosphere->External() == true)
803     needTrim=true;
804 }
805   
806
807 void FGJSBsim::update_Velocities_Local_Airmass (double wnorth, 
808                          double weast, 
809                          double wdown ) {
810     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::update_Velocities_Local_Airmass: " 
811        << wnorth << ", " << weast << ", " << wdown );
812     
813     _set_Velocities_Local_Airmass( wnorth, weast, wdown );
814     snap_shot();
815     Atmosphere->SetWindNED(wnorth, weast, wdown );
816     if(Atmosphere->External() == true)
817         needTrim=true;
818 }     
819