FlightGear next
MagicCarpet.cxx
Go to the documentation of this file.
1// MagicCarpet.cxx -- interface to the "Magic Carpet" flight model
2//
3// Written by Curtis Olson, started October 1999.
4//
5// Copyright (C) 1999 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
24#ifdef HAVE_CONFIG_H
25# include <config.h>
26#endif
27
28#include <simgear/math/sg_geodesy.hxx>
29
30#include <Aircraft/controls.hxx>
31#include <Main/globals.hxx>
32#include <Main/fg_props.hxx>
33
34#include "MagicCarpet.hxx"
35
36
38// set_delta_t( dt );
39}
40
41
44
45
46// Initialize the Magic Carpet flight model, dt is the time increment
47// for each subsequent iteration through the EOM
51
52
53// Run an iteration of the EOM (equations of motion)
54void FGMagicCarpet::update( double dt ) {
55 // cout << "FGLaRCsim::update()" << endl;
56
57 if (is_suspended())
58 return;
59
60 // int multiloop = _calc_multiloop(dt);
61
62 double time_step = dt;
63
64 // speed and distance traveled
65 double speed = globals->get_controls()->get_throttle( 0 ) * 2000; // meters/sec
66 if ( globals->get_controls()->get_brake_left() > 0.0
67 || globals->get_controls()->get_brake_right() > 0.0 )
68 {
69 speed = -speed;
70 }
71
72 double dist = speed * time_step;
73 double kts = speed * SG_METER_TO_NM * 3600.0;
74 _set_V_equiv_kts( kts );
77
78 // angle of turn
79 double turn_rate = globals->get_controls()->get_aileron() * SGD_PI_4; // radians/sec
80 double turn = turn_rate * time_step;
81
82 // update euler angles
84 SGMiscd::normalizePeriodic(0, SGD_2PI, get_Psi() + turn) );
85 _set_Euler_Rates(0,0,0);
86
87 // update (lon/lat) position
88 double lat2 = 0.0, lon2 = 0.0, az2 = 0.0;
89 if ( fabs( speed ) > SG_EPSILON ) {
90 geo_direct_wgs_84 ( get_Altitude(),
91 get_Latitude() * SGD_RADIANS_TO_DEGREES,
92 get_Longitude() * SGD_RADIANS_TO_DEGREES,
93 get_Psi() * SGD_RADIANS_TO_DEGREES,
94 dist, &lat2, &lon2, &az2 );
95
96 _set_Geodetic_Position( lat2 * SGD_DEGREES_TO_RADIANS, lon2 * SGD_DEGREES_TO_RADIANS );
97 }
98
99 // cout << "lon error = " << fabs(end.x()*SGD_RADIANS_TO_DEGREES - lon2)
100 // << " lat error = " << fabs(end.y()*SGD_RADIANS_TO_DEGREES - lat2)
101 // << endl;
102
103 double sl_radius, lat_geoc;
104 sgGeodToGeoc( get_Latitude(), get_Altitude(), &sl_radius, &lat_geoc );
105
106 // update altitude
107 double real_climb_rate = -globals->get_controls()->get_elevator() * 5000; // feet/sec
108 _set_Climb_Rate( real_climb_rate / 500.0 );
109 double climb = real_climb_rate * time_step;
110
112 sl_radius + get_Altitude() + climb );
113 // cout << "sea level radius (ft) = " << sl_radius << endl;
114 // cout << "(setto) sea level radius (ft) = " << get_Sea_level_radius() << endl;
116 _set_Sea_level_radius( sl_radius * SG_METER_TO_FEET);
117 _set_Altitude( get_Altitude() + climb );
119}
120
121
122// Register the subsystem.
123#if 0
124SGSubsystemMgr::Registrant<FGMagicCarpet> registrantFGMagicCarpet;
125#endif
double lat_geoc
Definition ADA.cxx:44
void _set_Altitude(double altitude)
Definition flight.hxx:353
double get_Psi() const
Definition flight.hxx:650
void _set_Geodetic_Position(double lat, double lon)
Definition flight.hxx:359
void set_V_ground_speed_kt(double ground_speed)
Definition flight.hxx:591
double get_Longitude() const
Definition flight.hxx:631
double get_Latitude() const
Definition flight.hxx:628
void _update_ground_elev_at_pos(void)
Definition flight.cxx:540
double get_Theta() const
Definition flight.hxx:649
void _set_Climb_Rate(double rate)
Definition flight.hxx:389
void common_init()
Initialize the state of the FDM.
Definition flight.cxx:137
void _set_Geocentric_Position(double lat, double lon, double rad)
Definition flight.hxx:338
double get_Runway_altitude() const
Definition flight.hxx:679
double get_Phi() const
Definition flight.hxx:648
void _set_V_calibrated_kts(double kts)
Definition flight.hxx:306
void _set_Sea_level_radius(double r)
Definition flight.hxx:386
double get_Altitude() const
Definition flight.hxx:634
void _set_Altitude_AGL(double agl)
Definition flight.hxx:356
void _set_Euler_Rates(double phi, double theta, double psi)
Definition flight.hxx:312
void _set_V_equiv_kts(double kts)
Definition flight.hxx:305
void _set_Euler_Angles(double phi, double theta, double psi)
Definition flight.hxx:368
void update(double dt) override
FGMagicCarpet(double dt)
void init() override
FGGlobals * globals
Definition globals.cxx:142