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