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