]> git.mxchange.org Git - flightgear.git/blob - src/FDM/MagicCarpet.cxx
56cd1381d22c4b41e3bae77a839b3e6490cce926
[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 <Controls/controls.hxx>
25 #include <Main/options.hxx>
26 #include <Math/fg_geodesy.hxx>
27 #include <Math/point3d.hxx>
28 #include <Math/polar3d.hxx>
29
30 #include "MagicCarpet.hxx"
31
32
33 // Initialize the Magic Carpet flight model, dt is the time increment
34 // for each subsequent iteration through the EOM
35 int FGMagicCarpet::init( double dt ) {
36     // set valid time for this record
37     stamp_time();
38
39     return 1;
40 }
41
42
43 // Run an iteration of the EOM (equations of motion)
44 int FGMagicCarpet::update( int multiloop ) {
45     // cout << "FGLaRCsim::update()" << endl;
46
47     double time_step = (1.0 / current_options.get_model_hz()) * multiloop;
48
49     // speed and distance traveled
50     double speed = controls.get_throttle( 0 ) * 2000; // meters/sec
51     double dist = speed * time_step;
52     double kts = speed * METER_TO_NM * 3600.0;
53     set_V_equiv_kts( kts );
54     set_V_calibrated_kts( kts );
55     set_V_ground_speed( kts );
56     set_Mach_number(0);
57
58     // angle of turn
59     double turn_rate = controls.get_aileron() * FG_PI_4; // radians/sec
60     double turn = turn_rate * time_step;
61
62     // update euler angles
63     set_Euler_Angles( get_Phi(), get_Theta(), fmod(get_Psi() + turn, FG_2PI) );
64
65     // update (lon/lat) position
66     double lat2, lon2, az2;
67     geo_direct_wgs_84 ( get_Altitude(),
68                         get_Latitude() * RAD_TO_DEG,
69                         get_Longitude() * RAD_TO_DEG,
70                         get_Psi() * RAD_TO_DEG,
71                         dist, &lat2, &lon2, &az2 );
72     set_Longitude( lon2 * DEG_TO_RAD );
73     set_Latitude( lat2 * DEG_TO_RAD );
74
75     // cout << "lon error = " << fabs(end.x()*RAD_TO_DEG - lon2)
76     //      << "  lat error = " << fabs(end.y()*RAD_TO_DEG - lat2)
77     //      << endl;
78
79     double sl_radius, lat_geoc;
80     fgGeodToGeoc( get_Latitude(), get_Altitude(), &sl_radius, &lat_geoc );
81
82     // update altitude
83     double real_climb_rate = -controls.get_elevator() * 5000; // feet/sec
84     set_Climb_Rate( real_climb_rate / 500.0 );
85     double climb = real_climb_rate * time_step;
86
87     set_Geocentric_Position( lat_geoc, get_Longitude(), 
88                              sl_radius + get_Altitude() + climb );
89     // cout << "sea level radius (ft) = " << sl_radius << endl;
90     // cout << "(setto) sea level radius (ft) = " << get_Sea_level_radius() << endl;
91     set_Sea_level_radius( sl_radius * METER_TO_FEET);
92     set_Altitude( get_Altitude() + climb );
93
94     return 1;
95 }