1 // ACMS.cxx -- interface to the ACMS FDM
3 // Written by Erik Hofman, started October 2004
5 // Copyright (C) 2004 Erik Hofman <erik@ehofman.com>
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.
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.
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.
26 #include <simgear/math/sg_geodesy.hxx>
27 #include <Main/fg_props.hxx>
31 FGACMS::FGACMS( double dt )
32 : _alt (fgGetNode("/fdm/acms/position/altitude-ft", true)),
33 _speed (fgGetNode("/fdm/acms/velocities/airspeed-kt", true)),
34 _climb_rate( fgGetNode("/fdm/acms/velocities/vertical-speed-fps", true)),
35 _pitch (fgGetNode("/fdm/acms/orientation/pitch-rad", true)),
36 _roll (fgGetNode("/fdm/acms/orientation/roll-rad", true)),
37 _heading(fgGetNode("/fdm/acms/orientation/heading-rad", true)),
38 _acc_lat(fgGetNode("/fdm/acms/accelerations/ned/east-accel-fps_sec", true)),
39 _acc_lon(fgGetNode("/fdm/acms/accelerations/ned/north-accel-fps_sec", true)),
40 _acc_down(fgGetNode("/fdm/acms/accelerations/ned/down-accel-fps_sec", true)),
41 _temp (fgGetNode("/fdm/acms/environment/temperature-degc", true)),
42 _wow (fgGetNode("/fdm/acms/gear/wow", true))
52 // Initialize the ACMSFDM flight model, dt is the time increment
53 // for each subsequent iteration through the EOM
58 // Run an iteration of the EOM (equations of motion)
59 void FGACMS::update( double dt ) {
64 double pitch = _pitch->getDoubleValue();
65 double roll = _roll->getDoubleValue();
66 double heading = _heading->getDoubleValue();
67 double alt = _alt->getDoubleValue();
73 _set_Climb_Rate( _climb_rate->getDoubleValue() );
76 double acc_lat = _acc_lat->getDoubleValue();
77 double acc_lon = _acc_lon->getDoubleValue();
78 double acc_down = _acc_down->getDoubleValue();
79 _set_Accels_Local( acc_lon, acc_lat, acc_down );
82 sgSetVec3(accel_ned, acc_lon, acc_lat, acc_down);
83 double accel = sgLengthVec3 (accel_ned) * SG_FEET_TO_METER;
85 double velocity = (_speed->getDoubleValue() * SG_KT_TO_MPS) + accel * dt;
86 double dist = cos (pitch) * velocity * dt;
87 double kts = velocity * SG_MPS_TO_KT;
88 _set_V_equiv_kts( kts );
89 _set_V_calibrated_kts( kts );
90 _set_V_ground_speed( kts );
92 // update (lon/lat) position
93 double lat2, lon2, az2;
94 geo_direct_wgs_84 ( get_Altitude(),
95 get_Latitude() * SGD_RADIANS_TO_DEGREES,
96 get_Longitude() * SGD_RADIANS_TO_DEGREES,
97 heading * SGD_RADIANS_TO_DEGREES,
98 dist, &lat2, &lon2, &az2 );
100 _set_Longitude( lon2 * SGD_DEGREES_TO_RADIANS );
101 _set_Latitude( lat2 * SGD_DEGREES_TO_RADIANS );
103 double sl_radius, lat_geoc;
104 sgGeodToGeoc( get_Latitude(), get_Altitude(), &sl_radius, &lat_geoc );
106 _set_Euler_Angles( roll, pitch, heading );
107 _set_Euler_Rates(0,0,0);
109 _set_Geocentric_Position( lat_geoc, get_Longitude(), sl_radius);
110 _update_ground_elev_at_pos();
111 _set_Sea_level_radius( sl_radius * SG_METER_TO_FEET);