1 // flightProperties.cxx -- expose FDM properties via helper methods
3 // Written by James Turner, started June 2010.
5 // Copyright (C) 2010 Curtis L. Olson - http://www.flightgear.org/~curt
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.
23 #include <FDM/flightProperties.hxx>
25 #include <simgear/props/props.hxx>
26 #include <simgear/math/SGMath.hxx>
28 #include <Main/globals.hxx>
30 FlightProperties::FlightProperties(SGPropertyNode* root) :
34 _root = globals->get_props();
38 FlightProperties::~FlightProperties()
42 double FlightProperties::get_V_north() const
44 return _root->getDoubleValue("velocities/speed-north-fps", 0.0);
47 double FlightProperties::get_V_east() const
49 return _root->getDoubleValue("velocities/speed-east-fps", 0.0);
52 double FlightProperties::get_V_down() const
54 return _root->getDoubleValue("velocities/speed-down-fps", 0.0);
57 double FlightProperties::get_uBody () const
59 return _root->getDoubleValue("velocities/uBody-fps", 0.0);
62 double FlightProperties::get_vBody () const
64 return _root->getDoubleValue("velocities/vBody-fps", 0.0);
67 double FlightProperties::get_wBody () const
69 return _root->getDoubleValue("velocities/wBody-fps", 0.0);
72 double FlightProperties::get_A_X_pilot() const
74 return _root->getDoubleValue("accelerations/pilot/x-accel-fps_sec", 0.0);
77 double FlightProperties::get_A_Y_pilot() const
79 return _root->getDoubleValue("/accelerations/pilot/y-accel-fps_sec", 0.0);
82 double FlightProperties::get_A_Z_pilot() const
84 return _root->getDoubleValue("/accelerations/pilot/z-accel-fps_sec", 0.0);
87 SGGeod FlightProperties::getPosition() const
89 return SGGeod::fromDegFt(get_Longitude_deg(), get_Latitude_deg(), get_Altitude());
92 double FlightProperties::get_Latitude() const
94 return get_Latitude_deg() * SG_DEGREES_TO_RADIANS;
97 double FlightProperties::get_Longitude() const
99 return get_Longitude_deg() * SG_DEGREES_TO_RADIANS;
102 double FlightProperties::get_Altitude() const
104 return _root->getDoubleValue("position/altitude-ft");
107 double FlightProperties::get_Altitude_AGL(void) const
109 return _root->getDoubleValue("position/altitude-agl-ft");
112 double FlightProperties::get_Latitude_deg () const
114 return _root->getDoubleValue("position/latitude-deg");
117 double FlightProperties::get_Longitude_deg () const
119 return _root->getDoubleValue("position/longitude-deg");
122 double FlightProperties::get_Track(void) const
124 return _root->getDoubleValue("orientation/track-deg");
127 double FlightProperties::get_Phi_deg() const
129 return _root->getDoubleValue("orientation/roll-deg");
132 double FlightProperties::get_Theta_deg() const
134 return _root->getDoubleValue("orientation/pitch-deg");
137 double FlightProperties::get_Psi_deg() const
139 return _root->getDoubleValue("orientation/heading-deg");
142 double FlightProperties::get_Phi_dot() const
144 return get_Phi_dot_degps() * SG_DEGREES_TO_RADIANS;
147 double FlightProperties::get_Theta_dot() const
149 return get_Theta_dot_degps() * SG_DEGREES_TO_RADIANS;
152 double FlightProperties::get_Psi_dot() const
154 return get_Psi_dot_degps() * SG_DEGREES_TO_RADIANS;
157 double FlightProperties::get_Alpha() const
159 return _root->getDoubleValue("orientation/alpha-deg") * SG_DEGREES_TO_RADIANS;
162 double FlightProperties::get_Beta() const
164 return _root->getDoubleValue("orientation/beta-deg") * SG_DEGREES_TO_RADIANS;
167 double FlightProperties::get_Phi_dot_degps() const
169 return _root->getDoubleValue("orientation/roll-rate-degps");
172 double FlightProperties::get_Theta_dot_degps() const
174 return _root->getDoubleValue("orientation/pitch-rate-degps");
177 double FlightProperties::get_Psi_dot_degps() const
179 return _root->getDoubleValue("orientation/yaw-rate-degps");
182 double FlightProperties::get_Total_temperature() const
187 double FlightProperties::get_Total_pressure() const
192 double FlightProperties::get_Dynamic_pressure() const
197 void FlightProperties::set_Longitude(double l)
199 _root->setDoubleValue("position/longitude-deg", l * SG_RADIANS_TO_DEGREES);
202 void FlightProperties::set_Latitude(double l)
204 _root->setDoubleValue("position/latitude-deg", l * SG_RADIANS_TO_DEGREES);
207 void FlightProperties::set_Altitude(double ft)
209 _root->setDoubleValue("position/altitude-ft", ft);
212 void FlightProperties::set_Euler_Angles(double phi, double theta, double psi)
214 _root->setDoubleValue("orientation/roll-deg", phi * SG_RADIANS_TO_DEGREES);
215 _root->setDoubleValue("orientation/pitch-deg", theta * SG_RADIANS_TO_DEGREES);
216 _root->setDoubleValue("orientation/heading-deg", psi * SG_RADIANS_TO_DEGREES);
219 void FlightProperties::set_V_calibrated_kts(double kts)
221 _root->setDoubleValue("velocities/airspeed-kt", kts);
224 void FlightProperties::set_Climb_Rate(double fps)
226 _root->setDoubleValue("velocities/vertical-speed-fps", fps);
229 double FlightProperties::get_V_ground_speed() const
231 const double KNOTS_TO_FTS = (SG_NM_TO_METER * SG_METER_TO_FEET)/ 3600.0;
232 return _root->getDoubleValue("velocities/groundspeed-kt") * KNOTS_TO_FTS;
235 double FlightProperties::get_V_calibrated_kts() const
237 return _root->getDoubleValue("velocities/airspeed-kt");
240 double FlightProperties::get_V_equiv_kts() const
242 return _root->getDoubleValue("velocities/equivalent-kt");
245 double FlightProperties::get_Climb_Rate() const
247 return _root->getDoubleValue("velocities/vertical-speed-fps");
250 double FlightProperties::get_Runway_altitude_m() const
252 return _root->getDoubleValue("environment/ground-elevation-m");
255 void FlightProperties::set_Accels_Pilot_Body(double x, double y, double z)
257 _root->setDoubleValue("accelerations/pilot/x-accel-fps_sec", x);
258 _root->setDoubleValue("accelerations/pilot/y-accel-fps_sec", y);
259 _root->setDoubleValue("accelerations/pilot/z-accel-fps_sec", z);
262 void FlightProperties::set_Velocities_Local(double x, double y, double z)
264 _root->setDoubleValue("velocities/speed-north-fps", x);
265 _root->setDoubleValue("velocities/speed-east-fps", y);
266 _root->setDoubleValue("velocities/speed-down-fps", z);
269 void FlightProperties::set_Velocities_Body(double x, double y, double z)
271 _root->setDoubleValue("velocities/uBody-fps", x);
272 _root->setDoubleValue("velocities/vBody-fps", y);
273 _root->setDoubleValue("velocities/wBody-fps", z);
276 void FlightProperties::set_Euler_Rates(double x, double y, double z)
278 _root->setDoubleValue("orientation/roll-rate-degps", x * SG_RADIANS_TO_DEGREES);
279 _root->setDoubleValue("orientation/pitch-rate-degps", y * SG_RADIANS_TO_DEGREES);
280 _root->setDoubleValue("orientation/yaw-rate-degps", z * SG_RADIANS_TO_DEGREES);
283 void FlightProperties::set_Alpha(double a)
285 _root->setDoubleValue("orientation/alpha-deg", a * SG_RADIANS_TO_DEGREES);
288 void FlightProperties::set_Beta(double b)
290 _root->setDoubleValue("orientation/side-slip-rad", b);
293 void FlightProperties::set_Altitude_AGL(double ft)
295 _root->setDoubleValue("position/altitude-agl-ft", ft);
298 double FlightProperties::get_P_body() const
300 return _root->getDoubleValue("orientation/p-body", 0.0);
303 double FlightProperties::get_Q_body() const
305 return _root->getDoubleValue("orientation/q-body", 0.0);
308 double FlightProperties::get_R_body() const
310 return _root->getDoubleValue("orientation/r-body", 0.0);