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