]> git.mxchange.org Git - flightgear.git/blob - FDM/LaRCsim.cxx
Converted fgFLIGHT to a class.
[flightgear.git] / FDM / LaRCsim.cxx
1 // LaRCsim.cxx -- interface to the LaRCsim flight model
2 //
3 // Written by Curtis Olson, started October 1998.
4 //
5 // Copyright (C) 1998  Curtis L. Olson  - curt@me.umn.edu
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., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22 // (Log is kept at end of this file)
23
24
25 #include "LaRCsim.hxx"
26
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>
33
34
35 // Initialize the LaRCsim flight model, dt is the time increment for
36 // each subsequent iteration through the EOM
37 int fgLaRCsimInit(double dt) {
38     ls_toplevel_init(dt);
39
40     return(1);
41 }
42
43
44 // Run an iteration of the EOM (equations of motion)
45 int fgLaRCsimUpdate(fgFLIGHT& f, int multiloop) {
46     double save_alt = 0.0;
47
48     // lets try to avoid really screwing up the LaRCsim model
49     if ( f.get_Altitude() < -9000 ) {
50         save_alt = f.get_Altitude();
51         f.set_Altitude( 0.0 );
52     }
53
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);
59
60     ls_update(multiloop);
61
62     // printf("%d FG_Altitude = %.2f\n", i, FG_Altitude * 0.3048);
63     // printf("%d Altitude = %.2f\n", i, Altitude * 0.3048);
64     
65     // translate LaRCsim back to FG structure so that the
66     // autopilot (and the rest of the sim can use the updated
67     // values
68     fgLaRCsim_2_Flight(f);
69
70     // but lets restore our original bogus altitude when we are done
71     if ( save_alt < -9000.0 ) {
72         f.set_Altitude( save_alt );
73     }
74
75     return 1;
76 }
77
78
79 // Convert from the fgFLIGHT struct to the LaRCsim generic_ struct
80 int fgFlight_2_LaRCsim (fgFLIGHT& f) {
81
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 );
88
89     Mass =      f.get_Mass();
90     I_xx =      f.get_I_xx();
91     I_yy =      f.get_I_yy();
92     I_zz =      f.get_I_zz();
93     I_xz =      f.get_I_xz();
94     Dx_pilot =  f.get_Dx_pilot();
95     Dy_pilot =  f.get_Dy_pilot();
96     Dz_pilot =  f.get_Dz_pilot();
97     Dx_cg =     f.get_Dx_cg();
98     Dy_cg =     f.get_Dy_cg();
99     Dz_cg =     f.get_Dz_cg();
100     F_X =       f.get_F_X();
101     F_Y =       f.get_F_Y();
102     F_Z =       f.get_F_Z();
103     F_north =   f.get_F_north();
104     F_east =    f.get_F_east();
105     F_down =    f.get_F_down();
106     F_X_aero =  f.get_F_X_aero();
107     F_Y_aero =  f.get_F_Y_aero();
108     F_Z_aero =  f.get_F_Z_aero();
109     F_X_engine =        f.get_F_X_engine();
110     F_Y_engine =        f.get_F_Y_engine();
111     F_Z_engine =        f.get_F_Z_engine();
112     F_X_gear =  f.get_F_X_gear();
113     F_Y_gear =  f.get_F_Y_gear();
114     F_Z_gear =  f.get_F_Z_gear();
115     M_l_rp =    f.get_M_l_rp();
116     M_m_rp =    f.get_M_m_rp();
117     M_n_rp =    f.get_M_n_rp();
118     M_l_cg =    f.get_M_l_cg();
119     M_m_cg =    f.get_M_m_cg();
120     M_n_cg =    f.get_M_n_cg();
121     M_l_aero =  f.get_M_l_aero();
122     M_m_aero =  f.get_M_m_aero();
123     M_n_aero =  f.get_M_n_aero();
124     M_l_engine =        f.get_M_l_engine();
125     M_m_engine =        f.get_M_m_engine();
126     M_n_engine =        f.get_M_n_engine();
127     M_l_gear =  f.get_M_l_gear();
128     M_m_gear =  f.get_M_m_gear();
129     M_n_gear =  f.get_M_n_gear();
130     V_dot_north =       f.get_V_dot_north();
131     V_dot_east =        f.get_V_dot_east();
132     V_dot_down =        f.get_V_dot_down();
133     U_dot_body =        f.get_U_dot_body();
134     V_dot_body =        f.get_V_dot_body();
135     W_dot_body =        f.get_W_dot_body();
136     A_X_cg =    f.get_A_X_cg();
137     A_Y_cg =    f.get_A_Y_cg();
138     A_Z_cg =    f.get_A_Z_cg();
139     A_X_pilot = f.get_A_X_pilot();
140     A_Y_pilot = f.get_A_Y_pilot();
141     A_Z_pilot = f.get_A_Z_pilot();
142     N_X_cg =    f.get_N_X_cg();
143     N_Y_cg =    f.get_N_Y_cg();
144     N_Z_cg =    f.get_N_Z_cg();
145     N_X_pilot = f.get_N_X_pilot();
146     N_Y_pilot = f.get_N_Y_pilot();
147     N_Z_pilot = f.get_N_Z_pilot();
148     P_dot_body =        f.get_P_dot_body();
149     Q_dot_body =        f.get_Q_dot_body();
150     R_dot_body =        f.get_R_dot_body();
151     V_north =   f.get_V_north();
152     V_east =    f.get_V_east();
153     V_down =    f.get_V_down();
154     V_north_rel_ground =        f.get_V_north_rel_ground();
155     V_east_rel_ground = f.get_V_east_rel_ground();
156     V_down_rel_ground = f.get_V_down_rel_ground();
157     V_north_airmass =   f.get_V_north_airmass();
158     V_east_airmass =    f.get_V_east_airmass();
159     V_down_airmass =    f.get_V_down_airmass();
160     V_north_rel_airmass =       f.get_V_north_rel_airmass();
161     V_east_rel_airmass =        f.get_V_east_rel_airmass();
162     V_down_rel_airmass =        f.get_V_down_rel_airmass();
163     U_gust =    f.get_U_gust();
164     V_gust =    f.get_V_gust();
165     W_gust =    f.get_W_gust();
166     U_body =    f.get_U_body();
167     V_body =    f.get_V_body();
168     W_body =    f.get_W_body();
169     V_rel_wind =        f.get_V_rel_wind();
170     V_true_kts =        f.get_V_true_kts();
171     V_rel_ground =      f.get_V_rel_ground();
172     V_inertial =        f.get_V_inertial();
173     V_ground_speed =    f.get_V_ground_speed();
174     V_equiv =   f.get_V_equiv();
175     V_equiv_kts =       f.get_V_equiv_kts();
176     V_calibrated =      f.get_V_calibrated();
177     V_calibrated_kts =  f.get_V_calibrated_kts();
178     P_body =    f.get_P_body();
179     Q_body =    f.get_Q_body();
180     R_body =    f.get_R_body();
181     P_local =   f.get_P_local();
182     Q_local =   f.get_Q_local();
183     R_local =   f.get_R_local();
184     P_total =   f.get_P_total();
185     Q_total =   f.get_Q_total();
186     R_total =   f.get_R_total();
187     Phi_dot =   f.get_Phi_dot();
188     Theta_dot = f.get_Theta_dot();
189     Psi_dot =   f.get_Psi_dot();
190     Latitude_dot =      f.get_Latitude_dot();
191     Longitude_dot =     f.get_Longitude_dot();
192     Radius_dot =        f.get_Radius_dot();
193     Lat_geocentric =    f.get_Lat_geocentric();
194     Lon_geocentric =    f.get_Lon_geocentric();
195     Radius_to_vehicle = f.get_Radius_to_vehicle();
196     Latitude =  f.get_Latitude();
197     Longitude = f.get_Longitude();
198     Altitude =  f.get_Altitude();
199     Phi =       f.get_Phi();
200     Theta =     f.get_Theta();
201     Psi =       f.get_Psi();
202     T_local_to_body_11 =        f.get_T_local_to_body_11();
203     T_local_to_body_12 =        f.get_T_local_to_body_12();
204     T_local_to_body_13 =        f.get_T_local_to_body_13();
205     T_local_to_body_21 =        f.get_T_local_to_body_21();
206     T_local_to_body_22 =        f.get_T_local_to_body_22();
207     T_local_to_body_23 =        f.get_T_local_to_body_23();
208     T_local_to_body_31 =        f.get_T_local_to_body_31();
209     T_local_to_body_32 =        f.get_T_local_to_body_32();
210     T_local_to_body_33 =        f.get_T_local_to_body_33();
211     Gravity =   f.get_Gravity();
212     Centrifugal_relief =        f.get_Centrifugal_relief();
213     Alpha =     f.get_Alpha();
214     Beta =      f.get_Beta();
215     Alpha_dot = f.get_Alpha_dot();
216     Beta_dot =  f.get_Beta_dot();
217     Cos_alpha = f.get_Cos_alpha();
218     Sin_alpha = f.get_Sin_alpha();
219     Cos_beta =  f.get_Cos_beta();
220     Sin_beta =  f.get_Sin_beta();
221     Cos_phi =   f.get_Cos_phi();
222     Sin_phi =   f.get_Sin_phi();
223     Cos_theta = f.get_Cos_theta();
224     Sin_theta = f.get_Sin_theta();
225     Cos_psi =   f.get_Cos_psi();
226     Sin_psi =   f.get_Sin_psi();
227     Gamma_vert_rad =    f.get_Gamma_vert_rad();
228     Gamma_horiz_rad =   f.get_Gamma_horiz_rad();
229     Sigma =     f.get_Sigma();
230     Density =   f.get_Density();
231     V_sound =   f.get_V_sound();
232     Mach_number =       f.get_Mach_number();
233     Static_pressure =   f.get_Static_pressure();
234     Total_pressure =    f.get_Total_pressure();
235     Impact_pressure =   f.get_Impact_pressure();
236     Dynamic_pressure =  f.get_Dynamic_pressure();
237     Static_temperature =        f.get_Static_temperature();
238     Total_temperature = f.get_Total_temperature();
239     Sea_level_radius =  f.get_Sea_level_radius();
240     Earth_position_angle =      f.get_Earth_position_angle();
241     Runway_altitude =   f.get_Runway_altitude();
242     Runway_latitude =   f.get_Runway_latitude();
243     Runway_longitude =  f.get_Runway_longitude();
244     Runway_heading =    f.get_Runway_heading();
245     Radius_to_rwy =     f.get_Radius_to_rwy();
246     D_cg_north_of_rwy = f.get_D_cg_north_of_rwy();
247     D_cg_east_of_rwy =  f.get_D_cg_east_of_rwy();
248     D_cg_above_rwy =    f.get_D_cg_above_rwy();
249     X_cg_rwy =  f.get_X_cg_rwy();
250     Y_cg_rwy =  f.get_Y_cg_rwy();
251     H_cg_rwy =  f.get_H_cg_rwy();
252     D_pilot_north_of_rwy =      f.get_D_pilot_north_of_rwy();
253     D_pilot_east_of_rwy =       f.get_D_pilot_east_of_rwy();
254     D_pilot_above_rwy = f.get_D_pilot_above_rwy();
255     X_pilot_rwy =       f.get_X_pilot_rwy();
256     Y_pilot_rwy =       f.get_Y_pilot_rwy();
257     H_pilot_rwy =       f.get_H_pilot_rwy();
258
259     return( 0 );
260 }
261
262
263 // Convert from the LaRCsim generic_ struct to the fgFLIGHT struct
264 int fgLaRCsim_2_Flight (fgFLIGHT& f) {
265     f.set_Inertias( Mass, I_xx, I_yy, I_zz, I_xz );
266
267     /*
268     f.get_Dx_pilot() =       Dx_pilot;
269     f.get_Dy_pilot() =       Dy_pilot;
270     f.get_Dz_pilot() =       Dz_pilot;
271     f.get_Dx_cg() =  Dx_cg;
272     f.get_Dy_cg() =  Dy_cg;
273     f.get_Dz_cg() =  Dz_cg;
274     f.get_F_X() =    F_X;
275     f.get_F_Y() =    F_Y;
276     f.get_F_Z() =    F_Z;
277     f.get_F_north() =        F_north;
278     f.get_F_east() = F_east;
279     f.get_F_down() = F_down;
280     f.get_F_X_aero() =       F_X_aero;
281     f.get_F_Y_aero() =       F_Y_aero;
282     f.get_F_Z_aero() =       F_Z_aero;
283     f.get_F_X_engine() =     F_X_engine;
284     f.get_F_Y_engine() =     F_Y_engine;
285     f.get_F_Z_engine() =     F_Z_engine;
286     f.get_F_X_gear() =       F_X_gear;
287     f.get_F_Y_gear() =       F_Y_gear;
288     f.get_F_Z_gear() =       F_Z_gear;
289     f.get_M_l_rp() = M_l_rp;
290     f.get_M_m_rp() = M_m_rp;
291     f.get_M_n_rp() = M_n_rp;
292     f.get_M_l_cg() = M_l_cg;
293     f.get_M_m_cg() = M_m_cg;
294     f.get_M_n_cg() = M_n_cg;
295     f.get_M_l_aero() =       M_l_aero;
296     f.get_M_m_aero() =       M_m_aero;
297     f.get_M_n_aero() =       M_n_aero;
298     f.get_M_l_engine() =     M_l_engine;
299     f.get_M_m_engine() =     M_m_engine;
300     f.get_M_n_engine() =     M_n_engine;
301     f.get_M_l_gear() =       M_l_gear;
302     f.get_M_m_gear() =       M_m_gear;
303     f.get_M_n_gear() =       M_n_gear;
304     f.get_V_dot_north() =    V_dot_north;
305     f.get_V_dot_east() =     V_dot_east;
306     f.get_V_dot_down() =     V_dot_down;
307     f.get_U_dot_body() =     U_dot_body;
308     f.get_V_dot_body() =     V_dot_body;
309     f.get_W_dot_body() =     W_dot_body;
310     f.get_A_X_cg() = A_X_cg;
311     f.get_A_Y_cg() = A_Y_cg;
312     f.get_A_Z_cg() = A_Z_cg;
313     f.get_A_X_pilot() =      A_X_pilot;
314     f.get_A_Y_pilot() =      A_Y_pilot;
315     f.get_A_Z_pilot() =      A_Z_pilot;
316     f.get_N_X_cg() = N_X_cg;
317     f.get_N_Y_cg() = N_Y_cg;
318     f.get_N_Z_cg() = N_Z_cg;
319     f.get_N_X_pilot() =      N_X_pilot;
320     f.get_N_Y_pilot() =      N_Y_pilot;
321     f.get_N_Z_pilot() =      N_Z_pilot;
322     f.get_P_dot_body() =     P_dot_body;
323     f.get_Q_dot_body() =     Q_dot_body;
324     f.get_R_dot_body() =     R_dot_body;
325     f.get_V_north() =        V_north;
326     f.get_V_east() = V_east;
327     f.get_V_down() = V_down;
328     f.get_V_north_rel_ground() =     V_north_rel_ground;
329     f.get_V_east_rel_ground() =      V_east_rel_ground;
330     f.get_V_down_rel_ground() =      V_down_rel_ground;
331     f.get_V_north_airmass() =        V_north_airmass;
332     f.get_V_east_airmass() = V_east_airmass;
333     f.get_V_down_airmass() = V_down_airmass;
334     f.get_V_north_rel_airmass() =    V_north_rel_airmass;
335     f.get_V_east_rel_airmass() =     V_east_rel_airmass;
336     f.get_V_down_rel_airmass() =     V_down_rel_airmass;
337     f.get_U_gust() = U_gust;
338     f.get_V_gust() = V_gust;
339     f.get_W_gust() = W_gust;
340     f.get_U_body() = U_body;
341     f.get_V_body() = V_body;
342     f.get_W_body() = W_body;
343     f.get_V_rel_wind() =     V_rel_wind;
344     f.get_V_true_kts() =     V_true_kts;
345     f.get_V_rel_ground() =   V_rel_ground;
346     f.get_V_inertial() =     V_inertial;
347     f.get_V_ground_speed() = V_ground_speed;
348     f.get_V_equiv() =        V_equiv;
349     f.get_V_equiv_kts() =    V_equiv_kts;
350     f.get_V_calibrated() =   V_calibrated;
351     f.get_V_calibrated_kts() =       V_calibrated_kts;
352     f.get_P_body() = P_body;
353     f.get_Q_body() = Q_body;
354     f.get_R_body() = R_body;
355     f.get_P_local() =        P_local;
356     f.get_Q_local() =        Q_local;
357     f.get_R_local() =        R_local;
358     f.get_P_total() =        P_total;
359     f.get_Q_total() =        Q_total;
360     f.get_R_total() =        R_total;
361     f.get_Phi_dot() =        Phi_dot;
362     f.get_Theta_dot() =      Theta_dot;
363     f.get_Psi_dot() =        Psi_dot;
364     f.get_Latitude_dot() =   Latitude_dot;
365     f.get_Longitude_dot() =  Longitude_dot;
366     f.get_Radius_dot() =     Radius_dot;
367     f.get_Lat_geocentric() = Lat_geocentric;
368     f.get_Lon_geocentric() = Lon_geocentric;
369     f.get_Radius_to_vehicle() =      Radius_to_vehicle;
370     f.get_Latitude() =       Latitude;
371     f.get_Longitude() =      Longitude;
372     f.get_Altitude() =       Altitude;
373     f.get_Phi() =    Phi;
374     f.get_Theta() =  Theta;
375     f.get_Psi() =    Psi;
376     f.get_T_local_to_body_11() =     T_local_to_body_11;
377     f.get_T_local_to_body_12() =     T_local_to_body_12;
378     f.get_T_local_to_body_13() =     T_local_to_body_13;
379     f.get_T_local_to_body_21() =     T_local_to_body_21;
380     f.get_T_local_to_body_22() =     T_local_to_body_22;
381     f.get_T_local_to_body_23() =     T_local_to_body_23;
382     f.get_T_local_to_body_31() =     T_local_to_body_31;
383     f.get_T_local_to_body_32() =     T_local_to_body_32;
384     f.get_T_local_to_body_33() =     T_local_to_body_33;
385     f.get_Gravity() =        Gravity;
386     f.get_Centrifugal_relief() =     Centrifugal_relief;
387     f.get_Alpha() =  Alpha;
388     f.get_Beta() =   Beta;
389     f.get_Alpha_dot() =      Alpha_dot;
390     f.get_Beta_dot() =       Beta_dot;
391     f.get_Cos_alpha() =      Cos_alpha;
392     f.get_Sin_alpha() =      Sin_alpha;
393     f.get_Cos_beta() =       Cos_beta;
394     f.get_Sin_beta() =       Sin_beta;
395     f.get_Cos_phi() =        Cos_phi;
396     f.get_Sin_phi() =        Sin_phi;
397     f.get_Cos_theta() =      Cos_theta;
398     f.get_Sin_theta() =      Sin_theta;
399     f.get_Cos_psi() =        Cos_psi;
400     f.get_Sin_psi() =        Sin_psi;
401     f.get_Gamma_vert_rad() = Gamma_vert_rad;
402     f.get_Gamma_horiz_rad() =        Gamma_horiz_rad;
403     f.get_Sigma() =  Sigma;
404     f.get_Density() =        Density;
405     f.get_V_sound() =        V_sound;
406     f.get_Mach_number() =    Mach_number;
407     f.get_Static_pressure() =        Static_pressure;
408     f.get_Total_pressure() = Total_pressure;
409     f.get_Impact_pressure() =        Impact_pressure;
410     f.get_Dynamic_pressure() =       Dynamic_pressure;
411     f.get_Static_temperature() =     Static_temperature;
412     f.get_Total_temperature() =      Total_temperature;
413     f.get_Sea_level_radius() =       Sea_level_radius;
414     f.get_Earth_position_angle() =   Earth_position_angle;
415     f.get_Runway_altitude() =        Runway_altitude;
416     f.get_Runway_latitude() =        Runway_latitude;
417     f.get_Runway_longitude() =       Runway_longitude;
418     f.get_Runway_heading() = Runway_heading;
419     f.get_Radius_to_rwy() =  Radius_to_rwy;
420     f.get_D_cg_north_of_rwy() =      D_cg_north_of_rwy;
421     f.get_D_cg_east_of_rwy() =       D_cg_east_of_rwy;
422     f.get_D_cg_above_rwy() = D_cg_above_rwy;
423     f.get_X_cg_rwy() =       X_cg_rwy;
424     f.get_Y_cg_rwy() =       Y_cg_rwy;
425     f.get_H_cg_rwy() =       H_cg_rwy;
426     f.get_D_pilot_north_of_rwy() =   D_pilot_north_of_rwy;
427     f.get_D_pilot_east_of_rwy() =    D_pilot_east_of_rwy;
428     f.get_D_pilot_above_rwy() =      D_pilot_above_rwy;
429     f.get_X_pilot_rwy() =    X_pilot_rwy;
430     f.get_Y_pilot_rwy() =    Y_pilot_rwy;
431     f.get_H_pilot_rwy() =    H_pilot_rwy;
432     */
433     return ( 0 );
434 }
435
436
437 // $Log$
438 // Revision 1.4  1998/12/03 01:16:37  curt
439 // Converted fgFLIGHT to a class.
440 //
441 // Revision 1.3  1998/10/25 14:08:43  curt
442 // Turned "struct fgCONTROLS" into a class, with inlined accessor functions.
443 //
444 // Revision 1.2  1998/10/17 01:34:11  curt
445 // C++ ifying ...
446 //
447 // Revision 1.1  1998/10/17 00:43:58  curt
448 // Initial revision.
449 //
450 //