]> git.mxchange.org Git - flightgear.git/blob - src/FDM/flight.cxx
Use the density values from the environment subsystem, to properly handle
[flightgear.git] / src / FDM / flight.cxx
1 // flight.cxx -- a general interface to the various flight models
2 //
3 // Written by Curtis Olson, started May 1997.
4 //
5 // Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
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 <stdio.h>
25
26 #include <plib/sg.h>
27
28 #include <simgear/constants.h>
29 #include <simgear/debug/logstream.hxx>
30 #include <simgear/math/sg_geodesy.hxx>
31 #include <simgear/timing/timestamp.hxx>
32
33 #include <Scenery/scenery.hxx>
34 #include <FDM/LaRCsim/ls_interface.h>
35 #include <Main/globals.hxx>
36 #include <Main/fg_props.hxx>
37
38 #include "flight.hxx"
39
40
41 // base_fdm_state is the internal state that is updated in integer
42 // multiples of "dt".  This leads to "jitter" with respect to the real
43 // world time, so we introduce cur_fdm_state which is extrapolated by
44 // the difference between sim time and real world time
45
46 FGInterface *cur_fdm_state = 0;
47 FGInterface base_fdm_state;
48
49 inline void init_vec(FG_VECTOR_3 vec) {
50     vec[0] = 0.0; vec[1] = 0.0; vec[2] = 0.0;
51 }
52
53 // Constructor
54 FGInterface::FGInterface() {
55     _setup();
56 }
57
58 FGInterface::FGInterface( double dt ) {
59     _setup();
60 //     delta_t = dt;
61 //     remainder = elapsed = multi_loop = 0;
62     remainder = 0;
63 }
64
65 // Destructor
66 FGInterface::~FGInterface() {
67     // unbind();                   // FIXME: should be called explicitly
68 }
69
70
71 int
72 FGInterface::_calc_multiloop (double dt)
73 {
74   int hz = fgGetInt("/sim/model-hz");
75   int speedup = fgGetInt("/sim/speed-up");
76
77   dt += remainder;
78   remainder = 0;
79   double ml = dt * hz;
80   int multiloop = int(floor(ml));
81   remainder = (ml - multiloop) / hz;
82   return (multiloop * speedup);
83 }
84
85
86 /**
87  * Set default values for the state of the FDM.
88  *
89  * This method is invoked by the constructors.
90  */
91 void
92 FGInterface::_setup ()
93 {
94     inited = false;
95     bound = false;
96
97     init_vec( d_pilot_rp_body_v );
98     init_vec( d_cg_rp_body_v );
99     init_vec( f_body_total_v );
100     init_vec( f_local_total_v );
101     init_vec( f_aero_v );
102     init_vec( f_engine_v );
103     init_vec( f_gear_v );
104     init_vec( m_total_rp_v );
105     init_vec( m_total_cg_v );
106     init_vec( m_aero_v );
107     init_vec( m_engine_v );
108     init_vec( m_gear_v );
109     init_vec( v_dot_local_v );
110     init_vec( v_dot_body_v );
111     init_vec( a_cg_body_v );
112     init_vec( a_pilot_body_v );
113     init_vec( n_cg_body_v );
114     init_vec( n_pilot_body_v );
115     init_vec( omega_dot_body_v );
116     init_vec( v_local_v );
117     init_vec( v_local_rel_ground_v );
118     init_vec( v_local_airmass_v );
119     init_vec( v_local_rel_airmass_v );
120     init_vec( v_local_gust_v );
121     init_vec( v_wind_body_v );
122     init_vec( omega_body_v );
123     init_vec( omega_local_v );
124     init_vec( omega_total_v );
125     init_vec( euler_rates_v );
126     init_vec( geocentric_rates_v );
127     init_vec( geocentric_position_v );
128     init_vec( geodetic_position_v );
129     init_vec( euler_angles_v );
130     init_vec( d_cg_rwy_local_v );
131     init_vec( d_cg_rwy_rwy_v );
132     init_vec( d_pilot_rwy_local_v );
133     init_vec( d_pilot_rwy_rwy_v );
134     init_vec( t_local_to_body_m[0] );
135     init_vec( t_local_to_body_m[1] );
136     init_vec( t_local_to_body_m[2] );
137
138     mass=i_xx=i_yy=i_zz=i_xz=0;
139     nlf=0;
140     v_rel_wind=v_true_kts=v_rel_ground=v_inertial=0;
141     v_ground_speed=v_equiv=v_equiv_kts=0;
142     v_calibrated=v_calibrated_kts=0;
143     gravity=0;
144     centrifugal_relief=0;
145     alpha=beta=alpha_dot=beta_dot=0;
146     cos_alpha=sin_alpha=cos_beta=sin_beta=0;
147     cos_phi=sin_phi=cos_theta=sin_theta=cos_psi=sin_psi=0;
148     gamma_vert_rad=gamma_horiz_rad=0;
149     sigma=density=v_sound=mach_number=0;
150     static_pressure=total_pressure=impact_pressure=0;
151     dynamic_pressure=0;
152     static_temperature=total_temperature=0;
153     sea_level_radius=earth_position_angle=0;
154     runway_altitude=runway_latitude=runway_longitude=0;
155     runway_heading=0;
156     radius_to_rwy=0;
157     climb_rate=0;
158     sin_lat_geocentric=cos_lat_geocentric=0;
159     sin_latitude=cos_latitude=0;
160     sin_longitude=cos_longitude=0;
161     altitude_agl=0;
162     _acmodel = 0;
163 }
164
165 void
166 FGInterface::init () {}
167
168 /**
169  * Initialize the state of the FDM.
170  *
171  * Subclasses of FGInterface may do their own, additional initialization,
172  * but there is some that is common to all.  Normally, they should call
173  * this before they begin their own init to make sure the basic structures
174  * are set up properly.
175  */
176 void
177 FGInterface::common_init ()
178 {
179     SG_LOG( SG_FLIGHT, SG_INFO, "Start common FDM init" );
180
181     set_inited( true );
182
183 //     stamp();
184 //     set_remainder( 0 );
185
186     // linking in FGAircraft instance...
187     // FIXME: when using multiple instances, then there will be more than
188     // one model so get_aircraft_model will have to be indexed to the correct
189     // model.
190     _acmodel = globals->get_aircraft_model();
191
192     // Set initial position
193     SG_LOG( SG_FLIGHT, SG_INFO, "...initializing position..." );
194     set_Longitude( fgGetDouble("/position/longitude-deg")
195                    * SGD_DEGREES_TO_RADIANS );
196     set_Latitude( fgGetDouble("/position/latitude-deg")
197                   * SGD_DEGREES_TO_RADIANS );
198     double ground_elev_m = globals->get_scenery()->get_cur_elev();
199     double ground_elev_ft = ground_elev_m * SG_METER_TO_FEET;
200     _acmodel->get3DModel()->getFGLocation()->set_cur_elev_m( ground_elev_m );
201     _set_Runway_altitude ( ground_elev_ft );
202     if ( fgGetBool("/sim/startup/onground")
203          || fgGetDouble("/position/altitude-ft") < ground_elev_ft ) {
204         fgSetDouble("/position/altitude-ft", ground_elev_ft);
205     }
206     set_Altitude( fgGetDouble("/position/altitude-ft") );
207
208     // Set ground elevation
209     SG_LOG( SG_FLIGHT, SG_INFO,
210             "...initializing ground elevation to " << ground_elev_ft
211             << "ft..." );
212
213     // Set sea-level radius
214     SG_LOG( SG_FLIGHT, SG_INFO, "...initializing sea-level radius..." );
215     SG_LOG( SG_FLIGHT, SG_INFO, " lat = "
216             << fgGetDouble("/position/latitude-deg")
217             << " alt = " << fgGetDouble("/position/altitude-ft") );
218     double sea_level_radius_meters;
219     double lat_geoc;
220     sgGeodToGeoc( fgGetDouble("/position/latitude-deg")
221                     * SGD_DEGREES_TO_RADIANS,
222                   fgGetDouble("/position/altitude-ft") * SG_FEET_TO_METER,
223                   &sea_level_radius_meters, &lat_geoc );
224     _set_Sea_level_radius( sea_level_radius_meters * SG_METER_TO_FEET );
225
226     // Set initial velocities
227     SG_LOG( SG_FLIGHT, SG_INFO, "...initializing velocities..." );
228     if ( !fgHasNode("/sim/startup/speed-set") ) {
229         set_V_calibrated_kts(0.0);
230     } else {
231         const string speedset = fgGetString("/sim/startup/speed-set");
232         if ( speedset == "knots" || speedset == "KNOTS" ) {
233             set_V_calibrated_kts( fgGetDouble("/velocities/airspeed-kt") );
234         } else if ( speedset == "mach" || speedset == "MACH" ) {
235             set_Mach_number( fgGetDouble("/velocities/mach") );
236         } else if ( speedset == "UVW" || speedset == "uvw" ) {
237             set_Velocities_Wind_Body(
238                                      fgGetDouble("/velocities/uBody-fps"),
239                                      fgGetDouble("/velocities/vBody-fps"),
240                                      fgGetDouble("/velocities/wBody-fps") );
241         } else if ( speedset == "NED" || speedset == "ned" ) {
242             set_Velocities_Local(
243                                  fgGetDouble("/velocities/speed-north-fps"),
244                                  fgGetDouble("/velocities/speed-east-fps"),
245                                  fgGetDouble("/velocities/speed-down-fps") );
246         } else {
247             SG_LOG( SG_FLIGHT, SG_ALERT,
248                     "Unrecognized value for /sim/startup/speed-set: "
249                     << speedset);
250             set_V_calibrated_kts( 0.0 );
251         }
252     }
253
254     // Set initial Euler angles
255     SG_LOG( SG_FLIGHT, SG_INFO, "...initializing Euler angles..." );
256     set_Euler_Angles( fgGetDouble("/orientation/roll-deg")
257                         * SGD_DEGREES_TO_RADIANS,
258                       fgGetDouble("/orientation/pitch-deg")
259                         * SGD_DEGREES_TO_RADIANS,
260                       fgGetDouble("/orientation/heading-deg")
261                         * SGD_DEGREES_TO_RADIANS );
262
263     SG_LOG( SG_FLIGHT, SG_INFO, "End common FDM init" );
264 }
265
266
267 /**
268  * Bind getters and setters to properties.
269  *
270  * The bind() method will be invoked after init().  Note that unlike
271  * the usual implementations of FGSubsystem::bind(), this method does
272  * not automatically pick up existing values for the properties at
273  * bind time; instead, all values are set explicitly in the init()
274  * method.
275  */
276 void
277 FGInterface::bind ()
278 {
279   bound = true;
280
281                                 // Time management (read-only)
282 //   fgTie("/fdm/time/delta_t", this,
283 //         &FGInterface::get_delta_t); // read-only
284 //   fgTie("/fdm/time/elapsed", this,
285 //         &FGInterface::get_elapsed); // read-only
286 //   fgTie("/fdm/time/remainder", this,
287 //         &FGInterface::get_remainder); // read-only
288 //   fgTie("/fdm/time/multi_loop", this,
289 //         &FGInterface::get_multi_loop); // read-only
290
291                         // Aircraft position
292   fgTie("/position/latitude-deg", this,
293         &FGInterface::get_Latitude_deg,
294         &FGInterface::set_Latitude_deg,
295         false);
296   fgSetArchivable("/position/latitude-deg");
297   fgTie("/position/longitude-deg", this,
298         &FGInterface::get_Longitude_deg,
299         &FGInterface::set_Longitude_deg,
300         false);
301   fgSetArchivable("/position/longitude-deg");
302   fgTie("/position/altitude-ft", this,
303         &FGInterface::get_Altitude,
304         &FGInterface::set_Altitude,
305         false);
306   fgSetArchivable("/position/altitude-ft");
307   fgTie("/position/altitude-agl-ft", this,
308         &FGInterface::get_Altitude_AGL); // read-only
309
310                                 // Orientation
311   fgTie("/orientation/roll-deg", this,
312         &FGInterface::get_Phi_deg,
313         &FGInterface::set_Phi_deg);
314   fgSetArchivable("/orientation/roll-deg");
315   fgTie("/orientation/pitch-deg", this,
316         &FGInterface::get_Theta_deg,
317         &FGInterface::set_Theta_deg);
318   fgSetArchivable("/orientation/pitch-deg");
319   fgTie("/orientation/heading-deg", this,
320         &FGInterface::get_Psi_deg,
321         &FGInterface::set_Psi_deg);
322   fgSetArchivable("/orientation/heading-deg");
323
324                                 // Calibrated airspeed
325   fgTie("/velocities/airspeed-kt", this,
326         &FGInterface::get_V_calibrated_kts,
327         &FGInterface::set_V_calibrated_kts,
328         false);
329
330                                 // Local velocities
331 //   fgTie("/velocities/speed-north-fps", this,
332 //      &FGInterface::get_V_north,
333 //      &FGInterface::set_V_north);
334 //   fgSetArchivable("/velocities/speed-north-fps");
335 //   fgTie("/velocities/speed-east-fps", this,
336 //      &FGInterface::get_V_east,
337 //      &FGInterface::set_V_east);
338 //   fgSetArchivable("/velocities/speed-east-fps");
339 //   fgTie("/velocities/speed-down-fps", this,
340 //      &FGInterface::get_V_down,
341 //      &FGInterface::set_V_down);
342 //   fgSetArchivable("/velocities/speed-down-fps");
343                                 // FIXME: Temporarily read-only, until the
344                                 // incompatibilities between JSBSim and
345                                 // LaRCSim are fixed (LaRCSim adds the
346                                 // earth's rotation to the east velocity).
347   fgTie("/velocities/speed-north-fps", this,
348         &FGInterface::get_V_north);
349   fgTie("/velocities/speed-east-fps", this,
350         &FGInterface::get_V_east);
351   fgTie("/velocities/speed-down-fps", this,
352         &FGInterface::get_V_down);
353
354                                 // Relative wind
355                                 // FIXME: temporarily archivable, until
356                                 // the NED problem is fixed.
357   fgTie("/velocities/uBody-fps", this,
358         &FGInterface::get_uBody,
359         &FGInterface::set_uBody,
360         false);
361   fgSetArchivable("/velocities/uBody-fps");
362   fgTie("/velocities/vBody-fps", this,
363         &FGInterface::get_vBody,
364         &FGInterface::set_vBody,
365         false);
366   fgSetArchivable("/velocities/vBody-fps");
367   fgTie("/velocities/wBody-fps", this,
368         &FGInterface::get_wBody,
369         &FGInterface::set_wBody,
370         false);
371   fgSetArchivable("/velocities/wBody-fps");
372
373                                 // Climb and slip (read-only)
374   fgTie("/velocities/vertical-speed-fps", this,
375         &FGInterface::get_Climb_Rate,
376   &FGInterface::set_Climb_Rate ); 
377   fgTie("/velocities/glideslope", this,
378   &FGInterface::get_Gamma_vert_rad,
379   &FGInterface::set_Gamma_vert_rad );
380   fgTie("/velocities/side-slip-rad", this,
381         &FGInterface::get_Beta); // read-only
382   fgTie("/velocities/side-slip-deg", this,
383   &FGInterface::get_Beta_deg); // read-only
384   fgTie("/velocities/alpha-deg", this,
385   &FGInterface::get_Alpha_deg); // read-only
386   fgTie("/accelerations/nlf", this,
387   &FGInterface::get_Nlf); // read-only
388 }
389
390
391 /**
392  * Unbind any properties bound to this FDM.
393  *
394  * This method allows the FDM to release properties so that a new
395  * FDM can bind them instead.
396  */
397 void
398 FGInterface::unbind ()
399 {
400   bound = false;
401
402   fgUntie("/fdm/time/delta_t");
403   fgUntie("/fdm/time/elapsed");
404   fgUntie("/fdm/time/remainder");
405   fgUntie("/fdm/time/multi_loop");
406   fgUntie("/position/latitude-deg");
407   fgUntie("/position/longitude-deg");
408   fgUntie("/position/altitude-ft");
409   fgUntie("/position/altitude-agl-ft");
410   fgUntie("/orientation/heading-deg");
411   fgUntie("/orientation/pitch-deg");
412   fgUntie("/orientation/roll-deg");
413   fgUntie("/velocities/airspeed-kt");
414   fgUntie("/velocities/speed-north-fps");
415   fgUntie("/velocities/speed-east-fps");
416   fgUntie("/velocities/speed-down-fps");
417   fgUntie("/velocities/uBody-fps");
418   fgUntie("/velocities/vBody-fps");
419   fgUntie("/velocities/wBody-fps");
420   fgUntie("/velocities/vertical-speed-fps");
421   fgUntie("/velocities/glideslope");
422   fgUntie("/velocities/side-slip-rad");
423   fgUntie("/velocities/side-slip-deg");
424   fgUntie("/velocities/alpha-deg");
425   fgUntie("/accelerations/nlf");
426   
427 }
428
429 /**
430  * Update the state of the FDM (i.e. run the equations of motion).
431  */
432 void
433 FGInterface::update (double dt)
434 {
435     SG_LOG(SG_FLIGHT, SG_ALERT, "dummy update() ... SHOULDN'T BE CALLED!");
436 }
437
438
439 void FGInterface::_updateGeodeticPosition( double lat, double lon, double alt )
440 {
441     double lat_geoc, sl_radius;
442
443     // cout << "starting sea level rad = " << get_Sea_level_radius() << endl;
444
445     sgGeodToGeoc( lat, alt * SG_FEET_TO_METER, &sl_radius, &lat_geoc );
446
447     SG_LOG( SG_FLIGHT, SG_DEBUG, "lon = " << lon 
448             << " lat_geod = " << lat
449             << " lat_geoc = " << lat_geoc
450             << " alt = " << alt 
451             << " sl_radius = " << sl_radius * SG_METER_TO_FEET
452             << " Equator = " << SG_EQUATORIAL_RADIUS_FT );
453
454     _set_Geocentric_Position( lat_geoc, lon, 
455                               sl_radius * SG_METER_TO_FEET + alt );
456         
457     _set_Geodetic_Position( lat, lon, alt );
458
459     _set_Sea_level_radius( sl_radius * SG_METER_TO_FEET );
460     _set_Runway_altitude( getACModel()->get3DModel()->getFGLocation()->get_cur_elev_m() * SG_METER_TO_FEET );
461
462     _set_sin_lat_geocentric( lat_geoc );
463     _set_cos_lat_geocentric( lat_geoc );
464
465     _set_sin_cos_longitude( lon );
466
467     _set_sin_cos_latitude( lat );
468
469     /* Norman's code for slope of the terrain */
470     /* needs to be tested -- get it on the HUD and taxi around */
471     /* double *tnorm = scenery.cur_normal;
472
473        double sy = sin ( -get_Psi() ) ;
474        double cy = cos ( -get_Psi() ) ;
475
476        double phitb, thetatb, psitb;
477        if ( tnorm[1] != 0.0 ) {
478            psitb = -atan2 ( tnorm[0], tnorm[1] );
479        }
480        if ( tnorm[2] != 0.0 ) { 
481            thetatb =  atan2 ( tnorm[0] * cy - tnorm[1] * sy, tnorm[2] );
482            phitb = -atan2 ( tnorm[1] * cy + tnorm[0] * sy, tnorm[2] );  
483        }        
484         
485        _set_terrain_slope(phitb, thetatb, psitb) 
486      */
487 }
488
489
490 void FGInterface::_updateGeocentricPosition( double lat_geoc, double lon,
491                                              double alt )
492 {
493     double lat_geod, tmp_alt, sl_radius1, sl_radius2, tmp_lat_geoc;
494
495     // cout << "starting sea level rad = " << get_Sea_level_radius() << endl;
496
497     sgGeocToGeod( lat_geoc, ( get_Sea_level_radius() + alt ) * SG_FEET_TO_METER,
498                   &lat_geod, &tmp_alt, &sl_radius1 );
499     sgGeodToGeoc( lat_geod, alt * SG_FEET_TO_METER, &sl_radius2, &tmp_lat_geoc );
500
501     SG_LOG( SG_FLIGHT, SG_DEBUG, "lon = " << lon 
502             << " lat_geod = " << lat_geod
503             << " lat_geoc = " << lat_geoc
504             << " alt = " << alt 
505             << " tmp_alt = " << tmp_alt * SG_METER_TO_FEET
506             << " sl_radius1 = " << sl_radius1 * SG_METER_TO_FEET
507             << " sl_radius2 = " << sl_radius2 * SG_METER_TO_FEET
508             << " Equator = " << SG_EQUATORIAL_RADIUS_FT );
509
510     _set_Geocentric_Position( lat_geoc, lon, 
511                               sl_radius2 * SG_METER_TO_FEET + alt );
512         
513     _set_Geodetic_Position( lat_geod, lon, alt );
514
515     _set_Sea_level_radius( sl_radius2 * SG_METER_TO_FEET );
516     _set_Runway_altitude( getACModel()->get3DModel()->getFGLocation()->get_cur_elev_m() * SG_METER_TO_FEET );
517
518     _set_sin_lat_geocentric( lat_geoc );
519     _set_cos_lat_geocentric( lat_geoc );
520
521     _set_sin_cos_longitude( lon );
522
523     _set_sin_cos_latitude( lat_geod );
524
525     /* Norman's code for slope of the terrain */
526     /* needs to be tested -- get it on the HUD and taxi around */
527     /* double *tnorm = scenery.cur_normal;
528
529        double sy = sin ( -get_Psi() ) ;
530        double cy = cos ( -get_Psi() ) ;
531
532        double phitb, thetatb, psitb;
533        if ( tnorm[1] != 0.0 ) {
534            psitb = -atan2 ( tnorm[0], tnorm[1] );
535        }
536        if ( tnorm[2] != 0.0 ) { 
537            thetatb =  atan2 ( tnorm[0] * cy - tnorm[1] * sy, tnorm[2] );
538            phitb = -atan2 ( tnorm[1] * cy + tnorm[0] * sy, tnorm[2] );  
539        }        
540         
541        _set_terrain_slope(phitb, thetatb, psitb) 
542      */
543 }
544
545
546 // Extrapolate fdm based on time_offset (in usec)
547 void FGInterface::extrapolate( int time_offset ) {
548     double dt = time_offset / 1000000.0;
549
550     // -dw- metrowerks complains about ambiguous access, not critical
551     // to keep this ;)
552 #ifndef __MWERKS__
553     SG_LOG(SG_FLIGHT, SG_INFO, "extrapolating FDM by dt = " << dt);
554 #endif
555
556     double lat = geodetic_position_v[0] + geocentric_rates_v[0] * dt;
557     double lat_geoc = geocentric_position_v[0] + geocentric_rates_v[0] * dt;
558
559     double lon = geodetic_position_v[1] + geocentric_rates_v[1] * dt;
560     double lon_geoc = geocentric_position_v[1] + geocentric_rates_v[1] * dt;
561
562     double alt = geodetic_position_v[2] + geocentric_rates_v[2] * dt;
563     double radius = geocentric_position_v[2] + geocentric_rates_v[2] * dt;
564
565     geodetic_position_v[0] = lat;
566     geocentric_position_v[0] = lat_geoc;
567
568     geodetic_position_v[1] = lon;
569     geocentric_position_v[1] = lon_geoc;
570
571     geodetic_position_v[2] = alt;
572     geocentric_position_v[2] = radius;
573 }
574
575 // Positions
576 void FGInterface::set_Latitude(double lat) {
577     geodetic_position_v[0] = lat;
578 }
579
580 void FGInterface::set_Longitude(double lon) {
581     geodetic_position_v[1] = lon;
582 }
583
584 void FGInterface::set_Altitude(double alt) {
585     geodetic_position_v[2] = alt;
586 }
587
588 void FGInterface::set_AltitudeAGL(double altagl) {
589     altitude_agl=altagl;
590 }
591
592 // Velocities
593 void FGInterface::set_V_calibrated_kts(double vc) {
594     v_calibrated_kts = vc;
595 }
596
597 void FGInterface::set_Mach_number(double mach) {
598     mach_number = mach;
599 }
600
601 void FGInterface::set_Velocities_Local( double north, 
602                                         double east, 
603                                         double down ){
604     v_local_v[0] = north;
605     v_local_v[1] = east;
606     v_local_v[2] = down;
607 }
608
609 void FGInterface::set_Velocities_Wind_Body( double u, 
610                                             double v, 
611                                             double w){
612     v_wind_body_v[0] = u;
613     v_wind_body_v[1] = v;
614     v_wind_body_v[2] = w;
615 }
616
617 // Euler angles 
618 void FGInterface::set_Euler_Angles( double phi, 
619                                     double theta, 
620                                     double psi ) {
621     euler_angles_v[0] = phi;
622     euler_angles_v[1] = theta;
623     euler_angles_v[2] = psi;                                            
624 }  
625
626 // Flight Path
627 void FGInterface::set_Climb_Rate( double roc) {
628     climb_rate = roc;
629 }
630
631 void FGInterface::set_Gamma_vert_rad( double gamma) {
632     gamma_vert_rad = gamma;
633 }
634
635 void FGInterface::set_Static_pressure(double p) { static_pressure = p; }
636 void FGInterface::set_Static_temperature(double T) { static_temperature = T; }
637 void FGInterface::set_Density(double rho) { density = rho; }
638
639 void FGInterface::set_Velocities_Local_Airmass (double wnorth, 
640                                                 double weast, 
641                                                 double wdown ) {
642     v_local_airmass_v[0] = wnorth;
643     v_local_airmass_v[1] = weast;
644     v_local_airmass_v[2] = wdown;
645 }
646
647
648 void FGInterface::_busdump(void) {
649
650     SG_LOG(SG_FLIGHT,SG_INFO,"d_pilot_rp_body_v[3]: " << d_pilot_rp_body_v[0] << ", " << d_pilot_rp_body_v[1] << ", " << d_pilot_rp_body_v[2]);
651     SG_LOG(SG_FLIGHT,SG_INFO,"d_cg_rp_body_v[3]: " << d_cg_rp_body_v[0] << ", " << d_cg_rp_body_v[1] << ", " << d_cg_rp_body_v[2]);
652     SG_LOG(SG_FLIGHT,SG_INFO,"f_body_total_v[3]: " << f_body_total_v[0] << ", " << f_body_total_v[1] << ", " << f_body_total_v[2]);
653     SG_LOG(SG_FLIGHT,SG_INFO,"f_local_total_v[3]: " << f_local_total_v[0] << ", " << f_local_total_v[1] << ", " << f_local_total_v[2]);
654     SG_LOG(SG_FLIGHT,SG_INFO,"f_aero_v[3]: " << f_aero_v[0] << ", " << f_aero_v[1] << ", " << f_aero_v[2]);
655     SG_LOG(SG_FLIGHT,SG_INFO,"f_engine_v[3]: " << f_engine_v[0] << ", " << f_engine_v[1] << ", " << f_engine_v[2]);
656     SG_LOG(SG_FLIGHT,SG_INFO,"f_gear_v[3]: " << f_gear_v[0] << ", " << f_gear_v[1] << ", " << f_gear_v[2]);
657     SG_LOG(SG_FLIGHT,SG_INFO,"m_total_rp_v[3]: " << m_total_rp_v[0] << ", " << m_total_rp_v[1] << ", " << m_total_rp_v[2]);
658     SG_LOG(SG_FLIGHT,SG_INFO,"m_total_cg_v[3]: " << m_total_cg_v[0] << ", " << m_total_cg_v[1] << ", " << m_total_cg_v[2]);
659     SG_LOG(SG_FLIGHT,SG_INFO,"m_aero_v[3]: " << m_aero_v[0] << ", " << m_aero_v[1] << ", " << m_aero_v[2]);
660     SG_LOG(SG_FLIGHT,SG_INFO,"m_engine_v[3]: " << m_engine_v[0] << ", " << m_engine_v[1] << ", " << m_engine_v[2]);
661     SG_LOG(SG_FLIGHT,SG_INFO,"m_gear_v[3]: " << m_gear_v[0] << ", " << m_gear_v[1] << ", " << m_gear_v[2]);
662     SG_LOG(SG_FLIGHT,SG_INFO,"v_dot_local_v[3]: " << v_dot_local_v[0] << ", " << v_dot_local_v[1] << ", " << v_dot_local_v[2]);
663     SG_LOG(SG_FLIGHT,SG_INFO,"v_dot_body_v[3]: " << v_dot_body_v[0] << ", " << v_dot_body_v[1] << ", " << v_dot_body_v[2]);
664     SG_LOG(SG_FLIGHT,SG_INFO,"a_cg_body_v[3]: " << a_cg_body_v[0] << ", " << a_cg_body_v[1] << ", " << a_cg_body_v[2]);
665     SG_LOG(SG_FLIGHT,SG_INFO,"a_pilot_body_v[3]: " << a_pilot_body_v[0] << ", " << a_pilot_body_v[1] << ", " << a_pilot_body_v[2]);
666     SG_LOG(SG_FLIGHT,SG_INFO,"n_cg_body_v[3]: " << n_cg_body_v[0] << ", " << n_cg_body_v[1] << ", " << n_cg_body_v[2]);
667     SG_LOG(SG_FLIGHT,SG_INFO,"n_pilot_body_v[3]: " << n_pilot_body_v[0] << ", " << n_pilot_body_v[1] << ", " << n_pilot_body_v[2]);
668     SG_LOG(SG_FLIGHT,SG_INFO,"omega_dot_body_v[3]: " << omega_dot_body_v[0] << ", " << omega_dot_body_v[1] << ", " << omega_dot_body_v[2]);
669     SG_LOG(SG_FLIGHT,SG_INFO,"v_local_v[3]: " << v_local_v[0] << ", " << v_local_v[1] << ", " << v_local_v[2]);
670     SG_LOG(SG_FLIGHT,SG_INFO,"v_local_rel_ground_v[3]: " << v_local_rel_ground_v[0] << ", " << v_local_rel_ground_v[1] << ", " << v_local_rel_ground_v[2]);
671     SG_LOG(SG_FLIGHT,SG_INFO,"v_local_airmass_v[3]: " << v_local_airmass_v[0] << ", " << v_local_airmass_v[1] << ", " << v_local_airmass_v[2]);
672     SG_LOG(SG_FLIGHT,SG_INFO,"v_local_rel_airmass_v[3]: " << v_local_rel_airmass_v[0] << ", " << v_local_rel_airmass_v[1] << ", " << v_local_rel_airmass_v[2]);
673     SG_LOG(SG_FLIGHT,SG_INFO,"v_local_gust_v[3]: " << v_local_gust_v[0] << ", " << v_local_gust_v[1] << ", " << v_local_gust_v[2]);
674     SG_LOG(SG_FLIGHT,SG_INFO,"v_wind_body_v[3]: " << v_wind_body_v[0] << ", " << v_wind_body_v[1] << ", " << v_wind_body_v[2]);
675     SG_LOG(SG_FLIGHT,SG_INFO,"omega_body_v[3]: " << omega_body_v[0] << ", " << omega_body_v[1] << ", " << omega_body_v[2]);
676     SG_LOG(SG_FLIGHT,SG_INFO,"omega_local_v[3]: " << omega_local_v[0] << ", " << omega_local_v[1] << ", " << omega_local_v[2]);
677     SG_LOG(SG_FLIGHT,SG_INFO,"omega_total_v[3]: " << omega_total_v[0] << ", " << omega_total_v[1] << ", " << omega_total_v[2]);
678     SG_LOG(SG_FLIGHT,SG_INFO,"euler_rates_v[3]: " << euler_rates_v[0] << ", " << euler_rates_v[1] << ", " << euler_rates_v[2]);
679     SG_LOG(SG_FLIGHT,SG_INFO,"geocentric_rates_v[3]: " << geocentric_rates_v[0] << ", " << geocentric_rates_v[1] << ", " << geocentric_rates_v[2]);
680     SG_LOG(SG_FLIGHT,SG_INFO,"geocentric_position_v[3]: " << geocentric_position_v[0] << ", " << geocentric_position_v[1] << ", " << geocentric_position_v[2]);
681     SG_LOG(SG_FLIGHT,SG_INFO,"geodetic_position_v[3]: " << geodetic_position_v[0] << ", " << geodetic_position_v[1] << ", " << geodetic_position_v[2]);
682     SG_LOG(SG_FLIGHT,SG_INFO,"euler_angles_v[3]: " << euler_angles_v[0] << ", " << euler_angles_v[1] << ", " << euler_angles_v[2]);
683     SG_LOG(SG_FLIGHT,SG_INFO,"d_cg_rwy_local_v[3]: " << d_cg_rwy_local_v[0] << ", " << d_cg_rwy_local_v[1] << ", " << d_cg_rwy_local_v[2]);
684     SG_LOG(SG_FLIGHT,SG_INFO,"d_cg_rwy_rwy_v[3]: " << d_cg_rwy_rwy_v[0] << ", " << d_cg_rwy_rwy_v[1] << ", " << d_cg_rwy_rwy_v[2]);
685     SG_LOG(SG_FLIGHT,SG_INFO,"d_pilot_rwy_local_v[3]: " << d_pilot_rwy_local_v[0] << ", " << d_pilot_rwy_local_v[1] << ", " << d_pilot_rwy_local_v[2]);
686     SG_LOG(SG_FLIGHT,SG_INFO,"d_pilot_rwy_rwy_v[3]: " << d_pilot_rwy_rwy_v[0] << ", " << d_pilot_rwy_rwy_v[1] << ", " << d_pilot_rwy_rwy_v[2]);
687
688     SG_LOG(SG_FLIGHT,SG_INFO,"t_local_to_body_m[0][3]: " << t_local_to_body_m[0][0] << ", " << t_local_to_body_m[0][1] << ", " << t_local_to_body_m[0][2]);
689     SG_LOG(SG_FLIGHT,SG_INFO,"t_local_to_body_m[1][3]: " << t_local_to_body_m[1][0] << ", " << t_local_to_body_m[1][1] << ", " << t_local_to_body_m[1][2]);
690     SG_LOG(SG_FLIGHT,SG_INFO,"t_local_to_body_m[2][3]: " << t_local_to_body_m[2][0] << ", " << t_local_to_body_m[2][1] << ", " << t_local_to_body_m[2][2]);
691
692     SG_LOG(SG_FLIGHT,SG_INFO,"mass: " << mass );
693     SG_LOG(SG_FLIGHT,SG_INFO,"i_xx: " << i_xx );
694     SG_LOG(SG_FLIGHT,SG_INFO,"i_yy: " << i_yy );
695     SG_LOG(SG_FLIGHT,SG_INFO,"i_zz: " << i_zz );
696     SG_LOG(SG_FLIGHT,SG_INFO,"i_xz: " << i_xz );
697     SG_LOG(SG_FLIGHT,SG_INFO,"nlf: " << nlf );
698     SG_LOG(SG_FLIGHT,SG_INFO,"v_rel_wind: " << v_rel_wind );
699     SG_LOG(SG_FLIGHT,SG_INFO,"v_true_kts: " << v_true_kts );
700     SG_LOG(SG_FLIGHT,SG_INFO,"v_rel_ground: " << v_rel_ground );
701     SG_LOG(SG_FLIGHT,SG_INFO,"v_inertial: " << v_inertial );
702     SG_LOG(SG_FLIGHT,SG_INFO,"v_ground_speed: " << v_ground_speed );
703     SG_LOG(SG_FLIGHT,SG_INFO,"v_equiv: " << v_equiv );
704     SG_LOG(SG_FLIGHT,SG_INFO,"v_equiv_kts: " << v_equiv_kts );
705     SG_LOG(SG_FLIGHT,SG_INFO,"v_calibrated: " << v_calibrated );
706     SG_LOG(SG_FLIGHT,SG_INFO,"v_calibrated_kts: " << v_calibrated_kts );
707     SG_LOG(SG_FLIGHT,SG_INFO,"gravity: " << gravity );
708     SG_LOG(SG_FLIGHT,SG_INFO,"centrifugal_relief: " << centrifugal_relief );
709     SG_LOG(SG_FLIGHT,SG_INFO,"alpha: " << alpha );
710     SG_LOG(SG_FLIGHT,SG_INFO,"beta: " << beta );
711     SG_LOG(SG_FLIGHT,SG_INFO,"alpha_dot: " << alpha_dot );
712     SG_LOG(SG_FLIGHT,SG_INFO,"beta_dot: " << beta_dot );
713     SG_LOG(SG_FLIGHT,SG_INFO,"cos_alpha: " << cos_alpha );
714     SG_LOG(SG_FLIGHT,SG_INFO,"sin_alpha: " << sin_alpha );
715     SG_LOG(SG_FLIGHT,SG_INFO,"cos_beta: " << cos_beta );
716     SG_LOG(SG_FLIGHT,SG_INFO,"sin_beta: " << sin_beta );
717     SG_LOG(SG_FLIGHT,SG_INFO,"cos_phi: " << cos_phi );
718     SG_LOG(SG_FLIGHT,SG_INFO,"sin_phi: " << sin_phi );
719     SG_LOG(SG_FLIGHT,SG_INFO,"cos_theta: " << cos_theta );
720     SG_LOG(SG_FLIGHT,SG_INFO,"sin_theta: " << sin_theta );
721     SG_LOG(SG_FLIGHT,SG_INFO,"cos_psi: " << cos_psi );
722     SG_LOG(SG_FLIGHT,SG_INFO,"sin_psi: " << sin_psi );
723     SG_LOG(SG_FLIGHT,SG_INFO,"gamma_vert_rad: " << gamma_vert_rad );
724     SG_LOG(SG_FLIGHT,SG_INFO,"gamma_horiz_rad: " << gamma_horiz_rad );
725     SG_LOG(SG_FLIGHT,SG_INFO,"sigma: " << sigma );
726     SG_LOG(SG_FLIGHT,SG_INFO,"density: " << density );
727     SG_LOG(SG_FLIGHT,SG_INFO,"v_sound: " << v_sound );
728     SG_LOG(SG_FLIGHT,SG_INFO,"mach_number: " << mach_number );
729     SG_LOG(SG_FLIGHT,SG_INFO,"static_pressure: " << static_pressure );
730     SG_LOG(SG_FLIGHT,SG_INFO,"total_pressure: " << total_pressure );
731     SG_LOG(SG_FLIGHT,SG_INFO,"impact_pressure: " << impact_pressure );
732     SG_LOG(SG_FLIGHT,SG_INFO,"dynamic_pressure: " << dynamic_pressure );
733     SG_LOG(SG_FLIGHT,SG_INFO,"static_temperature: " << static_temperature );
734     SG_LOG(SG_FLIGHT,SG_INFO,"total_temperature: " << total_temperature );
735     SG_LOG(SG_FLIGHT,SG_INFO,"sea_level_radius: " << sea_level_radius );
736     SG_LOG(SG_FLIGHT,SG_INFO,"earth_position_angle: " << earth_position_angle );
737     SG_LOG(SG_FLIGHT,SG_INFO,"runway_altitude: " << runway_altitude );
738     SG_LOG(SG_FLIGHT,SG_INFO,"runway_latitude: " << runway_latitude );
739     SG_LOG(SG_FLIGHT,SG_INFO,"runway_longitude: " << runway_longitude );
740     SG_LOG(SG_FLIGHT,SG_INFO,"runway_heading: " << runway_heading );
741     SG_LOG(SG_FLIGHT,SG_INFO,"radius_to_rwy: " << radius_to_rwy );
742     SG_LOG(SG_FLIGHT,SG_INFO,"climb_rate: " << climb_rate );
743     SG_LOG(SG_FLIGHT,SG_INFO,"sin_lat_geocentric: " << sin_lat_geocentric );
744     SG_LOG(SG_FLIGHT,SG_INFO,"cos_lat_geocentric: " << cos_lat_geocentric );
745     SG_LOG(SG_FLIGHT,SG_INFO,"sin_longitude: " << sin_longitude );
746     SG_LOG(SG_FLIGHT,SG_INFO,"cos_longitude: " << cos_longitude );
747     SG_LOG(SG_FLIGHT,SG_INFO,"sin_latitude: " << sin_latitude );
748     SG_LOG(SG_FLIGHT,SG_INFO,"cos_latitude: " << cos_latitude );
749     SG_LOG(SG_FLIGHT,SG_INFO,"altitude_agl: " << altitude_agl );
750 }
751
752
753 void fgToggleFDMdataLogging(void) {
754   cur_fdm_state->ToggleDataLogging();
755 }