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