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