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