FlightGear next
ACMS.cxx
Go to the documentation of this file.
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#ifdef HAVE_CONFIG_H
23# include <config.h>
24#endif
25
26#include <simgear/math/SGMath.hxx>
27#include <simgear/math/sg_geodesy.hxx>
28#include <Main/fg_props.hxx>
29
30#include "ACMS.hxx"
31
32FGACMS::FGACMS( double dt )
33 : _alt (fgGetNode("/fdm/acms/position/altitude-ft", true)),
34 _speed (fgGetNode("/fdm/acms/velocities/airspeed-kt", true)),
35 _climb_rate( fgGetNode("/fdm/acms/velocities/vertical-speed-fps", true)),
36 _pitch (fgGetNode("/fdm/acms/orientation/pitch-rad", true)),
37 _roll (fgGetNode("/fdm/acms/orientation/roll-rad", true)),
38 _heading(fgGetNode("/fdm/acms/orientation/heading-rad", true)),
39 _acc_lat(fgGetNode("/fdm/acms/accelerations/ned/east-accel-fps_sec", true)),
40 _acc_lon(fgGetNode("/fdm/acms/accelerations/ned/north-accel-fps_sec", true)),
41 _acc_down(fgGetNode("/fdm/acms/accelerations/ned/down-accel-fps_sec", true)),
42 _temp (fgGetNode("/fdm/acms/environment/temperature-degc", true)),
43 _wow (fgGetNode("/fdm/acms/gear/wow", true))
44{
45// set_delta_t( dt );
46}
47
48
51
52
53// Initialize the ACMSFDM flight model, dt is the time increment
54// for each subsequent iteration through the EOM
57}
58
59// Run an iteration of the EOM (equations of motion)
60void FGACMS::update( double dt ) {
61
62 if (is_suspended())
63 return;
64
65 double pitch = _pitch->getDoubleValue();
66 double roll = _roll->getDoubleValue();
67 double heading = _heading->getDoubleValue();
68 double alt = _alt->getDoubleValue();
69
70 set_Theta(pitch);
71 set_Phi(roll);
72 set_Psi(heading);
73 set_Altitude(alt);
74 _set_Climb_Rate( _climb_rate->getDoubleValue() );
75
76
77 double acc_lat = _acc_lat->getDoubleValue();
78 double acc_lon = _acc_lon->getDoubleValue();
79 double acc_down = _acc_down->getDoubleValue();
80 _set_Accels_Local( acc_lon, acc_lat, acc_down );
81
82 double accel = norm(SGVec3d(acc_lon, acc_lat, acc_down)) * SG_FEET_TO_METER;
83
84 double velocity = (_speed->getDoubleValue() * SG_KT_TO_MPS) + accel * dt;
85 double dist = cos (pitch) * velocity * dt;
86 double kts = velocity * SG_MPS_TO_KT;
87 _set_V_equiv_kts( kts );
90
91 SGGeod pos = getPosition();
92 // update (lon/lat) position
93 SGGeod pos2;
94 double az2;
95 geo_direct_wgs_84 ( pos, heading * SGD_RADIANS_TO_DEGREES,
96 dist, pos2, &az2 );
97
98 _set_Geodetic_Position( pos2.getLatitudeRad(), pos2.getLongitudeRad(), pos.getElevationFt() );
99
100 double sl_radius, lat_geoc;
101 sgGeodToGeoc( get_Latitude(), get_Altitude(), &sl_radius, &lat_geoc );
102
103 _set_Euler_Angles( roll, pitch, heading );
104 _set_Euler_Rates(0,0,0);
105
108 _set_Sea_level_radius( sl_radius * SG_METER_TO_FEET);
109
110}
111
112
113// Register the subsystem.
114#if 0
115SGSubsystemMgr::Registrant<FGACMS> registrantFGACMS;
116#endif
double lat_geoc
Definition ADA.cxx:44
~FGACMS()
Definition ACMS.cxx:49
FGACMS(double dt)
Definition ACMS.cxx:32
void update(double dt) override
Definition ACMS.cxx:60
void init() override
Definition ACMS.cxx:55
void _set_Geodetic_Position(double lat, double lon)
Definition flight.hxx:359
const SGGeod & getPosition() const
Definition flight.hxx:624
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
virtual void set_Psi(double psi)
Definition flight.hxx:497
virtual void set_Theta(double theta)
Definition flight.hxx:494
void _set_Climb_Rate(double rate)
Definition flight.hxx:389
void _set_Accels_Local(double north, double east, double down)
Definition flight.hxx:255
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
virtual void set_Phi(double phi)
Definition flight.hxx:491
virtual void set_Altitude(double alt)
Definition flight.cxx:554
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_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_V_ground_speed(double v)
Definition flight.hxx:304
void _set_Euler_Angles(double phi, double theta, double psi)
Definition flight.hxx:368
SGPropertyNode * fgGetNode(const char *path, bool create)
Get a property node.
Definition proptest.cpp:27