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