]> git.mxchange.org Git - flightgear.git/blob - src/FDM/MagicCarpet.cxx
Fix coordinate conventions for reporting pilot acceleration. Add a few
[flightgear.git] / src / FDM / MagicCarpet.cxx
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  - curt@flightgear.org
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 <simgear/math/sg_geodesy.hxx>
25 #include <simgear/math/point3d.hxx>
26 #include <simgear/math/polar3d.hxx>
27
28 #include <Controls/controls.hxx>
29 #include <Main/globals.hxx>
30 #include <Main/fg_props.hxx>
31
32 #include "MagicCarpet.hxx"
33
34
35 FGMagicCarpet::FGMagicCarpet( double dt ) {
36 //     set_delta_t( dt );
37 }
38
39
40 FGMagicCarpet::~FGMagicCarpet() {
41 }
42
43
44 // Initialize the Magic Carpet flight model, dt is the time increment
45 // for each subsequent iteration through the EOM
46 void FGMagicCarpet::init() {
47     common_init();
48 }
49
50
51 // Run an iteration of the EOM (equations of motion)
52 void FGMagicCarpet::update( double dt ) {
53     // cout << "FGLaRCsim::update()" << endl;
54
55     if (is_suspended())
56       return;
57
58     int multiloop = _calc_multiloop(dt);
59
60     double time_step = dt;
61
62     // speed and distance traveled
63     double speed = globals->get_controls()->get_throttle( 0 ) * 2000; // meters/sec
64     if ( globals->get_controls()->get_brake( 0 ) ) {
65         speed = -speed;
66     }
67
68     double dist = speed * time_step;
69     double kts = speed * SG_METER_TO_NM * 3600.0;
70     _set_V_equiv_kts( kts );
71     _set_V_calibrated_kts( kts );
72     _set_V_ground_speed( kts );
73
74     // angle of turn
75     double turn_rate = globals->get_controls()->get_aileron() * SGD_PI_4; // radians/sec
76     double turn = turn_rate * time_step;
77
78     // update euler angles
79     _set_Euler_Angles( get_Phi(), get_Theta(),
80                        fmod(get_Psi() + turn, SGD_2PI) );
81     _set_Euler_Rates(0,0,0);
82
83     // update (lon/lat) position
84     double lat2, lon2, az2;
85     if ( fabs( speed ) > SG_EPSILON ) {
86         geo_direct_wgs_84 ( get_Altitude(),
87                             get_Latitude() * SGD_RADIANS_TO_DEGREES,
88                             get_Longitude() * SGD_RADIANS_TO_DEGREES,
89                             get_Psi() * SGD_RADIANS_TO_DEGREES,
90                             dist, &lat2, &lon2, &az2 );
91
92         _set_Longitude( lon2 * SGD_DEGREES_TO_RADIANS );
93         _set_Latitude( lat2 * SGD_DEGREES_TO_RADIANS );
94     }
95
96     // cout << "lon error = " << fabs(end.x()*SGD_RADIANS_TO_DEGREES - lon2)
97     //      << "  lat error = " << fabs(end.y()*SGD_RADIANS_TO_DEGREES - lat2)
98     //      << endl;
99
100     double sl_radius, lat_geoc;
101     sgGeodToGeoc( get_Latitude(), get_Altitude(), &sl_radius, &lat_geoc );
102
103     // update altitude
104     double real_climb_rate = -globals->get_controls()->get_elevator() * 5000; // feet/sec
105     _set_Climb_Rate( real_climb_rate / 500.0 );
106     double climb = real_climb_rate * time_step;
107
108     _set_Geocentric_Position( lat_geoc, get_Longitude(), 
109                              sl_radius + get_Altitude() + climb );
110     // cout << "sea level radius (ft) = " << sl_radius << endl;
111     // cout << "(setto) sea level radius (ft) = " << get_Sea_level_radius() << endl;
112     _set_Sea_level_radius( sl_radius * SG_METER_TO_FEET);
113     _set_Altitude( get_Altitude() + climb );
114 }