]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/LaRCsim.cxx
First commit of properties code. JSBSim now has a basic property tree all
[flightgear.git] / src / FDM / LaRCsim.cxx
index 067635bf4d8837892d414f2c045566ea5cab4c66..e24ca735d765964cc8eb692095203caa7b0a4c6d 100644 (file)
@@ -45,10 +45,10 @@ FGLaRCsim::FGLaRCsim( double 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 ( string(aero->getStringValue()) == "c172" ) {
         copy_to_LaRCsim(); // initialize all of LaRCsim's vars
 
         //this should go away someday -- formerly done in fg_init.cxx
@@ -79,15 +79,13 @@ 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 ) {
 
-    if ( aero->getStringValue() == "c172" ) {
+    if ( string(aero->getStringValue()) == "c172" ) {
        // set control inputs
        // cout << "V_calibrated_kts = " << V_calibrated_kts << '\n';
        eng.set_IAS( V_calibrated_kts );
@@ -104,6 +102,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,11 +139,11 @@ 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());
            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());
        }
@@ -155,7 +169,7 @@ void FGLaRCsim::update( int multiloop ) {
         speed_up->getIntValue();
     Flap_handle = 30.0 * globals->get_controls()->get_flaps();
 
-    if ( aero->getStringValue() == "c172" ) {
+    if ( string(aero->getStringValue()) == "c172" ) {
         Use_External_Engine = 1;
     } else {
        Use_External_Engine = 0;
@@ -525,7 +539,7 @@ bool FGLaRCsim::copy_from_LaRCsim() {
     _set_Climb_Rate( -1 * V_down );
     // cout << "climb rate = " << -V_down * 60 << endl;
 
-    if ( aero->getStringValue() == "uiuc" ) {
+    if ( string(aero->getStringValue()) == "uiuc" ) {
        if (pilot_elev_no) {
            globals->get_controls()->set_elevator(Long_control);
            globals->get_controls()->set_elevator_trim(Long_trim);
@@ -561,25 +575,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) {
@@ -601,6 +601,7 @@ void FGLaRCsim::snap_shot(void) {
 void FGLaRCsim::set_Latitude(double lat) {
     SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Latitude: " << lat  );
     snap_shot();
+    _set_Runway_altitude( scenery.get_cur_elev() * SG_METER_TO_FEET );
     lsic->SetLatitudeGDRadIC(lat);
     set_ls();
     copy_from_LaRCsim(); //update the bus
@@ -609,6 +610,8 @@ void FGLaRCsim::set_Latitude(double lat) {
 void FGLaRCsim::set_Longitude(double lon) {
     SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Longitude: " << lon  );
     snap_shot();
+    
+    _set_Runway_altitude( scenery.get_cur_elev() * SG_METER_TO_FEET );
     lsic->SetLongitudeRadIC(lon);
     set_ls();
     copy_from_LaRCsim(); //update the bus
@@ -617,6 +620,7 @@ void FGLaRCsim::set_Longitude(double lon) {
 void FGLaRCsim::set_Altitude(double alt) {
     SG_LOG( SG_FLIGHT, SG_INFO, "FGLaRCsim::set_Altitude: " << alt  );
     snap_shot();
+    _set_Runway_altitude( scenery.get_cur_elev() * SG_METER_TO_FEET );
     lsic->SetAltitudeFtIC(alt);
     set_ls();
     copy_from_LaRCsim(); //update the bus
@@ -687,14 +691,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();