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