]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/LaRCsim.cxx
b) FDM - ada.cxx, ada.hxx have been updated with the faux, daux and iaux arrays that...
[flightgear.git] / src / FDM / LaRCsim.cxx
index 2903f92d78b0d7940c6336d6ac243e592a053899..07ebb0ea55852328f0d8190a12eaee2feef1786a 100644 (file)
@@ -34,6 +34,7 @@
 #include <FDM/LaRCsim/ls_generic.h>
 #include <FDM/LaRCsim/ls_interface.h>
 #include <FDM/LaRCsimIC.hxx>
+#include <FDM/UIUCModel/uiuc_aircraft.h>
 
 #include "IO360.hxx"
 #include "LaRCsim.hxx"
 FGLaRCsim::FGLaRCsim( double dt ) {
     set_delta_t( dt );
 
-    ls_toplevel_init( 0.0, 
-                     (char *)fgGetString("/sim/aircraft").c_str() );
-    lsic=new LaRCsimIC; //this needs to be brought up after LaRCsim is
-    copy_to_LaRCsim(); // initialize all of LaRCsim's vars
-    //this should go away someday -- formerly done in fg_init.cxx
-    Mass = 8.547270E+01;
-    I_xx = 1.048000E+03;
-    I_yy = 3.000000E+03;
-    I_zz = 3.530000E+03;
-    I_xz = 0.000000E+00;
-    //current_aircraft.fdm_state->set_Tank1Fuel(15.0);
-    //current_aircraft.fdm_state->set_Tank2Fuel(15.0);
-    //Tank1Fuel = 15.0;
-    //Tank2Fuel = 15.0;
-}
+    speed_up = fgGetNode("/sim/speed-up", true);
+    aircraft = fgGetNode("/sim/aircraft", true);
+    
+    ls_toplevel_init( 0.0, (char *)(aircraft->getStringValue().c_str()) );
 
