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