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