-FGLaRCsim::~FGLaRCsim(void) {
-    if(lsic != NULL) {
-       delete lsic;
+    lsic=new LaRCsimIC; //this needs to be brought up after LaRCsim is
+    if ( aircraft->getStringValue() == "c172" ) {
+       copy_to_LaRCsim(); // initialize all of LaRCsim's vars
+
+       //this should go away someday -- formerly done in fg_init.cxx
+       Mass = 8.547270E+01;
+       I_xx = 1.048000E+03;
+       I_yy = 3.000000E+03;
+       I_zz = 3.530000E+03;
+       I_xz = 0.000000E+00;
     }
-}    
-
-// Initialize the LaRCsim flight model, dt is the time increment for
-// each subsequent iteration through the EOM
-void FGLaRCsim::init() {
-
-    speed_up = fgGetValue("/sim/speed-up", true);
     
     ls_set_model_dt( get_delta_t() );
-    // Initialize our little engine that hopefully might
+    
+               // Initialize our little engine that hopefully might
     eng.init( get_delta_t() );
     // 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)
@@ -86,44 +77,38 @@ void FGLaRCsim::init() {
     set_Tank1Fuel(28.0);
     set_Tank2Fuel(28.0);  
 
-    // FG_LOG( FG_FLIGHT, FG_INFO, "FGLaRCsim::init()"  );
 
-    double save_alt = 0.0;
+}
 
-    if ( get_Altitude() < -9000.0 ) {
-       save_alt = get_Altitude();
-       set_Altitude( 0.0 );
+FGLaRCsim::~FGLaRCsim(void) {
+    if ( lsic != NULL ) {
+       delete lsic;
+       lsic = NULL;
     }
+}    
 
-    // translate FG to LaRCsim structure
-    copy_to_LaRCsim();
-
-    // actual LaRCsim top level init
-    // ls_toplevel_init( dt, (char *)fgGetString("/sim/aircraft").c_str() );
-
-    FG_LOG( FG_FLIGHT, FG_INFO, "FG pos = " << 
-           get_Latitude() );
-
-    // translate LaRCsim back to FG structure
-    copy_from_LaRCsim();
+// Initialize the LaRCsim flight model, dt is the time increment for
+// each subsequent iteration through the EOM
+void FGLaRCsim::init() {
 
-    // but lets restore our original bogus altitude when we are done
-    if ( save_alt < -9000.0 ) {
-       set_Altitude( save_alt );
-    }
+               // Explicitly call the superclass's
+                               // init method first.
+    FGInterface::init();
 }
 
 
 // Run an iteration of the EOM (equations of motion)
 bool FGLaRCsim::update( int multiloop ) {
 
-    if ( fgGetString("/sim/aircraft") == "c172" ) {
+    if ( aircraft->getStringValue() == "c172" ) {
        // set control inputs
        // cout << "V_calibrated_kts = " << V_calibrated_kts << '\n';
        eng.set_IAS( V_calibrated_kts );
-       eng.set_Throttle_Lever_Pos( controls.get_throttle( 0 ) * 100.0 );
+       eng.set_Throttle_Lever_Pos( globals->get_controls()->get_throttle( 0 )
+                                   * 100.0 );
        eng.set_Propeller_Lever_Pos( 100 );
-        eng.set_Mixture_Lever_Pos( controls.get_mixture( 0 ) * 100.0 );
+        eng.set_Mixture_Lever_Pos( globals->get_controls()->get_mixture( 0 )
+                                  * 100.0 );
        eng.set_p_amb( Static_pressure );
        eng.set_T_amb( Static_temperature );
 
@@ -132,7 +117,7 @@ bool FGLaRCsim::update( int multiloop ) {
 
        // copy engine state values onto "bus"
        FGEngInterface *e = get_engine( 0 );
-       e->set_Throttle( controls.get_throttle( 0 ) * 100.0 );
+       e->set_Throttle( globals->get_controls()->get_throttle( 0 ) * 100.0 );
        e->set_Mixture( 80 );
        e->set_Prop_Advance( 100 );
        e->set_RPM( eng.get_RPM() );
@@ -151,17 +136,17 @@ bool FGLaRCsim::update( int multiloop ) {
                          * get_delta_t() ); 
 
 #if 0
-       FG_LOG( FG_FLIGHT, FG_INFO, "Throttle = "
-               << controls.get_throttle( 0 ) * 100.0);
-       FG_LOG( FG_FLIGHT, FG_INFO, " Mixture = " << 80);
-       FG_LOG( FG_FLIGHT, FG_INFO, " RPM = " << eng.get_RPM());
-       FG_LOG( FG_FLIGHT, FG_INFO, " MP = " << eng.get_Manifold_Pressure());
-       FG_LOG( FG_FLIGHT, FG_INFO, " HP = "
+       SG_LOG( SG_FLIGHT, SG_INFO, "Throttle = "
+               << globals->get_controls()->get_throttle( 0 ) * 100.0);
+       SG_LOG( SG_FLIGHT, SG_INFO, " Mixture = " << 80);
+       SG_LOG( SG_FLIGHT, SG_INFO, " RPM = " << eng.get_RPM());
+       SG_LOG( SG_FLIGHT, SG_INFO, " MP = " << eng.get_Manifold_Pressure());
+       SG_LOG( SG_FLIGHT, SG_INFO, " HP = "
                << ( eng.get_MaxHP() * eng.get_Percentage_Power()/ 100.0) );
-       FG_LOG( FG_FLIGHT, FG_INFO, " EGT = " << eng.get_EGT());
-       FG_LOG( FG_FLIGHT, FG_INFO, " Thrust (N) "
+       SG_LOG( SG_FLIGHT, SG_INFO, " EGT = " << eng.get_EGT());
+       SG_LOG( SG_FLIGHT, SG_INFO, " Thrust (N) "
                << eng.get_prop_thrust_SI());   // Thrust in Newtons
-       FG_LOG( FG_FLIGHT, FG_INFO, '\n');
+       SG_LOG( SG_FLIGHT, SG_INFO, '\n');
 #endif
         F_X_engine = eng.get_prop_thrust_lbs();
        // cout << "F_X_engine = " << F_X_engine << '\n';
@@ -176,28 +161,28 @@ bool FGLaRCsim::update( int multiloop ) {
     }
 
     // copy control positions into the LaRCsim structure
-    Lat_control = controls.get_aileron() /
+    Lat_control = globals->get_controls()->get_aileron() /
        speed_up->getIntValue();
-    Long_control = controls.get_elevator();
-    Long_trim = controls.get_elevator_trim();
-    Rudder_pedal = controls.get_rudder() /
+    Long_control = globals->get_controls()->get_elevator();
+    Long_trim = globals->get_controls()->get_elevator_trim();
+    Rudder_pedal = globals->get_controls()->get_rudder() /
         speed_up->getIntValue();
-    Flap_handle = 30.0 * controls.get_flaps();
+    Flap_handle = 30.0 * globals->get_controls()->get_flaps();
 
-    if ( fgGetString("/sim/aircraft") == "c172" ) {
+    if ( aircraft->getStringValue() == "c172" ) {
        Use_External_Engine = 1;
     } else {
        Use_External_Engine = 0;
     }
 
-    Throttle_pct = controls.get_throttle( 0 ) * 1.0;
+    Throttle_pct = globals->get_controls()->get_throttle( 0 ) * 1.0;
 
-    Brake_pct[0] = controls.get_brake( 1 );
-    Brake_pct[1] = controls.get_brake( 0 );
+    Brake_pct[0] = globals->get_controls()->get_brake( 1 );
+    Brake_pct[1] = globals->get_controls()->get_brake( 0 );
 
     // Inform LaRCsim of the local terrain altitude
     // Runway_altitude = get_Runway_altitude();
-    Runway_altitude = scenery.cur_elev * METER_TO_FEET;
+    Runway_altitude = scenery.cur_elev * SG_METER_TO_FEET;
 
     // Weather
     /* V_north_airmass = get_V_north_airmass();
@@ -468,7 +453,7 @@ bool FGLaRCsim::copy_from_LaRCsim() {
 
     _set_Mach_number( Mach_number );
 
-    FG_LOG( FG_FLIGHT, FG_DEBUG, "lon = " << Longitude 
+    SG_LOG( SG_FLIGHT, SG_DEBUG, "lon = " << Longitude 
            << " lat_geoc = " << Lat_geocentric << " lat_geod = " << Latitude 
            << " alt = " << Altitude << " sl_radius = " << Sea_level_radius 
            << " radius_to_vehicle = " << Radius_to_vehicle );
@@ -487,7 +472,7 @@ bool FGLaRCsim::copy_from_LaRCsim() {
     _set_Geodetic_Position( Latitude, tmp_lon, Altitude );
     _set_Euler_Angles( Phi, Theta, Psi );
 
-    _set_Altitude_AGL( Altitude-Runway_altitude );
+    _set_Altitude_AGL( Altitude - Runway_altitude );
 
     // Miscellaneous quantities
     _set_T_Local_to_Body(T_local_to_body_m);
@@ -554,6 +539,28 @@ bool FGLaRCsim::copy_from_LaRCsim() {
     //        get_sin_longitude(), get_cos_longitude());
 
     _set_Climb_Rate( -1 * V_down );
+    // cout << "climb rate = " << -V_down * 60 << endl;
+
+    if ( aircraft->getStringValue() == "uiuc" ) {
+       if (pilot_elev_no) {
+           globals->get_controls()->set_elevator(Long_control);
+           globals->get_controls()->set_elevator_trim(Long_trim);
+           //      controls.set_elevator(Long_control);
+           //      controls.set_elevator_trim(Long_trim);
+        }
+       if (pilot_ail_no) {
+            globals->get_controls()->set_aileron(Lat_control);
+            //   controls.set_aileron(Lat_control);
+        }
+       if (pilot_rud_no) {
+            globals->get_controls()->set_rudder(Rudder_pedal);
+            //   controls.set_rudder(Rudder_pedal);
+        }
+       if (Throttle_pct_input) {
+            globals->get_controls()->set_throttle(0,Throttle_pct);
+            //   controls.set_throttle(0,Throttle_pct);
+        }
+    }
 
     return true;
 }
@@ -575,20 +582,20 @@ void FGLaRCsim::set_ls(void) {
     V_down_airmass = lsic->GetVdownAirmassFpsIC();
     ls_loop(0.0,-1);
     copy_from_LaRCsim();
-    FG_LOG( FG_FLIGHT, FG_INFO, "  FGLaRCsim::set_ls(): "  );
-    FG_LOG( FG_FLIGHT, FG_INFO, "     Phi: " <<  Phi  );
-    FG_LOG( FG_FLIGHT, FG_INFO, "     Theta: " <<  Theta  );
-    FG_LOG( FG_FLIGHT, FG_INFO, "     Psi: " <<  Psi  );
-    FG_LOG( FG_FLIGHT, FG_INFO, "     V_north: " <<  V_north  );
-    FG_LOG( FG_FLIGHT, FG_INFO, "     V_east: " <<  V_east  );
-    FG_LOG( FG_FLIGHT, FG_INFO, "     V_down: " <<  V_down  );
-    FG_LOG( FG_FLIGHT, FG_INFO, "     Altitude: " <<  Altitude  );
-    FG_LOG( FG_FLIGHT, FG_INFO, "     Latitude: " <<  Latitude  );
-    FG_LOG( FG_FLIGHT, FG_INFO, "     Longitude: " <<  Longitude  );
-    FG_LOG( FG_FLIGHT, FG_INFO, "     Runway_altitude: " <<  Runway_altitude  );
-    FG_LOG( FG_FLIGHT, FG_INFO, "     V_north_airmass: " <<  V_north_airmass  );
-    FG_LOG( FG_FLIGHT, FG_INFO, "     V_east_airmass: " <<  V_east_airmass  );
-    FG_LOG( FG_FLIGHT, FG_INFO, "     V_down_airmass: " <<  V_down_airmass  );
+    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) {
@@ -608,7 +615,7 @@ void FGLaRCsim::snap_shot(void) {
 
 //Positions
 void FGLaRCsim::set_Latitude(double lat) {
-    FG_LOG( FG_FLIGHT, FG_INFO, "FGLaRCsim::set_Latitude: " << lat  );
+    SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Latitude: " << lat  );
     snap_shot();
     lsic->SetLatitudeGDRadIC(lat);
     set_ls();
@@ -616,7 +623,7 @@ void FGLaRCsim::set_Latitude(double lat) {
 }  
 
 void FGLaRCsim::set_Longitude(double lon) {
-    FG_LOG( FG_FLIGHT, FG_INFO, "FGLaRCsim::set_Longitude: " << lon  );
+    SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Longitude: " << lon  );
     snap_shot();
     lsic->SetLongitudeRadIC(lon);
     set_ls();
@@ -624,7 +631,7 @@ void FGLaRCsim::set_Longitude(double lon) {
 }  
 
 void FGLaRCsim::set_Altitude(double alt) {
-    FG_LOG( FG_FLIGHT, FG_INFO, "FGLaRCsim::set_Altitude: " << alt  );
+    SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Altitude: " << alt  );
     snap_shot();
     lsic->SetAltitudeFtIC(alt);
     set_ls();
@@ -632,7 +639,7 @@ void FGLaRCsim::set_Altitude(double alt) {
 }
 
 void FGLaRCsim::set_V_calibrated_kts(double vc) {
-    FG_LOG( FG_FLIGHT, FG_INFO, 
+    SG_LOG( SG_FLIGHT, SG_INFO, 
            "FGLaRCsim::set_V_calibrated_kts: " << vc  );
     snap_shot();
     lsic->SetVcalibratedKtsIC(vc);
@@ -641,7 +648,7 @@ void FGLaRCsim::set_V_calibrated_kts(double vc) {
 }  
 
 void FGLaRCsim::set_Mach_number(double mach) {
-    FG_LOG( FG_FLIGHT, FG_INFO, "FGLaRCsim::set_Mach_number: " << mach  );
+    SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Mach_number: " << mach  );
     snap_shot();
     lsic->SetMachIC(mach);
     set_ls();
@@ -649,7 +656,7 @@ void FGLaRCsim::set_Mach_number(double mach) {
 }  
 
 void FGLaRCsim::set_Velocities_Local( double north, double east, double down ){
-    FG_LOG( FG_FLIGHT, FG_INFO, "FGLaRCsim::set_Velocities_local: " 
+    SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Velocities_local: " 
            << north << "  " << east << "  " << down   );
     snap_shot();
     lsic->SetVNEDFpsIC(north, east, down);
@@ -658,7 +665,7 @@ void FGLaRCsim::set_Velocities_Local( double north, double east, double down ){
 }  
 
 void FGLaRCsim::set_Velocities_Wind_Body( double u, double v, double w){
-    FG_LOG( FG_FLIGHT, FG_INFO, "FGLaRCsim::set_Velocities_Wind_Body: " 
+    SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Velocities_Wind_Body: " 
            << u << "  " << v << "  " << w   );
     snap_shot();
     lsic->SetUVWFpsIC(u,v,w);
@@ -668,7 +675,7 @@ void FGLaRCsim::set_Velocities_Wind_Body( double u, double v, double w){
 
 //Euler angles 
 void FGLaRCsim::set_Euler_Angles( double phi, double theta, double psi ) {
-    FG_LOG( FG_FLIGHT, FG_INFO, "FGLaRCsim::set_Euler_angles: " 
+    SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Euler_angles: " 
            << phi << "  " << theta << "  " << psi   );
 
     snap_shot();
@@ -681,7 +688,7 @@ void FGLaRCsim::set_Euler_Angles( double phi, double theta, double psi ) {
 
 //Flight Path
 void FGLaRCsim::set_Climb_Rate( double roc) {
-    FG_LOG( FG_FLIGHT, FG_INFO, "FGLaRCsim::set_Climb_rate: " << roc  );
+    SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Climb_rate: " << roc  );
     snap_shot();
     lsic->SetClimbRateFpsIC(roc);
     set_ls();
@@ -689,7 +696,7 @@ void FGLaRCsim::set_Climb_Rate( double roc) {
 }  
 
 void FGLaRCsim::set_Gamma_vert_rad( double gamma) {
-    FG_LOG( FG_FLIGHT, FG_INFO, "FGLaRCsim::set_Gamma_vert_rad: " << gamma  );
+    SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Gamma_vert_rad: " << gamma  );
     snap_shot();
     lsic->SetFlightPathAngleRadIC(gamma);
     set_ls();
@@ -697,7 +704,7 @@ void FGLaRCsim::set_Gamma_vert_rad( double gamma) {
 }  
 
 void FGLaRCsim::set_Runway_altitude(double ralt) {
-    FG_LOG( FG_FLIGHT, FG_INFO, "FGLaRCsim::set_Runway_altitude: " << ralt  );
+    SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Runway_altitude: " << ralt  );
     snap_shot();
     lsic->SetRunwayAltitudeFtIC(ralt);
     set_ls();
@@ -705,7 +712,7 @@ void FGLaRCsim::set_Runway_altitude(double ralt) {
 } 
 
 void FGLaRCsim::set_AltitudeAGL(double altagl) {
-    FG_LOG( FG_FLIGHT, FG_INFO, "FGLaRCsim::set_AltitudeAGL: " << altagl  );
+    SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_AltitudeAGL: " << altagl  );
     snap_shot();
     lsic->SetAltitudeAGLFtIC(altagl);
     set_ls();
@@ -715,7 +722,7 @@ void FGLaRCsim::set_AltitudeAGL(double altagl) {
 void FGLaRCsim::set_Velocities_Local_Airmass (double wnorth, 
                                              double weast, 
                                              double wdown ) {
-    FG_LOG( FG_FLIGHT, FG_INFO, "FGLaRCsim::set_Velocities_Local_Airmass: " 
+    SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Velocities_Local_Airmass: " 
            << wnorth << "  " << weast << "  " << wdown );
     snap_shot();
     lsic->SetVNEDAirmassFpsIC( wnorth, weast, wdown );
@@ -724,23 +731,23 @@ void FGLaRCsim::set_Velocities_Local_Airmass (double wnorth,
 }     
 
 void FGLaRCsim::set_Static_pressure(double p) { 
-    FG_LOG( FG_FLIGHT, FG_INFO, 
+    SG_LOG( SG_FLIGHT, SG_INFO, 
            "FGLaRCsim::set_Static_pressure: " << p  );
-    FG_LOG( FG_FLIGHT, FG_INFO, 
+    SG_LOG( SG_FLIGHT, SG_INFO, 
            "LaRCsim does not support externally supplied atmospheric data" );
 }
 
 void FGLaRCsim::set_Static_temperature(double T) { 
-    FG_LOG( FG_FLIGHT, FG_INFO, 
+    SG_LOG( SG_FLIGHT, SG_INFO, 
            "FGLaRCsim::set_Static_temperature: " << T  );
-    FG_LOG( FG_FLIGHT, FG_INFO, 
+    SG_LOG( SG_FLIGHT, SG_INFO, 
            "LaRCsim does not support externally supplied atmospheric data" );
 
 }
 
 void FGLaRCsim::set_Density(double rho) { 
-    FG_LOG( FG_FLIGHT, FG_INFO, "FGLaRCsim::set_Density: " << rho  );
-    FG_LOG( FG_FLIGHT, FG_INFO, 
+    SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Density: " << rho  );
+    SG_LOG( SG_FLIGHT, SG_INFO, 
            "LaRCsim does not support externally supplied atmospheric data" );
 
 }