diff --git a/ArduCopter/Parameters.h b/ArduCopter/Parameters.h index 32f3a28e88..2f78f8604c 100644 --- a/ArduCopter/Parameters.h +++ b/ArduCopter/Parameters.h @@ -407,7 +407,7 @@ public: AP_Int16 rtl_alt_final; AP_Int16 rtl_climb_min; // rtl minimum climb in cm AP_Int32 rtl_loiter_time; - AP_Int8 rtl_alt_type; + AP_Enum rtl_alt_type; #endif AP_Int8 failsafe_gcs; // ground station failsafe behavior diff --git a/ArduCopter/mode.h b/ArduCopter/mode.h index a6dcda9c85..6ad1deffde 100644 --- a/ArduCopter/mode.h +++ b/ArduCopter/mode.h @@ -1338,7 +1338,7 @@ public: void restart_without_terrain(); // enum for RTL_ALT_TYPE parameter - enum class RTLAltType { + enum class RTLAltType : int8_t { RTL_ALTTYPE_RELATIVE = 0, RTL_ALTTYPE_TERRAIN = 1 }; diff --git a/ArduCopter/mode_rtl.cpp b/ArduCopter/mode_rtl.cpp index 4718bd7421..fc08b39b19 100644 --- a/ArduCopter/mode_rtl.cpp +++ b/ArduCopter/mode_rtl.cpp @@ -49,10 +49,12 @@ void ModeRTL::restart_without_terrain() ModeRTL::RTLAltType ModeRTL::get_alt_type() const { // sanity check parameter - if (g.rtl_alt_type < 0 || g.rtl_alt_type > (int)RTLAltType::RTL_ALTTYPE_TERRAIN) { - return RTLAltType::RTL_ALTTYPE_RELATIVE; + switch ((ModeRTL::RTLAltType)g.rtl_alt_type) { + case RTLAltType::RTL_ALTTYPE_RELATIVE ... RTLAltType::RTL_ALTTYPE_TERRAIN: + return g.rtl_alt_type; } - return (RTLAltType)g.rtl_alt_type.get(); + // user has an invalid value + return RTLAltType::RTL_ALTTYPE_RELATIVE; } // rtl_run - runs the return-to-launch controller