]> git.mxchange.org Git - flightgear.git/blobdiff - src/Autopilot/newauto.cxx
Default to glider again when model is not present.
[flightgear.git] / src / Autopilot / newauto.cxx
index fb9a37814f4f9b5ffb5b04b751c6c542cca47732..ccbf01cb4ee324aac7f00ffa40f929f7f4806cd8 100644 (file)
 #endif
 
 #include <stdio.h>             // sprintf()
+#include <string.h>            // strcmp()
 
 #include <simgear/constants.h>
 #include <simgear/sg_inlines.h>
 #include <simgear/debug/logstream.hxx>
 #include <simgear/math/sg_geodesy.hxx>
 #include <simgear/math/sg_random.h>
+#include <simgear/route/route.hxx>
 
 #include <Cockpit/steam.hxx>
 #include <Cockpit/radiostack.hxx>
@@ -254,6 +256,7 @@ void FGAutopilot::init ()
     altitude_hold = false ;     // turn the altitude hold off
     auto_throttle = false ;    // turn the auto throttle off
     heading_mode = DEFAULT_AP_HEADING_LOCK;
+    altitude_mode = DEFAULT_AP_ALTITUDE_LOCK;
 
     DGTargetHeading = fgGetDouble("/autopilot/settings/heading-bug-deg");
     TargetHeading = fgGetDouble("/autopilot/settings/heading-bug-deg");
@@ -375,7 +378,7 @@ void FGAutopilot::reset() {
        
     update_old_control_values();
 
-    sprintf( NewTgtAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
+    sprintf( NewTgtAirportId, "%s", fgGetString("/sim/startup/airport-id") );
        
     MakeTargetLatLonStr( get_TargetLatitude(), get_TargetLongitude() );
 }
@@ -418,7 +421,7 @@ static double LinearExtrapolate( double x, double x1, double y1, double x2, doub
 
 
 void
-FGAutopilot::update (int dt)
+FGAutopilot::update (double dt)
 {
     // Remove the following lines when the calling funcitons start
     // passing in the data pointer
@@ -594,8 +597,10 @@ FGAutopilot::update (int dt)
            // figure out how far off we are from desired heading
 
            // Now it is time to deterime how far we should be rolled.
-           SG_LOG( SG_AUTOPILOT, SG_DEBUG, "RelHeading: " << RelHeading );
-
+           SG_LOG( SG_AUTOPILOT, SG_DEBUG,
+                    "Heading = " << heading_node->getDoubleValue() <<
+                    " TargetHeading = " << TargetHeading <<
+                    " RelHeading = " << RelHeading );
 
            // Check if we are further from heading than the roll out point
            if ( fabs( RelHeading ) > RollOut ) {
@@ -905,7 +910,7 @@ void FGAutopilot::set_AltitudeMode( fgAutoAltitudeMode mode ) {
              * SG_FEET_TO_METER ) {
        }
 
-       if ( fgGetString("/sim/startup/units") == "feet" ) {
+       if ( !strcmp(fgGetString("/sim/startup/units"), "feet") ) {
            MakeTargetAltitudeStr( TargetAltitude * SG_METER_TO_FEET );
        } else {
            MakeTargetAltitudeStr( TargetAltitude * SG_METER_TO_FEET );
@@ -916,7 +921,7 @@ void FGAutopilot::set_AltitudeMode( fgAutoAltitudeMode mode ) {
     } else if ( altitude_mode == FG_ALTITUDE_TERRAIN ) {
        TargetAGL = altitude_agl_node->getDoubleValue() * SG_FEET_TO_METER;
 
-       if ( fgGetString("/sim/startup/units") == "feet" ) {
+       if ( !strcmp(fgGetString("/sim/startup/units"), "feet") ) {
            MakeTargetAltitudeStr( TargetAGL * SG_METER_TO_FEET );
        } else {
            MakeTargetAltitudeStr( TargetAGL * SG_METER_TO_FEET );
@@ -931,18 +936,18 @@ void FGAutopilot::set_AltitudeMode( fgAutoAltitudeMode mode ) {
 void FGAutopilot::AltitudeSet( double new_altitude ) {
     double target_alt = new_altitude;
 
-    if ( fgGetString("/sim/startup/units") == "feet" ) {
+    if ( !strcmp(fgGetString("/sim/startup/units"), "feet") ) {
        target_alt = new_altitude * SG_FEET_TO_METER;
     }
 
-    if( target_alt < scenery.get_cur_elev() ) {
-       target_alt = scenery.get_cur_elev();
+    if( target_alt < globals->get_scenery()->get_cur_elev() ) {
+       target_alt = globals->get_scenery()->get_cur_elev();
     }
 
     TargetAltitude = target_alt;
     altitude_mode = FG_ALTITUDE_LOCK;
 
-    if ( fgGetString("/sim/startup/units") == "feet" ) {
+    if ( !strcmp(fgGetString("/sim/startup/units"), "feet") ) {
        target_alt *= SG_METER_TO_FEET;
     }
     // ApAltitudeDialogInput->setValue((float)target_alt);
@@ -956,7 +961,7 @@ void FGAutopilot::AltitudeAdjust( double inc )
 {
     double target_alt, target_agl;
 
-    if ( fgGetString("/sim/startup/units") == "feet" ) {
+    if ( !strcmp(fgGetString("/sim/startup/units"), "feet") ) {
        target_alt = TargetAltitude * SG_METER_TO_FEET;
        target_agl = TargetAGL * SG_METER_TO_FEET;
     } else {
@@ -976,7 +981,7 @@ void FGAutopilot::AltitudeAdjust( double inc )
        target_agl = ( int ) ( target_agl / inc ) * inc + inc;
     }
 
-    if ( fgGetString("/sim/startup/units") == "feet" ) {
+    if ( !strcmp(fgGetString("/sim/startup/units"), "feet") ) {
        target_alt *= SG_FEET_TO_METER;
        target_agl *= SG_FEET_TO_METER;
     }
@@ -984,9 +989,9 @@ void FGAutopilot::AltitudeAdjust( double inc )
     TargetAltitude = target_alt;
     TargetAGL = target_agl;
        
-    if ( fgGetString("/sim/startup/units") == "feet" )
+    if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
        target_alt *= SG_METER_TO_FEET;
-    if ( fgGetString("/sim/startup/units") == "feet" )
+    if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
        target_agl *= SG_METER_TO_FEET;
 
     if ( altitude_mode == FG_ALTITUDE_LOCK ) {