]> git.mxchange.org Git - flightgear.git/blob - src/FDM/flightProperties.cxx
considering u,v,wbody-fps are the ECEF velocity expressed in body axis, change in...
[flightgear.git] / src / FDM / flightProperties.cxx
1 // flightProperties.cxx -- expose FDM properties via helper methods
2 //
3 // Written by James Turner, started June 2010.
4 //
5 // Copyright (C) 2010  Curtis L. Olson  - http://www.flightgear.org/~curt
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 // $Id$
22
23 #include <FDM/flightProperties.hxx>
24
25 #include <simgear/props/props.hxx>
26 #include <simgear/math/SGMath.hxx>
27
28 #include <Main/globals.hxx>
29
30 FlightProperties::FlightProperties(SGPropertyNode* root) :
31   _root(root)
32 {
33   if (!_root) {
34     _root = globals->get_props();
35   }
36 }
37
38 FlightProperties::~FlightProperties()
39 {
40 }
41
42 double FlightProperties::get_V_north() const
43 {
44   return _root->getDoubleValue("velocities/speed-north-fps", 0.0);
45 }
46
47 double FlightProperties::get_V_east() const
48 {
49   return _root->getDoubleValue("velocities/speed-east-fps", 0.0);
50 }
51
52 double FlightProperties::get_V_down() const
53 {
54   return _root->getDoubleValue("velocities/speed-down-fps", 0.0);
55 }
56
57 double FlightProperties::get_uBody () const
58 {
59   return _root->getDoubleValue("velocities/uBody-fps", 0.0);
60 }
61
62 double FlightProperties::get_vBody () const
63 {
64   return _root->getDoubleValue("velocities/vBody-fps", 0.0);
65 }
66
67 double FlightProperties::get_wBody () const
68 {
69   return _root->getDoubleValue("velocities/wBody-fps", 0.0);
70 }
71
72 double FlightProperties::get_A_X_pilot() const
73 {
74   return _root->getDoubleValue("accelerations/pilot/x-accel-fps_sec", 0.0);
75 }
76
77 double FlightProperties::get_A_Y_pilot() const
78 {
79   return _root->getDoubleValue("/accelerations/pilot/y-accel-fps_sec", 0.0);
80 }
81
82 double FlightProperties::get_A_Z_pilot() const
83 {
84   return _root->getDoubleValue("/accelerations/pilot/z-accel-fps_sec", 0.0);
85 }
86
87 SGGeod FlightProperties::getPosition() const
88 {
89   return SGGeod::fromDegFt(get_Longitude_deg(), get_Latitude_deg(), get_Altitude());
90 }
91
92 double FlightProperties::get_Latitude() const
93 {
94   return get_Latitude_deg() * SG_DEGREES_TO_RADIANS;
95 }
96
97 double FlightProperties::get_Longitude() const
98 {
99   return get_Longitude_deg() * SG_DEGREES_TO_RADIANS;
100 }
101
102 double FlightProperties::get_Altitude() const
103 {
104   return _root->getDoubleValue("position/altitude-ft");
105 }
106
107 double FlightProperties::get_Altitude_AGL(void) const
108 {
109   return _root->getDoubleValue("position/altitude-agl-ft");
110 }
111
112 double FlightProperties::get_Latitude_deg () const
113 {
114   return _root->getDoubleValue("position/latitude-deg");
115 }
116
117 double FlightProperties::get_Longitude_deg () const
118 {
119   return _root->getDoubleValue("position/longitude-deg");
120 }
121
122 double FlightProperties::get_Track(void) const
123 {
124   return _root->getDoubleValue("orientation/track-deg");
125 }
126
127 double FlightProperties::get_Phi_deg() const
128 {
129   return _root->getDoubleValue("orientation/roll-deg");
130 }
131
132 double FlightProperties::get_Theta_deg() const
133 {
134   return _root->getDoubleValue("orientation/pitch-deg");
135 }
136
137 double FlightProperties::get_Psi_deg() const
138 {
139   return _root->getDoubleValue("orientation/heading-deg");
140 }
141
142 double FlightProperties::get_Phi_dot() const
143 {
144   return get_Phi_dot_degps() * SG_DEGREES_TO_RADIANS;
145 }
146
147 double FlightProperties::get_Theta_dot() const
148 {
149    return get_Theta_dot_degps() * SG_DEGREES_TO_RADIANS;
150 }
151
152 double FlightProperties::get_Psi_dot() const
153 {
154    return get_Psi_dot_degps() * SG_DEGREES_TO_RADIANS;
155 }
156
157 double FlightProperties::get_Alpha() const
158 {
159   return _root->getDoubleValue("orientation/alpha-deg") * SG_DEGREES_TO_RADIANS;
160 }
161
162 double FlightProperties::get_Beta() const
163 {
164   return _root->getDoubleValue("orientation/beta-deg") * SG_DEGREES_TO_RADIANS;
165 }
166
167 double FlightProperties::get_Phi_dot_degps() const
168 {
169   return _root->getDoubleValue("orientation/roll-rate-degps");
170 }
171
172 double FlightProperties::get_Theta_dot_degps() const
173 {
174   return _root->getDoubleValue("orientation/pitch-rate-degps");
175 }
176
177 double FlightProperties::get_Psi_dot_degps() const
178 {
179   return _root->getDoubleValue("orientation/yaw-rate-degps");
180 }
181   
182 double FlightProperties::get_Total_temperature() const
183 {
184   return 0.0;
185 }
186
187 double FlightProperties::get_Total_pressure() const
188 {
189   return 0.0;
190 }
191
192 double FlightProperties::get_Dynamic_pressure() const
193 {
194   return 0.0;
195 }
196
197 void FlightProperties::set_Longitude(double l)
198 {
199   _root->setDoubleValue("position/longitude-deg", l * SG_RADIANS_TO_DEGREES);
200 }
201
202 void FlightProperties::set_Latitude(double l)
203 {
204   _root->setDoubleValue("position/latitude-deg", l * SG_RADIANS_TO_DEGREES);
205 }
206
207 void FlightProperties::set_Altitude(double ft)
208 {
209   _root->setDoubleValue("position/altitude-ft", ft);
210 }
211
212 void FlightProperties::set_Euler_Angles(double phi, double theta, double psi)
213 {
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);
217 }
218
219 void FlightProperties::set_V_calibrated_kts(double kts)
220 {
221   _root->setDoubleValue("velocities/airspeed-kt", kts);
222 }
223
224 void FlightProperties::set_Climb_Rate(double fps)
225 {
226   _root->setDoubleValue("velocities/vertical-speed-fps", fps);
227 }
228
229 double FlightProperties::get_V_ground_speed() const
230 {
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;
233 }
234
235 double FlightProperties::get_V_calibrated_kts() const
236 {
237   return _root->getDoubleValue("velocities/airspeed-kt");
238 }
239
240 double FlightProperties::get_V_equiv_kts() const
241 {
242   return _root->getDoubleValue("velocities/equivalent-kt");
243 }
244
245 double FlightProperties::get_Climb_Rate() const
246 {
247   return _root->getDoubleValue("velocities/vertical-speed-fps");
248 }
249
250 double FlightProperties::get_Runway_altitude_m() const
251 {
252   return _root->getDoubleValue("environment/ground-elevation-m");
253 }
254
255 void FlightProperties::set_Accels_Pilot_Body(double x, double y, double z)
256 {
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);
260 }
261
262 void FlightProperties::set_Velocities_Local(double x, double y, double z)
263 {
264   _root->setDoubleValue("velocities/speed-north-fps", x);
265   _root->setDoubleValue("velocities/speed-east-fps", y);
266   _root->setDoubleValue("velocities/speed-down-fps", z);
267 }
268
269 void FlightProperties::set_Velocities_Body(double x, double y, double z)
270 {
271   _root->setDoubleValue("velocities/uBody-fps", x);
272   _root->setDoubleValue("velocities/vBody-fps", y);
273   _root->setDoubleValue("velocities/wBody-fps", z);
274 }
275
276 void FlightProperties::set_Euler_Rates(double x, double y, double z)
277 {
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);
281 }
282
283 void FlightProperties::set_Alpha(double a)
284 {
285   _root->setDoubleValue("orientation/alpha-deg", a * SG_RADIANS_TO_DEGREES);
286 }
287
288 void FlightProperties::set_Beta(double b)
289 {
290   _root->setDoubleValue("orientation/side-slip-rad", b);
291 }
292
293 void FlightProperties::set_Altitude_AGL(double ft)
294 {
295   _root->setDoubleValue("position/altitude-agl-ft", ft);
296 }
297
298 double FlightProperties::get_P_body() const
299 {
300   return _root->getDoubleValue("orientation/p-body", 0.0);
301 }
302
303 double FlightProperties::get_Q_body() const
304 {
305   return _root->getDoubleValue("orientation/q-body", 0.0);
306 }
307
308 double FlightProperties::get_R_body() const
309 {
310   return _root->getDoubleValue("orientation/r-body", 0.0);
311 }