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