]> git.mxchange.org Git - flightgear.git/blob - src/FDM/LaRCsim.cxx
Moved some of the low level scene graph construction code over to simgear.
[flightgear.git] / src / 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
23 #include <math.h>
24 #include <string.h>             // strcmp()
25
26 #include <simgear/constants.h>
27 #include <simgear/debug/logstream.hxx>
28 #include <simgear/scene/model/location.hxx>
29 #include <simgear/scene/model/placement.hxx>
30
31 #include <Aircraft/aircraft.hxx>
32 #include <Controls/controls.hxx>
33 #include <FDM/flight.hxx>
34 #include <FDM/LaRCsim/ls_cockpit.h>
35 #include <FDM/LaRCsim/ls_generic.h>
36 #include <FDM/LaRCsim/ls_interface.h>
37 #include <FDM/LaRCsim/ls_constants.h>
38 #include <FDM/LaRCsimIC.hxx>
39 #include <FDM/UIUCModel/uiuc_aircraft.h>
40 #include <Main/fg_props.hxx>
41 #include <Model/acmodel.hxx>
42
43 #include "IO360.hxx"
44 #include "LaRCsim.hxx"
45
46
47 FGLaRCsim::FGLaRCsim( double dt ) {
48 //     set_delta_t( dt );
49
50     speed_up = fgGetNode("/sim/speed-up", true);
51     aero = fgGetNode("/sim/aero", true);
52     uiuc_type = fgGetNode("/sim/uiuc-type", true);
53
54     ls_toplevel_init( 0.0, (char *)(aero->getStringValue()) );
55
56     lsic=new LaRCsimIC; //this needs to be brought up after LaRCsim is
57     if ( !strcmp(aero->getStringValue(), "c172") ) {
58         copy_to_LaRCsim(); // initialize all of LaRCsim's vars
59
60         //this should go away someday -- formerly done in fg_init.cxx
61         Mass = 8.547270E+01;
62         I_xx = 1.048000E+03;
63         I_yy = 3.000000E+03;
64         I_zz = 3.530000E+03;
65         I_xz = 0.000000E+00;
66     }
67
68     ls_set_model_dt(dt);
69     
70     // Initialize our little engine that hopefully might
71     eng.init(dt);
72     // dcl - in passing dt to init rather than update I am assuming
73     // that the LaRCsim dt is fixed at one value (yes it is 120hz CLO)
74 }
75
76 FGLaRCsim::~FGLaRCsim(void) {
77     if ( lsic != NULL ) {
78         delete lsic;
79         lsic = NULL;
80     }
81 }
82
83 // Initialize the LaRCsim flight model, dt is the time increment for
84 // each subsequent iteration through the EOM
85 void FGLaRCsim::init() {
86    //do init common to all FDM's
87    common_init();
88 }
89
90
91 // Run an iteration of the EOM (equations of motion)
92 void FGLaRCsim::update( double dt ) {
93
94     if (is_suspended())
95       return;
96
97     int multiloop = _calc_multiloop(dt);
98
99     // if flying c172-larcsim, do the following
100     if ( !strcmp(aero->getStringValue(), "c172") ) {
101         // set control inputs
102         // cout << "V_calibrated_kts = " << V_calibrated_kts << '\n';
103         eng.set_IAS( V_calibrated_kts );
104         eng.set_Throttle_Lever_Pos( globals->get_controls()->get_throttle( 0 )
105                                     * 100.0 );
106         eng.set_Propeller_Lever_Pos( 100 );
107         eng.set_Mixture_Lever_Pos( globals->get_controls()->get_mixture( 0 )
108                                    * 100.0 );
109         eng.set_Magneto_Switch_Pos( globals->get_controls()->get_magnetos(0) );
110         eng.setStarterFlag( globals->get_controls()->get_starter(0) );
111         eng.set_p_amb( Static_pressure );
112         eng.set_T_amb( Static_temperature );
113
114         // update engine model
115         eng.update();
116
117         // Fake control-surface positions
118         fgSetDouble("/surface-positions/flap-pos-norm",
119                     fgGetDouble("/controls/flight/flaps"));
120                                 // FIXME: ignoring trim
121         fgSetDouble("/surface-positions/elevator-pos-norm",
122                     fgGetDouble("/controls/flight/elevator"));
123                                 // FIXME: ignoring trim
124         fgSetDouble("/surface-positions/left-aileron-pos-norm",
125                     fgGetDouble("/controls/flight/aileron"));
126                                 // FIXME: ignoring trim
127         fgSetDouble("/surface-positions/right-aileron-pos-norm",
128                     -1 * fgGetDouble("/controls/flight/aileron"));
129                                 // FIXME: ignoring trim
130         fgSetDouble("/surface-positions/rudder-pos-norm",
131                     fgGetDouble("/controls/flight/rudder"));
132
133         // copy engine state values onto "bus"
134         fgSetDouble("/engines/engine/rpm", eng.get_RPM());
135         fgSetDouble("/engines/engine/mp-osi", eng.get_Manifold_Pressure());
136         fgSetDouble("/engines/engine/max-hp", eng.get_MaxHP());
137         fgSetDouble("/engines/engine/power-pct", eng.get_Percentage_Power());
138         fgSetDouble("/engines/engine/egt-degf", eng.get_EGT());
139         fgSetDouble("/engines/engine/cht-degf", eng.get_CHT());
140         fgSetDouble("/engines/engine/prop-thrust", eng.get_prop_thrust_SI());
141         fgSetDouble("/engines/engine/fuel-flow-gph",
142                     eng.get_fuel_flow_gals_hr());
143         fgSetDouble("/engines/engine/oil-temperature-degf",
144                     eng.get_oil_temp());
145         fgSetDouble("/engines/engine/running", eng.getRunningFlag());
146         fgSetDouble("/engines/engine/cranking", eng.getCrankingFlag());
147
148         static const SGPropertyNode *fuel_freeze
149             = fgGetNode("/sim/freeze/fuel");
150
151         if ( ! fuel_freeze->getBoolValue() ) {
152             //Assume we are using both tanks equally for now
153             fgSetDouble("/consumables/fuel/tank[0]/level-gal_us",
154                         fgGetDouble("/consumables/fuel/tank[0]/level-gal_us")
155                         - (eng.get_fuel_flow_gals_hr() / (2 * 3600))
156                         * dt);
157             fgSetDouble("/consumables/fuel/tank[1]/level-gal_us",
158                         fgGetDouble("/consumables/fuel/tank[1]/level-gal_us")
159                         - (eng.get_fuel_flow_gals_hr() / (2 * 3600))
160                         * dt);
161         }
162
163         F_X_engine = eng.get_prop_thrust_lbs();
164         // cout << "F_X_engine = " << F_X_engine << '\n';
165         // end c172 if block
166
167         Flap_handle = 30.0 * globals->get_controls()->get_flaps();
168     }
169     // done with c172-larcsim if-block
170
171     double save_alt = 0.0;
172
173     // lets try to avoid really screwing up the LaRCsim model
174     if ( get_Altitude() < -9000.0 ) {
175         save_alt = get_Altitude();
176         set_Altitude( 0.0 );
177     }
178
179     // copy control positions into the LaRCsim structure
180     Lat_control = globals->get_controls()->get_aileron() / speed_up->getIntValue();
181     Long_control = globals->get_controls()->get_elevator();
182     Long_trim = globals->get_controls()->get_elevator_trim();
183     Rudder_pedal = globals->get_controls()->get_rudder() / speed_up->getIntValue();
184
185     if ( !strcmp(aero->getStringValue(), "c172") ) {
186         Use_External_Engine = 1;
187     } else {
188         Use_External_Engine = 0;
189     }
190
191     Throttle_pct = globals->get_controls()->get_throttle( 0 ) * 1.0;
192
193     Brake_pct[0] = globals->get_controls()->get_brake( 1 );
194     Brake_pct[1] = globals->get_controls()->get_brake( 0 );
195
196     // Inform LaRCsim of the local terrain altitude
197     // Runway_altitude = get_Runway_altitude();
198     Runway_altitude = getACModel()->get3DModel()->getSGLocation()->get_cur_elev_m() * SG_METER_TO_FEET;
199     // Weather
200     /* V_north_airmass = get_V_north_airmass();
201        V_east_airmass =  get_V_east_airmass();
202        V_down_airmass =  get_V_down_airmass(); */
203
204
205     // old -- FGInterface_2_LaRCsim() not needed except for Init()
206     // translate FG to LaRCsim structure
207     // FGInterface_2_LaRCsim(f);
208     // printf("FG_Altitude = %.2f\n", FG_Altitude * 0.3048);
209     // printf("Altitude = %.2f\n", Altitude * 0.3048);
210     // printf("Radius to Vehicle = %.2f\n", Radius_to_vehicle * 0.3048);
211
212     // for engine functions (sounds and instruments)
213     // drive the rpm gauge
214     fgSetDouble("/engines/engine/rpm", (globals->get_controls()->get_throttle( 0 ) * 100.0 * 25 ));
215     // manifold air pressure, which drives the sound (see *sound.xml file)
216     fgSetDouble("/engines/engine/mp-osi", (globals->get_controls()->get_throttle( 0 ) * 100.0 ));
217     // make the engine cranking and running sounds when fgfs starts up
218     fgSetDouble("/engines/engine/cranking", 1);
219     fgSetDouble("/engines/engine/running", 1);
220
221     // if flying uiuc, set some properties and over-ride some previous ones
222     if ( !strcmp(aero->getStringValue(), "uiuc")) {
223
224       // surface positions
225       fgSetDouble("/surface-positions/rudder-pos-norm",             fgGetDouble("/controls/flight/rudder"));
226       fgSetDouble("/surface-positions/elevator-pos-norm",           fgGetDouble("/controls/flight/elevator")); // FIXME: ignoring trim
227       fgSetDouble("/surface-positions/right-aileron-pos-norm", -1 * fgGetDouble("/controls/flight/aileron")); // FIXME: ignoring trim
228       fgSetDouble("/surface-positions/left-aileron-pos-norm",       fgGetDouble("/controls/flight/aileron")); // FIXME: ignoring trim
229
230       Flap_handle = flap_max * globals->get_controls()->get_flaps();
231
232       // flaps with transition occuring in uiuc_aerodeflections.cpp
233       if (use_flaps) {
234       fgSetDouble("/surface-positions/flight/flap-pos-norm",               flap_pos_pct);
235       }
236
237       // spoilers with transition occurring in uiuc_aerodeflections.cpp
238       if(use_spoilers) {
239         Spoiler_handle = spoiler_max * fgGetDouble("/controls/spoilers");
240       }
241       // gear with transition occurring here in LaRCsim.cxx
242       if (use_gear) {
243         if(fgGetBool("/controls/gear-down")) {
244           Gear_handle = 1.0;
245         }
246         else {
247           Gear_handle = 0.;
248         }
249         // commanded gear is 0 or 1
250         gear_cmd_norm = Gear_handle;
251         // amount gear moves per time step [relative to 1]
252         gear_increment_per_timestep = gear_rate * dt; 
253         // determine gear position with respect to gear command
254         if (gear_pos_norm < gear_cmd_norm) {
255           gear_pos_norm += gear_increment_per_timestep;
256           if (gear_pos_norm > gear_cmd_norm) 
257             gear_pos_norm = gear_cmd_norm;
258         } else if (gear_pos_norm > gear_cmd_norm) {
259           gear_pos_norm -= gear_increment_per_timestep;
260           if (gear_pos_norm < gear_cmd_norm)
261             gear_pos_norm = gear_cmd_norm;
262         } 
263         // set the gear position
264         fgSetDouble("/gear/gear[0]/position-norm", gear_pos_norm);
265         fgSetDouble("/gear/gear[1]/position-norm", gear_pos_norm);
266         fgSetDouble("/gear/gear[2]/position-norm", gear_pos_norm);
267       }
268
269
270       // engine functions (sounds and instruments)
271       // drive the rpm gauge
272       fgSetDouble("/engines/engine/rpm", (globals->get_controls()->get_throttle( 0 ) * 100.0 * 25 ));
273       // manifold air pressure
274       fgSetDouble("/engines/engine/mp-osi", (globals->get_controls()->get_throttle( 0 ) * 100.0 ));
275       // make the engine cranking and running sounds when fgfs starts up
276       fgSetDouble("/engines/engine/cranking", 1);
277       fgSetDouble("/engines/engine/running", 1);
278       if ( !strcmp(uiuc_type->getStringValue(), "uiuc-prop")) {
279         // uiuc prop driven airplane, e.g. Wright Flyer
280       }
281       else if ( !strcmp(uiuc_type->getStringValue(), "uiuc-jet")) {
282         // uiuc jet aircraft, e.g. a4d
283         fgSetDouble("/engines/engine/n1", (75 + (globals->get_controls()->get_throttle( 0 ) * 100.0 )/400));
284         fgSetDouble("/engines/engine/prop-thrust", (4000 + F_X_engine/2));
285       }
286       else if ( !strcmp(uiuc_type->getStringValue(), "uiuc-sailplane")) {
287         // uiuc sailplane, e.g. asw20
288         fgSetDouble("/engines/engine/cranking", 0);
289         // set the wind speed for use in setting wind sound level
290         fgSetDouble("/velocities/V_rel_wind_kts", (V_rel_wind * 1.274));
291       }
292       else if ( !strcmp(uiuc_type->getStringValue(), "uiuc-hangglider")) {
293         // uiuc sailplane, e.g. asw20
294         fgSetDouble("/engines/engine/cranking", 0);
295       }
296       else if ( !strcmp(uiuc_type->getStringValue(), "uiuc-ornithopter")) {
297         // mechanical flapping wings
298         // flapping wings (using seahawk for now)
299         fgSetDouble("/canopy/position-norm", 0);
300         fgSetDouble("/wing-phase/position-norm", sin(flapper_phi - 3 * LS_PI / 2));
301         //      fgSetDouble("/wing-phase/position-norm", fgGetDouble("/controls/rudder"));
302         fgSetDouble("/wing-phase/position-deg", flapper_phi*RAD_TO_DEG);
303         fgSetDouble("/wing-phase/position-one", 1);
304         fgSetDouble("/thorax/volume", 0);
305         fgSetDouble("/thorax/rpm",    0);
306         //      fgSetDouble("/wing-phase/position-norm", ((1+cos(flapper_phi - LS_PI/2))/2 -.36 ));
307         //      fgSetDouble("/thorax/volume", ((1+sin(2*(flapper_phi+LS_PI)))/2));
308         //      fgSetDouble("/thorax/rpm",    ((1+sin(2*(flapper_phi+LS_PI)))/2));
309       }
310     }
311
312
313     // add Gamma_horiz_deg to properties, mss 021213
314     if (use_gamma_horiz_on_speed) {
315       if (V_rel_wind > gamma_horiz_on_speed) {
316         fgSetDouble("/orientation/Gamma_horiz_deg", (Gamma_horiz_rad * RAD_TO_DEG));
317       }
318       else {
319         fgSetDouble("/orientation/Gamma_horiz_deg",  fgGetDouble("/orientation/heading-deg"));
320       }
321     }
322     else {
323       fgSetDouble("/orientation/Gamma_horiz_deg",  fgGetDouble("/orientation/heading-deg"));
324     }
325     ls_update(multiloop);
326
327     // printf("%d FG_Altitude = %.2f\n", i, FG_Altitude * 0.3048);
328     // printf("%d Altitude = %.2f\n", i, Altitude * 0.3048);
329
330     // translate LaRCsim back to FG structure so that the
331     // autopilot (and the rest of the sim can use the updated
332     // values
333     copy_from_LaRCsim();
334
335     // but lets restore our original bogus altitude when we are done
336     if ( save_alt < -9000.0 ) {
337         set_Altitude( save_alt );
338     }
339 }
340
341
342 // Convert from the FGInterface struct to the LaRCsim generic_ struct
343 bool FGLaRCsim::copy_to_LaRCsim () {
344     Mass =      get_Mass();
345     I_xx =      get_I_xx();
346     I_yy =      get_I_yy();
347     I_zz =      get_I_zz();
348     I_xz =      get_I_xz();
349     // Dx_pilot =  get_Dx_pilot();
350     // Dy_pilot =  get_Dy_pilot();
351     // Dz_pilot =  get_Dz_pilot();
352     Dx_cg =     get_Dx_cg();
353     Dy_cg =     get_Dy_cg();
354     Dz_cg =     get_Dz_cg();
355     // F_X =       get_F_X();
356     // F_Y =       get_F_Y();
357     // F_Z =       get_F_Z();
358     // F_north =   get_F_north();
359     // F_east =    get_F_east();
360     // F_down =    get_F_down();
361     // F_X_aero =  get_F_X_aero();
362     // F_Y_aero =  get_F_Y_aero();
363     // F_Z_aero =  get_F_Z_aero();
364     // F_X_engine =        get_F_X_engine();
365     // F_Y_engine =        get_F_Y_engine();
366     // F_Z_engine =        get_F_Z_engine();
367     // F_X_gear =  get_F_X_gear();
368     // F_Y_gear =  get_F_Y_gear();
369     // F_Z_gear =  get_F_Z_gear();
370     // M_l_rp =    get_M_l_rp();
371     // M_m_rp =    get_M_m_rp();
372     // M_n_rp =    get_M_n_rp();
373     // M_l_cg =    get_M_l_cg();
374     // M_m_cg =    get_M_m_cg();
375     // M_n_cg =    get_M_n_cg();
376     // M_l_aero =  get_M_l_aero();
377     // M_m_aero =  get_M_m_aero();
378     // M_n_aero =  get_M_n_aero();
379     // M_l_engine =        get_M_l_engine();
380     // M_m_engine =        get_M_m_engine();
381     // M_n_engine =        get_M_n_engine();
382     // M_l_gear =  get_M_l_gear();
383     // M_m_gear =  get_M_m_gear();
384     // M_n_gear =  get_M_n_gear();
385     // V_dot_north =       get_V_dot_north();
386     // V_dot_east =        get_V_dot_east();
387     // V_dot_down =        get_V_dot_down();
388     // U_dot_body =        get_U_dot_body();
389     // V_dot_body =        get_V_dot_body();
390     // W_dot_body =        get_W_dot_body();
391     // A_X_cg =    get_A_X_cg();
392     // A_Y_cg =    get_A_Y_cg();
393     // A_Z_cg =    get_A_Z_cg();
394     // A_X_pilot = get_A_X_pilot();
395     // A_Y_pilot = get_A_Y_pilot();
396     // A_Z_pilot = get_A_Z_pilot();
397     // N_X_cg =    get_N_X_cg();
398     // N_Y_cg =    get_N_Y_cg();
399     // N_Z_cg =    get_N_Z_cg();
400     // N_X_pilot = get_N_X_pilot();
401     // N_Y_pilot = get_N_Y_pilot();
402     // N_Z_pilot = get_N_Z_pilot();
403     // P_dot_body =        get_P_dot_body();
404     // Q_dot_body =        get_Q_dot_body();
405     // R_dot_body =        get_R_dot_body();
406     // V_north =   get_V_north();
407     // V_east =    get_V_east();
408     // V_down =    get_V_down();
409     // V_north_rel_ground =        get_V_north_rel_ground();
410     // V_east_rel_ground = get_V_east_rel_ground();
411     // V_down_rel_ground = get_V_down_rel_ground();
412     // V_north_airmass =   get_V_north_airmass();
413     // V_east_airmass =    get_V_east_airmass();
414     // V_down_airmass =    get_V_down_airmass();
415     // V_north_rel_airmass =       get_V_north_rel_airmass();
416     // V_east_rel_airmass =        get_V_east_rel_airmass();
417     // V_down_rel_airmass =        get_V_down_rel_airmass();
418     // U_gust =    get_U_gust();
419     // V_gust =    get_V_gust();
420     // W_gust =    get_W_gust();
421     // U_body =    get_U_body();
422     // V_body =    get_V_body();
423     // W_body =    get_W_body();
424     // V_rel_wind =        get_V_rel_wind();
425     // V_true_kts =        get_V_true_kts();
426     // V_rel_ground =      get_V_rel_ground();
427     // V_inertial =        get_V_inertial();
428     // V_ground_speed =    get_V_ground_speed();
429     // V_equiv =   get_V_equiv();
430     // V_equiv_kts =       get_V_equiv_kts();
431     // V_calibrated =      get_V_calibrated();
432     // V_calibrated_kts =  get_V_calibrated_kts();
433     // P_body =    get_P_body();
434     // Q_body =    get_Q_body();
435     // R_body =    get_R_body();
436     // P_local =   get_P_local();
437     // Q_local =   get_Q_local();
438     // R_local =   get_R_local();
439     // P_total =   get_P_total();
440     // Q_total =   get_Q_total();
441     // R_total =   get_R_total();
442     // Phi_dot =   get_Phi_dot();
443     // Theta_dot = get_Theta_dot();
444     // Psi_dot =   get_Psi_dot();
445     // Latitude_dot =      get_Latitude_dot();
446     // Longitude_dot =     get_Longitude_dot();
447     // Radius_dot =        get_Radius_dot();
448     // Lat_geocentric =    get_Lat_geocentric();
449     // Lon_geocentric =    get_Lon_geocentric();
450     // Radius_to_vehicle = get_Radius_to_vehicle();
451     // Latitude =  get_Latitude();
452     // Longitude = get_Longitude();
453     // Altitude =  get_Altitude();
454     // Phi =       get_Phi();
455     // Theta =     get_Theta();
456     // Psi =       get_Psi();
457     // T_local_to_body_11 =        get_T_local_to_body_11();
458     // T_local_to_body_12 =        get_T_local_to_body_12();
459     // T_local_to_body_13 =        get_T_local_to_body_13();
460     // T_local_to_body_21 =        get_T_local_to_body_21();
461     // T_local_to_body_22 =        get_T_local_to_body_22();
462     // T_local_to_body_23 =        get_T_local_to_body_23();
463     // T_local_to_body_31 =        get_T_local_to_body_31();
464     // T_local_to_body_32 =        get_T_local_to_body_32();
465     // T_local_to_body_33 =        get_T_local_to_body_33();
466     // Gravity =   get_Gravity();
467     // Centrifugal_relief =        get_Centrifugal_relief();
468     // Alpha =     get_Alpha();
469     // Beta =      get_Beta();
470     // Alpha_dot = get_Alpha_dot();
471     // Beta_dot =  get_Beta_dot();
472     // Cos_alpha = get_Cos_alpha();
473     // Sin_alpha = get_Sin_alpha();
474     // Cos_beta =  get_Cos_beta();
475     // Sin_beta =  get_Sin_beta();
476     // Cos_phi =   get_Cos_phi();
477     // Sin_phi =   get_Sin_phi();
478     // Cos_theta = get_Cos_theta();
479     // Sin_theta = get_Sin_theta();
480     // Cos_psi =   get_Cos_psi();
481     // Sin_psi =   get_Sin_psi();
482     // Gamma_vert_rad =    get_Gamma_vert_rad();
483     // Gamma_horiz_rad =   get_Gamma_horiz_rad();
484     // Sigma =     get_Sigma();
485     // Density =   get_Density();
486     // V_sound =   get_V_sound();
487     // Mach_number =       get_Mach_number();
488     // Static_pressure =   get_Static_pressure();
489     // Total_pressure =    get_Total_pressure();
490     // Impact_pressure =   get_Impact_pressure();
491     // Dynamic_pressure =  get_Dynamic_pressure();
492     // Static_temperature =        get_Static_temperature();
493     // Total_temperature = get_Total_temperature();
494     // Sea_level_radius =  get_Sea_level_radius();
495     // Earth_position_angle =      get_Earth_position_angle();
496     // Runway_altitude =   get_Runway_altitude();
497     // Runway_latitude =   get_Runway_latitude();
498     // Runway_longitude =  get_Runway_longitude();
499     // Runway_heading =    get_Runway_heading();
500     // Radius_to_rwy =     get_Radius_to_rwy();
501     // D_cg_north_of_rwy = get_D_cg_north_of_rwy();
502     // D_cg_east_of_rwy =  get_D_cg_east_of_rwy();
503     // D_cg_above_rwy =    get_D_cg_above_rwy();
504     // X_cg_rwy =  get_X_cg_rwy();
505     // Y_cg_rwy =  get_Y_cg_rwy();
506     // H_cg_rwy =  get_H_cg_rwy();
507     // D_pilot_north_of_rwy =      get_D_pilot_north_of_rwy();
508     // D_pilot_east_of_rwy =       get_D_pilot_east_of_rwy();
509     // D_pilot_above_rwy = get_D_pilot_above_rwy();
510     // X_pilot_rwy =       get_X_pilot_rwy();
511     // Y_pilot_rwy =       get_Y_pilot_rwy();
512     // H_pilot_rwy =       get_H_pilot_rwy();
513
514     return true;
515 }
516
517
518 // Convert from the LaRCsim generic_ struct to the FGInterface struct
519 bool FGLaRCsim::copy_from_LaRCsim() {
520
521     // Mass properties and geometry values
522     _set_Inertias( Mass, I_xx, I_yy, I_zz, I_xz );
523     // set_Pilot_Location( Dx_pilot, Dy_pilot, Dz_pilot );
524     _set_CG_Position( Dx_cg, Dy_cg, Dz_cg );
525
526     // Forces
527     // set_Forces_Body_Total( F_X, F_Y, F_Z );
528     // set_Forces_Local_Total( F_north, F_east, F_down );
529     // set_Forces_Aero( F_X_aero, F_Y_aero, F_Z_aero );
530     // set_Forces_Engine( F_X_engine, F_Y_engine, F_Z_engine );
531     // set_Forces_Gear( F_X_gear, F_Y_gear, F_Z_gear );
532
533     // Moments
534     // set_Moments_Total_RP( M_l_rp, M_m_rp, M_n_rp );
535     // set_Moments_Total_CG( M_l_cg, M_m_cg, M_n_cg );
536     // set_Moments_Aero( M_l_aero, M_m_aero, M_n_aero );
537     // set_Moments_Engine( M_l_engine, M_m_engine, M_n_engine );
538     // set_Moments_Gear( M_l_gear, M_m_gear, M_n_gear );
539
540     // Accelerations
541     _set_Accels_Local( V_dot_north, V_dot_east, V_dot_down );
542     _set_Accels_Body( U_dot_body, V_dot_body, W_dot_body );
543     _set_Accels_CG_Body( A_X_cg, A_Y_cg, A_Z_cg );
544     _set_Accels_Pilot_Body( A_X_pilot, A_Y_pilot, A_Z_pilot );
545     _set_Accels_CG_Body_N( N_X_cg, N_Y_cg, -N_Z_cg );
546     // set_Accels_Pilot_Body_N( N_X_pilot, N_Y_pilot, N_Z_pilot );
547     // set_Accels_Omega( P_dot_body, Q_dot_body, R_dot_body );
548
549     // Velocities
550     _set_Velocities_Local( V_north, V_east, V_down );
551     // set_Velocities_Ground( V_north_rel_ground, V_east_rel_ground, 
552     //               V_down_rel_ground );
553     _set_Velocities_Local_Airmass( V_north_airmass, V_east_airmass,
554                                    V_down_airmass );
555     // set_Velocities_Local_Rel_Airmass( V_north_rel_airmass, 
556     //                          V_east_rel_airmass, V_down_rel_airmass );
557     // set_Velocities_Gust( U_gust, V_gust, W_gust );
558     _set_Velocities_Wind_Body( U_body, V_body, W_body );
559
560     _set_V_rel_wind( V_rel_wind );
561     // set_V_true_kts( V_true_kts );
562     // set_V_rel_ground( V_rel_ground );
563     // set_V_inertial( V_inertial );
564     _set_V_ground_speed( V_ground_speed );
565     // set_V_equiv( V_equiv );
566     _set_V_equiv_kts( V_equiv_kts );
567     // set_V_calibrated( V_calibrated );
568     _set_V_calibrated_kts( V_calibrated_kts );
569
570     _set_Omega_Body( P_body, Q_body, R_body );
571     // set_Omega_Local( P_local, Q_local, R_local );
572     // set_Omega_Total( P_total, Q_total, R_total );
573
574     _set_Euler_Rates( Phi_dot, Theta_dot, Psi_dot );
575     _set_Geocentric_Rates( Latitude_dot, Longitude_dot, Radius_dot );
576
577     _set_Mach_number( Mach_number );
578
579     SG_LOG( SG_FLIGHT, SG_DEBUG, "lon = " << Longitude 
580             << " lat_geoc = " << Lat_geocentric << " lat_geod = " << Latitude 
581             << " alt = " << Altitude << " sl_radius = " << Sea_level_radius 
582             << " radius_to_vehicle = " << Radius_to_vehicle );
583
584     double tmp_lon_geoc = Lon_geocentric;
585     while ( tmp_lon_geoc < -SGD_PI ) { tmp_lon_geoc += SGD_2PI; }
586     while ( tmp_lon_geoc > SGD_PI ) { tmp_lon_geoc -= SGD_2PI; }
587
588     double tmp_lon = Longitude;
589     while ( tmp_lon < -SGD_PI ) { tmp_lon += SGD_2PI; }
590     while ( tmp_lon > SGD_PI ) { tmp_lon -= SGD_2PI; }
591
592     // Positions
593     _set_Geocentric_Position( Lat_geocentric, tmp_lon_geoc, 
594                               Radius_to_vehicle );
595     _set_Geodetic_Position( Latitude, tmp_lon, Altitude );
596     _set_Euler_Angles( Phi, Theta, Psi );
597
598     _set_Altitude_AGL( Altitude - Runway_altitude );
599
600     // Miscellaneous quantities
601     _set_T_Local_to_Body(T_local_to_body_m);
602     // set_Gravity( Gravity );
603     // set_Centrifugal_relief( Centrifugal_relief );
604
605     _set_Alpha( Alpha );
606     _set_Beta( Beta );
607     // set_Alpha_dot( Alpha_dot );
608     // set_Beta_dot( Beta_dot );
609
610     // set_Cos_alpha( Cos_alpha );
611     // set_Sin_alpha( Sin_alpha );
612     // set_Cos_beta( Cos_beta );
613     // set_Sin_beta( Sin_beta );
614
615     _set_Cos_phi( Cos_phi );
616     // set_Sin_phi( Sin_phi );
617     _set_Cos_theta( Cos_theta );
618     // set_Sin_theta( Sin_theta );
619     // set_Cos_psi( Cos_psi );
620     // set_Sin_psi( Sin_psi );
621
622     _set_Gamma_vert_rad( Gamma_vert_rad );
623     // set_Gamma_horiz_rad( Gamma_horiz_rad );
624
625     // set_Sigma( Sigma );
626     _set_Density( Density );
627     // set_V_sound( V_sound );
628     // set_Mach_number( Mach_number );
629
630     _set_Static_pressure( Static_pressure );
631     // set_Total_pressure( Total_pressure );
632     // set_Impact_pressure( Impact_pressure );
633     // set_Dynamic_pressure( Dynamic_pressure );
634
635     _set_Static_temperature( Static_temperature );
636     // set_Total_temperature( Total_temperature );
637
638     _set_Sea_level_radius( Sea_level_radius );
639     _set_Earth_position_angle( Earth_position_angle );
640
641     _set_Runway_altitude( Runway_altitude );
642     // set_Runway_latitude( Runway_latitude );
643     // set_Runway_longitude( Runway_longitude );
644     // set_Runway_heading( Runway_heading );
645     // set_Radius_to_rwy( Radius_to_rwy );
646
647     // set_CG_Rwy_Local( D_cg_north_of_rwy, D_cg_east_of_rwy, D_cg_above_rwy);
648     // set_CG_Rwy_Rwy( X_cg_rwy, Y_cg_rwy, H_cg_rwy );
649     // set_Pilot_Rwy_Local( D_pilot_north_of_rwy, D_pilot_east_of_rwy, 
650     //                        D_pilot_above_rwy );
651     // set_Pilot_Rwy_Rwy( X_pilot_rwy, Y_pilot_rwy, H_pilot_rwy );
652
653     _set_sin_lat_geocentric(Lat_geocentric);
654     _set_cos_lat_geocentric(Lat_geocentric);
655     _set_sin_cos_longitude(Longitude);
656     _set_sin_cos_latitude(Latitude);
657
658     // printf("sin_lat_geo %f  cos_lat_geo %f\n", sin_Lat_geoc, cos_Lat_geoc);
659     // printf("sin_lat     %f  cos_lat     %f\n", 
660     //        get_sin_latitude(), get_cos_latitude());
661     // printf("sin_lon     %f  cos_lon     %f\n",
662     //        get_sin_longitude(), get_cos_longitude());
663
664     _set_Climb_Rate( -1 * V_down );
665     // cout << "climb rate = " << -V_down * 60 << endl;
666
667     if ( !strcmp(aero->getStringValue(), "uiuc") ) {
668         if (pilot_elev_no) {
669             globals->get_controls()->set_elevator(Long_control);
670             globals->get_controls()->set_elevator_trim(Long_trim);
671             //      controls.set_elevator(Long_control);
672             //      controls.set_elevator_trim(Long_trim);
673         }
674         if (pilot_ail_no) {
675             globals->get_controls()->set_aileron(Lat_control);
676             //    controls.set_aileron(Lat_control);
677         }
678         if (pilot_rud_no) {
679             globals->get_controls()->set_rudder(Rudder_pedal);
680             //    controls.set_rudder(Rudder_pedal);
681         }
682         if (pilot_throttle_no) {
683             globals->get_controls()->set_throttle(0,Throttle_pct);
684             //    controls.set_throttle(0,Throttle_pct);
685         }
686     }
687
688     return true;
689 }
690
691
692 void FGLaRCsim::set_ls(void) {
693     Phi=lsic->GetRollAngleRadIC();
694     Theta=lsic->GetPitchAngleRadIC();
695     Psi=lsic->GetHeadingRadIC();
696     V_north=lsic->GetVnorthFpsIC();
697     V_east=lsic->GetVeastFpsIC();
698     V_down=lsic->GetVdownFpsIC();
699     Altitude=lsic->GetAltitudeFtIC();
700     Latitude=lsic->GetLatitudeGDRadIC();
701     Longitude=lsic->GetLongitudeRadIC();
702     Runway_altitude=lsic->GetRunwayAltitudeFtIC();
703     V_north_airmass = lsic->GetVnorthAirmassFpsIC() * -1;
704     V_east_airmass = lsic->GetVeastAirmassFpsIC() * -1;
705     V_down_airmass = lsic->GetVdownAirmassFpsIC() * -1;
706     ls_loop(0.0,-1);
707     copy_from_LaRCsim();
708 }
709
710 void FGLaRCsim::snap_shot(void) {
711     lsic->SetLatitudeGDRadIC( get_Latitude() );
712     lsic->SetLongitudeRadIC( get_Longitude() );
713     lsic->SetAltitudeFtIC( get_Altitude() );
714     lsic->SetRunwayAltitudeFtIC( get_Runway_altitude() );
715     lsic->SetVtrueFpsIC( get_V_rel_wind() );
716     lsic->SetPitchAngleRadIC( get_Theta() );
717     lsic->SetRollAngleRadIC( get_Phi() );
718     lsic->SetHeadingRadIC( get_Psi() );
719     lsic->SetClimbRateFpsIC( get_Climb_Rate() );
720     lsic->SetVNEDAirmassFpsIC( get_V_north_airmass(),
721                                get_V_east_airmass(),
722                                get_V_down_airmass() );
723 }                               
724
725 //Positions
726 void FGLaRCsim::set_Latitude(double lat) {
727     SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Latitude: " << lat  );
728     snap_shot();
729     lsic->SetLatitudeGDRadIC(lat);
730     set_ls();
731     copy_from_LaRCsim(); //update the bus
732 }
733
734 void FGLaRCsim::set_Longitude(double lon) {
735     SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Longitude: " << lon  );
736     snap_shot();
737     lsic->SetLongitudeRadIC(lon);
738     set_ls();
739     copy_from_LaRCsim(); //update the bus
740 }
741
742 void FGLaRCsim::set_Altitude(double alt) {
743     SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Altitude: " << alt  );
744     snap_shot();
745     lsic->SetAltitudeFtIC(alt);
746     set_ls();
747     copy_from_LaRCsim(); //update the bus
748 }
749
750 void FGLaRCsim::set_V_calibrated_kts(double vc) {
751     SG_LOG( SG_FLIGHT, SG_INFO, 
752             "FGLaRCsim::set_V_calibrated_kts: " << vc  );
753     snap_shot();
754     lsic->SetVcalibratedKtsIC(vc);
755     set_ls();
756     copy_from_LaRCsim(); //update the bus
757 }
758
759 void FGLaRCsim::set_Mach_number(double mach) {
760     SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Mach_number: " << mach  );
761     snap_shot();
762     lsic->SetMachIC(mach);
763     set_ls();
764     copy_from_LaRCsim(); //update the bus
765 }
766
767 void FGLaRCsim::set_Velocities_Local( double north, double east, double down ){
768     SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Velocities_local: " 
769             << north << "  " << east << "  " << down   );
770     snap_shot();
771     lsic->SetVNEDFpsIC(north, east, down);
772     set_ls();
773     copy_from_LaRCsim(); //update the bus
774 }
775
776 void FGLaRCsim::set_Velocities_Wind_Body( double u, double v, double w){
777     SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Velocities_Wind_Body: " 
778             << u << "  " << v << "  " << w   );
779     snap_shot();
780     lsic->SetUVWFpsIC(u,v,w);
781     set_ls();
782     copy_from_LaRCsim(); //update the bus
783 }
784
785 //Euler angles 
786 void FGLaRCsim::set_Euler_Angles( double phi, double theta, double psi ) {
787     SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Euler_angles: " 
788             << phi << "  " << theta << "  " << psi   );
789
790     snap_shot();
791     lsic->SetPitchAngleRadIC(theta);
792     lsic->SetRollAngleRadIC(phi);
793     lsic->SetHeadingRadIC(psi);
794     set_ls();
795     copy_from_LaRCsim(); //update the bus
796 }
797
798 //Flight Path
799 void FGLaRCsim::set_Climb_Rate( double roc) {
800     SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Climb_rate: " << roc  );
801     snap_shot();
802     lsic->SetClimbRateFpsIC(roc);
803     set_ls();
804     copy_from_LaRCsim(); //update the bus
805 }
806
807 void FGLaRCsim::set_Gamma_vert_rad( double gamma) {
808     SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Gamma_vert_rad: " << gamma  );
809     snap_shot();
810     lsic->SetFlightPathAngleRadIC(gamma);
811     set_ls();
812     copy_from_LaRCsim(); //update the bus
813 }
814
815 void FGLaRCsim::set_AltitudeAGL(double altagl) {
816     SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_AltitudeAGL: " << altagl  );
817     snap_shot();
818     lsic->SetAltitudeAGLFtIC(altagl);
819     set_ls();
820     copy_from_LaRCsim();
821 }
822
823 /*  getting a namespace conflict...
824 void FGLaRCsim::set_Velocities_Local_Airmass (double wnorth, 
825                                               double weast, 
826                                               double wdown ) {
827     SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Velocities_Local_Airmass: " 
828             << wnorth << "  " << weast << "  " << wdown );
829     snap_shot();
830     lsic->SetVNEDAirmassFpsIC( wnorth, weast, wdown );
831     set_ls();
832     copy_from_LaRCsim();
833 }
834 */
835
836 void FGLaRCsim::set_Static_pressure(double p) { 
837     SG_LOG( SG_FLIGHT, SG_INFO, 
838             "FGLaRCsim::set_Static_pressure: " << p  );
839     SG_LOG( SG_FLIGHT, SG_INFO, 
840             "LaRCsim does not support externally supplied atmospheric data" );
841 }
842
843 void FGLaRCsim::set_Static_temperature(double T) { 
844     SG_LOG( SG_FLIGHT, SG_INFO, 
845             "FGLaRCsim::set_Static_temperature: " << T  );
846     SG_LOG( SG_FLIGHT, SG_INFO, 
847             "LaRCsim does not support externally supplied atmospheric data" );
848
849 }
850
851 void FGLaRCsim::set_Density(double rho) {
852     SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Density: " << rho  );
853     SG_LOG( SG_FLIGHT, SG_INFO, 
854             "LaRCsim does not support externally supplied atmospheric data" );
855
856 }
857