-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Corrrect SmartRTL internal error by preserving home srtl point #17419
Open
peterbarker
wants to merge
3
commits into
ArduPilot:master
Choose a base branch
from
peterbarker:pr/smartrtl-alt-hold-fix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+61
−32
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,7 +74,7 @@ void ModeSmartRTL::wait_cleanup_run() | |
|
||
// check if return path is computed and if yes, begin journey home | ||
if (g2.smart_rtl.request_thorough_cleanup()) { | ||
path_follow_last_pop_fail_ms = 0; | ||
path_follow_last_semtake_fail_ms = 0; | ||
smart_rtl_state = SubMode::PATH_FOLLOW; | ||
} | ||
} | ||
|
@@ -83,42 +83,45 @@ void ModeSmartRTL::path_follow_run() | |
{ | ||
// if we are close to current target point, switch the next point to be our target. | ||
if (wp_nav->reached_wp_destination()) { | ||
Vector3f dest_NED; | ||
// this pop_point can fail if the IO task currently has the | ||
// path semaphore. | ||
if (g2.smart_rtl.pop_point(dest_NED)) { | ||
path_follow_last_pop_fail_ms = 0; | ||
if (g2.smart_rtl.get_num_points() == 0) { | ||
// this is the very last point, add 2m to the target alt and move to pre-land state | ||
dest_NED.z -= 2.0f; | ||
HAL_Semaphore &sem = g2.smart_rtl.path_semaphore(); | ||
if (sem.take_nonblocking()) { | ||
Vector3f dest_NED; | ||
const uint32_t num_points = g2.smart_rtl.get_num_points(); | ||
if (num_points == 0) { | ||
// we don't even have a home point set in | ||
// SmartRTL... how did we manage to get here? | ||
INTERNAL_ERROR(AP_InternalError::error_t::flow_of_control); | ||
smart_rtl_state = SubMode::PRELAND_POSITION; | ||
wp_nav->set_wp_destination_NED(dest_NED); | ||
} else { | ||
// peek at the next point. this can fail if the IO task currently has the path semaphore | ||
Vector3f next_dest_NED; | ||
if (g2.smart_rtl.peek_point(next_dest_NED)) { | ||
} else if (num_points == 1) { | ||
// we don't remove the home point | ||
if (g2.smart_rtl.peek_point(dest_NED)) { | ||
// this is the very last point, add 2m to the target alt | ||
dest_NED.z -= 2.0f; | ||
smart_rtl_state = SubMode::PRELAND_POSITION; | ||
wp_nav->set_wp_destination_NED(dest_NED); | ||
if (g2.smart_rtl.get_num_points() == 1) { | ||
// this is the very last point, add 2m to the target alt | ||
next_dest_NED.z -= 2.0f; | ||
} | ||
wp_nav->set_wp_destination_next_NED(next_dest_NED); | ||
} else { | ||
// this can only happen if peek failed to take the semaphore | ||
// send next point anyway which will cause the vehicle to slow at the next point | ||
// we're holding the semaphore lock and we checked | ||
// the number of points - so we should *always* be | ||
// able to get an item: | ||
INTERNAL_ERROR(AP_InternalError::error_t::flow_of_control); | ||
smart_rtl_state = SubMode::PRELAND_POSITION; | ||
} | ||
} else { | ||
if (g2.smart_rtl.pop_point(dest_NED)) { | ||
wp_nav->set_wp_destination_NED(dest_NED); | ||
} else { | ||
// we're holding the semaphore lock and we checked | ||
// the number of points - so we should *always* be | ||
// able to get an item: | ||
INTERNAL_ERROR(AP_InternalError::error_t::flow_of_control); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we probably need a comment here saying why this shouldn't happen. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added comments in this case and the similar case below it. |
||
smart_rtl_state = SubMode::PRELAND_POSITION; | ||
} | ||
} | ||
} else if (g2.smart_rtl.get_num_points() == 0) { | ||
// We should never get here; should always have at least | ||
// two points and the "zero points left" is handled above. | ||
INTERNAL_ERROR(AP_InternalError::error_t::flow_of_control); | ||
smart_rtl_state = SubMode::PRELAND_POSITION; | ||
} else if (path_follow_last_pop_fail_ms == 0) { | ||
// first time we've failed to pop off (ever, or after a success) | ||
path_follow_last_pop_fail_ms = AP_HAL::millis(); | ||
} else if (AP_HAL::millis() - path_follow_last_pop_fail_ms > 10000) { | ||
sem.give(); | ||
} else if (path_follow_last_semtake_fail_ms == 0) { | ||
// first time we've failed to take the semaphore | ||
path_follow_last_semtake_fail_ms = AP_HAL::millis(); | ||
} else if (AP_HAL::millis() - path_follow_last_semtake_fail_ms > 10000) { | ||
// we failed to pop a point off for 10 seconds. This is | ||
// almost certainly a bug. | ||
INTERNAL_ERROR(AP_InternalError::error_t::flow_of_control); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we always used a WITH_SEMAPHORE macro instead of writing the take and give directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case we're not taking this semaphore in a blocking fashion - we're using take_nonblocking. As we're in the main thread and the path-tidying thread can take the path sempahore for prolonged periods of time so we don't want to block.
Doing it this way does mean we have to be extra-special-careful to release the semaphore, of course.
Note that this is pre-existing. I've just moved the "take" of the semaphore to be out around all of the work the main thread is doing to ensure consistency of the path count with the pop/peek operations.