]> git.mxchange.org Git - flightgear.git/blob - src/FDM/SP/ACMS.cxx
new FSF address
[flightgear.git] / src / FDM / SP / ACMS.cxx
1 // ACMS.cxx -- interface to the ACMS FDM
2 //
3 // Written by Erik Hofman, started October 2004
4 //
5 // Copyright (C) 2004  Erik Hofman <erik@ehofman.com>
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
22 #include <simgear/math/sg_geodesy.hxx>
23 #include <Main/fg_props.hxx>
24
25 #include "ACMS.hxx"
26
27 FGACMS::FGACMS( double dt )
28  : _alt    (fgGetNode("/fdm/acms/position/altitude-ft", true)),
29    _speed  (fgGetNode("/fdm/acms/velocities/airspeed-kt", true)),
30    _climb_rate( fgGetNode("/fdm/acms/velocities/vertical-speed-fps", true)),
31    _pitch  (fgGetNode("/fdm/acms/orientation/pitch-rad", true)),
32    _roll   (fgGetNode("/fdm/acms/orientation/roll-rad", true)),
33    _heading(fgGetNode("/fdm/acms/orientation/heading-rad", true)),
34    _acc_lat(fgGetNode("/fdm/acms/accelerations/ned/east-accel-fps_sec", true)),
35    _acc_lon(fgGetNode("/fdm/acms/accelerations/ned/north-accel-fps_sec", true)),
36    _acc_down(fgGetNode("/fdm/acms/accelerations/ned/down-accel-fps_sec", true)),
37    _temp    (fgGetNode("/fdm/acms/environment/temperature-degc", true)),
38    _wow     (fgGetNode("/fdm/acms/gear/wow", true))
39 {
40 //     set_delta_t( dt );
41 }
42
43
44 FGACMS::~FGACMS() {
45 }
46
47
48 // Initialize the ACMSFDM flight model, dt is the time increment
49 // for each subsequent iteration through the EOM
50 void FGACMS::init() {
51     common_init();
52 }
53
54 // Run an iteration of the EOM (equations of motion)
55 void FGACMS::update( double dt ) {
56
57     if (is_suspended())
58         return;
59
60     double pitch = _pitch->getDoubleValue();
61     double roll = _roll->getDoubleValue();
62     double heading = _heading->getDoubleValue();
63     double alt = _alt->getDoubleValue();
64
65     set_Theta(pitch);
66     set_Phi(roll);
67     set_Psi(heading);
68     set_Altitude(alt);
69     _set_Climb_Rate( _climb_rate->getDoubleValue() );
70
71
72     double acc_lat = _acc_lat->getDoubleValue();
73     double acc_lon = _acc_lon->getDoubleValue();
74     double acc_down = _acc_down->getDoubleValue();
75     _set_Accels_Local( acc_lon, acc_lat, acc_down );
76
77     sgVec3 accel_ned;
78     sgSetVec3(accel_ned, acc_lon, acc_lat, acc_down);
79     double accel = sgLengthVec3 (accel_ned) * SG_FEET_TO_METER;
80
81     double velocity = (_speed->getDoubleValue() * SG_KT_TO_MPS) + accel * dt;
82     double dist = cos (pitch) * velocity * dt;
83     double kts = velocity * SG_MPS_TO_KT;
84     _set_V_equiv_kts( kts );
85     _set_V_calibrated_kts( kts );
86     _set_V_ground_speed( kts );
87
88     // update (lon/lat) position
89     double lat2, lon2, az2;
90     geo_direct_wgs_84 ( get_Altitude(),
91                         get_Latitude() * SGD_RADIANS_TO_DEGREES,
92                         get_Longitude() * SGD_RADIANS_TO_DEGREES,
93                         heading * SGD_RADIANS_TO_DEGREES,
94                         dist, &lat2, &lon2, &az2 );
95
96     _set_Longitude( lon2 * SGD_DEGREES_TO_RADIANS );
97     _set_Latitude( lat2 * SGD_DEGREES_TO_RADIANS );
98
99     double sl_radius, lat_geoc;
100     sgGeodToGeoc( get_Latitude(), get_Altitude(), &sl_radius, &lat_geoc );
101
102     _set_Euler_Angles( roll, pitch, heading );
103     _set_Euler_Rates(0,0,0);
104
105     _set_Geocentric_Position( lat_geoc, get_Longitude(), sl_radius);
106     _update_ground_elev_at_pos();
107     _set_Sea_level_radius( sl_radius * SG_METER_TO_FEET);
108
109 }