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.h>
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) {
86 Dx_pilot = FG_Dx_pilot;
87 Dy_pilot = FG_Dy_pilot;
88 Dz_pilot = FG_Dz_pilot;
98 F_X_aero = FG_F_X_aero;
99 F_Y_aero = FG_F_Y_aero;
100 F_Z_aero = FG_F_Z_aero;
101 F_X_engine = FG_F_X_engine;
102 F_Y_engine = FG_F_Y_engine;
103 F_Z_engine = FG_F_Z_engine;
104 F_X_gear = FG_F_X_gear;
105 F_Y_gear = FG_F_Y_gear;
106 F_Z_gear = FG_F_Z_gear;
113 M_l_aero = FG_M_l_aero;
114 M_m_aero = FG_M_m_aero;
115 M_n_aero = FG_M_n_aero;
116 M_l_engine = FG_M_l_engine;
117 M_m_engine = FG_M_m_engine;
118 M_n_engine = FG_M_n_engine;
119 M_l_gear = FG_M_l_gear;
120 M_m_gear = FG_M_m_gear;
121 M_n_gear = FG_M_n_gear;
122 V_dot_north = FG_V_dot_north;
123 V_dot_east = FG_V_dot_east;
124 V_dot_down = FG_V_dot_down;
125 U_dot_body = FG_U_dot_body;
126 V_dot_body = FG_V_dot_body;
127 W_dot_body = FG_W_dot_body;
131 A_X_pilot = FG_A_X_pilot;
132 A_Y_pilot = FG_A_Y_pilot;
133 A_Z_pilot = FG_A_Z_pilot;
137 N_X_pilot = FG_N_X_pilot;
138 N_Y_pilot = FG_N_Y_pilot;
139 N_Z_pilot = FG_N_Z_pilot;
140 P_dot_body = FG_P_dot_body;
141 Q_dot_body = FG_Q_dot_body;
142 R_dot_body = FG_R_dot_body;
143 V_north = FG_V_north;
146 V_north_rel_ground = FG_V_north_rel_ground;
147 V_east_rel_ground = FG_V_east_rel_ground;
148 V_down_rel_ground = FG_V_down_rel_ground;
149 V_north_airmass = FG_V_north_airmass;
150 V_east_airmass = FG_V_east_airmass;
151 V_down_airmass = FG_V_down_airmass;
152 V_north_rel_airmass = FG_V_north_rel_airmass;
153 V_east_rel_airmass = FG_V_east_rel_airmass;
154 V_down_rel_airmass = FG_V_down_rel_airmass;
161 V_rel_wind = FG_V_rel_wind;
162 V_true_kts = FG_V_true_kts;
163 V_rel_ground = FG_V_rel_ground;
164 V_inertial = FG_V_inertial;
165 V_ground_speed = FG_V_ground_speed;
166 V_equiv = FG_V_equiv;
167 V_equiv_kts = FG_V_equiv_kts;
168 V_calibrated = FG_V_calibrated;
169 V_calibrated_kts = FG_V_calibrated_kts;
173 P_local = FG_P_local;
174 Q_local = FG_Q_local;
175 R_local = FG_R_local;
176 P_total = FG_P_total;
177 Q_total = FG_Q_total;
178 R_total = FG_R_total;
179 Phi_dot = FG_Phi_dot;
180 Theta_dot = FG_Theta_dot;
181 Psi_dot = FG_Psi_dot;
182 Latitude_dot = FG_Latitude_dot;
183 Longitude_dot = FG_Longitude_dot;
184 Radius_dot = FG_Radius_dot;
185 Lat_geocentric = FG_Lat_geocentric;
186 Lon_geocentric = FG_Lon_geocentric;
187 Radius_to_vehicle = FG_Radius_to_vehicle;
188 Latitude = FG_Latitude;
189 Longitude = FG_Longitude;
190 Altitude = FG_Altitude;
194 T_local_to_body_11 = FG_T_local_to_body_11;
195 T_local_to_body_12 = FG_T_local_to_body_12;
196 T_local_to_body_13 = FG_T_local_to_body_13;
197 T_local_to_body_21 = FG_T_local_to_body_21;
198 T_local_to_body_22 = FG_T_local_to_body_22;
199 T_local_to_body_23 = FG_T_local_to_body_23;
200 T_local_to_body_31 = FG_T_local_to_body_31;
201 T_local_to_body_32 = FG_T_local_to_body_32;
202 T_local_to_body_33 = FG_T_local_to_body_33;
203 Gravity = FG_Gravity;
204 Centrifugal_relief = FG_Centrifugal_relief;
207 Alpha_dot = FG_Alpha_dot;
208 Beta_dot = FG_Beta_dot;
209 Cos_alpha = FG_Cos_alpha;
210 Sin_alpha = FG_Sin_alpha;
211 Cos_beta = FG_Cos_beta;
212 Sin_beta = FG_Sin_beta;
213 Cos_phi = FG_Cos_phi;
214 Sin_phi = FG_Sin_phi;
215 Cos_theta = FG_Cos_theta;
216 Sin_theta = FG_Sin_theta;
217 Cos_psi = FG_Cos_psi;
218 Sin_psi = FG_Sin_psi;
219 Gamma_vert_rad = FG_Gamma_vert_rad;
220 Gamma_horiz_rad = FG_Gamma_horiz_rad;
222 Density = FG_Density;
223 V_sound = FG_V_sound;
224 Mach_number = FG_Mach_number;
225 Static_pressure = FG_Static_pressure;
226 Total_pressure = FG_Total_pressure;
227 Impact_pressure = FG_Impact_pressure;
228 Dynamic_pressure = FG_Dynamic_pressure;
229 Static_temperature = FG_Static_temperature;
230 Total_temperature = FG_Total_temperature;
231 Sea_level_radius = FG_Sea_level_radius;
232 Earth_position_angle = FG_Earth_position_angle;
233 Runway_altitude = FG_Runway_altitude;
234 Runway_latitude = FG_Runway_latitude;
235 Runway_longitude = FG_Runway_longitude;
236 Runway_heading = FG_Runway_heading;
237 Radius_to_rwy = FG_Radius_to_rwy;
238 D_cg_north_of_rwy = FG_D_cg_north_of_rwy;
239 D_cg_east_of_rwy = FG_D_cg_east_of_rwy;
240 D_cg_above_rwy = FG_D_cg_above_rwy;
241 X_cg_rwy = FG_X_cg_rwy;
242 Y_cg_rwy = FG_Y_cg_rwy;
243 H_cg_rwy = FG_H_cg_rwy;
244 D_pilot_north_of_rwy = FG_D_pilot_north_of_rwy;
245 D_pilot_east_of_rwy = FG_D_pilot_east_of_rwy;
246 D_pilot_above_rwy = FG_D_pilot_above_rwy;
247 X_pilot_rwy = FG_X_pilot_rwy;
248 Y_pilot_rwy = FG_Y_pilot_rwy;
249 H_pilot_rwy = FG_H_pilot_rwy;
255 // Convert from the LaRCsim generic_ struct to the fgFLIGHT struct
256 int fgLaRCsim_2_Flight (fgFLIGHT *f) {
259 c = current_aircraft.controls;
261 Lat_control = FG_Aileron;
262 Long_control = FG_Elevator;
263 Long_trim = FG_Elev_Trim;
264 Rudder_pedal = FG_Rudder;
265 Throttle_pct = FG_Throttle[0];
272 FG_Dx_pilot = Dx_pilot;
273 FG_Dy_pilot = Dy_pilot;
274 FG_Dz_pilot = Dz_pilot;
281 FG_F_north = F_north;
284 FG_F_X_aero = F_X_aero;
285 FG_F_Y_aero = F_Y_aero;
286 FG_F_Z_aero = F_Z_aero;
287 FG_F_X_engine = F_X_engine;
288 FG_F_Y_engine = F_Y_engine;
289 FG_F_Z_engine = F_Z_engine;
290 FG_F_X_gear = F_X_gear;
291 FG_F_Y_gear = F_Y_gear;
292 FG_F_Z_gear = F_Z_gear;
299 FG_M_l_aero = M_l_aero;
300 FG_M_m_aero = M_m_aero;
301 FG_M_n_aero = M_n_aero;
302 FG_M_l_engine = M_l_engine;
303 FG_M_m_engine = M_m_engine;
304 FG_M_n_engine = M_n_engine;
305 FG_M_l_gear = M_l_gear;
306 FG_M_m_gear = M_m_gear;
307 FG_M_n_gear = M_n_gear;
308 FG_V_dot_north = V_dot_north;
309 FG_V_dot_east = V_dot_east;
310 FG_V_dot_down = V_dot_down;
311 FG_U_dot_body = U_dot_body;
312 FG_V_dot_body = V_dot_body;
313 FG_W_dot_body = W_dot_body;
317 FG_A_X_pilot = A_X_pilot;
318 FG_A_Y_pilot = A_Y_pilot;
319 FG_A_Z_pilot = A_Z_pilot;
323 FG_N_X_pilot = N_X_pilot;
324 FG_N_Y_pilot = N_Y_pilot;
325 FG_N_Z_pilot = N_Z_pilot;
326 FG_P_dot_body = P_dot_body;
327 FG_Q_dot_body = Q_dot_body;
328 FG_R_dot_body = R_dot_body;
329 FG_V_north = V_north;
332 FG_V_north_rel_ground = V_north_rel_ground;
333 FG_V_east_rel_ground = V_east_rel_ground;
334 FG_V_down_rel_ground = V_down_rel_ground;
335 FG_V_north_airmass = V_north_airmass;
336 FG_V_east_airmass = V_east_airmass;
337 FG_V_down_airmass = V_down_airmass;
338 FG_V_north_rel_airmass = V_north_rel_airmass;
339 FG_V_east_rel_airmass = V_east_rel_airmass;
340 FG_V_down_rel_airmass = V_down_rel_airmass;
347 FG_V_rel_wind = V_rel_wind;
348 FG_V_true_kts = V_true_kts;
349 FG_V_rel_ground = V_rel_ground;
350 FG_V_inertial = V_inertial;
351 FG_V_ground_speed = V_ground_speed;
352 FG_V_equiv = V_equiv;
353 FG_V_equiv_kts = V_equiv_kts;
354 FG_V_calibrated = V_calibrated;
355 FG_V_calibrated_kts = V_calibrated_kts;
359 FG_P_local = P_local;
360 FG_Q_local = Q_local;
361 FG_R_local = R_local;
362 FG_P_total = P_total;
363 FG_Q_total = Q_total;
364 FG_R_total = R_total;
365 FG_Phi_dot = Phi_dot;
366 FG_Theta_dot = Theta_dot;
367 FG_Psi_dot = Psi_dot;
368 FG_Latitude_dot = Latitude_dot;
369 FG_Longitude_dot = Longitude_dot;
370 FG_Radius_dot = Radius_dot;
371 FG_Lat_geocentric = Lat_geocentric;
372 FG_Lon_geocentric = Lon_geocentric;
373 FG_Radius_to_vehicle = Radius_to_vehicle;
374 FG_Latitude = Latitude;
375 FG_Longitude = Longitude;
376 FG_Altitude = Altitude;
380 FG_T_local_to_body_11 = T_local_to_body_11;
381 FG_T_local_to_body_12 = T_local_to_body_12;
382 FG_T_local_to_body_13 = T_local_to_body_13;
383 FG_T_local_to_body_21 = T_local_to_body_21;
384 FG_T_local_to_body_22 = T_local_to_body_22;
385 FG_T_local_to_body_23 = T_local_to_body_23;
386 FG_T_local_to_body_31 = T_local_to_body_31;
387 FG_T_local_to_body_32 = T_local_to_body_32;
388 FG_T_local_to_body_33 = T_local_to_body_33;
389 FG_Gravity = Gravity;
390 FG_Centrifugal_relief = Centrifugal_relief;
393 FG_Alpha_dot = Alpha_dot;
394 FG_Beta_dot = Beta_dot;
395 FG_Cos_alpha = Cos_alpha;
396 FG_Sin_alpha = Sin_alpha;
397 FG_Cos_beta = Cos_beta;
398 FG_Sin_beta = Sin_beta;
399 FG_Cos_phi = Cos_phi;
400 FG_Sin_phi = Sin_phi;
401 FG_Cos_theta = Cos_theta;
402 FG_Sin_theta = Sin_theta;
403 FG_Cos_psi = Cos_psi;
404 FG_Sin_psi = Sin_psi;
405 FG_Gamma_vert_rad = Gamma_vert_rad;
406 FG_Gamma_horiz_rad = Gamma_horiz_rad;
408 FG_Density = Density;
409 FG_V_sound = V_sound;
410 FG_Mach_number = Mach_number;
411 FG_Static_pressure = Static_pressure;
412 FG_Total_pressure = Total_pressure;
413 FG_Impact_pressure = Impact_pressure;
414 FG_Dynamic_pressure = Dynamic_pressure;
415 FG_Static_temperature = Static_temperature;
416 FG_Total_temperature = Total_temperature;
417 FG_Sea_level_radius = Sea_level_radius;
418 FG_Earth_position_angle = Earth_position_angle;
419 FG_Runway_altitude = Runway_altitude;
420 FG_Runway_latitude = Runway_latitude;
421 FG_Runway_longitude = Runway_longitude;
422 FG_Runway_heading = Runway_heading;
423 FG_Radius_to_rwy = Radius_to_rwy;
424 FG_D_cg_north_of_rwy = D_cg_north_of_rwy;
425 FG_D_cg_east_of_rwy = D_cg_east_of_rwy;
426 FG_D_cg_above_rwy = D_cg_above_rwy;
427 FG_X_cg_rwy = X_cg_rwy;
428 FG_Y_cg_rwy = Y_cg_rwy;
429 FG_H_cg_rwy = H_cg_rwy;
430 FG_D_pilot_north_of_rwy = D_pilot_north_of_rwy;
431 FG_D_pilot_east_of_rwy = D_pilot_east_of_rwy;
432 FG_D_pilot_above_rwy = D_pilot_above_rwy;
433 FG_X_pilot_rwy = X_pilot_rwy;
434 FG_Y_pilot_rwy = Y_pilot_rwy;
435 FG_H_pilot_rwy = H_pilot_rwy;
442 // Revision 1.1 1998/10/17 00:43:58 curt