]> git.mxchange.org Git - flightgear.git/blob - src/FDM/flight.cxx
544f9b672ed7c3d9786a8424b1dec64b02696737
[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 <simgear/constants.h>
27 #include <simgear/debug/logstream.hxx>
28 #include <simgear/math/sg_geodesy.hxx>
29
30 #include <FDM/LaRCsim/ls_interface.h>
31 #include <Main/globals.hxx>
32 #include <Time/timestamp.hxx>
33
34 #include "External.hxx"
35 #include "flight.hxx"
36 #include "JSBSim.hxx"
37 #include "LaRCsim.hxx"
38 #include "Balloon.h"
39
40
41 // base_fdm_state is the internal state that is updated in integer
42 // multiples of "dt".  This leads to "jitter" with respect to the real
43 // world time, so we introduce cur_fdm_state which is extrapolated by
44 // the difference between sim time and real world time
45
46 FGInterface *cur_fdm_state;
47 FGInterface base_fdm_state;
48
49
50 // Constructor
51 FGInterface::FGInterface(void) {
52    mass=i_xx=i_yy=i_zz=i_xz=0;
53    nlf=0;  
54    v_rel_wind=v_true_kts=v_rel_ground=v_inertial=0;
55    v_ground_speed=v_equiv=v_equiv_kts=0;
56    v_calibrated=v_calibrated_kts=0;
57    gravity=0;            
58    centrifugal_relief=0; 
59    alpha=beta=alpha_dot=beta_dot=0;   
60    cos_alpha=sin_alpha=cos_beta=sin_beta=0;
61    cos_phi=sin_phi=cos_theta=sin_theta=cos_psi=sin_psi=0;
62    gamma_vert_rad=gamma_horiz_rad=0;    
63    sigma=density=v_sound=mach_number=0;
64    static_pressure=total_pressure=impact_pressure=0;
65    dynamic_pressure=0;
66    static_temperature=total_temperature=0;
67    sea_level_radius=earth_position_angle=0;
68    runway_altitude=runway_latitude=runway_longitude=0;
69    runway_heading=0;
70    radius_to_rwy=0;
71    climb_rate=0;           
72    sin_lat_geocentric=cos_lat_geocentric=0;
73    sin_longitude=cos_longitude=0;
74 }  
75
76
77 // Destructor
78 FGInterface::~FGInterface() {
79 }
80
81
82 bool FGInterface::init( double dt ) {
83     cout << "dummy init() ... SHOULDN'T BE CALLED!" << endl;
84     return false;
85 }
86
87
88 bool FGInterface::update( int multi_loop ) {
89     cout << "dummy update() ... SHOULDN'T BE CALLED!" << endl;
90     return false;
91 }
92
93
94 // Extrapolate fdm based on time_offset (in usec)
95 void FGInterface::extrapolate( int time_offset ) {
96     double dt = time_offset / 1000000.0;
97
98     // -dw- metrowerks complains about ambiguous access, not critical
99     // to keep this ;)
100 #ifndef __MWERKS__
101     cout << "extrapolating FDM by dt = " << dt << endl;
102 #endif
103
104     double lat = geodetic_position_v[0] + geocentric_rates_v[0] * dt;
105     double lat_geoc = geocentric_position_v[0] + geocentric_rates_v[0] * dt;
106
107     double lon = geodetic_position_v[1] + geocentric_rates_v[1] * dt;
108     double lon_geoc = geocentric_position_v[1] + geocentric_rates_v[1] * dt;
109
110     double alt = geodetic_position_v[2] + geocentric_rates_v[2] * dt;
111     double radius = geocentric_position_v[2] + geocentric_rates_v[2] * dt;
112
113     geodetic_position_v[0] = lat;
114     geocentric_position_v[0] = lat_geoc;
115
116     geodetic_position_v[1] = lon;
117     geocentric_position_v[1] = lon_geoc;
118
119     geodetic_position_v[2] = alt;
120     geocentric_position_v[2] = radius;
121 }
122
123
124 // Set the altitude (force)
125 void fgFDMForceAltitude(int model, double alt_meters) {
126     double sea_level_radius_meters;
127     double lat_geoc;
128
129     // Set the FG variables first
130     sgGeodToGeoc( base_fdm_state.get_Latitude(), alt_meters, 
131                   &sea_level_radius_meters, &lat_geoc);
132
133     base_fdm_state.set_Altitude( alt_meters * METER_TO_FEET );
134     base_fdm_state.set_Radius_to_vehicle( base_fdm_state.get_Altitude() + 
135                                           (sea_level_radius_meters * 
136                                            METER_TO_FEET) );
137
138     // additional work needed for some flight models
139     if ( model == FGInterface::FG_LARCSIM ) {
140         ls_ForceAltitude( base_fdm_state.get_Altitude() );
141     }
142 }
143
144
145 // Set the local ground elevation
146 void fgFDMSetGroundElevation(int model, double ground_meters) {
147     base_fdm_state.set_Runway_altitude( ground_meters * METER_TO_FEET );
148     cur_fdm_state->set_Runway_altitude( ground_meters * METER_TO_FEET );
149 }
150
151