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