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