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

Clear registered handles of DiffDriveController on deactivate #596

Merged
merged 5 commits into from
May 11, 2023

Conversation

Noel215
Copy link
Contributor

@Noel215 Noel215 commented May 4, 2023

Hi,

With the current implementation, the wheel handles are not being reset when running on_deactivate method. Then, if the controller is deactivated and then activated again the handles are accumulated and that can lead to issues (See ros-controls/ros2_control_demos#239)

on_activate and on_deactivate are the opposite, so everything that is enabled in on_activate have to be disabled in on_deactivate (or reset at the beginning of the on_activate). Following that, I propose two possible solutions, let me know which one fits better:

Current Solution: Reset the handles with registered_handles.clear(); in the configure_side() method.

Alternative Solution: Clear each of the handles in on_deactivate method:

controller_interface::CallbackReturn DiffDriveController::on_deactivate(
  const rclcpp_lifecycle::State &)
{
  subscriber_is_active_ = false;
  registered_left_wheel_handles_.clear();
  registered_right_wheel_handles_.clear();
  return controller_interface::CallbackReturn::SUCCESS;
}

@Noel215 Noel215 changed the title Clear registered_handles of DiffDriveController Clear registered handles of DiffDriveController May 4, 2023
@codecov-commenter
Copy link

Codecov Report

Merging #596 (d57fcd3) into master (e7f9962) will increase coverage by 0.12%.
The diff coverage is 33.33%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##           master     #596      +/-   ##
==========================================
+ Coverage   35.78%   35.90%   +0.12%     
==========================================
  Files         189        7     -182     
  Lines       17570      674   -16896     
  Branches    11592      361   -11231     
==========================================
- Hits         6287      242    -6045     
+ Misses        994      132     -862     
+ Partials    10289      300    -9989     
Flag Coverage Δ
unittests 35.90% <33.33%> (+0.12%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ontroller/test/test_load_diff_drive_controller.cpp 11.11% <0.00%> (ø)
diff_drive_controller/src/odometry.cpp 42.16% <11.11%> (ø)
diff_drive_controller/src/speed_limiter.cpp 46.55% <11.11%> (ø)
...ive_controller/test/test_diff_drive_controller.cpp 17.62% <12.08%> (ø)
...iff_drive_controller/src/diff_drive_controller.cpp 45.70% <44.44%> (ø)
...de/diff_drive_controller/diff_drive_controller.hpp 100.00% <100.00%> (ø)
...troller/include/diff_drive_controller/odometry.hpp 100.00% <100.00%> (ø)

... and 189 files with indirect coverage changes

@@ -558,6 +558,7 @@ controller_interface::CallbackReturn DiffDriveController::configure_side(
}

// register handles
registered_handles.clear();
Copy link
Member

Choose a reason for hiding this comment

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

should this happen on deactivate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is being executed on activate, before creating the handles.
I can change it to use the other solution if you think it's better.

@bmagyar
Copy link
Member

bmagyar commented May 6, 2023 via email

@Noel215 Noel215 changed the title Clear registered handles of DiffDriveController Clear registered handles of DiffDriveController on deactivate May 6, 2023
@bmagyar
Copy link
Member

bmagyar commented May 7, 2023

Houston, we have a problem. Some tests are failing and they seem legit caused by this PR. Possible they are badly designed tests...

Copy link
Contributor

@christophfroehlich christophfroehlich 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 pointing in this direction, I was not able to find this on my own ;)

The tests fail now, because it is assumed that the commands are zero after deactivation

EXPECT_EQ(0.0, left_wheel_vel_cmd_.get_value()) << "Wheels are halted on deactivate()";
EXPECT_EQ(0.0, right_wheel_vel_cmd_.get_value()) << "Wheels are halted on deactivate()";

This is now not the case, because DiffDriveController::halt() has no effect if no handles are registered.

Let it explicitly halt before releasing the handles?

Noel215 and others added 3 commits May 8, 2023 20:59
@bmagyar bmagyar merged commit 83042fb into ros-controls:master May 11, 2023
10 of 12 checks passed
@bmagyar
Copy link
Member

bmagyar commented May 11, 2023

@Mergifyio backport humble

@mergify
Copy link
Contributor

mergify bot commented May 11, 2023

backport humble

✅ Backports have been created

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

4 participants