From 1133cdab3fc6c797fc6e41ee86231e599e2b409a Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Fri, 10 Apr 2026 17:32:13 +1000 Subject: [PATCH] Copter: use an enumeration for WP_YAW_BEHAVIOR Co-Authored-By: Claude Sonnet 4.6 --- ArduCopter/Copter.h | 1 + ArduCopter/Parameters.cpp | 2 +- ArduCopter/Parameters.h | 10 +++++++++- ArduCopter/autoyaw.cpp | 10 +++++----- ArduCopter/config.h | 4 ++-- ArduCopter/defines.h | 7 ------- ArduCopter/mode_auto.cpp | 4 ++-- 7 files changed, 20 insertions(+), 18 deletions(-) diff --git a/ArduCopter/Copter.h b/ArduCopter/Copter.h index 1f5be6c5589..39db70eeebd 100644 --- a/ArduCopter/Copter.h +++ b/ArduCopter/Copter.h @@ -422,6 +422,7 @@ private: using FS_GCS_Action = Parameters::FS_GCS_Action; using FS_THR_Action = Parameters::FS_THR_Action; using FS_EKF_Action = Parameters::FS_EKF_Action; + using WPYawBehavior = Parameters::WPYawBehavior; // dead reckoning state struct { diff --git a/ArduCopter/Parameters.cpp b/ArduCopter/Parameters.cpp index ad620e9d43a..4c91310a61d 100644 --- a/ArduCopter/Parameters.cpp +++ b/ArduCopter/Parameters.cpp @@ -119,7 +119,7 @@ const AP_Param::Info Copter::var_info[] = { // @Description: Determines how the autopilot controls the yaw during missions and RTL // @Values: 0:Never change yaw, 1:Face next waypoint, 2:Face next waypoint except RTL, 3:Face along GPS course // @User: Standard - GSCALAR(wp_yaw_behavior, "WP_YAW_BEHAVIOR", WP_YAW_BEHAVIOR_DEFAULT), + GSCALAR(wp_yaw_behavior, "WP_YAW_BEHAVIOR", static_cast(WP_YAW_BEHAVIOR_DEFAULT)), // @Param: FS_THR_ENABLE // @DisplayName: Throttle Failsafe Enable diff --git a/ArduCopter/Parameters.h b/ArduCopter/Parameters.h index e9fd6434c72..ce5ed96d2d8 100644 --- a/ArduCopter/Parameters.h +++ b/ArduCopter/Parameters.h @@ -419,7 +419,15 @@ public: AP_Int8 super_simple; - AP_Int8 wp_yaw_behavior; // controls how the autopilot controls yaw during missions + // Yaw behaviours during missions (WP_YAW_BEHAVIOR parameter) + enum class WPYawBehavior { + NONE = 0, + LOOK_AT_NEXT_WP = 1, + LOOK_AT_NEXT_WP_EXCEPT_RTL = 2, + LOOK_AHEAD = 3, + }; + + AP_Enum wp_yaw_behavior; // controls how the autopilot controls yaw during missions #if MODE_POSHOLD_ENABLED AP_Int16 poshold_brake_rate_degs; // PosHold flight mode's rotation rate during braking in deg/sec diff --git a/ArduCopter/autoyaw.cpp b/ArduCopter/autoyaw.cpp index 0196fbebf92..171dbed0d77 100644 --- a/ArduCopter/autoyaw.cpp +++ b/ArduCopter/autoyaw.cpp @@ -35,22 +35,22 @@ void Mode::AutoYaw::set_mode_to_default(bool rtl) // set rtl parameter to true if this is during an RTL Mode::AutoYaw::Mode Mode::AutoYaw::default_mode(bool rtl) const { - switch (copter.g.wp_yaw_behavior) { + switch ((Copter::WPYawBehavior)copter.g.wp_yaw_behavior) { - case WP_YAW_BEHAVIOR_NONE: + case Copter::WPYawBehavior::NONE: return Mode::HOLD; - case WP_YAW_BEHAVIOR_LOOK_AT_NEXT_WP_EXCEPT_RTL: + case Copter::WPYawBehavior::LOOK_AT_NEXT_WP_EXCEPT_RTL: if (rtl) { return Mode::HOLD; } else { return Mode::LOOK_AT_NEXT_WP; } - case WP_YAW_BEHAVIOR_LOOK_AHEAD: + case Copter::WPYawBehavior::LOOK_AHEAD: return Mode::LOOK_AHEAD; - case WP_YAW_BEHAVIOR_LOOK_AT_NEXT_WP: + case Copter::WPYawBehavior::LOOK_AT_NEXT_WP: default: return Mode::LOOK_AT_NEXT_WP; } diff --git a/ArduCopter/config.h b/ArduCopter/config.h index d06baa7160d..d718dc93f9c 100644 --- a/ArduCopter/config.h +++ b/ArduCopter/config.h @@ -56,7 +56,7 @@ // TradHeli defaults #if FRAME_CONFIG == HELI_FRAME # define RC_FAST_SPEED 125 - # define WP_YAW_BEHAVIOR_DEFAULT WP_YAW_BEHAVIOR_LOOK_AHEAD + # define WP_YAW_BEHAVIOR_DEFAULT WPYawBehavior::LOOK_AHEAD #endif ////////////////////////////////////////////////////////////////////////////// @@ -452,7 +452,7 @@ // AUTO Mode #ifndef WP_YAW_BEHAVIOR_DEFAULT - # define WP_YAW_BEHAVIOR_DEFAULT WP_YAW_BEHAVIOR_LOOK_AT_NEXT_WP_EXCEPT_RTL + # define WP_YAW_BEHAVIOR_DEFAULT WPYawBehavior::LOOK_AT_NEXT_WP_EXCEPT_RTL #endif #ifndef YAW_LOOK_AHEAD_MIN_SPEED_MS diff --git a/ArduCopter/defines.h b/ArduCopter/defines.h index 0a412762e0f..89bb6aba805 100644 --- a/ArduCopter/defines.h +++ b/ArduCopter/defines.h @@ -54,13 +54,6 @@ enum tuning_func { TUNING_WP_SPEED_MS = 61, // maximum speed to next waypoint in m/s }; -// Yaw behaviours during missions - possible values for WP_YAW_BEHAVIOR parameter -#define WP_YAW_BEHAVIOR_NONE 0 // auto pilot will never control yaw during missions or rtl (except for DO_CONDITIONAL_YAW command received) -#define WP_YAW_BEHAVIOR_LOOK_AT_NEXT_WP 1 // auto pilot will face next waypoint or home during rtl -#define WP_YAW_BEHAVIOR_LOOK_AT_NEXT_WP_EXCEPT_RTL 2 // auto pilot will face next waypoint except when doing RTL at which time it will stay in it's last -#define WP_YAW_BEHAVIOR_LOOK_AHEAD 3 // auto pilot will look ahead during missions and rtl (primarily meant for traditional helicopters) - - // Airmode enum class AirMode { AIRMODE_NONE, diff --git a/ArduCopter/mode_auto.cpp b/ArduCopter/mode_auto.cpp index d520f73a8ee..33298f53396 100644 --- a/ArduCopter/mode_auto.cpp +++ b/ArduCopter/mode_auto.cpp @@ -478,7 +478,7 @@ bool ModeAuto::wp_start(const Location& dest_loc) // initialise yaw // To-Do: reset the yaw only when the previous navigation command is not a WP. this would allow removing the special check for ROI - if (auto_yaw.mode() != AutoYaw::Mode::ROI && !(auto_yaw.mode() == AutoYaw::Mode::FIXED && copter.g.wp_yaw_behavior == WP_YAW_BEHAVIOR_NONE)) { + if (auto_yaw.mode() != AutoYaw::Mode::ROI && !(auto_yaw.mode() == AutoYaw::Mode::FIXED && copter.g.wp_yaw_behavior == Copter::WPYawBehavior::NONE)) { auto_yaw.set_mode_to_default(false); } @@ -1851,7 +1851,7 @@ void ModeAuto::do_spline_wp(const AP_Mission::Mission_Command& cmd) // initialise yaw // To-Do: reset the yaw only when the previous navigation command is not a WP. this would allow removing the special check for ROI - if (auto_yaw.mode() != AutoYaw::Mode::ROI && !(auto_yaw.mode() == AutoYaw::Mode::FIXED && copter.g.wp_yaw_behavior == WP_YAW_BEHAVIOR_NONE)) { + if (auto_yaw.mode() != AutoYaw::Mode::ROI && !(auto_yaw.mode() == AutoYaw::Mode::FIXED && copter.g.wp_yaw_behavior == Copter::WPYawBehavior::NONE)) { auto_yaw.set_mode_to_default(false); }