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., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <simgear/math/sg_geodesy.hxx>
23 #include <Main/fg_props.hxx>
27 FGACMS::FGACMS( double dt )
37 // Initialize the ACMSFDM flight model, dt is the time increment
38 // for each subsequent iteration through the EOM
44 // Run an iteration of the EOM (equations of motion)
45 void FGACMS::update( double dt ) {
47 double pitch = get_Theta();
48 double roll = get_Phi();
49 double heading = get_Psi() * SG_DEGREES_TO_RADIANS;
50 double alt = get_Altitude();
52 double sl_radius, lat_geoc;
53 sgGeodToGeoc( get_Latitude(), get_Altitude(), &sl_radius, &lat_geoc );
55 double lon_acc = get_V_north();
56 double lat_acc = get_V_east();
57 double vert_acc = get_V_down();
59 double accel_heading = atan( lon_acc/lat_acc );
60 double accel_pitch = atan( vert_acc/accel_heading );
62 double accel = sqrt(sqrt(lon_acc*lon_acc + lat_acc*lat_acc)
65 double velocity = get_V_true_kts() * accel / (SG_METER_TO_NM * 3600.0);
66 double speed = cos (pitch) * velocity; // meters/sec
67 double dist = speed * dt;
68 double kts = velocity * 6076.11549 * 3600.0;
70 double climb_rate = fgGetDouble("/velocities/climb-rate", 0);
71 double climb = climb_rate * dt;
73 _set_Alpha( pitch - accel_pitch);
74 _set_Beta( heading - accel_heading);
75 _set_Climb_Rate( climb_rate );
76 _set_V_equiv_kts( kts );
77 _set_V_calibrated_kts( kts );
78 _set_V_ground_speed( kts );
79 _set_Altitude( get_Altitude() + climb );
81 // update (lon/lat) position
82 double lat2, lon2, az2;
83 geo_direct_wgs_84 ( get_Altitude(),
84 get_Latitude() * SGD_RADIANS_TO_DEGREES,
85 get_Longitude() * SGD_RADIANS_TO_DEGREES,
86 get_Psi() * SGD_RADIANS_TO_DEGREES,
87 dist, &lat2, &lon2, &az2 );
88 _set_Geocentric_Position( lat_geoc, get_Longitude(),
89 sl_radius + get_Altitude() + climb );
90 _set_Sea_level_radius( sl_radius * SG_METER_TO_FEET);
92 _set_Longitude( lon2 * SGD_DEGREES_TO_RADIANS );
93 _set_Latitude( lat2 * SGD_DEGREES_TO_RADIANS );