Debian Codegraph @

src/FDM/flightProperties.cxx

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