]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim.cxx
Data logging patches from Jon Berndt
[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
57 #include "JSBSim.hxx"
58
59 /******************************************************************************/
60
61 FGJSBsim::FGJSBsim( double dt ) 
62   : FGInterface(dt)
63 {
64     bool result;
65    
66     fdmex=new FGFDMExec;
67     fgic=new FGInitialCondition(fdmex);
68     needTrim=true;
69   
70     SGPath aircraft_path( globals->get_fg_root() );
71     aircraft_path.append( "Aircraft" );
72
73     SGPath engine_path( globals->get_fg_root() );
74     engine_path.append( "Engine" );
75     set_delta_t( dt );
76     fdmex->GetState()->Setdt( dt );
77
78     result = fdmex->LoadModel( aircraft_path.str(),
79                                engine_path.str(),
80                                fgGetString("/sim/aircraft") );
81     int Neng=fdmex->GetPropulsion()->GetNumEngines();
82 //     int Neng=fdmex->GetAircraft()->GetNumEngines();
83     SG_LOG(SG_FLIGHT,SG_INFO, "Neng: " << Neng );
84     for(int i=0;i<Neng;i++) {
85         add_engine( FGEngInterface() );
86     }  
87     
88     fgSetDouble("/fdm/trim/pitch-trim", fdmex->GetFCS()->GetPitchTrimCmd());
89     fgSetDouble("/fdm/trim/throttle", fdmex->GetFCS()->GetThrottleCmd(0));
90     fgSetDouble("/fdm/trim/aileron", fdmex->GetFCS()->GetDaCmd());
91     fgSetDouble("/fdm/trim/rudder", fdmex->GetFCS()->GetDrCmd());
92
93     trimmed = fgGetValue("/fdm/trim/trimmed",true);
94     trimmed->setBoolValue(false);
95
96 }
97
98 /******************************************************************************/
99 FGJSBsim::~FGJSBsim(void) {
100     if(fdmex != NULL) {
101         delete fdmex;
102         delete fgic;
103     }  
104 }
105
106 /******************************************************************************/
107
108 // Initialize the JSBsim flight model, dt is the time increment for
109 // each subsequent iteration through the EOM
110
111 void FGJSBsim::init() {
112
113     bool result;
114
115     SG_LOG( SG_FLIGHT, SG_INFO, "Starting and initializing JSBsim" );
116
117 #if 0
118     SGPath aircraft_path( globals->get_fg_root() );
119     aircraft_path.append( "Aircraft" );
120
121     SGPath engine_path( globals->get_fg_root() );
122     engine_path.append( "Engine" );
123
124     fdmex->GetState()->Setdt( get_delta_t() );
125
126     result = fdmex->LoadModel( aircraft_path.str(),
127                                engine_path.str(),
128                                fgGetString("/sim/aircraft") );
129
130     if (result) {
131         SG_LOG( SG_FLIGHT, SG_INFO, "  loaded aircraft " << fgGetString("/sim/aircraft") );
132     } else {
133         SG_LOG( SG_FLIGHT, SG_INFO, "  aircraft "
134                 << fgGetString("/sim/aircraft")
135                 << " does not exist" );
136         exit(-1);
137     }
138 #endif    
139
140     fdmex->GetAtmosphere()->UseInternal();
141   
142     SG_LOG( SG_FLIGHT, SG_INFO, "  Initializing JSBSim with:" );
143     switch(fgic->GetSpeedSet()) {
144     case setned:
145         SG_LOG(SG_FLIGHT,SG_INFO, "  Vn,Ve,Vd= " 
146                << fdmex->GetPosition()->GetVn()
147                << ", " << fdmex->GetPosition()->GetVe()
148                << ", " << fdmex->GetPosition()->GetVd()
149                << " ft/s");
150         break;       
151     case setuvw:
152         SG_LOG(SG_FLIGHT,SG_INFO, "  U,V,W= " 
153                << fdmex->GetTranslation()->GetUVW()(1)
154                << ", " << fdmex->GetTranslation()->GetUVW()(2)
155                << ", " << fdmex->GetTranslation()->GetUVW()(3)
156                << " ft/s");
157         break;       
158     case setmach:
159         SG_LOG(SG_FLIGHT,SG_INFO, "  Mach: " 
160                << fdmex->GetTranslation()->GetMach() );
161         break;
162     case setvc:
163     default:
164         SG_LOG(SG_FLIGHT,SG_INFO, "  Indicated Airspeed: " 
165                << fdmex->GetAuxiliary()->GetVcalibratedKTS() << " knots" );
166       
167     }
168
169     SG_LOG( SG_FLIGHT, SG_INFO, "  Bank Angle: " 
170             <<  fdmex->GetRotation()->Getphi()*RADTODEG << " deg");
171     SG_LOG( SG_FLIGHT, SG_INFO, "  Pitch Angle: " 
172             << fdmex->GetRotation()->Gettht()*RADTODEG << " deg"  );
173     SG_LOG( SG_FLIGHT, SG_INFO, "  True Heading: " 
174             << fdmex->GetRotation()->Getpsi()*RADTODEG << " deg"  );
175     SG_LOG( SG_FLIGHT, SG_INFO, "  Latitude: " 
176             <<  fdmex->GetPosition()->GetLatitude() << " deg" );
177     SG_LOG( SG_FLIGHT, SG_INFO, "  Longitude: " 
178             <<  fdmex->GetPosition()->GetLongitude() << " deg"  );
179   
180     // for debug only
181     /* SG_LOG( SG_FLIGHT, SG_DEBUG, "  FGJSBSim::get_Altitude(): " <<  get_Altitude() );
182        SG_LOG( SG_FLIGHT, SG_DEBUG, "  FGJSBSim::get_Sea_level_radius(): " << get_Sea_level_radius()  );
183        SG_LOG( SG_FLIGHT, SG_DEBUG, "  scenery.cur_radius*SG_METER_TO_FEET: "
184        <<  scenery.cur_radius*SG_METER_TO_FEET );
185        SG_LOG( SG_FLIGHT, SG_DEBUG, "  Calculated Terrain ASL: " << endl 
186        << "    " << "scenery.cur_radius*SG_METER_TO_FEET -get_Sea_level_radius()= " 
187        <<  scenery.cur_radius*SG_METER_TO_FEET - get_Sea_level_radius()  );
188
189        SG_LOG( SG_FLIGHT, SG_DEBUG, "  Calculated Aircraft AGL: " << endl 
190        << "    " << "get_Altitude() + get_Sea_level_radius() - scenery.cur_radius*SG_METER_TO_FEET= " 
191        <<  get_Altitude() + get_Sea_level_radius()- scenery.cur_radius*SG_METER_TO_FEET );
192        SG_LOG( SG_FLIGHT, SG_DEBUG, "  fgGetDouble("/position/altitude"): " 
193        <<  fgGetDouble("/position/altitude") );
194        SG_LOG( SG_FLIGHT, SG_DEBUG, "  FGBFI::getAltitude(): " 
195        <<  FGBFI::getAltitude() );    */
196
197
198     SG_LOG( SG_FLIGHT, SG_INFO, "  loaded initial conditions" );
199
200     SG_LOG( SG_FLIGHT, SG_INFO, "  set dt" );
201
202     SG_LOG( SG_FLIGHT, SG_INFO, "Finished initializing JSBSim" );
203 }
204
205 /******************************************************************************/
206
207 // Run an iteration of the EOM (equations of motion)
208
209 bool FGJSBsim::update( int multiloop ) {
210   
211     int i;
212   
213     double save_alt = 0.0;
214     
215
216     copy_to_JSBsim();
217
218     trimmed->setBoolValue(false);
219
220     if(needTrim && fgGetBool("/sim/startup/trim")) {
221         //fgic->SetSeaLevelRadiusFtIC( get_Sea_level_radius() );
222         //fgic->SetTerrainAltitudeFtIC( scenery.cur_elev * SG_METER_TO_FEET );
223         FGTrim *fgtrim;
224         if(fgic->GetVcalibratedKtsIC() < 10 ) {
225                 fgic->SetVcalibratedKtsIC(0.0);
226                 fgtrim=new FGTrim(fdmex,fgic,tGround);
227         } else {
228                 fgtrim=new FGTrim(fdmex,fgic,tLongitudinal);
229         }       
230         if(!fgtrim->DoTrim()) {
231             fgtrim->Report();
232             fgtrim->TrimStats();
233         } else {
234             trimmed->setBoolValue(true);
235         }    
236         fgtrim->ReportState();
237         delete fgtrim;
238   
239         needTrim=false;
240   
241         fgSetDouble("/fdm/trim/pitch-trim", fdmex->GetFCS()->GetPitchTrimCmd());
242         fgSetDouble("/fdm/trim/throttle", fdmex->GetFCS()->GetThrottleCmd(0));
243         fgSetDouble("/fdm/trim/aileron", fdmex->GetFCS()->GetDaCmd());
244         fgSetDouble("/fdm/trim/rudder", fdmex->GetFCS()->GetDrCmd());
245   
246         controls.set_elevator_trim(fdmex->GetFCS()->GetPitchTrimCmd());
247         controls.set_elevator(fdmex->GetFCS()->GetDeCmd());
248         controls.set_throttle(FGControls::ALL_ENGINES,
249                               fdmex->GetFCS()->GetThrottleCmd(0));
250
251         controls.set_aileron(fdmex->GetFCS()->GetDaCmd());
252         controls.set_rudder(fdmex->GetFCS()->GetDrCmd());
253     
254         SG_LOG( SG_FLIGHT, SG_INFO, "  Trim complete" );
255     }  
256   
257     for( i=0; i<get_num_engines(); i++ ) {
258         get_engine(i)->set_RPM( controls.get_throttle(i)*2700 );
259         get_engine(i)->set_Throttle( controls.get_throttle(i) );
260     }
261     
262   
263     for ( i = 0; i < multiloop; i++ ) {
264         fdmex->Run();
265     }
266
267     // printf("%d FG_Altitude = %.2f\n", i, FG_Altitude * 0.3048);
268     // printf("%d Altitude = %.2f\n", i, Altitude * 0.3048);
269
270     // translate JSBsim back to FG structure so that the
271     // autopilot (and the rest of the sim can use the updated values
272
273     copy_from_JSBsim();
274     
275  
276
277     // but lets restore our original bogus altitude when we are done
278
279
280   
281     //climb rate now set from FDM in copy_from_x()
282     return true;
283 }
284
285 /******************************************************************************/
286
287 // Convert from the FGInterface struct to the JSBsim generic_ struct
288
289 bool FGJSBsim::copy_to_JSBsim() {
290     // copy control positions into the JSBsim structure
291
292     fdmex->GetFCS()->SetDaCmd( controls.get_aileron());
293     fdmex->GetFCS()->SetDeCmd( controls.get_elevator());
294     fdmex->GetFCS()->SetPitchTrimCmd(controls.get_elevator_trim());
295     fdmex->GetFCS()->SetDrCmd( -1*controls.get_rudder());
296     fdmex->GetFCS()->SetDfCmd( controls.get_flaps() );
297     fdmex->GetFCS()->SetDsbCmd( 0.0 ); //speedbrakes
298     fdmex->GetFCS()->SetDspCmd( 0.0 ); //spoilers
299     fdmex->GetFCS()->SetThrottleCmd( FGControls::ALL_ENGINES,
300                                      controls.get_throttle( 0 ));
301     fdmex->GetFCS()->SetLBrake( controls.get_brake( 0 ) );
302     fdmex->GetFCS()->SetRBrake( controls.get_brake( 1 ) );
303     fdmex->GetFCS()->SetCBrake( controls.get_brake( 2 ) );
304
305     fdmex->GetPosition()->SetSeaLevelRadius( get_Sea_level_radius() );
306     fdmex->GetPosition()->SetRunwayRadius( scenery.cur_elev*SG_METER_TO_FEET
307                                                 + get_Sea_level_radius() );
308     
309     fdmex->GetAtmosphere()->SetExTemperature(get_Static_temperature());
310     fdmex->GetAtmosphere()->SetExPressure(get_Static_pressure());
311     fdmex->GetAtmosphere()->SetExDensity(get_Density());
312     fdmex->GetAtmosphere()->SetWindNED(get_V_north_airmass(),
313                                        get_V_east_airmass(),
314                                        get_V_down_airmass());
315
316     return true;
317 }
318
319 /******************************************************************************/
320
321 // Convert from the JSBsim generic_ struct to the FGInterface struct
322
323 bool FGJSBsim::copy_from_JSBsim() {
324     unsigned i, j;
325   
326     _set_Inertias( fdmex->GetAircraft()->GetMass(),
327                    fdmex->GetAircraft()->GetIxx(),
328                    fdmex->GetAircraft()->GetIyy(),
329                    fdmex->GetAircraft()->GetIzz(),
330                    fdmex->GetAircraft()->GetIxz() );
331   
332     _set_CG_Position( fdmex->GetAircraft()->GetXYZcg()(1),
333                       fdmex->GetAircraft()->GetXYZcg()(2),
334                       fdmex->GetAircraft()->GetXYZcg()(3) );
335   
336     _set_Accels_Body( fdmex->GetTranslation()->GetUVWdot()(1),
337                       fdmex->GetTranslation()->GetUVWdot()(2),
338                       fdmex->GetTranslation()->GetUVWdot()(3) );
339   
340     _set_Accels_CG_Body( fdmex->GetTranslation()->GetUVWdot()(1),
341                          fdmex->GetTranslation()->GetUVWdot()(2),
342                          fdmex->GetTranslation()->GetUVWdot()(3) );
343   
344     //_set_Accels_CG_Body_N ( fdmex->GetTranslation()->GetNcg()(1),
345     //                       fdmex->GetTranslation()->GetNcg()(2),
346     //                       fdmex->GetTranslation()->GetNcg()(3) );
347     //
348     _set_Accels_Pilot_Body( fdmex->GetAuxiliary()->GetPilotAccel()(1),
349                             fdmex->GetAuxiliary()->GetPilotAccel()(2),
350                             fdmex->GetAuxiliary()->GetPilotAccel()(3) );
351   
352     //_set_Accels_Pilot_Body_N( fdmex->GetAuxiliary()->GetNpilot()(1),
353     //                         fdmex->GetAuxiliary()->GetNpilot()(2),
354     //                         fdmex->GetAuxiliary()->GetNpilot()(3) );
355   
356     _set_Nlf( fdmex->GetAircraft()->GetNlf() );
357   
358     // Velocities
359
360     _set_Velocities_Local( fdmex->GetPosition()->GetVn(),
361                            fdmex->GetPosition()->GetVe(),
362                            fdmex->GetPosition()->GetVd() );
363
364     _set_Velocities_Wind_Body( fdmex->GetTranslation()->GetUVW()(1),
365                                fdmex->GetTranslation()->GetUVW()(2),
366                                fdmex->GetTranslation()->GetUVW()(3) );
367     
368     _set_V_rel_wind( fdmex->GetTranslation()->GetVt() );
369     
370     _set_V_equiv_kts( fdmex->GetAuxiliary()->GetVequivalentKTS() );
371
372     // _set_V_calibrated( fdmex->GetAuxiliary()->GetVcalibratedFPS() );
373
374     _set_V_calibrated_kts( fdmex->GetAuxiliary()->GetVcalibratedKTS() );
375   
376     _set_V_ground_speed( fdmex->GetPosition()->GetVground() );
377
378     _set_Omega_Body( fdmex->GetRotation()->GetPQR()(1),
379                      fdmex->GetRotation()->GetPQR()(2),
380                      fdmex->GetRotation()->GetPQR()(3) );
381
382     _set_Euler_Rates( fdmex->GetRotation()->GetEulerRates()(1),
383                       fdmex->GetRotation()->GetEulerRates()(2),
384                       fdmex->GetRotation()->GetEulerRates()(3) );
385
386     _set_Geocentric_Rates(fdmex->GetPosition()->GetLatitudeDot(),
387                           fdmex->GetPosition()->GetLongitudeDot(),
388                           fdmex->GetPosition()->Gethdot() );
389
390     _set_Mach_number( fdmex->GetTranslation()->GetMach() );
391
392     // Positions
393     _updatePosition( fdmex->GetPosition()->GetLatitude(),
394                      fdmex->GetPosition()->GetLongitude(),
395                      fdmex->GetPosition()->Geth() );
396     
397     _set_Euler_Angles( fdmex->GetRotation()->Getphi(),
398                        fdmex->GetRotation()->Gettht(),
399                        fdmex->GetRotation()->Getpsi() );
400
401     _set_Alpha( fdmex->GetTranslation()->Getalpha() );
402     _set_Beta( fdmex->GetTranslation()->Getbeta() );
403
404     
405     _set_Gamma_vert_rad( fdmex->GetPosition()->GetGamma() );
406     // set_Gamma_horiz_rad( Gamma_horiz_rad );
407
408     _set_Earth_position_angle( fdmex->GetAuxiliary()->GetEarthPositionAngle() );
409
410     _set_Climb_Rate( fdmex->GetPosition()->Gethdot() );
411     
412
413     for ( i = 1; i <= 3; i++ ) {
414         for ( j = 1; j <= 3; j++ ) {
415             _set_T_Local_to_Body( i, j, fdmex->GetState()->GetTl2b()(i,j) );
416         }
417     }
418     return true;
419 }
420
421 void FGJSBsim::snap_shot(void) {
422         fgic->SetLatitudeRadIC(get_Lat_geocentric() );
423         fgic->SetLongitudeRadIC( get_Longitude() );
424         fgic->SetAltitudeFtIC( get_Altitude() );
425         fgic->SetTerrainAltitudeFtIC( get_Runway_altitude() );
426         fgic->SetVtrueFpsIC( get_V_rel_wind() );
427         fgic->SetPitchAngleRadIC( get_Theta() );
428         fgic->SetRollAngleRadIC( get_Phi() );
429         fgic->SetTrueHeadingRadIC( get_Psi() );
430         fgic->SetClimbRateFpsIC( get_Climb_Rate() );
431 }                               
432
433
434 bool FGJSBsim::ToggleDataLogging(void) {
435     return fdmex->GetOutput()->Toggle();
436 }
437
438
439 bool FGJSBsim::ToggleDataLogging(bool state) {
440     if (state) {
441       fdmex->GetOutput()->Enable();
442       return true;
443     } else {
444       fdmex->GetOutput()->Disable();
445       return false;
446     }
447 }
448
449
450 //Positions
451 void FGJSBsim::set_Latitude(double lat) {
452     double sea_level_radius_meters,lat_geoc;
453     
454     SG_LOG(SG_FLIGHT,SG_INFO,"FGJSBsim::set_Latitude: " << lat ); 
455     
456     snap_shot();
457     sgGeodToGeoc( lat, get_Altitude() , &sea_level_radius_meters, &lat_geoc);
458     _set_Sea_level_radius( sea_level_radius_meters * SG_METER_TO_FEET  );
459     fgic->SetSeaLevelRadiusFtIC( sea_level_radius_meters * SG_METER_TO_FEET  );
460     fgic->SetLatitudeRadIC( lat_geoc );
461     fdmex->RunIC(fgic); //loop JSBSim once
462     copy_from_JSBsim(); //update the bus
463     needTrim=true;
464 }  
465
466 void FGJSBsim::set_Longitude(double lon) {
467     
468     SG_LOG(SG_FLIGHT,SG_INFO,"FGJSBsim::set_Longitude: " << lon );
469     
470     snap_shot();
471     fgic->SetLongitudeRadIC(lon);
472     fdmex->RunIC(fgic); //loop JSBSim once
473     copy_from_JSBsim(); //update the bus
474     needTrim=true;
475 }  
476
477 void FGJSBsim::set_Altitude(double alt) {
478     double sea_level_radius_meters,lat_geoc;
479     
480     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Altitude: " << alt );    
481     
482     snap_shot();
483     sgGeodToGeoc( get_Latitude(), alt , &sea_level_radius_meters, &lat_geoc);
484     _set_Sea_level_radius( sea_level_radius_meters * SG_METER_TO_FEET  );
485     fgic->SetSeaLevelRadiusFtIC( sea_level_radius_meters * SG_METER_TO_FEET );
486     fgic->SetLatitudeRadIC( lat_geoc );
487     fgic->SetAltitudeFtIC(alt);
488     fdmex->RunIC(fgic); //loop JSBSim once
489     copy_from_JSBsim(); //update the bus
490     needTrim=true;
491 }
492   
493 void FGJSBsim::set_V_calibrated_kts(double vc) {
494     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_V_calibrated_kts: " <<  vc );
495     
496     snap_shot();
497     fgic->SetVcalibratedKtsIC(vc);
498     fdmex->RunIC(fgic); //loop JSBSim once
499     copy_from_JSBsim(); //update the bus
500     needTrim=true;
501 }  
502
503 void FGJSBsim::set_Mach_number(double mach) {
504     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Mach_number: " <<  mach );
505     
506     snap_shot();
507     fgic->SetMachIC(mach);
508     fdmex->RunIC(fgic); //loop JSBSim once
509     copy_from_JSBsim(); //update the bus
510     needTrim=true;
511 }  
512
513 void FGJSBsim::set_Velocities_Local( double north, double east, double down ){
514     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Velocities_Local: " 
515            << north << ", " <<  east << ", " << down ); 
516     
517     snap_shot();
518     fgic->SetVnorthFpsIC(north);
519     fgic->SetVeastFpsIC(east);
520     fgic->SetVdownFpsIC(down);
521     fdmex->RunIC(fgic); //loop JSBSim once
522     copy_from_JSBsim(); //update the bus
523     needTrim=true;
524 }  
525
526 void FGJSBsim::set_Velocities_Wind_Body( double u, double v, double w){
527     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Velocities_Wind_Body: " 
528            << u << ", " <<  v << ", " <<  w );
529     
530     snap_shot();
531     fgic->SetUBodyFpsIC(u);
532     fgic->SetVBodyFpsIC(v);
533     fgic->SetWBodyFpsIC(w);
534     fdmex->RunIC(fgic); //loop JSBSim once
535     copy_from_JSBsim(); //update the bus
536     needTrim=true;
537
538
539 //Euler angles 
540 void FGJSBsim::set_Euler_Angles( double phi, double theta, double psi ) {
541     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Euler_Angles: " 
542            << phi << ", " << theta << ", " << psi );
543     
544     snap_shot();
545     fgic->SetPitchAngleRadIC(theta);
546     fgic->SetRollAngleRadIC(phi);
547     fgic->SetTrueHeadingRadIC(psi);
548     fdmex->RunIC(fgic); //loop JSBSim once
549     copy_from_JSBsim(); //update the bus 
550     needTrim=true;                                        
551 }  
552
553 //Flight Path
554 void FGJSBsim::set_Climb_Rate( double roc) {
555     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Climb_Rate: " << roc );
556     
557     snap_shot();
558     fgic->SetClimbRateFpsIC(roc);
559     fdmex->RunIC(fgic); //loop JSBSim once
560     copy_from_JSBsim(); //update the bus 
561     needTrim=true;                                        
562 }  
563
564 void FGJSBsim::set_Gamma_vert_rad( double gamma) {
565     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Gamma_vert_rad: " << gamma );
566     
567     snap_shot();
568     fgic->SetFlightPathAngleRadIC(gamma);
569     fdmex->RunIC(fgic); //loop JSBSim once
570     copy_from_JSBsim(); //update the bus  
571     needTrim=true;                                       
572 }  
573
574 //Earth
575 void FGJSBsim::set_Sea_level_radius(double slr) {
576     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Sea_level_radius: " << slr );
577     
578     snap_shot();
579     fgic->SetSeaLevelRadiusFtIC(slr);
580     fdmex->RunIC(fgic); //loop JSBSim once
581     copy_from_JSBsim(); //update the bus 
582     needTrim=true;  
583 }  
584
585 void FGJSBsim::set_Runway_altitude(double ralt) {
586     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Runway_altitude: " << ralt );
587     
588     snap_shot();
589     _set_Runway_altitude( ralt );
590     fgic->SetTerrainAltitudeFtIC( ralt );
591     fdmex->RunIC(fgic); //loop JSBSim once
592     copy_from_JSBsim(); //update the bus 
593     needTrim=true;  
594 }  
595
596 void FGJSBsim::set_Static_pressure(double p) { 
597     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Static_pressure: " << p );
598     
599     snap_shot();
600     fdmex->GetAtmosphere()->SetExPressure(p);
601     if(fdmex->GetAtmosphere()->External() == true)
602         needTrim=true;
603 }
604   
605 void FGJSBsim::set_Static_temperature(double T) { 
606     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Static_temperature: " << T );
607     
608     snap_shot();
609     fdmex->GetAtmosphere()->SetExTemperature(T);
610     if(fdmex->GetAtmosphere()->External() == true)
611         needTrim=true;
612 }
613  
614
615 void FGJSBsim::set_Density(double rho) {
616     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Density: " << rho );
617     
618     snap_shot();
619     fdmex->GetAtmosphere()->SetExDensity(rho);
620     if(fdmex->GetAtmosphere()->External() == true)
621         needTrim=true;
622 }
623   
624
625 void FGJSBsim::set_Velocities_Local_Airmass (double wnorth, 
626                                              double weast, 
627                                              double wdown ) {
628     SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Velocities_Local_Airmass: " 
629            << wnorth << ", " << weast << ", " << wdown );
630     
631     snap_shot();
632     fdmex->GetAtmosphere()->SetWindNED(wnorth, weast, wdown );
633     if(fdmex->GetAtmosphere()->External() == true)
634         needTrim=true;
635 }     
636