Skip to content
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

Fix battery drain crash for GoToPlace #94

Merged
merged 2 commits into from
Jul 13, 2023
Merged

Conversation

Yadunund
Copy link
Member

Addresses open-rmf/rmf#359

Signed-off-by: Yadunund <yadunund@openrobotics.org>
Copy link
Contributor

@mxgrey mxgrey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for jumping on this problem.

I think for both cases we should do

const auto new_battery_soc = finish.battery_soc().value() - travel->change_in_charge();
if (new_battery_soc < 0.0)
  return std::nullopt;

finish.battery_soc(new_battery_soc);

instead of doing finish.battery_soc(std::max(0.0, ...)).

In the PR as it currently stands, there's a very narrow edge case where the user might have specified a battery_threshold <= 0.0, in which case a negative final battery charge would get disguised as a charge of 0.0 which is technically within the threshold, so the task would be performed even though it should be discarded.

Admittedly if the user is specifying a battery threshold of <= 0.0 then they're probably doing something very wrong already, but we should avoid making that bad situation even worse by allowing tasks to be performed when they won't even be able to finish.

Signed-off-by: Yadunund <yadunund@openrobotics.org>

if (state.battery_soc().value() <= _invariant_battery_drain)
if (state.battery_soc().value() <= constraints.threshold_soc())
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected this bug too.

@Yadunund
Copy link
Member Author

Thanks for the quick feedback and catching the edge case. I've updated the code as suggested. Also addressed this other issue in WaitFor event when the duration count is negative. Added some tests too.

Copy link
Contributor

@mxgrey mxgrey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for these fixes and the new unit tests!

@@ -115,9 +115,13 @@ WaitFor::Model::Model(
{
if (parameters.ambient_sink())
{
// Handle cases where duration is invalid.
const auto duration =
_duration.count() < 0 ? rmf_traffic::Duration(0) : _duration;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a really great catch!

@mxgrey mxgrey merged commit 6d5184f into main Jul 13, 2023
5 checks passed
@mxgrey mxgrey deleted the yadu/fix_battery_soc_error branch July 13, 2023 03:06
Yadunund added a commit that referenced this pull request Jul 13, 2023
Signed-off-by: Yadunund <yadunund@openrobotics.org>
Yadunund added a commit that referenced this pull request Jul 13, 2023
Signed-off-by: Yadunund <yadunund@openrobotics.org>
Yadunund added a commit that referenced this pull request Jul 13, 2023
Signed-off-by: Yadunund <yadunund@openrobotics.org>
Yadunund added a commit that referenced this pull request Jul 13, 2023
Signed-off-by: Yadunund <yadunund@openrobotics.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants