1998-09-29 14:56:30 +00:00
|
|
|
// flight.c -- a general interface to the various flight models
|
|
|
|
//
|
|
|
|
// Written by Curtis Olson, started May 1997.
|
|
|
|
//
|
|
|
|
// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
1997-05-29 02:35:04 +00:00
|
|
|
|
1997-05-29 22:39:49 +00:00
|
|
|
#include <stdio.h>
|
1998-04-18 04:13:51 +00:00
|
|
|
|
2000-02-15 03:30:01 +00:00
|
|
|
#include <simgear/constants.h>
|
2000-02-16 23:01:03 +00:00
|
|
|
#include <simgear/debug/logstream.hxx>
|
2000-09-27 20:16:22 +00:00
|
|
|
#include <simgear/math/sg_geodesy.hxx>
|
2000-02-15 03:30:01 +00:00
|
|
|
|
1999-02-01 21:33:23 +00:00
|
|
|
#include <FDM/LaRCsim/ls_interface.h>
|
1999-09-01 20:24:54 +00:00
|
|
|
#include <Main/options.hxx>
|
1999-01-19 17:52:06 +00:00
|
|
|
#include <Time/timestamp.hxx>
|
1997-05-29 02:35:04 +00:00
|
|
|
|
1999-11-19 02:12:46 +00:00
|
|
|
#include "External.hxx"
|
1999-02-26 22:09:10 +00:00
|
|
|
#include "flight.hxx"
|
2000-07-24 17:26:05 +00:00
|
|
|
#include "JSBSim.hxx"
|
1999-02-26 22:09:10 +00:00
|
|
|
#include "LaRCsim.hxx"
|
1999-10-12 03:27:06 +00:00
|
|
|
#include "Balloon.h"
|
1999-02-26 22:09:10 +00:00
|
|
|
|
1998-02-07 15:29:31 +00:00
|
|
|
|
1999-01-08 03:23:51 +00:00
|
|
|
// base_fdm_state is the internal state that is updated in integer
|
|
|
|
// multiples of "dt". This leads to "jitter" with respect to the real
|
|
|
|
// world time, so we introduce cur_fdm_state which is extrapolated by
|
|
|
|
// the difference between sim time and real world time
|
|
|
|
|
1999-11-24 14:15:00 +00:00
|
|
|
FGInterface *cur_fdm_state;
|
1999-02-05 21:28:09 +00:00
|
|
|
FGInterface base_fdm_state;
|
1998-02-07 15:29:31 +00:00
|
|
|
|
|
|
|
|
2000-08-14 20:12:17 +00:00
|
|
|
// Constructor
|
|
|
|
FGInterface::FGInterface(void) {
|
|
|
|
mass=i_xx=i_yy=i_zz=i_xz=0;
|
|
|
|
nlf=0;
|
|
|
|
v_rel_wind=v_true_kts=v_rel_ground=v_inertial=0;
|
|
|
|
v_ground_speed=v_equiv=v_equiv_kts=0;
|
|
|
|
v_calibrated=v_calibrated_kts=0;
|
|
|
|
gravity=0;
|
|
|
|
centrifugal_relief=0;
|
|
|
|
alpha=beta=alpha_dot=beta_dot=0;
|
|
|
|
cos_alpha=sin_alpha=cos_beta=sin_beta=0;
|
|
|
|
cos_phi=sin_phi=cos_theta=sin_theta=cos_psi=sin_psi=0;
|
|
|
|
gamma_vert_rad=gamma_horiz_rad=0;
|
|
|
|
sigma=density=v_sound=mach_number=0;
|
|
|
|
static_pressure=total_pressure=impact_pressure=0;
|
|
|
|
dynamic_pressure=0;
|
|
|
|
static_temperature=total_temperature=0;
|
|
|
|
sea_level_radius=earth_position_angle=0;
|
|
|
|
runway_altitude=runway_latitude=runway_longitude=0;
|
|
|
|
runway_heading=0;
|
|
|
|
radius_to_rwy=0;
|
|
|
|
climb_rate=0;
|
|
|
|
sin_lat_geocentric=cos_lat_geocentric=0;
|
|
|
|
sin_longitude=cos_longitude=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Destructor
|
|
|
|
FGInterface::~FGInterface() {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-16 14:54:41 +00:00
|
|
|
bool FGInterface::init( double dt ) {
|
1999-10-11 23:09:07 +00:00
|
|
|
cout << "dummy init() ... SHOULDN'T BE CALLED!" << endl;
|
2000-10-16 14:54:41 +00:00
|
|
|
return false;
|
1999-10-11 23:09:07 +00:00
|
|
|
}
|
|
|
|
|
2000-08-14 20:12:17 +00:00
|
|
|
|
2000-10-16 14:54:41 +00:00
|
|
|
bool FGInterface::update( int multi_loop ) {
|
1999-10-11 23:09:07 +00:00
|
|
|
cout << "dummy update() ... SHOULDN'T BE CALLED!" << endl;
|
2000-10-16 14:54:41 +00:00
|
|
|
return false;
|
1999-10-11 23:09:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-01-19 17:52:06 +00:00
|
|
|
// Extrapolate fdm based on time_offset (in usec)
|
1999-02-05 21:28:09 +00:00
|
|
|
void FGInterface::extrapolate( int time_offset ) {
|
1999-01-19 17:52:06 +00:00
|
|
|
double dt = time_offset / 1000000.0;
|
1999-04-27 19:27:45 +00:00
|
|
|
|
|
|
|
// -dw- metrowerks complains about ambiguous access, not critical
|
|
|
|
// to keep this ;)
|
|
|
|
#ifndef __MWERKS__
|
1999-01-19 17:52:06 +00:00
|
|
|
cout << "extrapolating FDM by dt = " << dt << endl;
|
1999-04-27 19:27:45 +00:00
|
|
|
#endif
|
1999-01-19 17:52:06 +00:00
|
|
|
|
|
|
|
double lat = geodetic_position_v[0] + geocentric_rates_v[0] * dt;
|
|
|
|
double lat_geoc = geocentric_position_v[0] + geocentric_rates_v[0] * dt;
|
|
|
|
|
|
|
|
double lon = geodetic_position_v[1] + geocentric_rates_v[1] * dt;
|
|
|
|
double lon_geoc = geocentric_position_v[1] + geocentric_rates_v[1] * dt;
|
|
|
|
|
|
|
|
double alt = geodetic_position_v[2] + geocentric_rates_v[2] * dt;
|
|
|
|
double radius = geocentric_position_v[2] + geocentric_rates_v[2] * dt;
|
|
|
|
|
|
|
|
geodetic_position_v[0] = lat;
|
|
|
|
geocentric_position_v[0] = lat_geoc;
|
|
|
|
|
|
|
|
geodetic_position_v[1] = lon;
|
|
|
|
geocentric_position_v[1] = lon_geoc;
|
|
|
|
|
|
|
|
geodetic_position_v[2] = alt;
|
|
|
|
geocentric_position_v[2] = radius;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-12-04 01:29:37 +00:00
|
|
|
// Set the altitude (force)
|
1999-01-20 13:42:22 +00:00
|
|
|
void fgFDMForceAltitude(int model, double alt_meters) {
|
1998-07-12 03:08:27 +00:00
|
|
|
double sea_level_radius_meters;
|
|
|
|
double lat_geoc;
|
1999-01-08 03:23:51 +00:00
|
|
|
|
1998-07-12 03:08:27 +00:00
|
|
|
// Set the FG variables first
|
2000-09-27 20:16:22 +00:00
|
|
|
sgGeodToGeoc( base_fdm_state.get_Latitude(), alt_meters,
|
1998-07-12 03:08:27 +00:00
|
|
|
&sea_level_radius_meters, &lat_geoc);
|
|
|
|
|
1999-01-08 03:23:51 +00:00
|
|
|
base_fdm_state.set_Altitude( alt_meters * METER_TO_FEET );
|
|
|
|
base_fdm_state.set_Radius_to_vehicle( base_fdm_state.get_Altitude() +
|
|
|
|
(sea_level_radius_meters *
|
|
|
|
METER_TO_FEET) );
|
1998-07-12 03:08:27 +00:00
|
|
|
|
1998-12-04 01:29:37 +00:00
|
|
|
// additional work needed for some flight models
|
1999-02-05 21:28:09 +00:00
|
|
|
if ( model == FGInterface::FG_LARCSIM ) {
|
1999-01-08 03:23:51 +00:00
|
|
|
ls_ForceAltitude( base_fdm_state.get_Altitude() );
|
1998-07-12 03:08:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-01-20 13:42:22 +00:00
|
|
|
// Set the local ground elevation
|
|
|
|
void fgFDMSetGroundElevation(int model, double ground_meters) {
|
|
|
|
base_fdm_state.set_Runway_altitude( ground_meters * METER_TO_FEET );
|
1999-10-11 23:09:07 +00:00
|
|
|
cur_fdm_state->set_Runway_altitude( ground_meters * METER_TO_FEET );
|
1999-01-20 13:42:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|