1999-10-14 01:54:11 +00:00
|
|
|
// MagicCarpet.cxx -- interface to the "Magic Carpet" flight model
|
|
|
|
//
|
|
|
|
// Written by Curtis Olson, started October 1999.
|
|
|
|
//
|
|
|
|
// Copyright (C) 1999 Curtis L. Olson - curt@flightgear.org
|
|
|
|
//
|
|
|
|
// 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$
|
|
|
|
|
|
|
|
|
2000-02-16 23:01:03 +00:00
|
|
|
#include <simgear/math/fg_geodesy.hxx>
|
|
|
|
#include <simgear/math/point3d.hxx>
|
|
|
|
#include <simgear/math/polar3d.hxx>
|
2000-02-15 03:30:01 +00:00
|
|
|
|
1999-10-14 01:54:11 +00:00
|
|
|
#include <Controls/controls.hxx>
|
|
|
|
#include <Main/options.hxx>
|
|
|
|
|
|
|
|
#include "MagicCarpet.hxx"
|
|
|
|
|
|
|
|
|
|
|
|
// Initialize the Magic Carpet flight model, dt is the time increment
|
|
|
|
// for each subsequent iteration through the EOM
|
|
|
|
int FGMagicCarpet::init( double dt ) {
|
|
|
|
// set valid time for this record
|
|
|
|
stamp_time();
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Run an iteration of the EOM (equations of motion)
|
|
|
|
int FGMagicCarpet::update( int multiloop ) {
|
|
|
|
// cout << "FGLaRCsim::update()" << endl;
|
|
|
|
|
|
|
|
double time_step = (1.0 / current_options.get_model_hz()) * multiloop;
|
|
|
|
|
|
|
|
// speed and distance traveled
|
|
|
|
double speed = controls.get_throttle( 0 ) * 2000; // meters/sec
|
|
|
|
double dist = speed * time_step;
|
|
|
|
double kts = speed * METER_TO_NM * 3600.0;
|
|
|
|
set_V_equiv_kts( kts );
|
2000-01-10 21:07:26 +00:00
|
|
|
set_V_calibrated_kts( kts );
|
1999-10-14 01:54:11 +00:00
|
|
|
set_V_ground_speed( kts );
|
2000-01-10 21:07:26 +00:00
|
|
|
set_Mach_number(0);
|
1999-10-14 01:54:11 +00:00
|
|
|
|
|
|
|
// angle of turn
|
|
|
|
double turn_rate = controls.get_aileron() * FG_PI_4; // radians/sec
|
|
|
|
double turn = turn_rate * time_step;
|
|
|
|
|
|
|
|
// update euler angles
|
|
|
|
set_Euler_Angles( get_Phi(), get_Theta(), fmod(get_Psi() + turn, FG_2PI) );
|
2000-04-11 21:45:42 +00:00
|
|
|
set_Euler_Rates(0,0,0);
|
1999-10-14 01:54:11 +00:00
|
|
|
|
|
|
|
// update (lon/lat) position
|
1999-10-14 19:32:15 +00:00
|
|
|
double lat2, lon2, az2;
|
|
|
|
geo_direct_wgs_84 ( get_Altitude(),
|
|
|
|
get_Latitude() * RAD_TO_DEG,
|
|
|
|
get_Longitude() * RAD_TO_DEG,
|
|
|
|
get_Psi() * RAD_TO_DEG,
|
|
|
|
dist, &lat2, &lon2, &az2 );
|
|
|
|
set_Longitude( lon2 * DEG_TO_RAD );
|
|
|
|
set_Latitude( lat2 * DEG_TO_RAD );
|
|
|
|
|
|
|
|
// cout << "lon error = " << fabs(end.x()*RAD_TO_DEG - lon2)
|
|
|
|
// << " lat error = " << fabs(end.y()*RAD_TO_DEG - lat2)
|
|
|
|
// << endl;
|
1999-10-14 01:54:11 +00:00
|
|
|
|
|
|
|
double sl_radius, lat_geoc;
|
|
|
|
fgGeodToGeoc( get_Latitude(), get_Altitude(), &sl_radius, &lat_geoc );
|
|
|
|
|
|
|
|
// update altitude
|
|
|
|
double real_climb_rate = -controls.get_elevator() * 5000; // feet/sec
|
|
|
|
set_Climb_Rate( real_climb_rate / 500.0 );
|
|
|
|
double climb = real_climb_rate * time_step;
|
|
|
|
|
|
|
|
set_Geocentric_Position( lat_geoc, get_Longitude(),
|
|
|
|
sl_radius + get_Altitude() + climb );
|
1999-10-15 05:35:50 +00:00
|
|
|
// cout << "sea level radius (ft) = " << sl_radius << endl;
|
|
|
|
// cout << "(setto) sea level radius (ft) = " << get_Sea_level_radius() << endl;
|
|
|
|
set_Sea_level_radius( sl_radius * METER_TO_FEET);
|
1999-10-14 19:32:15 +00:00
|
|
|
set_Altitude( get_Altitude() + climb );
|
1999-10-14 01:54:11 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|