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