X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FFDM%2FLaRCsim%2FLaRCsim.cxx;h=850532f34532e698e28c3bbb84cca0899f846377;hb=13db36f67912be03c2e970e84cdcdbd41dddb61c;hp=5c3026d2e374b192b2b0f8e83b241fc7f253e7a7;hpb=de16c7d222aed60927d31c3e8a4c0325cb9c16b9;p=flightgear.git diff --git a/src/FDM/LaRCsim/LaRCsim.cxx b/src/FDM/LaRCsim/LaRCsim.cxx index 5c3026d2e..850532f34 100644 --- a/src/FDM/LaRCsim/LaRCsim.cxx +++ b/src/FDM/LaRCsim/LaRCsim.cxx @@ -2,7 +2,7 @@ // // Written by Curtis Olson, started October 1998. // -// Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu +// Copyright (C) 1998 Curtis L. Olson - http://www.flightgear.org/~curt // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License as @@ -16,20 +16,22 @@ // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software -// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // // $Id$ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include // strcmp() #include #include -#include #include -#include -#include +#include #include #include #include
@@ -46,6 +48,8 @@ FGLaRCsim::FGLaRCsim( double dt ) { + mass=i_xx=i_yy=i_zz=i_xz=0; + // set_delta_t( dt ); speed_up = fgGetNode("/sim/speed-up", true); @@ -66,6 +70,22 @@ FGLaRCsim::FGLaRCsim( double dt ) { I_xz = 0.000000E+00; } + if ( !strcmp(aero->getStringValue(), "basic") ) { + copy_to_LaRCsim(); // initialize all of LaRCsim's vars + + //this should go away someday -- formerly done in fg_init.cxx + Mass = 2./32.174; + I_xx = 0.0454; + I_yy = 0.0191; + I_zz = 0.0721; + I_xz = 0; +// Mass = 8.547270E+01; +// I_xx = 1.048000E+03; +// I_yy = 3.000000E+03; +// I_zz = 3.530000E+03; +// I_xz = 0.000000E+00; + } + ls_set_model_dt(dt); // Initialize our little engine that hopefully might @@ -161,14 +181,85 @@ void FGLaRCsim::update( double dt ) { * dt); } + // Apparently the IO360 thrust model is not working. + // F_X_engine is zero here. F_X_engine = eng.get_prop_thrust_lbs(); - // cout << "F_X_engine = " << F_X_engine << '\n'; - // end c172 if block Flap_handle = 30.0 * globals->get_controls()->get_flaps(); } // done with c172-larcsim if-block + if ( !strcmp(aero->getStringValue(), "basic") ) { + // set control inputs + // cout << "V_calibrated_kts = " << V_calibrated_kts << '\n'; + eng.set_IAS( V_calibrated_kts ); + eng.set_Throttle_Lever_Pos( globals->get_controls()->get_throttle( 0 ) + * 100.0 ); + eng.set_Propeller_Lever_Pos( 100 ); + eng.set_Mixture_Lever_Pos( globals->get_controls()->get_mixture( 0 ) + * 100.0 ); + eng.set_Magneto_Switch_Pos( globals->get_controls()->get_magnetos(0) ); + eng.setStarterFlag( globals->get_controls()->get_starter(0) ); + eng.set_p_amb( Static_pressure ); + eng.set_T_amb( Static_temperature ); + + // update engine model + eng.update(); + + // Fake control-surface positions + fgSetDouble("/surface-positions/flap-pos-norm", + fgGetDouble("/controls/flight/flaps")); + // FIXME: ignoring trim + fgSetDouble("/surface-positions/elevator-pos-norm", + fgGetDouble("/controls/flight/elevator")); + // FIXME: ignoring trim + fgSetDouble("/surface-positions/left-aileron-pos-norm", + fgGetDouble("/controls/flight/aileron")); + // FIXME: ignoring trim + fgSetDouble("/surface-positions/right-aileron-pos-norm", + -1 * fgGetDouble("/controls/flight/aileron")); + // FIXME: ignoring trim + fgSetDouble("/surface-positions/rudder-pos-norm", + fgGetDouble("/controls/flight/rudder")); + + // copy engine state values onto "bus" + fgSetDouble("/engines/engine/rpm", eng.get_RPM()); + fgSetDouble("/engines/engine/mp-osi", eng.get_Manifold_Pressure()); + fgSetDouble("/engines/engine/max-hp", eng.get_MaxHP()); + fgSetDouble("/engines/engine/power-pct", eng.get_Percentage_Power()); + fgSetDouble("/engines/engine/egt-degf", eng.get_EGT()); + fgSetDouble("/engines/engine/cht-degf", eng.get_CHT()); + fgSetDouble("/engines/engine/prop-thrust", eng.get_prop_thrust_SI()); + fgSetDouble("/engines/engine/fuel-flow-gph", + eng.get_fuel_flow_gals_hr()); + fgSetDouble("/engines/engine/oil-temperature-degf", + eng.get_oil_temp()); + fgSetDouble("/engines/engine/running", eng.getRunningFlag()); + fgSetDouble("/engines/engine/cranking", eng.getCrankingFlag()); + + static const SGPropertyNode *fuel_freeze + = fgGetNode("/sim/freeze/fuel"); + + if ( ! fuel_freeze->getBoolValue() ) { + //Assume we are using both tanks equally for now + fgSetDouble("/consumables/fuel/tank[0]/level-gal_us", + fgGetDouble("/consumables/fuel/tank[0]/level-gal_us") + - (eng.get_fuel_flow_gals_hr() / (2 * 3600)) + * dt); + fgSetDouble("/consumables/fuel/tank[1]/level-gal_us", + fgGetDouble("/consumables/fuel/tank[1]/level-gal_us") + - (eng.get_fuel_flow_gals_hr() / (2 * 3600)) + * dt); + } + + // Apparently the IO360 thrust model is not working. + // F_X_engine is zero here. + F_X_engine = eng.get_prop_thrust_lbs(); + + Flap_handle = 30.0 * globals->get_controls()->get_flaps(); + } + // done with basic-larcsim if-block + double save_alt = 0.0; // lets try to avoid really screwing up the LaRCsim model @@ -183,20 +274,25 @@ void FGLaRCsim::update( double dt ) { Long_trim = globals->get_controls()->get_elevator_trim(); Rudder_pedal = globals->get_controls()->get_rudder() / speed_up->getIntValue(); - if ( !strcmp(aero->getStringValue(), "c172") ) { - Use_External_Engine = 1; - } else { - Use_External_Engine = 0; - } + // IO360.cxx for the C172 thrust is broken (not sure why). + // So force C172 to use engine model in c172_engine.c instead of the IO360.cxx. + // if ( !strcmp(aero->getStringValue(), "c172") ) { + // Use_External_Engine = 1; + // } else { + // Use_External_Engine = 0; + // } + Use_External_Engine = 0; Throttle_pct = globals->get_controls()->get_throttle( 0 ) * 1.0; - Brake_pct[0] = globals->get_controls()->get_brake( 1 ); - Brake_pct[1] = globals->get_controls()->get_brake( 0 ); + Brake_pct[0] = globals->get_controls()->get_brake_right(); + Brake_pct[1] = globals->get_controls()->get_brake_left(); // Inform LaRCsim of the local terrain altitude - // Runway_altitude = get_Runway_altitude(); - Runway_altitude = getACModel()->get3DModel()->getSGLocation()->get_cur_elev_m() * SG_METER_TO_FEET; + Runway_altitude + = get_groundlevel_m(Latitude, Longitude, Altitude * SG_FEET_TO_METER) + * SG_METER_TO_FEET; + // Weather /* V_north_airmass = get_V_north_airmass(); V_east_airmass = get_V_east_airmass(); @@ -235,7 +331,7 @@ void FGLaRCsim::update( double dt ) { // flaps with transition occuring in uiuc_aerodeflections.cpp if (use_flaps) { - fgSetDouble("/surface-positions/flight/flap-pos-norm", flap_pos_pct); + fgSetDouble("/surface-positions/flight/flap-pos-norm", flap_pos_norm); } // spoilers with transition occurring in uiuc_aerodeflections.cpp @@ -600,7 +696,6 @@ bool FGLaRCsim::copy_from_LaRCsim() { _set_Altitude_AGL( Altitude - Runway_altitude ); // Miscellaneous quantities - _set_T_Local_to_Body(T_local_to_body_m); // set_Gravity( Gravity ); // set_Centrifugal_relief( Centrifugal_relief ); @@ -614,9 +709,9 @@ bool FGLaRCsim::copy_from_LaRCsim() { // set_Cos_beta( Cos_beta ); // set_Sin_beta( Sin_beta ); - _set_Cos_phi( Cos_phi ); + // _set_Cos_phi( Cos_phi ); // set_Sin_phi( Sin_phi ); - _set_Cos_theta( Cos_theta ); + // _set_Cos_theta( Cos_theta ); // set_Sin_theta( Sin_theta ); // set_Cos_psi( Cos_psi ); // set_Sin_psi( Sin_psi ); @@ -652,11 +747,6 @@ bool FGLaRCsim::copy_from_LaRCsim() { // D_pilot_above_rwy ); // set_Pilot_Rwy_Rwy( X_pilot_rwy, Y_pilot_rwy, H_pilot_rwy ); - _set_sin_lat_geocentric(Lat_geocentric); - _set_cos_lat_geocentric(Lat_geocentric); - _set_sin_cos_longitude(Longitude); - _set_sin_cos_latitude(Latitude); - // printf("sin_lat_geo %f cos_lat_geo %f\n", sin_Lat_geoc, cos_Lat_geoc); // printf("sin_lat %f cos_lat %f\n", // get_sin_latitude(), get_cos_latitude());