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