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