diff --git a/ArduPlane/commands_logic.cpp b/ArduPlane/commands_logic.cpp index 8e0819f0b4..6912dfc569 100644 --- a/ArduPlane/commands_logic.cpp +++ b/ArduPlane/commands_logic.cpp @@ -1074,5 +1074,9 @@ bool Plane::verify_loiter_heading(bool init) return true; } - return plane.mode_loiter.headingLinedUp(init, next_WP_loc, next_nav_cmd.content.location); + if (init) { + loiter.sum_cd = 0; + } + + return plane.mode_loiter.headingLinedUp(next_WP_loc, next_nav_cmd.content.location); } diff --git a/ArduPlane/mode.h b/ArduPlane/mode.h index 7b03492a75..8810c7fa4a 100644 --- a/ArduPlane/mode.h +++ b/ArduPlane/mode.h @@ -173,7 +173,7 @@ public: // methods that affect movement of the vehicle in this mode void update() override; - bool headingLinedUp(const bool init, const Location loiterCenterLoc, const Location targetLoc); + bool headingLinedUp(const Location loiterCenterLoc, const Location targetLoc); protected: diff --git a/ArduPlane/mode_loiter.cpp b/ArduPlane/mode_loiter.cpp index 9906e4aa92..e09e91abb6 100644 --- a/ArduPlane/mode_loiter.cpp +++ b/ArduPlane/mode_loiter.cpp @@ -7,6 +7,7 @@ bool ModeLoiter::_enter() plane.auto_throttle_mode = true; plane.auto_navigation_mode = true; plane.do_loiter_at_location(); + plane.loiter_angle_reset(); #if SOARING_ENABLED == ENABLED if (plane.g2.soaring_controller.is_active() && plane.g2.soaring_controller.suppress_throttle()) { @@ -25,7 +26,7 @@ void ModeLoiter::update() plane.calc_throttle(); } -bool ModeLoiter::headingLinedUp(const bool init, const Location loiterCenterLoc, const Location targetLoc) +bool ModeLoiter::headingLinedUp(const Location loiterCenterLoc, const Location targetLoc) { const uint16_t loiterRadius = abs(plane.aparm.loiter_radius); if (loiterCenterLoc.get_distance(targetLoc) < loiterRadius + loiterRadius*0.05) { @@ -44,10 +45,6 @@ bool ModeLoiter::headingLinedUp(const bool init, const Location loiterCenterLoc, const int32_t heading_err_cd = wrap_180_cd(bearing_cd - heading_cd); - if (init) { - plane.loiter.sum_cd = 0; - } - /* Check to see if the the plane is heading toward the land waypoint. We use 20 degrees (+/-10 deg) of margin so that diff --git a/ArduPlane/soaring.cpp b/ArduPlane/soaring.cpp index 503a9855c6..cbfc9b65bc 100644 --- a/ArduPlane/soaring.cpp +++ b/ArduPlane/soaring.cpp @@ -79,7 +79,7 @@ void Plane::update_soaring() { switch (loiterStatus) { case SoaringController::LoiterStatus::ALT_TOO_HIGH: { const bool homeIsSet = AP::ahrs().home_is_set(); - const bool headingLinedupToHome = homeIsSet && plane.mode_loiter.headingLinedUp(false, next_WP_loc, AP::ahrs().get_home()); + const bool headingLinedupToHome = homeIsSet && plane.mode_loiter.headingLinedUp(next_WP_loc, AP::ahrs().get_home()); if (!homeIsSet || headingLinedupToHome) { gcs().send_text(MAV_SEVERITY_INFO, "%s%s", strTooHigh, mode_fbwb.name()); set_mode(mode_fbwb, ModeReason::SOARING_ALT_TOO_HIGH); @@ -137,7 +137,7 @@ void Plane::update_soaring() { //Get the lat/lon of next Nav waypoint after this one: AP_Mission::Mission_Command next_nav_cmd; const bool nextWpisValid = mission.get_next_nav_cmd(mission.get_current_nav_index() + 1, next_nav_cmd); - const bool headingLinedupToWP = nextWpisValid && plane.mode_loiter.headingLinedUp(false, next_WP_loc, next_nav_cmd.content.location); + const bool headingLinedupToWP = nextWpisValid && plane.mode_loiter.headingLinedUp(next_WP_loc, next_nav_cmd.content.location); if (!nextWpisValid || headingLinedupToWP) { gcs().send_text(MAV_SEVERITY_INFO, "%s%s", strTooWeak, mode_auto.name()); set_mode(mode_auto, ModeReason::SOARING_THERMAL_ESTIMATE_DETERIORATED);