1 // LaRCsim.cxx -- interface to the LaRCsim flight model
3 // Written by Curtis Olson, started October 1998.
5 // Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu
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 // (Log is kept at end of this file)
25 #include "LaRCsim.hxx"
27 #include <Aircraft/aircraft.hxx>
28 #include <Controls/controls.hxx>
29 #include <Flight/flight.hxx>
30 #include <Flight/LaRCsim/ls_cockpit.h>
31 #include <Flight/LaRCsim/ls_generic.h>
32 #include <Flight/LaRCsim/ls_interface.h>
35 // Initialize the LaRCsim flight model, dt is the time increment for
36 // each subsequent iteration through the EOM
37 int fgLaRCsimInit(double dt) {
44 // Run an iteration of the EOM (equations of motion)
45 int fgLaRCsimUpdate(fgFLIGHT *f, int multiloop) {
46 double save_alt = 0.0;
48 // lets try to avoid really screwing up the LaRCsim model
49 if ( FG_Altitude < -9000 ) {
50 save_alt = FG_Altitude;
54 // translate FG to LaRCsim structure
55 fgFlight_2_LaRCsim(f);
56 // printf("FG_Altitude = %.2f\n", FG_Altitude * 0.3048);
57 // printf("Altitude = %.2f\n", Altitude * 0.3048);
58 // printf("Radius to Vehicle = %.2f\n", Radius_to_vehicle * 0.3048);
62 // printf("%d FG_Altitude = %.2f\n", i, FG_Altitude * 0.3048);
63 // printf("%d Altitude = %.2f\n", i, Altitude * 0.3048);
65 // translate LaRCsim back to FG structure so that the
66 // autopilot (and the rest of the sim can use the updated
68 fgLaRCsim_2_Flight(f);
70 // but lets restore our original bogus altitude when we are done
71 if ( save_alt < -9000 ) {
72 FG_Altitude = save_alt;
79 // Convert from the fgFLIGHT struct to the LaRCsim generic_ struct
80 int fgFlight_2_LaRCsim (fgFLIGHT *f) {
82 Lat_control = controls.get_aileron();
83 Long_control = controls.get_elevator();
84 Long_trim = controls.get_elevator_trim();
85 Rudder_pedal = controls.get_rudder();
86 Throttle_pct = controls.get_throttle( 0 );
87 Brake_pct = controls.get_brake( 0 );
94 Dx_pilot = FG_Dx_pilot;
95 Dy_pilot = FG_Dy_pilot;
96 Dz_pilot = FG_Dz_pilot;
103 F_north = FG_F_north;
106 F_X_aero = FG_F_X_aero;
107 F_Y_aero = FG_F_Y_aero;
108 F_Z_aero = FG_F_Z_aero;
109 F_X_engine = FG_F_X_engine;
110 F_Y_engine = FG_F_Y_engine;
111 F_Z_engine = FG_F_Z_engine;
112 F_X_gear = FG_F_X_gear;
113 F_Y_gear = FG_F_Y_gear;
114 F_Z_gear = FG_F_Z_gear;
121 M_l_aero = FG_M_l_aero;
122 M_m_aero = FG_M_m_aero;
123 M_n_aero = FG_M_n_aero;
124 M_l_engine = FG_M_l_engine;
125 M_m_engine = FG_M_m_engine;
126 M_n_engine = FG_M_n_engine;
127 M_l_gear = FG_M_l_gear;
128 M_m_gear = FG_M_m_gear;
129 M_n_gear = FG_M_n_gear;
130 V_dot_north = FG_V_dot_north;
131 V_dot_east = FG_V_dot_east;
132 V_dot_down = FG_V_dot_down;
133 U_dot_body = FG_U_dot_body;
134 V_dot_body = FG_V_dot_body;
135 W_dot_body = FG_W_dot_body;
139 A_X_pilot = FG_A_X_pilot;
140 A_Y_pilot = FG_A_Y_pilot;
141 A_Z_pilot = FG_A_Z_pilot;
145 N_X_pilot = FG_N_X_pilot;
146 N_Y_pilot = FG_N_Y_pilot;
147 N_Z_pilot = FG_N_Z_pilot;
148 P_dot_body = FG_P_dot_body;
149 Q_dot_body = FG_Q_dot_body;
150 R_dot_body = FG_R_dot_body;
151 V_north = FG_V_north;
154 V_north_rel_ground = FG_V_north_rel_ground;
155 V_east_rel_ground = FG_V_east_rel_ground;
156 V_down_rel_ground = FG_V_down_rel_ground;
157 V_north_airmass = FG_V_north_airmass;
158 V_east_airmass = FG_V_east_airmass;
159 V_down_airmass = FG_V_down_airmass;
160 V_north_rel_airmass = FG_V_north_rel_airmass;
161 V_east_rel_airmass = FG_V_east_rel_airmass;
162 V_down_rel_airmass = FG_V_down_rel_airmass;
169 V_rel_wind = FG_V_rel_wind;
170 V_true_kts = FG_V_true_kts;
171 V_rel_ground = FG_V_rel_ground;
172 V_inertial = FG_V_inertial;
173 V_ground_speed = FG_V_ground_speed;
174 V_equiv = FG_V_equiv;
175 V_equiv_kts = FG_V_equiv_kts;
176 V_calibrated = FG_V_calibrated;
177 V_calibrated_kts = FG_V_calibrated_kts;
181 P_local = FG_P_local;
182 Q_local = FG_Q_local;
183 R_local = FG_R_local;
184 P_total = FG_P_total;
185 Q_total = FG_Q_total;
186 R_total = FG_R_total;
187 Phi_dot = FG_Phi_dot;
188 Theta_dot = FG_Theta_dot;
189 Psi_dot = FG_Psi_dot;
190 Latitude_dot = FG_Latitude_dot;
191 Longitude_dot = FG_Longitude_dot;
192 Radius_dot = FG_Radius_dot;
193 Lat_geocentric = FG_Lat_geocentric;
194 Lon_geocentric = FG_Lon_geocentric;
195 Radius_to_vehicle = FG_Radius_to_vehicle;
196 Latitude = FG_Latitude;
197 Longitude = FG_Longitude;
198 Altitude = FG_Altitude;
202 T_local_to_body_11 = FG_T_local_to_body_11;
203 T_local_to_body_12 = FG_T_local_to_body_12;
204 T_local_to_body_13 = FG_T_local_to_body_13;
205 T_local_to_body_21 = FG_T_local_to_body_21;
206 T_local_to_body_22 = FG_T_local_to_body_22;
207 T_local_to_body_23 = FG_T_local_to_body_23;
208 T_local_to_body_31 = FG_T_local_to_body_31;
209 T_local_to_body_32 = FG_T_local_to_body_32;
210 T_local_to_body_33 = FG_T_local_to_body_33;
211 Gravity = FG_Gravity;
212 Centrifugal_relief = FG_Centrifugal_relief;
215 Alpha_dot = FG_Alpha_dot;
216 Beta_dot = FG_Beta_dot;
217 Cos_alpha = FG_Cos_alpha;
218 Sin_alpha = FG_Sin_alpha;
219 Cos_beta = FG_Cos_beta;
220 Sin_beta = FG_Sin_beta;
221 Cos_phi = FG_Cos_phi;
222 Sin_phi = FG_Sin_phi;
223 Cos_theta = FG_Cos_theta;
224 Sin_theta = FG_Sin_theta;
225 Cos_psi = FG_Cos_psi;
226 Sin_psi = FG_Sin_psi;
227 Gamma_vert_rad = FG_Gamma_vert_rad;
228 Gamma_horiz_rad = FG_Gamma_horiz_rad;
230 Density = FG_Density;
231 V_sound = FG_V_sound;
232 Mach_number = FG_Mach_number;
233 Static_pressure = FG_Static_pressure;
234 Total_pressure = FG_Total_pressure;
235 Impact_pressure = FG_Impact_pressure;
236 Dynamic_pressure = FG_Dynamic_pressure;
237 Static_temperature = FG_Static_temperature;
238 Total_temperature = FG_Total_temperature;
239 Sea_level_radius = FG_Sea_level_radius;
240 Earth_position_angle = FG_Earth_position_angle;
241 Runway_altitude = FG_Runway_altitude;
242 Runway_latitude = FG_Runway_latitude;
243 Runway_longitude = FG_Runway_longitude;
244 Runway_heading = FG_Runway_heading;
245 Radius_to_rwy = FG_Radius_to_rwy;
246 D_cg_north_of_rwy = FG_D_cg_north_of_rwy;
247 D_cg_east_of_rwy = FG_D_cg_east_of_rwy;
248 D_cg_above_rwy = FG_D_cg_above_rwy;
249 X_cg_rwy = FG_X_cg_rwy;
250 Y_cg_rwy = FG_Y_cg_rwy;
251 H_cg_rwy = FG_H_cg_rwy;
252 D_pilot_north_of_rwy = FG_D_pilot_north_of_rwy;
253 D_pilot_east_of_rwy = FG_D_pilot_east_of_rwy;
254 D_pilot_above_rwy = FG_D_pilot_above_rwy;
255 X_pilot_rwy = FG_X_pilot_rwy;
256 Y_pilot_rwy = FG_Y_pilot_rwy;
257 H_pilot_rwy = FG_H_pilot_rwy;
263 // Convert from the LaRCsim generic_ struct to the fgFLIGHT struct
264 int fgLaRCsim_2_Flight (fgFLIGHT *f) {
270 FG_Dx_pilot = Dx_pilot;
271 FG_Dy_pilot = Dy_pilot;
272 FG_Dz_pilot = Dz_pilot;
279 FG_F_north = F_north;
282 FG_F_X_aero = F_X_aero;
283 FG_F_Y_aero = F_Y_aero;
284 FG_F_Z_aero = F_Z_aero;
285 FG_F_X_engine = F_X_engine;
286 FG_F_Y_engine = F_Y_engine;
287 FG_F_Z_engine = F_Z_engine;
288 FG_F_X_gear = F_X_gear;
289 FG_F_Y_gear = F_Y_gear;
290 FG_F_Z_gear = F_Z_gear;
297 FG_M_l_aero = M_l_aero;
298 FG_M_m_aero = M_m_aero;
299 FG_M_n_aero = M_n_aero;
300 FG_M_l_engine = M_l_engine;
301 FG_M_m_engine = M_m_engine;
302 FG_M_n_engine = M_n_engine;
303 FG_M_l_gear = M_l_gear;
304 FG_M_m_gear = M_m_gear;
305 FG_M_n_gear = M_n_gear;
306 FG_V_dot_north = V_dot_north;
307 FG_V_dot_east = V_dot_east;
308 FG_V_dot_down = V_dot_down;
309 FG_U_dot_body = U_dot_body;
310 FG_V_dot_body = V_dot_body;
311 FG_W_dot_body = W_dot_body;
315 FG_A_X_pilot = A_X_pilot;
316 FG_A_Y_pilot = A_Y_pilot;
317 FG_A_Z_pilot = A_Z_pilot;
321 FG_N_X_pilot = N_X_pilot;
322 FG_N_Y_pilot = N_Y_pilot;
323 FG_N_Z_pilot = N_Z_pilot;
324 FG_P_dot_body = P_dot_body;
325 FG_Q_dot_body = Q_dot_body;
326 FG_R_dot_body = R_dot_body;
327 FG_V_north = V_north;
330 FG_V_north_rel_ground = V_north_rel_ground;
331 FG_V_east_rel_ground = V_east_rel_ground;
332 FG_V_down_rel_ground = V_down_rel_ground;
333 FG_V_north_airmass = V_north_airmass;
334 FG_V_east_airmass = V_east_airmass;
335 FG_V_down_airmass = V_down_airmass;
336 FG_V_north_rel_airmass = V_north_rel_airmass;
337 FG_V_east_rel_airmass = V_east_rel_airmass;
338 FG_V_down_rel_airmass = V_down_rel_airmass;
345 FG_V_rel_wind = V_rel_wind;
346 FG_V_true_kts = V_true_kts;
347 FG_V_rel_ground = V_rel_ground;
348 FG_V_inertial = V_inertial;
349 FG_V_ground_speed = V_ground_speed;
350 FG_V_equiv = V_equiv;
351 FG_V_equiv_kts = V_equiv_kts;
352 FG_V_calibrated = V_calibrated;
353 FG_V_calibrated_kts = V_calibrated_kts;
357 FG_P_local = P_local;
358 FG_Q_local = Q_local;
359 FG_R_local = R_local;
360 FG_P_total = P_total;
361 FG_Q_total = Q_total;
362 FG_R_total = R_total;
363 FG_Phi_dot = Phi_dot;
364 FG_Theta_dot = Theta_dot;
365 FG_Psi_dot = Psi_dot;
366 FG_Latitude_dot = Latitude_dot;
367 FG_Longitude_dot = Longitude_dot;
368 FG_Radius_dot = Radius_dot;
369 FG_Lat_geocentric = Lat_geocentric;
370 FG_Lon_geocentric = Lon_geocentric;
371 FG_Radius_to_vehicle = Radius_to_vehicle;
372 FG_Latitude = Latitude;
373 FG_Longitude = Longitude;
374 FG_Altitude = Altitude;
378 FG_T_local_to_body_11 = T_local_to_body_11;
379 FG_T_local_to_body_12 = T_local_to_body_12;
380 FG_T_local_to_body_13 = T_local_to_body_13;
381 FG_T_local_to_body_21 = T_local_to_body_21;
382 FG_T_local_to_body_22 = T_local_to_body_22;
383 FG_T_local_to_body_23 = T_local_to_body_23;
384 FG_T_local_to_body_31 = T_local_to_body_31;
385 FG_T_local_to_body_32 = T_local_to_body_32;
386 FG_T_local_to_body_33 = T_local_to_body_33;
387 FG_Gravity = Gravity;
388 FG_Centrifugal_relief = Centrifugal_relief;
391 FG_Alpha_dot = Alpha_dot;
392 FG_Beta_dot = Beta_dot;
393 FG_Cos_alpha = Cos_alpha;
394 FG_Sin_alpha = Sin_alpha;
395 FG_Cos_beta = Cos_beta;
396 FG_Sin_beta = Sin_beta;
397 FG_Cos_phi = Cos_phi;
398 FG_Sin_phi = Sin_phi;
399 FG_Cos_theta = Cos_theta;
400 FG_Sin_theta = Sin_theta;
401 FG_Cos_psi = Cos_psi;
402 FG_Sin_psi = Sin_psi;
403 FG_Gamma_vert_rad = Gamma_vert_rad;
404 FG_Gamma_horiz_rad = Gamma_horiz_rad;
406 FG_Density = Density;
407 FG_V_sound = V_sound;
408 FG_Mach_number = Mach_number;
409 FG_Static_pressure = Static_pressure;
410 FG_Total_pressure = Total_pressure;
411 FG_Impact_pressure = Impact_pressure;
412 FG_Dynamic_pressure = Dynamic_pressure;
413 FG_Static_temperature = Static_temperature;
414 FG_Total_temperature = Total_temperature;
415 FG_Sea_level_radius = Sea_level_radius;
416 FG_Earth_position_angle = Earth_position_angle;
417 FG_Runway_altitude = Runway_altitude;
418 FG_Runway_latitude = Runway_latitude;
419 FG_Runway_longitude = Runway_longitude;
420 FG_Runway_heading = Runway_heading;
421 FG_Radius_to_rwy = Radius_to_rwy;
422 FG_D_cg_north_of_rwy = D_cg_north_of_rwy;
423 FG_D_cg_east_of_rwy = D_cg_east_of_rwy;
424 FG_D_cg_above_rwy = D_cg_above_rwy;
425 FG_X_cg_rwy = X_cg_rwy;
426 FG_Y_cg_rwy = Y_cg_rwy;
427 FG_H_cg_rwy = H_cg_rwy;
428 FG_D_pilot_north_of_rwy = D_pilot_north_of_rwy;
429 FG_D_pilot_east_of_rwy = D_pilot_east_of_rwy;
430 FG_D_pilot_above_rwy = D_pilot_above_rwy;
431 FG_X_pilot_rwy = X_pilot_rwy;
432 FG_Y_pilot_rwy = Y_pilot_rwy;
433 FG_H_pilot_rwy = H_pilot_rwy;
440 // Revision 1.3 1998/10/25 14:08:43 curt
441 // Turned "struct fgCONTROLS" into a class, with inlined accessor functions.
443 // Revision 1.2 1998/10/17 01:34:11 curt
446 // Revision 1.1 1998/10/17 00:43:58 curt