]> git.mxchange.org Git - flightgear.git/blob - src/FDM/flight.cxx
Fix line endings
[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 #ifdef HAVE_CONFIG_H
24 #  include "config.h"
25 #endif
26
27 #include <stdio.h>
28
29 #include <plib/sg.h>
30
31 #include <simgear/constants.h>
32 #include <simgear/debug/logstream.hxx>
33 #include <simgear/math/sg_geodesy.hxx>
34 #include <simgear/scene/model/placement.hxx>
35 #include <simgear/timing/timestamp.hxx>
36
37 #include <Scenery/scenery.hxx>
38 #include <Main/globals.hxx>
39 #include <Main/fg_props.hxx>
40 #include <FDM/groundcache.hxx>
41
42 #include "flight.hxx"
43
44
45 // base_fdm_state is the internal state that is updated in integer
46 // multiples of "dt".  This leads to "jitter" with respect to the real
47 // world time, so we introduce cur_fdm_state which is extrapolated by
48 // the difference between sim time and real world time
49
50 FGInterface *cur_fdm_state = 0;
51 FGInterface base_fdm_state;
52
53 inline void init_vec(FG_VECTOR_3 vec) {
54     vec[0] = 0.0; vec[1] = 0.0; vec[2] = 0.0;
55 }
56
57 // Constructor
58 FGInterface::FGInterface()
59   : remainder(0)
60 {
61     _setup();
62 }
63
64 FGInterface::FGInterface( double dt )
65   : remainder(0)
66 {
67     _setup();
68 }
69
70 // Destructor
71 FGInterface::~FGInterface() {
72     // unbind();                   // FIXME: should be called explicitly
73 }
74
75
76 int
77 FGInterface::_calc_multiloop (double dt)
78 {
79   int hz = fgGetInt("/sim/model-hz");
80   int speedup = fgGetInt("/sim/speed-up");
81
82   dt += remainder;
83   remainder = 0;
84   double ml = dt * hz;
85   // Avoid roundoff problems by adding the roundoff itself.
86   // ... ok, two times the roundoff to have enough room.
87   int multiloop = int(floor(ml * (1.0 + 2.0*DBL_EPSILON)));
88   remainder = (ml - multiloop) / hz;
89   return (multiloop * speedup);
90 }
91
92
93 /**
94  * Set default values for the state of the FDM.
95  *
96  * This method is invoked by the constructors.
97  */
98 void
99 FGInterface::_setup ()
100 {
101     inited = false;
102     bound = false;
103
104     init_vec( d_pilot_rp_body_v );
105     init_vec( d_cg_rp_body_v );
106     init_vec( f_body_total_v );
107     init_vec( f_local_total_v );
108     init_vec( f_aero_v );
109     init_vec( f_engine_v );
110     init_vec( f_gear_v );
111     init_vec( m_total_rp_v );
112     init_vec( m_total_cg_v );
113     init_vec( m_aero_v );
114     init_vec( m_engine_v );
115     init_vec( m_gear_v );
116     init_vec( v_dot_local_v );
117     init_vec( v_dot_body_v );
118     init_vec( a_cg_body_v );
119     init_vec( a_pilot_body_v );
120     init_vec( n_cg_body_v );
121     init_vec( n_pilot_body_v );
122     init_vec( omega_dot_body_v );
123     init_vec( v_local_v );
124     init_vec( v_local_rel_ground_v );
125     init_vec( v_local_airmass_v );
126     init_vec( v_local_rel_airmass_v );
127     init_vec( v_local_gust_v );
128     init_vec( v_wind_body_v );
129     init_vec( omega_body_v );
130     init_vec( omega_local_v );
131     init_vec( omega_total_v );
132     init_vec( euler_rates_v );
133     init_vec( geocentric_rates_v );
134     init_vec( geocentric_position_v );
135     init_vec( geodetic_position_v );
136     init_vec( euler_angles_v );
137     init_vec( d_cg_rwy_local_v );
138     init_vec( d_cg_rwy_rwy_v );
139     init_vec( d_pilot_rwy_local_v );
140     init_vec( d_pilot_rwy_rwy_v );
141     init_vec( t_local_to_body_m[0] );
142     init_vec( t_local_to_body_m[1] );
143     init_vec( t_local_to_body_m[2] );
144
145     mass=i_xx=i_yy=i_zz=i_xz=0;
146     nlf=0;
147     v_rel_wind=v_true_kts=v_rel_ground=v_inertial=0;
148     v_ground_speed=v_equiv=v_equiv_kts=0;
149     v_calibrated=v_calibrated_kts=0;
150     gravity=0;
151     centrifugal_relief=0;
152     alpha=beta=alpha_dot=beta_dot=0;
153     cos_alpha=sin_alpha=cos_beta=sin_beta=0;
154     cos_phi=sin_phi=cos_theta=sin_theta=cos_psi=sin_psi=0;
155     gamma_vert_rad=gamma_horiz_rad=0;
156     sigma=density=v_sound=mach_number=0;
157     static_pressure=total_pressure=impact_pressure=0;
158     dynamic_pressure=0;
159     static_temperature=total_temperature=0;
160     sea_level_radius=earth_position_angle=0;
161     runway_altitude=runway_latitude=runway_longitude=0;
162     runway_heading=0;
163     radius_to_rwy=0;
164     climb_rate=0;
165     sin_lat_geocentric=cos_lat_geocentric=0;
166     sin_latitude=cos_latitude=0;
167     sin_longitude=cos_longitude=0;
168     altitude_agl=0;
169 }
170
171 void
172 FGInterface::init () {}
173
174 /**
175  * Initialize the state of the FDM.
176  *
177  * Subclasses of FGInterface may do their own, additional initialization,
178  * but there is some that is common to all.  Normally, they should call
179  * this before they begin their own init to make sure the basic structures
180  * are set up properly.
181  */
182 void
183 FGInterface::common_init ()
184 {
185     SG_LOG( SG_FLIGHT, SG_INFO, "Start common FDM init" );
186
187     set_inited( true );
188
189 //     stamp();
190 //     set_remainder( 0 );
191
192     // Set initial position
193     SG_LOG( SG_FLIGHT, SG_INFO, "...initializing position..." );
194     double lon = fgGetDouble("/sim/presets/longitude-deg")
195       * SGD_DEGREES_TO_RADIANS;
196     double lat = fgGetDouble("/sim/presets/latitude-deg")
197       * SGD_DEGREES_TO_RADIANS;
198     double alt_ft = fgGetDouble("/sim/presets/altitude-ft");
199     double alt_m = alt_ft * SG_FEET_TO_METER;
200     set_Longitude( lon );
201     set_Latitude( lat );
202     SG_LOG( SG_FLIGHT, SG_INFO, "Checking for lon = "
203             << lon*SGD_RADIANS_TO_DEGREES << "deg, lat = "
204             << lat*SGD_RADIANS_TO_DEGREES << "deg, alt = "
205             << alt_ft << "ft");
206
207     double ground_elev_m = get_groundlevel_m(lat, lon, alt_m);
208     double ground_elev_ft = ground_elev_m * SG_METER_TO_FEET;
209     _set_Runway_altitude ( ground_elev_ft );
210     if ( fgGetBool("/sim/presets/onground") || alt_ft < ground_elev_ft ) {
211         fgSetDouble("/position/altitude-ft", ground_elev_ft + 0.1);
212         set_Altitude( ground_elev_ft + 0.1);
213     } else {
214         set_Altitude( alt_ft );
215     }
216
217     // Set ground elevation
218     SG_LOG( SG_FLIGHT, SG_INFO,
219             "...initializing ground elevation to " << ground_elev_ft
220             << "ft..." );
221
222     // Set sea-level radius
223     SG_LOG( SG_FLIGHT, SG_INFO, "...initializing sea-level radius..." );
224     SG_LOG( SG_FLIGHT, SG_INFO, " lat = "
225             << fgGetDouble("/sim/presets/latitude-deg")
226             << " alt = " << get_Altitude() );
227     double sea_level_radius_meters;
228     double lat_geoc;
229     sgGeodToGeoc( fgGetDouble("/sim/presets/latitude-deg")
230                     * SGD_DEGREES_TO_RADIANS,
231                   get_Altitude() * SG_FEET_TO_METER,
232                   &sea_level_radius_meters, &lat_geoc );
233     _set_Sea_level_radius( sea_level_radius_meters * SG_METER_TO_FEET );
234
235     // Set initial velocities
236     SG_LOG( SG_FLIGHT, SG_INFO, "...initializing velocities..." );
237     if ( !fgHasNode("/sim/presets/speed-set") ) {
238         set_V_calibrated_kts(0.0);
239     } else {
240         const string speedset = fgGetString("/sim/presets/speed-set");
241         if ( speedset == "knots" || speedset == "KNOTS" ) {
242             set_V_calibrated_kts( fgGetDouble("/sim/presets/airspeed-kt") );
243         } else if ( speedset == "mach" || speedset == "MACH" ) {
244             set_Mach_number( fgGetDouble("/sim/presets/mach") );
245         } else if ( speedset == "UVW" || speedset == "uvw" ) {
246             set_Velocities_Wind_Body(
247                                      fgGetDouble("/sim/presets/uBody-fps"),
248                                      fgGetDouble("/sim/presets/vBody-fps"),
249                                      fgGetDouble("/sim/presets/wBody-fps") );
250         } else if ( speedset == "NED" || speedset == "ned" ) {
251             set_Velocities_Local(
252                                  fgGetDouble("/sim/presets/speed-north-fps"),
253                                  fgGetDouble("/sim/presets/speed-east-fps"),
254                                  fgGetDouble("/sim/presets/speed-down-fps") );
255         } else {
256             SG_LOG( SG_FLIGHT, SG_ALERT,
257                     "Unrecognized value for /sim/presets/speed-set: "
258                     << speedset);
259             set_V_calibrated_kts( 0.0 );
260         }
261     }
262
263     // Set initial Euler angles
264     SG_LOG( SG_FLIGHT, SG_INFO, "...initializing Euler angles..." );
265     set_Euler_Angles( fgGetDouble("/sim/presets/roll-deg")
266                         * SGD_DEGREES_TO_RADIANS,
267                       fgGetDouble("/sim/presets/pitch-deg")
268                         * SGD_DEGREES_TO_RADIANS,
269                       fgGetDouble("/sim/presets/heading-deg")
270                         * SGD_DEGREES_TO_RADIANS );
271
272     SG_LOG( SG_FLIGHT, SG_INFO, "End common FDM init" );
273 }
274
275
276 /**
277  * Bind getters and setters to properties.
278  *
279  * The bind() method will be invoked after init().  Note that unlike
280  * the usual implementations of FGSubsystem::bind(), this method does
281  * not automatically pick up existing values for the properties at
282  * bind time; instead, all values are set explicitly in the init()
283  * method.
284  */
285 void
286 FGInterface::bind ()
287 {
288   bound = true;
289
290                                 // Time management (read-only)
291 //   fgTie("/fdm/time/delta_t", this,
292 //         &FGInterface::get_delta_t); // read-only
293 //   fgTie("/fdm/time/elapsed", this,
294 //         &FGInterface::get_elapsed); // read-only
295 //   fgTie("/fdm/time/remainder", this,
296 //         &FGInterface::get_remainder); // read-only
297 //   fgTie("/fdm/time/multi_loop", this,
298 //         &FGInterface::get_multi_loop); // read-only
299
300                         // Aircraft position
301   fgTie("/position/latitude-deg", this,
302         &FGInterface::get_Latitude_deg,
303         &FGInterface::set_Latitude_deg,
304         false);
305   fgSetArchivable("/position/latitude-deg");
306   fgTie("/position/longitude-deg", this,
307         &FGInterface::get_Longitude_deg,
308         &FGInterface::set_Longitude_deg,
309         false);
310   fgSetArchivable("/position/longitude-deg");
311   fgTie("/position/altitude-ft", this,
312         &FGInterface::get_Altitude,
313         &FGInterface::set_Altitude,
314         false);
315   fgSetArchivable("/position/altitude-ft");
316   fgTie("/position/altitude-agl-ft", this,
317         &FGInterface::get_Altitude_AGL); // read-only
318   fgSetArchivable("/position/ground-elev-ft");
319   fgTie("/position/ground-elev-ft", this,
320         &FGInterface::get_Runway_altitude); // read-only
321   fgSetArchivable("/position/ground-elev-m");
322   fgTie("/position/ground-elev-m", this,
323         &FGInterface::get_Runway_altitude_m); // read-only
324   fgTie("/environment/ground-elevation-m", this,
325         &FGInterface::get_Runway_altitude_m); // read-only
326   fgSetArchivable("/position/sea-level-radius-ft");
327   fgTie("/position/sea-level-radius-ft", this,
328         &FGInterface::get_Sea_level_radius); // read-only
329
330                                 // Orientation
331   fgTie("/orientation/roll-deg", this,
332         &FGInterface::get_Phi_deg,
333         &FGInterface::set_Phi_deg);
334   fgSetArchivable("/orientation/roll-deg");
335   fgTie("/orientation/pitch-deg", this,
336         &FGInterface::get_Theta_deg,
337         &FGInterface::set_Theta_deg);
338   fgSetArchivable("/orientation/pitch-deg");
339   fgTie("/orientation/heading-deg", this,
340         &FGInterface::get_Psi_deg,
341         &FGInterface::set_Psi_deg);
342   fgSetArchivable("/orientation/heading-deg");
343
344   // Body-axis "euler rates" (rotation speed, but in a funny
345   // representation).
346   fgTie("/orientation/roll-rate-degps", this,
347         &FGInterface::get_Phi_dot_degps);
348   fgTie("/orientation/pitch-rate-degps", this,
349         &FGInterface::get_Theta_dot_degps);
350   fgTie("/orientation/yaw-rate-degps", this,
351         &FGInterface::get_Psi_dot_degps);
352
353                                 // Calibrated airspeed
354   fgTie("/velocities/airspeed-kt", this,
355         &FGInterface::get_V_calibrated_kts,
356         &FGInterface::set_V_calibrated_kts,
357         false);
358
359                                 // Mach number
360   fgTie("/velocities/mach", this,
361         &FGInterface::get_Mach_number,
362         &FGInterface::set_Mach_number,
363         false);
364
365                                 // Local velocities
366 //   fgTie("/velocities/speed-north-fps", this,
367 //      &FGInterface::get_V_north,
368 //      &FGInterface::set_V_north);
369 //   fgSetArchivable("/velocities/speed-north-fps");
370 //   fgTie("/velocities/speed-east-fps", this,
371 //      &FGInterface::get_V_east,
372 //      &FGInterface::set_V_east);
373 //   fgSetArchivable("/velocities/speed-east-fps");
374 //   fgTie("/velocities/speed-down-fps", this,
375 //      &FGInterface::get_V_down,
376 //      &FGInterface::set_V_down);
377 //   fgSetArchivable("/velocities/speed-down-fps");
378                                 // FIXME: Temporarily read-only, until the
379                                 // incompatibilities between JSBSim and
380                                 // LaRCSim are fixed (LaRCSim adds the
381                                 // earth's rotation to the east velocity).
382   fgTie("/velocities/speed-north-fps", this,
383         &FGInterface::get_V_north);
384   fgTie("/velocities/speed-east-fps", this,
385         &FGInterface::get_V_east);
386   fgTie("/velocities/speed-down-fps", this,
387         &FGInterface::get_V_down);
388
389                                 // Relative wind
390                                 // FIXME: temporarily archivable, until
391                                 // the NED problem is fixed.
392   fgTie("/velocities/uBody-fps", this,
393         &FGInterface::get_uBody,
394         &FGInterface::set_uBody,
395         false);
396   fgSetArchivable("/velocities/uBody-fps");
397   fgTie("/velocities/vBody-fps", this,
398         &FGInterface::get_vBody,
399         &FGInterface::set_vBody,
400         false);
401   fgSetArchivable("/velocities/vBody-fps");
402   fgTie("/velocities/wBody-fps", this,
403         &FGInterface::get_wBody,
404         &FGInterface::set_wBody,
405         false);
406   fgSetArchivable("/velocities/wBody-fps");
407
408                                 // Climb and slip (read-only)
409   fgTie("/velocities/vertical-speed-fps", this,
410         &FGInterface::get_Climb_Rate,
411   &FGInterface::set_Climb_Rate ); 
412   fgTie("/velocities/glideslope", this,
413   &FGInterface::get_Gamma_vert_rad,
414   &FGInterface::set_Gamma_vert_rad );
415   fgTie("/orientation/side-slip-rad", this,
416         &FGInterface::get_Beta); // read-only
417   fgTie("/orientation/side-slip-deg", this,
418   &FGInterface::get_Beta_deg); // read-only
419   fgTie("/orientation/alpha-deg", this,
420   &FGInterface::get_Alpha_deg); // read-only
421   fgTie("/accelerations/nlf", this,
422   &FGInterface::get_Nlf); // read-only
423
424                                 // NED accelerations
425   fgTie("/accelerations/ned/north-accel-fps_sec",
426         this, &FGInterface::get_V_dot_north);
427   fgTie("/accelerations/ned/east-accel-fps_sec",
428         this, &FGInterface::get_V_dot_east);
429   fgTie("/accelerations/ned/down-accel-fps_sec",
430         this, &FGInterface::get_V_dot_down);
431
432                                 // Pilot accelerations
433   fgTie("/accelerations/pilot/x-accel-fps_sec",
434         this, &FGInterface::get_A_X_pilot);
435   fgTie("/accelerations/pilot/y-accel-fps_sec",
436         this, &FGInterface::get_A_Y_pilot);
437   fgTie("/accelerations/pilot/z-accel-fps_sec",
438         this, &FGInterface::get_A_Z_pilot);
439
440 }
441
442
443 /**
444  * Unbind any properties bound to this FDM.
445  *
446  * This method allows the FDM to release properties so that a new
447  * FDM can bind them instead.
448  */
449 void
450 FGInterface::unbind ()
451 {
452   bound = false;
453
454   // fgUntie("/fdm/time/delta_t");
455   // fgUntie("/fdm/time/elapsed");
456   // fgUntie("/fdm/time/remainder");
457   // fgUntie("/fdm/time/multi_loop");
458   fgUntie("/position/latitude-deg");
459   fgUntie("/position/longitude-deg");
460   fgUntie("/position/altitude-ft");
461   fgUntie("/position/altitude-agl-ft");
462   fgUntie("/position/ground-elev-ft");
463   fgUntie("/position/ground-elev-m");
464   fgUntie("/environment/ground-elevation-m");
465   fgUntie("/position/sea-level-radius-ft");
466   fgUntie("/orientation/roll-deg");
467   fgUntie("/orientation/pitch-deg");
468   fgUntie("/orientation/heading-deg");
469   fgUntie("/orientation/roll-rate-degps");
470   fgUntie("/orientation/pitch-rate-degps");
471   fgUntie("/orientation/yaw-rate-degps");
472   fgUntie("/orientation/side-slip-rad");
473   fgUntie("/orientation/side-slip-deg");
474   fgUntie("/orientation/alpha-deg");
475   fgUntie("/velocities/airspeed-kt");
476   fgUntie("/velocities/mach");
477   fgUntie("/velocities/speed-north-fps");
478   fgUntie("/velocities/speed-east-fps");
479   fgUntie("/velocities/speed-down-fps");
480   fgUntie("/velocities/uBody-fps");
481   fgUntie("/velocities/vBody-fps");
482   fgUntie("/velocities/wBody-fps");
483   fgUntie("/velocities/vertical-speed-fps");
484   fgUntie("/velocities/glideslope");
485   fgUntie("/accelerations/nlf");
486   fgUntie("/accelerations/pilot/x-accel-fps_sec");
487   fgUntie("/accelerations/pilot/y-accel-fps_sec");
488   fgUntie("/accelerations/pilot/z-accel-fps_sec");
489   fgUntie("/accelerations/ned/north-accel-fps_sec");
490   fgUntie("/accelerations/ned/east-accel-fps_sec");
491   fgUntie("/accelerations/ned/down-accel-fps_sec");
492 }
493
494 /**
495  * Update the state of the FDM (i.e. run the equations of motion).
496  */
497 void
498 FGInterface::update (double dt)
499 {
500     SG_LOG(SG_FLIGHT, SG_ALERT, "dummy update() ... SHOULDN'T BE CALLED!");
501 }
502
503
504 void FGInterface::_updateGeodeticPosition( double lat, double lon, double alt )
505 {
506     double lat_geoc, sl_radius;
507
508     // cout << "starting sea level rad = " << get_Sea_level_radius() << endl;
509
510     sgGeodToGeoc( lat, alt * SG_FEET_TO_METER, &sl_radius, &lat_geoc );
511
512     SG_LOG( SG_FLIGHT, SG_DEBUG, "lon = " << lon 
513             << " lat_geod = " << lat
514             << " lat_geoc = " << lat_geoc
515             << " alt = " << alt 
516             << " sl_radius = " << sl_radius * SG_METER_TO_FEET
517             << " Equator = " << SG_EQUATORIAL_RADIUS_FT );
518
519     _set_Geocentric_Position( lat_geoc, lon, 
520                               sl_radius * SG_METER_TO_FEET + alt );
521         
522     _set_Geodetic_Position( lat, lon, alt );
523
524     _set_Sea_level_radius( sl_radius * SG_METER_TO_FEET );
525     _update_ground_elev_at_pos();
526
527     _set_sin_lat_geocentric( lat_geoc );
528     _set_cos_lat_geocentric( lat_geoc );
529
530     _set_sin_cos_longitude( lon );
531
532     _set_sin_cos_latitude( lat );
533 }
534
535
536 void FGInterface::_updateGeocentricPosition( double lat_geoc, double lon,
537                                              double alt )
538 {
539     double lat_geod, tmp_alt, sl_radius1, sl_radius2, tmp_lat_geoc;
540
541     // cout << "starting sea level rad = " << get_Sea_level_radius() << endl;
542
543     sgGeocToGeod( lat_geoc, ( get_Sea_level_radius() + alt ) * SG_FEET_TO_METER,
544                   &lat_geod, &tmp_alt, &sl_radius1 );
545     sgGeodToGeoc( lat_geod, alt * SG_FEET_TO_METER, &sl_radius2, &tmp_lat_geoc );
546
547     SG_LOG( SG_FLIGHT, SG_DEBUG, "lon = " << lon 
548             << " lat_geod = " << lat_geod
549             << " lat_geoc = " << lat_geoc
550             << " alt = " << alt 
551             << " tmp_alt = " << tmp_alt * SG_METER_TO_FEET
552             << " sl_radius1 = " << sl_radius1 * SG_METER_TO_FEET
553             << " sl_radius2 = " << sl_radius2 * SG_METER_TO_FEET
554             << " Equator = " << SG_EQUATORIAL_RADIUS_FT );
555
556     _set_Geocentric_Position( lat_geoc, lon, 
557                               sl_radius2 * SG_METER_TO_FEET + alt );
558         
559     _set_Geodetic_Position( lat_geod, lon, alt );
560
561     _set_Sea_level_radius( sl_radius2 * SG_METER_TO_FEET );
562     _update_ground_elev_at_pos();
563
564     _set_sin_lat_geocentric( lat_geoc );
565     _set_cos_lat_geocentric( lat_geoc );
566
567     _set_sin_cos_longitude( lon );
568
569     _set_sin_cos_latitude( lat_geod );
570 }
571
572 void FGInterface::_update_ground_elev_at_pos( void ) {
573     double lat = get_Latitude();
574     double lon = get_Longitude();
575     double alt_m = get_Altitude()*SG_FEET_TO_METER;
576     double groundlevel_m = get_groundlevel_m(lat, lon, alt_m);
577     _set_Runway_altitude( groundlevel_m * SG_METER_TO_FEET );
578 }
579
580 // Extrapolate fdm based on time_offset (in usec)
581 void FGInterface::extrapolate( int time_offset ) {
582     double dt = time_offset / 1000000.0;
583
584     // -dw- metrowerks complains about ambiguous access, not critical
585     // to keep this ;)
586 #ifndef __MWERKS__
587     SG_LOG(SG_FLIGHT, SG_INFO, "extrapolating FDM by dt = " << dt);
588 #endif
589
590     double lat = geodetic_position_v[0] + geocentric_rates_v[0] * dt;
591     double lat_geoc = geocentric_position_v[0] + geocentric_rates_v[0] * dt;
592
593     double lon = geodetic_position_v[1] + geocentric_rates_v[1] * dt;
594     double lon_geoc = geocentric_position_v[1] + geocentric_rates_v[1] * dt;
595
596     double alt = geodetic_position_v[2] + geocentric_rates_v[2] * dt;
597     double radius = geocentric_position_v[2] + geocentric_rates_v[2] * dt;
598
599     geodetic_position_v[0] = lat;
600     geocentric_position_v[0] = lat_geoc;
601
602     geodetic_position_v[1] = lon;
603     geocentric_position_v[1] = lon_geoc;
604
605     geodetic_position_v[2] = alt;
606     geocentric_position_v[2] = radius;
607 }
608
609 // Positions
610 void FGInterface::set_Latitude(double lat) {
611     geodetic_position_v[0] = lat;
612 }
613
614 void FGInterface::set_Longitude(double lon) {
615     geodetic_position_v[1] = lon;
616 }
617
618 void FGInterface::set_Altitude(double alt) {
619     geodetic_position_v[2] = alt;
620 }
621
622 void FGInterface::set_AltitudeAGL(double altagl) {
623     altitude_agl=altagl;
624 }
625
626 // Velocities
627 void FGInterface::set_V_calibrated_kts(double vc) {
628     v_calibrated_kts = vc;
629 }
630
631 void FGInterface::set_Mach_number(double mach) {
632     mach_number = mach;
633 }
634
635 void FGInterface::set_Velocities_Local( double north, 
636                                         double east, 
637                                         double down ){
638     v_local_v[0] = north;
639     v_local_v[1] = east;
640     v_local_v[2] = down;
641 }
642
643 void FGInterface::set_Velocities_Wind_Body( double u, 
644                                             double v, 
645                                             double w){
646     v_wind_body_v[0] = u;
647     v_wind_body_v[1] = v;
648     v_wind_body_v[2] = w;
649 }
650
651 // Euler angles 
652 void FGInterface::set_Euler_Angles( double phi, 
653                                     double theta, 
654                                     double psi ) {
655     euler_angles_v[0] = phi;
656     euler_angles_v[1] = theta;
657     euler_angles_v[2] = psi;                                            
658 }  
659
660 // Flight Path
661 void FGInterface::set_Climb_Rate( double roc) {
662     climb_rate = roc;
663 }
664
665 void FGInterface::set_Gamma_vert_rad( double gamma) {
666     gamma_vert_rad = gamma;
667 }
668
669 void FGInterface::set_Static_pressure(double p) { static_pressure = p; }
670 void FGInterface::set_Static_temperature(double T) { static_temperature = T; }
671 void FGInterface::set_Density(double rho) { density = rho; }
672
673 void FGInterface::set_Velocities_Local_Airmass (double wnorth, 
674                                                 double weast, 
675                                                 double wdown ) {
676     v_local_airmass_v[0] = wnorth;
677     v_local_airmass_v[1] = weast;
678     v_local_airmass_v[2] = wdown;
679 }
680
681
682 void FGInterface::_busdump(void) {
683
684     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]);
685     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]);
686     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]);
687     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]);
688     SG_LOG(SG_FLIGHT,SG_INFO,"f_aero_v[3]: " << f_aero_v[0] << ", " << f_aero_v[1] << ", " << f_aero_v[2]);
689     SG_LOG(SG_FLIGHT,SG_INFO,"f_engine_v[3]: " << f_engine_v[0] << ", " << f_engine_v[1] << ", " << f_engine_v[2]);
690     SG_LOG(SG_FLIGHT,SG_INFO,"f_gear_v[3]: " << f_gear_v[0] << ", " << f_gear_v[1] << ", " << f_gear_v[2]);
691     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]);
692     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]);
693     SG_LOG(SG_FLIGHT,SG_INFO,"m_aero_v[3]: " << m_aero_v[0] << ", " << m_aero_v[1] << ", " << m_aero_v[2]);
694     SG_LOG(SG_FLIGHT,SG_INFO,"m_engine_v[3]: " << m_engine_v[0] << ", " << m_engine_v[1] << ", " << m_engine_v[2]);
695     SG_LOG(SG_FLIGHT,SG_INFO,"m_gear_v[3]: " << m_gear_v[0] << ", " << m_gear_v[1] << ", " << m_gear_v[2]);
696     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]);
697     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]);
698     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]);
699     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]);
700     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]);
701     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]);
702     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]);
703     SG_LOG(SG_FLIGHT,SG_INFO,"v_local_v[3]: " << v_local_v[0] << ", " << v_local_v[1] << ", " << v_local_v[2]);
704     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]);
705     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]);
706     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]);
707     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]);
708     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]);
709     SG_LOG(SG_FLIGHT,SG_INFO,"omega_body_v[3]: " << omega_body_v[0] << ", " << omega_body_v[1] << ", " << omega_body_v[2]);
710     SG_LOG(SG_FLIGHT,SG_INFO,"omega_local_v[3]: " << omega_local_v[0] << ", " << omega_local_v[1] << ", " << omega_local_v[2]);
711     SG_LOG(SG_FLIGHT,SG_INFO,"omega_total_v[3]: " << omega_total_v[0] << ", " << omega_total_v[1] << ", " << omega_total_v[2]);
712     SG_LOG(SG_FLIGHT,SG_INFO,"euler_rates_v[3]: " << euler_rates_v[0] << ", " << euler_rates_v[1] << ", " << euler_rates_v[2]);
713     SG_LOG(SG_FLIGHT,SG_INFO,"geocentric_rates_v[3]: " << geocentric_rates_v[0] << ", " << geocentric_rates_v[1] << ", " << geocentric_rates_v[2]);
714     SG_LOG(SG_FLIGHT,SG_INFO,"geocentric_position_v[3]: " << geocentric_position_v[0] << ", " << geocentric_position_v[1] << ", " << geocentric_position_v[2]);
715     SG_LOG(SG_FLIGHT,SG_INFO,"geodetic_position_v[3]: " << geodetic_position_v[0] << ", " << geodetic_position_v[1] << ", " << geodetic_position_v[2]);
716     SG_LOG(SG_FLIGHT,SG_INFO,"euler_angles_v[3]: " << euler_angles_v[0] << ", " << euler_angles_v[1] << ", " << euler_angles_v[2]);
717     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]);
718     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]);
719     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]);
720     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]);
721
722     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]);
723     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]);
724     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]);
725
726     SG_LOG(SG_FLIGHT,SG_INFO,"mass: " << mass );
727     SG_LOG(SG_FLIGHT,SG_INFO,"i_xx: " << i_xx );
728     SG_LOG(SG_FLIGHT,SG_INFO,"i_yy: " << i_yy );
729     SG_LOG(SG_FLIGHT,SG_INFO,"i_zz: " << i_zz );
730     SG_LOG(SG_FLIGHT,SG_INFO,"i_xz: " << i_xz );
731     SG_LOG(SG_FLIGHT,SG_INFO,"nlf: " << nlf );
732     SG_LOG(SG_FLIGHT,SG_INFO,"v_rel_wind: " << v_rel_wind );
733     SG_LOG(SG_FLIGHT,SG_INFO,"v_true_kts: " << v_true_kts );
734     SG_LOG(SG_FLIGHT,SG_INFO,"v_rel_ground: " << v_rel_ground );
735     SG_LOG(SG_FLIGHT,SG_INFO,"v_inertial: " << v_inertial );
736     SG_LOG(SG_FLIGHT,SG_INFO,"v_ground_speed: " << v_ground_speed );
737     SG_LOG(SG_FLIGHT,SG_INFO,"v_equiv: " << v_equiv );
738     SG_LOG(SG_FLIGHT,SG_INFO,"v_equiv_kts: " << v_equiv_kts );
739     SG_LOG(SG_FLIGHT,SG_INFO,"v_calibrated: " << v_calibrated );
740     SG_LOG(SG_FLIGHT,SG_INFO,"v_calibrated_kts: " << v_calibrated_kts );
741     SG_LOG(SG_FLIGHT,SG_INFO,"gravity: " << gravity );
742     SG_LOG(SG_FLIGHT,SG_INFO,"centrifugal_relief: " << centrifugal_relief );
743     SG_LOG(SG_FLIGHT,SG_INFO,"alpha: " << alpha );
744     SG_LOG(SG_FLIGHT,SG_INFO,"beta: " << beta );
745     SG_LOG(SG_FLIGHT,SG_INFO,"alpha_dot: " << alpha_dot );
746     SG_LOG(SG_FLIGHT,SG_INFO,"beta_dot: " << beta_dot );
747     SG_LOG(SG_FLIGHT,SG_INFO,"cos_alpha: " << cos_alpha );
748     SG_LOG(SG_FLIGHT,SG_INFO,"sin_alpha: " << sin_alpha );
749     SG_LOG(SG_FLIGHT,SG_INFO,"cos_beta: " << cos_beta );
750     SG_LOG(SG_FLIGHT,SG_INFO,"sin_beta: " << sin_beta );
751     SG_LOG(SG_FLIGHT,SG_INFO,"cos_phi: " << cos_phi );
752     SG_LOG(SG_FLIGHT,SG_INFO,"sin_phi: " << sin_phi );
753     SG_LOG(SG_FLIGHT,SG_INFO,"cos_theta: " << cos_theta );
754     SG_LOG(SG_FLIGHT,SG_INFO,"sin_theta: " << sin_theta );
755     SG_LOG(SG_FLIGHT,SG_INFO,"cos_psi: " << cos_psi );
756     SG_LOG(SG_FLIGHT,SG_INFO,"sin_psi: " << sin_psi );
757     SG_LOG(SG_FLIGHT,SG_INFO,"gamma_vert_rad: " << gamma_vert_rad );
758     SG_LOG(SG_FLIGHT,SG_INFO,"gamma_horiz_rad: " << gamma_horiz_rad );
759     SG_LOG(SG_FLIGHT,SG_INFO,"sigma: " << sigma );
760     SG_LOG(SG_FLIGHT,SG_INFO,"density: " << density );
761     SG_LOG(SG_FLIGHT,SG_INFO,"v_sound: " << v_sound );
762     SG_LOG(SG_FLIGHT,SG_INFO,"mach_number: " << mach_number );
763     SG_LOG(SG_FLIGHT,SG_INFO,"static_pressure: " << static_pressure );
764     SG_LOG(SG_FLIGHT,SG_INFO,"total_pressure: " << total_pressure );
765     SG_LOG(SG_FLIGHT,SG_INFO,"impact_pressure: " << impact_pressure );
766     SG_LOG(SG_FLIGHT,SG_INFO,"dynamic_pressure: " << dynamic_pressure );
767     SG_LOG(SG_FLIGHT,SG_INFO,"static_temperature: " << static_temperature );
768     SG_LOG(SG_FLIGHT,SG_INFO,"total_temperature: " << total_temperature );
769     SG_LOG(SG_FLIGHT,SG_INFO,"sea_level_radius: " << sea_level_radius );
770     SG_LOG(SG_FLIGHT,SG_INFO,"earth_position_angle: " << earth_position_angle );
771     SG_LOG(SG_FLIGHT,SG_INFO,"runway_altitude: " << runway_altitude );
772     SG_LOG(SG_FLIGHT,SG_INFO,"runway_latitude: " << runway_latitude );
773     SG_LOG(SG_FLIGHT,SG_INFO,"runway_longitude: " << runway_longitude );
774     SG_LOG(SG_FLIGHT,SG_INFO,"runway_heading: " << runway_heading );
775     SG_LOG(SG_FLIGHT,SG_INFO,"radius_to_rwy: " << radius_to_rwy );
776     SG_LOG(SG_FLIGHT,SG_INFO,"climb_rate: " << climb_rate );
777     SG_LOG(SG_FLIGHT,SG_INFO,"sin_lat_geocentric: " << sin_lat_geocentric );
778     SG_LOG(SG_FLIGHT,SG_INFO,"cos_lat_geocentric: " << cos_lat_geocentric );
779     SG_LOG(SG_FLIGHT,SG_INFO,"sin_longitude: " << sin_longitude );
780     SG_LOG(SG_FLIGHT,SG_INFO,"cos_longitude: " << cos_longitude );
781     SG_LOG(SG_FLIGHT,SG_INFO,"sin_latitude: " << sin_latitude );
782     SG_LOG(SG_FLIGHT,SG_INFO,"cos_latitude: " << cos_latitude );
783     SG_LOG(SG_FLIGHT,SG_INFO,"altitude_agl: " << altitude_agl );
784 }
785
786 bool
787 FGInterface::prepare_ground_cache_m(double ref_time, const double pt[3],
788                                     double rad)
789 {
790   return ground_cache.prepare_ground_cache(ref_time, pt, rad);
791 }
792
793 bool FGInterface::prepare_ground_cache_ft(double ref_time, const double pt[3],
794                                           double rad)
795 {
796   // Convert units and do the real work.
797   sgdVec3 pt_ft;
798   sgdScaleVec3( pt_ft, pt, SG_FEET_TO_METER );
799   return ground_cache.prepare_ground_cache(ref_time, pt_ft, rad*SG_FEET_TO_METER);
800 }
801
802 bool
803 FGInterface::is_valid_m(double *ref_time, double pt[3], double *rad)
804 {
805   return ground_cache.is_valid(ref_time, pt, rad);
806 }
807
808 bool FGInterface::is_valid_ft(double *ref_time, double pt[3], double *rad)
809 {
810   // Convert units and do the real work.
811   bool found_ground = ground_cache.is_valid(ref_time, pt, rad);
812   sgdScaleVec3(pt, SG_METER_TO_FEET);
813   *rad *= SG_METER_TO_FEET;
814   return found_ground;
815 }
816
817 double
818 FGInterface::get_cat_m(double t, const double pt[3],
819                        double end[2][3], double vel[2][3])
820 {
821   return ground_cache.get_cat(t, pt, end, vel);
822 }
823
824 double
825 FGInterface::get_cat_ft(double t, const double pt[3],
826                         double end[2][3], double vel[2][3])
827 {
828   // Convert units and do the real work.
829   sgdVec3 pt_m;
830   sgdScaleVec3( pt_m, pt, SG_FEET_TO_METER );
831   double dist = ground_cache.get_cat(t, pt_m, end, vel);
832   for (int k=0; k<2; ++k) {
833     sgdScaleVec3( end[k], SG_METER_TO_FEET );
834     sgdScaleVec3( vel[k], SG_METER_TO_FEET );
835   }
836   return dist*SG_METER_TO_FEET;
837 }
838
839 bool
840 FGInterface::get_agl_m(double t, const double pt[3],
841                        double contact[3], double normal[3], double vel[3],
842                        int *type, double *loadCapacity,
843                        double *frictionFactor, double *agl)
844 {
845   return ground_cache.get_agl(t, pt, 2.0, contact, normal, vel, type,
846                               loadCapacity, frictionFactor, agl);
847 }
848
849 bool
850 FGInterface::get_agl_ft(double t, const double pt[3],
851                         double contact[3], double normal[3], double vel[3],
852                         int *type, double *loadCapacity,
853                         double *frictionFactor, double *agl)
854 {
855   // Convert units and do the real work.
856   sgdVec3 pt_m;
857   sgdScaleVec3( pt_m, pt, SG_FEET_TO_METER );
858   bool ret = ground_cache.get_agl(t, pt_m, 2.0, contact, normal, vel,
859                                   type, loadCapacity, frictionFactor, agl);
860   // Convert units back ...
861   sgdScaleVec3( contact, SG_METER_TO_FEET );
862   sgdScaleVec3( vel, SG_METER_TO_FEET );
863   *agl *= SG_METER_TO_FEET;
864   // FIXME: scale the load limit to something in the english unit system.
865   // Be careful with the DBL_MAX which is returned by default.
866   return ret;
867 }
868
869 bool
870 FGInterface::get_agl_m(double t, const double pt[3], double max_altoff,
871                        double contact[3], double normal[3], double vel[3],
872                        int *type, double *loadCapacity,
873                        double *frictionFactor, double *agl)
874 {
875   return ground_cache.get_agl(t, pt, max_altoff, contact, normal, vel, type,
876                               loadCapacity, frictionFactor, agl);
877 }
878
879 bool
880 FGInterface::get_agl_ft(double t, const double pt[3], double max_altoff,
881                         double contact[3], double normal[3], double vel[3],
882                         int *type, double *loadCapacity,
883                         double *frictionFactor, double *agl)
884 {
885   // Convert units and do the real work.
886   sgdVec3 pt_m;
887   sgdScaleVec3( pt_m, pt, SG_FEET_TO_METER );
888   bool ret = ground_cache.get_agl(t, pt_m, SG_FEET_TO_METER * max_altoff,
889                                   contact, normal, vel,
890                                   type, loadCapacity, frictionFactor, agl);
891   // Convert units back ...
892   sgdScaleVec3( contact, SG_METER_TO_FEET );
893   sgdScaleVec3( vel, SG_METER_TO_FEET );
894   *agl *= SG_METER_TO_FEET;
895   // FIXME: scale the load limit to something in the english unit system.
896   // Be careful with the DBL_MAX which is returned by default.
897   return ret;
898 }
899
900
901 double
902 FGInterface::get_groundlevel_m(double lat, double lon, double alt)
903 {
904   sgdVec3 pos, cpos;
905   // Compute the cartesian position of the given lat/lon/alt.
906   sgGeodToCart(lat, lon, alt, pos);
907
908   // FIXME: how to handle t - ref_time differences ???
909   double ref_time, radius;
910   // Prepare the ground cache for that position.
911   if (!is_valid_m(&ref_time, cpos, &radius)) {
912     bool ok = prepare_ground_cache_m(ref_time, pos, 10);
913     /// This is most likely the case when the given altitude is
914     /// too low, try with a new altitude of 10000m, that should be
915     /// sufficient to find a ground level below everywhere on our planet
916     if (!ok) {
917       sgGeodToCart(lat, lon, 10000, pos);
918       /// If there is still no ground, return sea level radius
919       if (!prepare_ground_cache_m(ref_time, pos, 10))
920         return 0;
921     }
922   } else if (radius*radius <= sgdDistanceSquaredVec3(pos, cpos)) {
923     /// We reuse the old radius value, but only if it is at least 10 Meters ..
924     if (!(10 < radius)) // Well this strange compare is nan safe
925       radius = 10;
926
927     bool ok = prepare_ground_cache_m(ref_time, pos, radius);
928     /// This is most likely the case when the given altitude is
929     /// too low, try with a new altitude of 10000m, that should be
930     /// sufficient to find a ground level below everywhere on our planet
931     if (!ok) {
932       sgGeodToCart(lat, lon, 10000, pos);
933       /// If there is still no ground, return sea level radius
934       if (!prepare_ground_cache_m(ref_time, pos, radius))
935         return 0;
936     }
937   }
938   
939   double contact[3], normal[3], vel[3], lc, ff, agl;
940   int type;
941   // Ignore the return value here, since it just tells us if
942   // the returns stem from the groundcache or from the coarse
943   // computations below the groundcache. The contact point is still something
944   // valid, the normals and the other returns just contain some defaults.
945   get_agl_m(ref_time, pos, 2.0, contact, normal, vel, &type, &lc, &ff, &agl);
946   Point3D geodPos = sgCartToGeod(Point3D(contact[0], contact[1], contact[2]));
947   return geodPos.elev();
948 }
949   
950 bool
951 FGInterface::caught_wire_m(double t, const double pt[4][3])
952 {
953   return ground_cache.caught_wire(t, pt);
954 }
955
956 bool
957 FGInterface::caught_wire_ft(double t, const double pt[4][3])
958 {
959   // Convert units and do the real work.
960   double pt_m[4][3];
961   for (int i=0; i<4; ++i)
962     sgdScaleVec3(pt_m[i], pt[i], SG_FEET_TO_METER);
963     
964   return ground_cache.caught_wire(t, pt_m);
965 }
966   
967 bool
968 FGInterface::get_wire_ends_m(double t, double end[2][3], double vel[2][3])
969 {
970   return ground_cache.get_wire_ends(t, end, vel);
971 }
972
973 bool
974 FGInterface::get_wire_ends_ft(double t, double end[2][3], double vel[2][3])
975 {
976   // Convert units and do the real work.
977   bool ret = ground_cache.get_wire_ends(t, end, vel);
978   for (int k=0; k<2; ++k) {
979     sgdScaleVec3( end[k], SG_METER_TO_FEET );
980     sgdScaleVec3( vel[k], SG_METER_TO_FEET );
981   }
982   return ret;
983 }
984
985 void
986 FGInterface::release_wire(void)
987 {
988   ground_cache.release_wire();
989 }
990
991 void fgToggleFDMdataLogging(void) {
992   cur_fdm_state->ToggleDataLogging();
993 }