]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/LaRCsim.cxx
Updated to match changes in radiostack.[ch]xx
[flightgear.git] / src / FDM / LaRCsim.cxx
index 067635bf4d8837892d414f2c045566ea5cab4c66..43223bf4cf9bfbde1f8fc6a0df2a7a126bf3e165 100644 (file)
 //
 // $Id$
 
+#include <string.h>            // strcmp()
 
 #include <simgear/constants.h>
 #include <simgear/debug/logstream.hxx>
 
-#include <Scenery/scenery.hxx>
-
 #include <Main/fg_props.hxx>
 #include <Aircraft/aircraft.hxx>
 #include <Controls/controls.hxx>
 #include "LaRCsim.hxx"
 
 FGLaRCsim::FGLaRCsim( double dt ) {
-    set_delta_t( dt );
+//     set_delta_t( dt );
 
     speed_up = fgGetNode("/sim/speed-up", true);
     aero = fgGetNode("/sim/aero", true);
 
-    ls_toplevel_init( 0.0, (char *)(aero->getStringValue().c_str()) );
+    ls_toplevel_init( 0.0, (char *)(aero->getStringValue()) );
 
     lsic=new LaRCsimIC; //this needs to be brought up after LaRCsim is
-    if ( aero->getStringValue() == "c172" ) {
+    if ( !strcmp(aero->getStringValue(), "c172") ) {
         copy_to_LaRCsim(); // initialize all of LaRCsim's vars
 
         //this should go away someday -- formerly done in fg_init.cxx
@@ -59,10 +58,10 @@ FGLaRCsim::FGLaRCsim( double dt ) {
         I_xz = 0.000000E+00;
     }
 
-    ls_set_model_dt( get_delta_t() );
+    ls_set_model_dt(dt);
 
             // Initialize our little engine that hopefully might
-    eng.init( get_delta_t() );
+    eng.init(dt);
     // dcl - in passing dt to init rather than update I am assuming
     // that the LaRCsim dt is fixed at one value (yes it is 120hz CLO)
 }
@@ -79,15 +78,18 @@ FGLaRCsim::~FGLaRCsim(void) {
 void FGLaRCsim::init() {
    //do init common to all FDM's
    common_init();
-
-   //now do any specific to LaRCsim
 }
 
 
 // Run an iteration of the EOM (equations of motion)
-void FGLaRCsim::update( int multiloop ) {
+void FGLaRCsim::update( double dt ) {
+
+    if (is_suspended())
+      return;
 
-    if ( aero->getStringValue() == "c172" ) {
+    int multiloop = _calc_multiloop(dt);
+
+    if ( !strcmp(aero->getStringValue(), "c172") ) {
        // set control inputs
        // cout << "V_calibrated_kts = " << V_calibrated_kts << '\n';
        eng.set_IAS( V_calibrated_kts );
@@ -104,6 +106,22 @@ void FGLaRCsim::update( int multiloop ) {
        // update engine model
        eng.update();
 
+       // Fake control-surface positions
+       fgSetDouble("/surface-positions/flap-pos-norm",
+                   fgGetDouble("/controls/flaps"));
+                               // FIXME: ignoring trim
+       fgSetDouble("/surface-positions/elevator-pos-norm",
+                   fgGetDouble("/controls/elevator"));
+                               // FIXME: ignoring trim
+       fgSetDouble("/surface-positions/left-aileron-pos-norm",
+                   fgGetDouble("/controls/aileron"));
+                               // FIXME: ignoring trim
+       fgSetDouble("/surface-positions/right-aileron-pos-norm",
+                   -1 * fgGetDouble("/controls/aileron"));
+                               // FIXME: ignoring trim
+       fgSetDouble("/surface-positions/rudder-pos-norm",
+                   fgGetDouble("/controls/rudder"));
+
        // copy engine state values onto "bus"
        fgSetDouble("/engines/engine/rpm", eng.get_RPM());
        fgSetDouble("/engines/engine/mp-osi", eng.get_Manifold_Pressure());
@@ -125,13 +143,13 @@ void FGLaRCsim::update( int multiloop ) {
        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]")
+                       fgGetDouble("/consumables/fuel/tank[0]/level-gal_us")
                        - (eng.get_fuel_flow_gals_hr() / (2 * 3600))
-                       * get_delta_t());
+                       * dt);
            fgSetDouble("/consumables/fuel/tank[1]/level-gal_us",
-                       fgGetDouble("/consumables/fuel/tank[1]")
+                       fgGetDouble("/consumables/fuel/tank[1]/level-gal_us")
                        - (eng.get_fuel_flow_gals_hr() / (2 * 3600))
-                       * get_delta_t());
+                       * dt);
        }
 
         F_X_engine = eng.get_prop_thrust_lbs();
@@ -155,7 +173,7 @@ void FGLaRCsim::update( int multiloop ) {
         speed_up->getIntValue();
     Flap_handle = 30.0 * globals->get_controls()->get_flaps();
 
-    if ( aero->getStringValue() == "c172" ) {
+    if ( !strcmp(aero->getStringValue(), "c172") ) {
         Use_External_Engine = 1;
     } else {
        Use_External_Engine = 0;
@@ -168,8 +186,7 @@ void FGLaRCsim::update( int multiloop ) {
 
     // Inform LaRCsim of the local terrain altitude
     // Runway_altitude = get_Runway_altitude();
-    Runway_altitude = scenery.get_cur_elev() * SG_METER_TO_FEET;
-
+    Runway_altitude = getACModel()->get3DModel()->getFGLocation()->get_cur_elev_m() * SG_METER_TO_FEET;
     // Weather
     /* V_north_airmass = get_V_north_airmass();
        V_east_airmass =  get_V_east_airmass();
@@ -183,6 +200,15 @@ void FGLaRCsim::update( int multiloop ) {
     // printf("Altitude = %.2f\n", Altitude * 0.3048);
     // printf("Radius to Vehicle = %.2f\n", Radius_to_vehicle * 0.3048);
 
+    // for engine functions (sounds and instruments)
+    // drive the rpm gauge
+    fgSetDouble("/engines/engine/rpm", (globals->get_controls()->get_throttle( 0 ) * 100.0 * 25 ));
+    // manifold air pressure, which drives the sound (see *sound.xml file)
+    fgSetDouble("/engines/engine/mp-osi", (globals->get_controls()->get_throttle( 0 ) * 100.0 ));
+    // make the engine cranking and running sounds when fgfs starts up
+    fgSetDouble("/engines/engine/cranking", 1);
+    fgSetDouble("/engines/engine/running", 1);
+
     ls_update(multiloop);
 
     // printf("%d FG_Altitude = %.2f\n", i, FG_Altitude * 0.3048);
@@ -525,7 +551,7 @@ bool FGLaRCsim::copy_from_LaRCsim() {
     _set_Climb_Rate( -1 * V_down );
     // cout << "climb rate = " << -V_down * 60 << endl;
 
-    if ( aero->getStringValue() == "uiuc" ) {
+    if ( !strcmp(aero->getStringValue(), "uiuc") ) {
        if (pilot_elev_no) {
            globals->get_controls()->set_elevator(Long_control);
            globals->get_controls()->set_elevator_trim(Long_trim);
@@ -561,25 +587,11 @@ void FGLaRCsim::set_ls(void) {
     Latitude=lsic->GetLatitudeGDRadIC();
     Longitude=lsic->GetLongitudeRadIC();
     Runway_altitude=lsic->GetRunwayAltitudeFtIC();
-    V_north_airmass = lsic->GetVnorthAirmassFpsIC();
-    V_east_airmass = lsic->GetVeastAirmassFpsIC();
-    V_down_airmass = lsic->GetVdownAirmassFpsIC();
+    V_north_airmass = lsic->GetVnorthAirmassFpsIC() * -1;
+    V_east_airmass = lsic->GetVeastAirmassFpsIC() * -1;
+    V_down_airmass = lsic->GetVdownAirmassFpsIC() * -1;
     ls_loop(0.0,-1);
     copy_from_LaRCsim();
-    SG_LOG( SG_FLIGHT, SG_INFO, "  FGLaRCsim::set_ls(): "  );
-    SG_LOG( SG_FLIGHT, SG_INFO, "     Phi: " <<  Phi  );
-    SG_LOG( SG_FLIGHT, SG_INFO, "     Theta: " <<  Theta  );
-    SG_LOG( SG_FLIGHT, SG_INFO, "     Psi: " <<  Psi  );
-    SG_LOG( SG_FLIGHT, SG_INFO, "     V_north: " <<  V_north  );
-    SG_LOG( SG_FLIGHT, SG_INFO, "     V_east: " <<  V_east  );
-    SG_LOG( SG_FLIGHT, SG_INFO, "     V_down: " <<  V_down  );
-    SG_LOG( SG_FLIGHT, SG_INFO, "     Altitude: " <<  Altitude  );
-    SG_LOG( SG_FLIGHT, SG_INFO, "     Latitude: " <<  Latitude  );
-    SG_LOG( SG_FLIGHT, SG_INFO, "     Longitude: " <<  Longitude  );
-    SG_LOG( SG_FLIGHT, SG_INFO, "     Runway_altitude: " <<  Runway_altitude  );
-    SG_LOG( SG_FLIGHT, SG_INFO, "     V_north_airmass: " <<  V_north_airmass  );
-    SG_LOG( SG_FLIGHT, SG_INFO, "     V_east_airmass: " <<  V_east_airmass  );
-    SG_LOG( SG_FLIGHT, SG_INFO, "     V_down_airmass: " <<  V_down_airmass  );
 }
 
 void FGLaRCsim::snap_shot(void) {
@@ -687,14 +699,6 @@ void FGLaRCsim::set_Gamma_vert_rad( double gamma) {
     copy_from_LaRCsim(); //update the bus
 }
 
-void FGLaRCsim::set_Runway_altitude(double ralt) {
-    SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Runway_altitude: " << ralt  );
-    snap_shot();
-    lsic->SetRunwayAltitudeFtIC(ralt);
-    set_ls();
-    copy_from_LaRCsim(); //update the bus
-}
-
 void FGLaRCsim::set_AltitudeAGL(double altagl) {
     SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_AltitudeAGL: " << altagl  );
     snap_shot();
@@ -703,6 +707,7 @@ void FGLaRCsim::set_AltitudeAGL(double altagl) {
     copy_from_LaRCsim();
 }
 
+/*  getting a namespace conflict...
 void FGLaRCsim::set_Velocities_Local_Airmass (double wnorth, 
                                              double weast, 
                                              double wdown ) {
@@ -713,6 +718,7 @@ void FGLaRCsim::set_Velocities_Local_Airmass (double wnorth,
     set_ls();
     copy_from_LaRCsim();
 }
+*/
 
 void FGLaRCsim::set_Static_pressure(double p) { 
     SG_LOG( SG_FLIGHT, SG_INFO,