1 // LaRCsim.cxx -- interface to the LaRCsim flight model
3 // Written by Curtis Olson, started October 1998.
5 // Copyright (C) 1998 Curtis L. Olson - http://www.flightgear.org/~curt
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28 #include <string.h> // strcmp()
30 #include <simgear/constants.h>
31 #include <simgear/debug/logstream.hxx>
32 #include <simgear/scene/model/placement.hxx>
34 #include <Aircraft/controls.hxx>
35 #include <FDM/flight.hxx>
36 #include <FDM/UIUCModel/uiuc_aircraft.h>
37 #include <Main/fg_props.hxx>
38 #include <Model/acmodel.hxx>
40 #include "ls_cockpit.h"
41 #include "ls_generic.h"
42 #include "ls_interface.h"
43 #include "ls_constants.h"
46 #include "LaRCsimIC.hxx"
47 #include "LaRCsim.hxx"
50 FGLaRCsim::FGLaRCsim( double dt ) {
51 mass=i_xx=i_yy=i_zz=i_xz=0;
55 speed_up = fgGetNode("/sim/speed-up", true);
56 aero = fgGetNode("/sim/aero", true);
57 uiuc_type = fgGetNode("/sim/uiuc-type", true);
59 ls_toplevel_init( 0.0, (char *)(aero->getStringValue()) );
61 lsic=new LaRCsimIC; //this needs to be brought up after LaRCsim is
62 if ( !strcmp(aero->getStringValue(), "c172") ) {
63 copy_to_LaRCsim(); // initialize all of LaRCsim's vars
65 //this should go away someday -- formerly done in fg_init.cxx
73 if ( !strcmp(aero->getStringValue(), "basic") ) {
74 copy_to_LaRCsim(); // initialize all of LaRCsim's vars
76 //this should go away someday -- formerly done in fg_init.cxx
82 // Mass = 8.547270E+01;
83 // I_xx = 1.048000E+03;
84 // I_yy = 3.000000E+03;
85 // I_zz = 3.530000E+03;
86 // I_xz = 0.000000E+00;
91 // Initialize our little engine that hopefully might
93 // dcl - in passing dt to init rather than update I am assuming
94 // that the LaRCsim dt is fixed at one value (yes it is 120hz CLO)
97 FGLaRCsim::~FGLaRCsim(void) {
104 // Initialize the LaRCsim flight model, dt is the time increment for
105 // each subsequent iteration through the EOM
106 void FGLaRCsim::init() {
107 //do init common to all FDM's
112 // Run an iteration of the EOM (equations of motion)
113 void FGLaRCsim::update( double dt ) {
118 int multiloop = _calc_multiloop(dt);
120 // if flying c172-larcsim, do the following
121 if ( !strcmp(aero->getStringValue(), "c172") ) {
122 // set control inputs
123 // cout << "V_calibrated_kts = " << V_calibrated_kts << '\n';
124 eng.set_IAS( V_calibrated_kts );
125 eng.set_Throttle_Lever_Pos( globals->get_controls()->get_throttle( 0 )
127 eng.set_Propeller_Lever_Pos( 100 );
128 eng.set_Mixture_Lever_Pos( globals->get_controls()->get_mixture( 0 )
130 eng.set_Magneto_Switch_Pos( globals->get_controls()->get_magnetos(0) );
131 eng.setStarterFlag( globals->get_controls()->get_starter(0) );
132 eng.set_p_amb( Static_pressure );
133 eng.set_T_amb( Static_temperature );
135 // update engine model
138 // Fake control-surface positions
139 fgSetDouble("/surface-positions/flap-pos-norm",
140 fgGetDouble("/controls/flight/flaps"));
141 // FIXME: ignoring trim
142 fgSetDouble("/surface-positions/elevator-pos-norm",
143 fgGetDouble("/controls/flight/elevator"));
144 // FIXME: ignoring trim
145 fgSetDouble("/surface-positions/left-aileron-pos-norm",
146 fgGetDouble("/controls/flight/aileron"));
147 // FIXME: ignoring trim
148 fgSetDouble("/surface-positions/right-aileron-pos-norm",
149 -1 * fgGetDouble("/controls/flight/aileron"));
150 // FIXME: ignoring trim
151 fgSetDouble("/surface-positions/rudder-pos-norm",
152 fgGetDouble("/controls/flight/rudder"));
154 // copy engine state values onto "bus"
155 fgSetDouble("/engines/engine/rpm", eng.get_RPM());
156 fgSetDouble("/engines/engine/mp-osi", eng.get_Manifold_Pressure());
157 fgSetDouble("/engines/engine/max-hp", eng.get_MaxHP());
158 fgSetDouble("/engines/engine/power-pct", eng.get_Percentage_Power());
159 fgSetDouble("/engines/engine/egt-degf", eng.get_EGT());
160 fgSetDouble("/engines/engine/cht-degf", eng.get_CHT());
161 fgSetDouble("/engines/engine/prop-thrust", eng.get_prop_thrust_SI());
162 fgSetDouble("/engines/engine/fuel-flow-gph",
163 eng.get_fuel_flow_gals_hr());
164 fgSetDouble("/engines/engine/oil-temperature-degf",
166 fgSetDouble("/engines/engine/running", eng.getRunningFlag());
167 fgSetDouble("/engines/engine/cranking", eng.getCrankingFlag());
169 static const SGPropertyNode *fuel_freeze
170 = fgGetNode("/sim/freeze/fuel");
172 if ( ! fuel_freeze->getBoolValue() ) {
173 //Assume we are using both tanks equally for now
174 fgSetDouble("/consumables/fuel/tank[0]/level-gal_us",
175 fgGetDouble("/consumables/fuel/tank[0]/level-gal_us")
176 - (eng.get_fuel_flow_gals_hr() / (2 * 3600))
178 fgSetDouble("/consumables/fuel/tank[1]/level-gal_us",
179 fgGetDouble("/consumables/fuel/tank[1]/level-gal_us")
180 - (eng.get_fuel_flow_gals_hr() / (2 * 3600))
184 // Apparently the IO360 thrust model is not working.
185 // F_X_engine is zero here.
186 F_X_engine = eng.get_prop_thrust_lbs();
188 Flap_handle = 30.0 * globals->get_controls()->get_flaps();
190 // done with c172-larcsim if-block
192 if ( !strcmp(aero->getStringValue(), "basic") ) {
193 // set control inputs
194 // cout << "V_calibrated_kts = " << V_calibrated_kts << '\n';
195 eng.set_IAS( V_calibrated_kts );
196 eng.set_Throttle_Lever_Pos( globals->get_controls()->get_throttle( 0 )
198 eng.set_Propeller_Lever_Pos( 100 );
199 eng.set_Mixture_Lever_Pos( globals->get_controls()->get_mixture( 0 )
201 eng.set_Magneto_Switch_Pos( globals->get_controls()->get_magnetos(0) );
202 eng.setStarterFlag( globals->get_controls()->get_starter(0) );
203 eng.set_p_amb( Static_pressure );
204 eng.set_T_amb( Static_temperature );
206 // update engine model
209 // Fake control-surface positions
210 fgSetDouble("/surface-positions/flap-pos-norm",
211 fgGetDouble("/controls/flight/flaps"));
212 // FIXME: ignoring trim
213 fgSetDouble("/surface-positions/elevator-pos-norm",
214 fgGetDouble("/controls/flight/elevator"));
215 // FIXME: ignoring trim
216 fgSetDouble("/surface-positions/left-aileron-pos-norm",
217 fgGetDouble("/controls/flight/aileron"));
218 // FIXME: ignoring trim
219 fgSetDouble("/surface-positions/right-aileron-pos-norm",
220 -1 * fgGetDouble("/controls/flight/aileron"));
221 // FIXME: ignoring trim
222 fgSetDouble("/surface-positions/rudder-pos-norm",
223 fgGetDouble("/controls/flight/rudder"));
225 // copy engine state values onto "bus"
226 fgSetDouble("/engines/engine/rpm", eng.get_RPM());
227 fgSetDouble("/engines/engine/mp-osi", eng.get_Manifold_Pressure());
228 fgSetDouble("/engines/engine/max-hp", eng.get_MaxHP());
229 fgSetDouble("/engines/engine/power-pct", eng.get_Percentage_Power());
230 fgSetDouble("/engines/engine/egt-degf", eng.get_EGT());
231 fgSetDouble("/engines/engine/cht-degf", eng.get_CHT());
232 fgSetDouble("/engines/engine/prop-thrust", eng.get_prop_thrust_SI());
233 fgSetDouble("/engines/engine/fuel-flow-gph",
234 eng.get_fuel_flow_gals_hr());
235 fgSetDouble("/engines/engine/oil-temperature-degf",
237 fgSetDouble("/engines/engine/running", eng.getRunningFlag());
238 fgSetDouble("/engines/engine/cranking", eng.getCrankingFlag());
240 static const SGPropertyNode *fuel_freeze
241 = fgGetNode("/sim/freeze/fuel");
243 if ( ! fuel_freeze->getBoolValue() ) {
244 //Assume we are using both tanks equally for now
245 fgSetDouble("/consumables/fuel/tank[0]/level-gal_us",
246 fgGetDouble("/consumables/fuel/tank[0]/level-gal_us")
247 - (eng.get_fuel_flow_gals_hr() / (2 * 3600))
249 fgSetDouble("/consumables/fuel/tank[1]/level-gal_us",
250 fgGetDouble("/consumables/fuel/tank[1]/level-gal_us")
251 - (eng.get_fuel_flow_gals_hr() / (2 * 3600))
255 // Apparently the IO360 thrust model is not working.
256 // F_X_engine is zero here.
257 F_X_engine = eng.get_prop_thrust_lbs();
259 Flap_handle = 30.0 * globals->get_controls()->get_flaps();
261 // done with basic-larcsim if-block
263 double save_alt = 0.0;
265 // lets try to avoid really screwing up the LaRCsim model
266 if ( get_Altitude() < -9000.0 ) {
267 save_alt = get_Altitude();
271 // copy control positions into the LaRCsim structure
272 Lat_control = globals->get_controls()->get_aileron() / speed_up->getIntValue();
273 Long_control = globals->get_controls()->get_elevator();
274 Long_trim = globals->get_controls()->get_elevator_trim();
275 Rudder_pedal = globals->get_controls()->get_rudder() / speed_up->getIntValue();
277 // IO360.cxx for the C172 thrust is broken (not sure why).
278 // So force C172 to use engine model in c172_engine.c instead of the IO360.cxx.
279 // if ( !strcmp(aero->getStringValue(), "c172") ) {
280 // Use_External_Engine = 1;
282 // Use_External_Engine = 0;
284 Use_External_Engine = 0;
286 Throttle_pct = globals->get_controls()->get_throttle( 0 ) * 1.0;
288 Brake_pct[0] = globals->get_controls()->get_brake_right();
289 Brake_pct[1] = globals->get_controls()->get_brake_left();
291 // Inform LaRCsim of the local terrain altitude
293 = get_groundlevel_m(Latitude, Longitude, Altitude * SG_FEET_TO_METER)
297 /* V_north_airmass = get_V_north_airmass();
298 V_east_airmass = get_V_east_airmass();
299 V_down_airmass = get_V_down_airmass(); */
302 // old -- FGInterface_2_LaRCsim() not needed except for Init()
303 // translate FG to LaRCsim structure
304 // FGInterface_2_LaRCsim(f);
305 // printf("FG_Altitude = %.2f\n", FG_Altitude * 0.3048);
306 // printf("Altitude = %.2f\n", Altitude * 0.3048);
307 // printf("Radius to Vehicle = %.2f\n", Radius_to_vehicle * 0.3048);
309 // for engine functions (sounds and instruments)
310 // drive the rpm gauge
311 fgSetDouble("/engines/engine/rpm", (globals->get_controls()->get_throttle( 0 ) * 100.0 * 25 ));
312 // manifold air pressure, which drives the sound (see *sound.xml file)
313 fgSetDouble("/engines/engine/mp-osi", (globals->get_controls()->get_throttle( 0 ) * 100.0 ));
314 // make the engine cranking and running sounds when fgfs starts up
315 fgSetDouble("/engines/engine/cranking", 1);
316 fgSetDouble("/engines/engine/running", 1);
318 // if flying uiuc, set some properties and over-ride some previous ones
319 if ( !strcmp(aero->getStringValue(), "uiuc")) {
321 // surface positions and other general properties
322 fgSetDouble("/surface-positions/flight/rudder-pos-norm", fgGetDouble("/controls/flight/rudder"));
323 fgSetDouble("/surface-positions/flight/elevator-pos-norm", fgGetDouble("/controls/flight/elevator")); // FIXME: ignoring trim
324 fgSetDouble("/surface-positions/flight/right-aileron-pos-norm", -1 * fgGetDouble("/controls/flight/aileron")); // FIXME: ignoring trim
325 fgSetDouble("/surface-positions/flight/left-aileron-pos-norm", fgGetDouble("/controls/flight/aileron")); // FIXME: ignoring trim
327 // used by Instruments/accel.xml
328 fgSetDouble("/accelerations/pilot-g", -N_Z_cg);
330 Flap_handle = flap_max * globals->get_controls()->get_flaps();
332 // flaps with transition occuring in uiuc_aerodeflections.cpp
334 fgSetDouble("/surface-positions/flight/flap-pos-norm", flap_pos_norm);
337 // spoilers with transition occurring in uiuc_aerodeflections.cpp
339 Spoiler_handle = spoiler_max * fgGetDouble("/controls/flight/spoilers");
341 // gear with transition occurring here in LaRCsim.cxx
343 if(fgGetBool("/controls/gear/gear-down")) {
349 // commanded gear is 0 or 1
350 gear_cmd_norm = Gear_handle;
351 // amount gear moves per time step [relative to 1]
352 gear_increment_per_timestep = gear_rate * dt;
353 // determine gear position with respect to gear command
354 if (gear_pos_norm < gear_cmd_norm) {
355 gear_pos_norm += gear_increment_per_timestep;
356 if (gear_pos_norm > gear_cmd_norm)
357 gear_pos_norm = gear_cmd_norm;
358 } else if (gear_pos_norm > gear_cmd_norm) {
359 gear_pos_norm -= gear_increment_per_timestep;
360 if (gear_pos_norm < gear_cmd_norm)
361 gear_pos_norm = gear_cmd_norm;
363 // set the gear position
364 fgSetDouble("/gear/gear[0]/position-norm", gear_pos_norm);
365 fgSetDouble("/gear/gear[1]/position-norm", gear_pos_norm);
366 fgSetDouble("/gear/gear[2]/position-norm", gear_pos_norm);
370 // engine functions (sounds and instruments)
371 // drive the rpm gauge
372 fgSetDouble("/engines/engine/rpm", (globals->get_controls()->get_throttle( 0 ) * 100.0 * 25 ));
373 // manifold air pressure
374 fgSetDouble("/engines/engine/mp-osi", (globals->get_controls()->get_throttle( 0 ) * 100.0 ));
375 // make the engine cranking and running sounds when fgfs starts up
376 fgSetDouble("/engines/engine/cranking", 1);
377 fgSetDouble("/engines/engine/running", 1);
378 if ( !strcmp(uiuc_type->getStringValue(), "uiuc-prop")) {
379 // uiuc prop driven airplane, e.g. Wright Flyer
381 else if ( !strcmp(uiuc_type->getStringValue(), "uiuc-jet")) {
382 // uiuc jet aircraft, e.g. a4d
383 // used for setting the sound
384 fgSetDouble("/engines/engine/n1", (75 + (globals->get_controls()->get_throttle( 0 ) * 100.0 )/400));
385 fgSetDouble("/engines/engine/prop-thrust", (4000 + F_X_engine/2));
386 // used for setting the instruments
387 fgSetDouble("/engines/engine[0]/n1", (50 + (globals->get_controls()->get_throttle( 0 ) * 50)));
389 else if ( !strcmp(uiuc_type->getStringValue(), "uiuc-sailplane")) {
390 // uiuc sailplane, e.g. asw20
391 fgSetDouble("/engines/engine/cranking", 0);
393 else if ( !strcmp(uiuc_type->getStringValue(), "uiuc-hangglider")) {
394 // uiuc hang glider, e.g. airwave
395 fgSetDouble("/engines/engine/cranking", 0);
397 else if ( !strcmp(uiuc_type->getStringValue(), "uiuc-ornithopter")) {
399 fgSetDouble("/canopy/position-norm", 0);
400 fgSetDouble("/wing-phase/position-norm", sin(flapper_phi - 3 * LS_PI / 2));
401 fgSetDouble("/wing-phase/position-deg", flapper_phi*RAD_TO_DEG);
402 fgSetDouble("/wing-phase/position-one", 1);
403 fgSetDouble("/thorax/volume", 0);
404 fgSetDouble("/thorax/rpm", 0);
405 // fgSetDouble("/thorax/volume", ((1+sin(2*(flapper_phi+LS_PI)))/2));
406 // fgSetDouble("/thorax/rpm", ((1+sin(2*(flapper_phi+LS_PI)))/2));
411 // add Gamma_horiz_deg to properties, mss 021213
412 if (use_gamma_horiz_on_speed) {
413 if (V_rel_wind > gamma_horiz_on_speed) {
414 fgSetDouble("/orientation/gamma-horiz-deg", (Gamma_horiz_rad * RAD_TO_DEG));
417 fgSetDouble("/orientation/gamma-horiz-deg", fgGetDouble("/orientation/heading-deg"));
421 fgSetDouble("/orientation/gamma-horiz-deg", fgGetDouble("/orientation/heading-deg"));
423 ls_update(multiloop);
425 // printf("%d FG_Altitude = %.2f\n", i, FG_Altitude * 0.3048);
426 // printf("%d Altitude = %.2f\n", i, Altitude * 0.3048);
428 // translate LaRCsim back to FG structure so that the
429 // autopilot (and the rest of the sim can use the updated
433 // but lets restore our original bogus altitude when we are done
434 if ( save_alt < -9000.0 ) {
435 set_Altitude( save_alt );
440 // Convert from the FGInterface struct to the LaRCsim generic_ struct
441 bool FGLaRCsim::copy_to_LaRCsim () {
447 // Dx_pilot = get_Dx_pilot();
448 // Dy_pilot = get_Dy_pilot();
449 // Dz_pilot = get_Dz_pilot();
456 // F_north = get_F_north();
457 // F_east = get_F_east();
458 // F_down = get_F_down();
459 // F_X_aero = get_F_X_aero();
460 // F_Y_aero = get_F_Y_aero();
461 // F_Z_aero = get_F_Z_aero();
462 // F_X_engine = get_F_X_engine();
463 // F_Y_engine = get_F_Y_engine();
464 // F_Z_engine = get_F_Z_engine();
465 // F_X_gear = get_F_X_gear();
466 // F_Y_gear = get_F_Y_gear();
467 // F_Z_gear = get_F_Z_gear();
468 // M_l_rp = get_M_l_rp();
469 // M_m_rp = get_M_m_rp();
470 // M_n_rp = get_M_n_rp();
471 // M_l_cg = get_M_l_cg();
472 // M_m_cg = get_M_m_cg();
473 // M_n_cg = get_M_n_cg();
474 // M_l_aero = get_M_l_aero();
475 // M_m_aero = get_M_m_aero();
476 // M_n_aero = get_M_n_aero();
477 // M_l_engine = get_M_l_engine();
478 // M_m_engine = get_M_m_engine();
479 // M_n_engine = get_M_n_engine();
480 // M_l_gear = get_M_l_gear();
481 // M_m_gear = get_M_m_gear();
482 // M_n_gear = get_M_n_gear();
483 // V_dot_north = get_V_dot_north();
484 // V_dot_east = get_V_dot_east();
485 // V_dot_down = get_V_dot_down();
486 // U_dot_body = get_U_dot_body();
487 // V_dot_body = get_V_dot_body();
488 // W_dot_body = get_W_dot_body();
489 // A_X_cg = get_A_X_cg();
490 // A_Y_cg = get_A_Y_cg();
491 // A_Z_cg = get_A_Z_cg();
492 // A_X_pilot = get_A_X_pilot();
493 // A_Y_pilot = get_A_Y_pilot();
494 // A_Z_pilot = get_A_Z_pilot();
495 // N_X_cg = get_N_X_cg();
496 // N_Y_cg = get_N_Y_cg();
497 // N_Z_cg = get_N_Z_cg();
498 // N_X_pilot = get_N_X_pilot();
499 // N_Y_pilot = get_N_Y_pilot();
500 // N_Z_pilot = get_N_Z_pilot();
501 // P_dot_body = get_P_dot_body();
502 // Q_dot_body = get_Q_dot_body();
503 // R_dot_body = get_R_dot_body();
504 // V_north = get_V_north();
505 // V_east = get_V_east();
506 // V_down = get_V_down();
507 // V_north_rel_ground = get_V_north_rel_ground();
508 // V_east_rel_ground = get_V_east_rel_ground();
509 // V_down_rel_ground = get_V_down_rel_ground();
510 // V_north_airmass = get_V_north_airmass();
511 // V_east_airmass = get_V_east_airmass();
512 // V_down_airmass = get_V_down_airmass();
513 // V_north_rel_airmass = get_V_north_rel_airmass();
514 // V_east_rel_airmass = get_V_east_rel_airmass();
515 // V_down_rel_airmass = get_V_down_rel_airmass();
516 // U_gust = get_U_gust();
517 // V_gust = get_V_gust();
518 // W_gust = get_W_gust();
519 // U_body = get_U_body();
520 // V_body = get_V_body();
521 // W_body = get_W_body();
522 // V_rel_wind = get_V_rel_wind();
523 // V_true_kts = get_V_true_kts();
524 // V_rel_ground = get_V_rel_ground();
525 // V_inertial = get_V_inertial();
526 // V_ground_speed = get_V_ground_speed();
527 // V_equiv = get_V_equiv();
528 // V_equiv_kts = get_V_equiv_kts();
529 // V_calibrated = get_V_calibrated();
530 // V_calibrated_kts = get_V_calibrated_kts();
531 // P_body = get_P_body();
532 // Q_body = get_Q_body();
533 // R_body = get_R_body();
534 // P_local = get_P_local();
535 // Q_local = get_Q_local();
536 // R_local = get_R_local();
537 // P_total = get_P_total();
538 // Q_total = get_Q_total();
539 // R_total = get_R_total();
540 // Phi_dot = get_Phi_dot();
541 // Theta_dot = get_Theta_dot();
542 // Psi_dot = get_Psi_dot();
543 // Latitude_dot = get_Latitude_dot();
544 // Longitude_dot = get_Longitude_dot();
545 // Radius_dot = get_Radius_dot();
546 // Lat_geocentric = get_Lat_geocentric();
547 // Lon_geocentric = get_Lon_geocentric();
548 // Radius_to_vehicle = get_Radius_to_vehicle();
549 // Latitude = get_Latitude();
550 // Longitude = get_Longitude();
551 // Altitude = get_Altitude();
553 // Theta = get_Theta();
555 // T_local_to_body_11 = get_T_local_to_body_11();
556 // T_local_to_body_12 = get_T_local_to_body_12();
557 // T_local_to_body_13 = get_T_local_to_body_13();
558 // T_local_to_body_21 = get_T_local_to_body_21();
559 // T_local_to_body_22 = get_T_local_to_body_22();
560 // T_local_to_body_23 = get_T_local_to_body_23();
561 // T_local_to_body_31 = get_T_local_to_body_31();
562 // T_local_to_body_32 = get_T_local_to_body_32();
563 // T_local_to_body_33 = get_T_local_to_body_33();
564 // Gravity = get_Gravity();
565 // Centrifugal_relief = get_Centrifugal_relief();
566 // Alpha = get_Alpha();
567 // Beta = get_Beta();
568 // Alpha_dot = get_Alpha_dot();
569 // Beta_dot = get_Beta_dot();
570 // Cos_alpha = get_Cos_alpha();
571 // Sin_alpha = get_Sin_alpha();
572 // Cos_beta = get_Cos_beta();
573 // Sin_beta = get_Sin_beta();
574 // Cos_phi = get_Cos_phi();
575 // Sin_phi = get_Sin_phi();
576 // Cos_theta = get_Cos_theta();
577 // Sin_theta = get_Sin_theta();
578 // Cos_psi = get_Cos_psi();
579 // Sin_psi = get_Sin_psi();
580 // Gamma_vert_rad = get_Gamma_vert_rad();
581 // Gamma_horiz_rad = get_Gamma_horiz_rad();
582 // Sigma = get_Sigma();
583 // Density = get_Density();
584 // V_sound = get_V_sound();
585 // Mach_number = get_Mach_number();
586 // Static_pressure = get_Static_pressure();
587 // Total_pressure = get_Total_pressure();
588 // Impact_pressure = get_Impact_pressure();
589 // Dynamic_pressure = get_Dynamic_pressure();
590 // Static_temperature = get_Static_temperature();
591 // Total_temperature = get_Total_temperature();
592 // Sea_level_radius = get_Sea_level_radius();
593 // Earth_position_angle = get_Earth_position_angle();
594 // Runway_altitude = get_Runway_altitude();
595 // Runway_latitude = get_Runway_latitude();
596 // Runway_longitude = get_Runway_longitude();
597 // Runway_heading = get_Runway_heading();
598 // Radius_to_rwy = get_Radius_to_rwy();
599 // D_cg_north_of_rwy = get_D_cg_north_of_rwy();
600 // D_cg_east_of_rwy = get_D_cg_east_of_rwy();
601 // D_cg_above_rwy = get_D_cg_above_rwy();
602 // X_cg_rwy = get_X_cg_rwy();
603 // Y_cg_rwy = get_Y_cg_rwy();
604 // H_cg_rwy = get_H_cg_rwy();
605 // D_pilot_north_of_rwy = get_D_pilot_north_of_rwy();
606 // D_pilot_east_of_rwy = get_D_pilot_east_of_rwy();
607 // D_pilot_above_rwy = get_D_pilot_above_rwy();
608 // X_pilot_rwy = get_X_pilot_rwy();
609 // Y_pilot_rwy = get_Y_pilot_rwy();
610 // H_pilot_rwy = get_H_pilot_rwy();
616 // Convert from the LaRCsim generic_ struct to the FGInterface struct
617 bool FGLaRCsim::copy_from_LaRCsim() {
619 // Mass properties and geometry values
620 _set_Inertias( Mass, I_xx, I_yy, I_zz, I_xz );
621 // set_Pilot_Location( Dx_pilot, Dy_pilot, Dz_pilot );
622 _set_CG_Position( Dx_cg, Dy_cg, Dz_cg );
625 // set_Forces_Body_Total( F_X, F_Y, F_Z );
626 // set_Forces_Local_Total( F_north, F_east, F_down );
627 // set_Forces_Aero( F_X_aero, F_Y_aero, F_Z_aero );
628 // set_Forces_Engine( F_X_engine, F_Y_engine, F_Z_engine );
629 // set_Forces_Gear( F_X_gear, F_Y_gear, F_Z_gear );
632 // set_Moments_Total_RP( M_l_rp, M_m_rp, M_n_rp );
633 // set_Moments_Total_CG( M_l_cg, M_m_cg, M_n_cg );
634 // set_Moments_Aero( M_l_aero, M_m_aero, M_n_aero );
635 // set_Moments_Engine( M_l_engine, M_m_engine, M_n_engine );
636 // set_Moments_Gear( M_l_gear, M_m_gear, M_n_gear );
639 _set_Accels_Local( V_dot_north, V_dot_east, V_dot_down );
640 _set_Accels_Body( U_dot_body, V_dot_body, W_dot_body );
641 _set_Accels_CG_Body( A_X_cg, A_Y_cg, A_Z_cg );
642 _set_Accels_Pilot_Body( A_X_pilot, A_Y_pilot, A_Z_pilot );
643 _set_Accels_CG_Body_N( N_X_cg, N_Y_cg, -N_Z_cg );
644 // set_Accels_Pilot_Body_N( N_X_pilot, N_Y_pilot, N_Z_pilot );
645 // set_Accels_Omega( P_dot_body, Q_dot_body, R_dot_body );
648 _set_Velocities_Local( V_north, V_east, V_down );
649 // set_Velocities_Ground( V_north_rel_ground, V_east_rel_ground,
650 // V_down_rel_ground );
651 _set_Velocities_Local_Airmass( V_north_airmass, V_east_airmass,
653 // set_Velocities_Local_Rel_Airmass( V_north_rel_airmass,
654 // V_east_rel_airmass, V_down_rel_airmass );
655 // set_Velocities_Gust( U_gust, V_gust, W_gust );
656 _set_Velocities_Wind_Body( U_body, V_body, W_body );
658 _set_V_rel_wind( V_rel_wind );
659 // set_V_true_kts( V_true_kts );
660 // set_V_rel_ground( V_rel_ground );
661 // set_V_inertial( V_inertial );
662 _set_V_ground_speed( V_ground_speed );
663 // set_V_equiv( V_equiv );
664 _set_V_equiv_kts( V_equiv_kts );
665 // set_V_calibrated( V_calibrated );
666 _set_V_calibrated_kts( V_calibrated_kts );
668 _set_Omega_Body( P_body, Q_body, R_body );
669 // set_Omega_Local( P_local, Q_local, R_local );
670 // set_Omega_Total( P_total, Q_total, R_total );
672 _set_Euler_Rates( Phi_dot, Theta_dot, Psi_dot );
673 _set_Geocentric_Rates( Latitude_dot, Longitude_dot, Radius_dot );
675 _set_Mach_number( Mach_number );
677 SG_LOG( SG_FLIGHT, SG_DEBUG, "lon = " << Longitude
678 << " lat_geoc = " << Lat_geocentric << " lat_geod = " << Latitude
679 << " alt = " << Altitude << " sl_radius = " << Sea_level_radius
680 << " radius_to_vehicle = " << Radius_to_vehicle );
682 double tmp_lon_geoc = Lon_geocentric;
683 while ( tmp_lon_geoc < -SGD_PI ) { tmp_lon_geoc += SGD_2PI; }
684 while ( tmp_lon_geoc > SGD_PI ) { tmp_lon_geoc -= SGD_2PI; }
686 double tmp_lon = Longitude;
687 while ( tmp_lon < -SGD_PI ) { tmp_lon += SGD_2PI; }
688 while ( tmp_lon > SGD_PI ) { tmp_lon -= SGD_2PI; }
691 _set_Geocentric_Position( Lat_geocentric, tmp_lon_geoc,
693 _set_Geodetic_Position( Latitude, tmp_lon, Altitude );
694 _set_Euler_Angles( Phi, Theta, Psi );
696 _set_Altitude_AGL( Altitude - Runway_altitude );
698 // Miscellaneous quantities
699 // set_Gravity( Gravity );
700 // set_Centrifugal_relief( Centrifugal_relief );
702 _set_Alpha( Std_Alpha );
703 _set_Beta( Std_Beta );
704 // set_Alpha_dot( Std_Alpha_dot );
705 // set_Beta_dot( Std_Beta_dot );
707 // set_Cos_alpha( Cos_alpha );
708 // set_Sin_alpha( Sin_alpha );
709 // set_Cos_beta( Cos_beta );
710 // set_Sin_beta( Sin_beta );
712 // _set_Cos_phi( Cos_phi );
713 // set_Sin_phi( Sin_phi );
714 // _set_Cos_theta( Cos_theta );
715 // set_Sin_theta( Sin_theta );
716 // set_Cos_psi( Cos_psi );
717 // set_Sin_psi( Sin_psi );
719 _set_Gamma_vert_rad( Gamma_vert_rad );
720 // set_Gamma_horiz_rad( Gamma_horiz_rad );
722 // set_Sigma( Sigma );
723 _set_Density( Density );
724 // set_V_sound( V_sound );
725 // set_Mach_number( Mach_number );
727 _set_Static_pressure( Static_pressure );
728 // set_Total_pressure( Total_pressure );
729 // set_Impact_pressure( Impact_pressure );
730 // set_Dynamic_pressure( Dynamic_pressure );
732 _set_Static_temperature( Static_temperature );
733 // set_Total_temperature( Total_temperature );
735 _set_Sea_level_radius( Sea_level_radius );
736 _set_Earth_position_angle( Earth_position_angle );
738 _set_Runway_altitude( Runway_altitude );
739 // set_Runway_latitude( Runway_latitude );
740 // set_Runway_longitude( Runway_longitude );
741 // set_Runway_heading( Runway_heading );
742 // set_Radius_to_rwy( Radius_to_rwy );
744 // set_CG_Rwy_Local( D_cg_north_of_rwy, D_cg_east_of_rwy, D_cg_above_rwy);
745 // set_CG_Rwy_Rwy( X_cg_rwy, Y_cg_rwy, H_cg_rwy );
746 // set_Pilot_Rwy_Local( D_pilot_north_of_rwy, D_pilot_east_of_rwy,
747 // D_pilot_above_rwy );
748 // set_Pilot_Rwy_Rwy( X_pilot_rwy, Y_pilot_rwy, H_pilot_rwy );
750 // printf("sin_lat_geo %f cos_lat_geo %f\n", sin_Lat_geoc, cos_Lat_geoc);
751 // printf("sin_lat %f cos_lat %f\n",
752 // get_sin_latitude(), get_cos_latitude());
753 // printf("sin_lon %f cos_lon %f\n",
754 // get_sin_longitude(), get_cos_longitude());
756 _set_Climb_Rate( -1 * V_down );
757 // cout << "climb rate = " << -V_down * 60 << endl;
759 if ( !strcmp(aero->getStringValue(), "uiuc") ) {
761 globals->get_controls()->set_elevator(Long_control);
762 globals->get_controls()->set_elevator_trim(Long_trim);
763 // controls.set_elevator(Long_control);
764 // controls.set_elevator_trim(Long_trim);
767 globals->get_controls()->set_aileron(Lat_control);
768 // controls.set_aileron(Lat_control);
771 globals->get_controls()->set_rudder(Rudder_pedal);
772 // controls.set_rudder(Rudder_pedal);
774 if (pilot_throttle_no) {
775 globals->get_controls()->set_throttle(0,Throttle_pct);
776 // controls.set_throttle(0,Throttle_pct);
784 void FGLaRCsim::set_ls(void) {
785 Phi=lsic->GetRollAngleRadIC();
786 Theta=lsic->GetPitchAngleRadIC();
787 Psi=lsic->GetHeadingRadIC();
788 V_north=lsic->GetVnorthFpsIC();
789 V_east=lsic->GetVeastFpsIC();
790 V_down=lsic->GetVdownFpsIC();
791 Altitude=lsic->GetAltitudeFtIC();
792 Latitude=lsic->GetLatitudeGDRadIC();
793 Longitude=lsic->GetLongitudeRadIC();
794 Runway_altitude=lsic->GetRunwayAltitudeFtIC();
795 V_north_airmass = lsic->GetVnorthAirmassFpsIC() * -1;
796 V_east_airmass = lsic->GetVeastAirmassFpsIC() * -1;
797 V_down_airmass = lsic->GetVdownAirmassFpsIC() * -1;
802 void FGLaRCsim::snap_shot(void) {
803 lsic->SetLatitudeGDRadIC( get_Latitude() );
804 lsic->SetLongitudeRadIC( get_Longitude() );
805 lsic->SetAltitudeFtIC( get_Altitude() );
806 lsic->SetRunwayAltitudeFtIC( get_Runway_altitude() );
807 lsic->SetVtrueFpsIC( get_V_rel_wind() );
808 lsic->SetPitchAngleRadIC( get_Theta() );
809 lsic->SetRollAngleRadIC( get_Phi() );
810 lsic->SetHeadingRadIC( get_Psi() );
811 lsic->SetClimbRateFpsIC( get_Climb_Rate() );
812 lsic->SetVNEDAirmassFpsIC( get_V_north_airmass(),
813 get_V_east_airmass(),
814 get_V_down_airmass() );
818 void FGLaRCsim::set_Latitude(double lat) {
819 SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Latitude: " << lat );
821 lsic->SetLatitudeGDRadIC(lat);
823 copy_from_LaRCsim(); //update the bus
826 void FGLaRCsim::set_Longitude(double lon) {
827 SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Longitude: " << lon );
829 lsic->SetLongitudeRadIC(lon);
831 copy_from_LaRCsim(); //update the bus
834 void FGLaRCsim::set_Altitude(double alt) {
835 SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Altitude: " << alt );
837 lsic->SetAltitudeFtIC(alt);
839 copy_from_LaRCsim(); //update the bus
842 void FGLaRCsim::set_V_calibrated_kts(double vc) {
843 SG_LOG( SG_FLIGHT, SG_INFO,
844 "FGLaRCsim::set_V_calibrated_kts: " << vc );
846 lsic->SetVcalibratedKtsIC(vc);
848 copy_from_LaRCsim(); //update the bus
851 void FGLaRCsim::set_Mach_number(double mach) {
852 SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Mach_number: " << mach );
854 lsic->SetMachIC(mach);
856 copy_from_LaRCsim(); //update the bus
859 void FGLaRCsim::set_Velocities_Local( double north, double east, double down ){
860 SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Velocities_local: "
861 << north << " " << east << " " << down );
863 lsic->SetVNEDFpsIC(north, east, down);
865 copy_from_LaRCsim(); //update the bus
868 void FGLaRCsim::set_Velocities_Wind_Body( double u, double v, double w){
869 SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Velocities_Wind_Body: "
870 << u << " " << v << " " << w );
872 lsic->SetUVWFpsIC(u,v,w);
874 copy_from_LaRCsim(); //update the bus
878 void FGLaRCsim::set_Euler_Angles( double phi, double theta, double psi ) {
879 SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Euler_angles: "
880 << phi << " " << theta << " " << psi );
883 lsic->SetPitchAngleRadIC(theta);
884 lsic->SetRollAngleRadIC(phi);
885 lsic->SetHeadingRadIC(psi);
887 copy_from_LaRCsim(); //update the bus
891 void FGLaRCsim::set_Climb_Rate( double roc) {
892 SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Climb_rate: " << roc );
894 lsic->SetClimbRateFpsIC(roc);
896 copy_from_LaRCsim(); //update the bus
899 void FGLaRCsim::set_Gamma_vert_rad( double gamma) {
900 SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Gamma_vert_rad: " << gamma );
902 lsic->SetFlightPathAngleRadIC(gamma);
904 copy_from_LaRCsim(); //update the bus
907 void FGLaRCsim::set_AltitudeAGL(double altagl) {
908 SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_AltitudeAGL: " << altagl );
910 lsic->SetAltitudeAGLFtIC(altagl);
915 /* getting a namespace conflict...
916 void FGLaRCsim::set_Velocities_Local_Airmass (double wnorth,
919 SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Velocities_Local_Airmass: "
920 << wnorth << " " << weast << " " << wdown );
922 lsic->SetVNEDAirmassFpsIC( wnorth, weast, wdown );
928 void FGLaRCsim::set_Static_pressure(double p) {
929 SG_LOG( SG_FLIGHT, SG_INFO,
930 "FGLaRCsim::set_Static_pressure: " << p );
931 SG_LOG( SG_FLIGHT, SG_INFO,
932 "LaRCsim does not support externally supplied atmospheric data" );
935 void FGLaRCsim::set_Static_temperature(double T) {
936 SG_LOG( SG_FLIGHT, SG_INFO,
937 "FGLaRCsim::set_Static_temperature: " << T );
938 SG_LOG( SG_FLIGHT, SG_INFO,
939 "LaRCsim does not support externally supplied atmospheric data" );
943 void FGLaRCsim::set_Density(double rho) {
944 SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Density: " << rho );
945 SG_LOG( SG_FLIGHT, SG_INFO,
946 "LaRCsim does not support externally supplied atmospheric data" );