]> git.mxchange.org Git - flightgear.git/blob - src/FDM/flight.cxx
Updates from the Jon and Tony show.
[flightgear.git] / src / FDM / flight.cxx
1 // flight.c -- 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 <Debug/logstream.hxx>
27 #include <FDM/LaRCsim/ls_interface.h>
28 #include <Include/fg_constants.h>
29 #include <Main/options.hxx>
30 #include <Math/fg_geodesy.hxx>
31 #include <Time/timestamp.hxx>
32
33 #include "External.hxx"
34 #include "flight.hxx"
35 #include "JSBsim.hxx"
36 #include "LaRCsim.hxx"
37 #include "Balloon.h"
38
39
40 // base_fdm_state is the internal state that is updated in integer
41 // multiples of "dt".  This leads to "jitter" with respect to the real
42 // world time, so we introduce cur_fdm_state which is extrapolated by
43 // the difference between sim time and real world time
44
45 FGInterface *cur_fdm_state;
46 FGInterface base_fdm_state;
47
48
49 int FGInterface::init( double dt ) {
50     cout << "dummy init() ... SHOULDN'T BE CALLED!" << endl;
51     return 0;
52 }
53
54 int FGInterface::update( int multi_loop ) {
55     cout << "dummy update() ... SHOULDN'T BE CALLED!" << endl;
56     return 0;
57 }
58
59 FGInterface::~FGInterface() {
60 }
61
62 // Extrapolate fdm based on time_offset (in usec)
63 void FGInterface::extrapolate( int time_offset ) {
64     double dt = time_offset / 1000000.0;
65
66     // -dw- metrowerks complains about ambiguous access, not critical
67     // to keep this ;)
68 #ifndef __MWERKS__
69     cout << "extrapolating FDM by dt = " << dt << endl;
70 #endif
71
72     double lat = geodetic_position_v[0] + geocentric_rates_v[0] * dt;
73     double lat_geoc = geocentric_position_v[0] + geocentric_rates_v[0] * dt;
74
75     double lon = geodetic_position_v[1] + geocentric_rates_v[1] * dt;
76     double lon_geoc = geocentric_position_v[1] + geocentric_rates_v[1] * dt;
77
78     double alt = geodetic_position_v[2] + geocentric_rates_v[2] * dt;
79     double radius = geocentric_position_v[2] + geocentric_rates_v[2] * dt;
80
81     geodetic_position_v[0] = lat;
82     geocentric_position_v[0] = lat_geoc;
83
84     geodetic_position_v[1] = lon;
85     geocentric_position_v[1] = lon_geoc;
86
87     geodetic_position_v[2] = alt;
88     geocentric_position_v[2] = radius;
89 }
90
91
92 // Set the altitude (force)
93 void fgFDMForceAltitude(int model, double alt_meters) {
94     double sea_level_radius_meters;
95     double lat_geoc;
96
97     // Set the FG variables first
98     fgGeodToGeoc( base_fdm_state.get_Latitude(), alt_meters, 
99                   &sea_level_radius_meters, &lat_geoc);
100
101     base_fdm_state.set_Altitude( alt_meters * METER_TO_FEET );
102     base_fdm_state.set_Radius_to_vehicle( base_fdm_state.get_Altitude() + 
103                                           (sea_level_radius_meters * 
104                                            METER_TO_FEET) );
105
106     // additional work needed for some flight models
107     if ( model == FGInterface::FG_LARCSIM ) {
108         ls_ForceAltitude( base_fdm_state.get_Altitude() );
109     }
110 }
111
112
113 // Set the local ground elevation
114 void fgFDMSetGroundElevation(int model, double ground_meters) {
115     base_fdm_state.set_Runway_altitude( ground_meters * METER_TO_FEET );
116     cur_fdm_state->set_Runway_altitude( ground_meters * METER_TO_FEET );
117 }
118
119