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

Update controller_manager_plugin to fix MoveIt-managed controller switching #785

Merged

Conversation

schornakj
Copy link
Contributor

@schornakj schornakj commented Nov 5, 2021

Description

This is a partial replacement for #731 that only includes the changes required to allow MoveIt-managed controller switching to work again while excluding changes to the behavior of the controller manager plugin.

  • Discover available controllers when initializing the controller manager plugin.
  • Account for changes to controller_manager_msgs in ros2_control v1.1.0. The most significant change is that resources that are required but not claimed by the controller (for example, if the controller is not active) are now listed in a separate message field than resources that are actively claimed by the controller.
  • Use scoped_lock in place of unique_lock.
  • Add more detailed comments and logging.

Checklist

  • Required by CI: Code is auto formatted using clang-format
  • Extend the tutorials / documentation reference
  • Document API changes relevant to the user in the MIGRATION.md notes
  • Create tests, which fail without this PR reference
  • Include a screenshot if changing a GUI
  • While waiting for someone to review your request, please help review another open pull request to support the maintainers

Copy link
Contributor

@AndyZe AndyZe left a comment

Choose a reason for hiding this comment

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

(deleted)

Copy link
Contributor

@AndyZe AndyZe left a comment

Choose a reason for hiding this comment

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

LGTM

@AndyZe AndyZe self-requested a review November 8, 2021 02:53
@schornakj
Copy link
Contributor Author

@AndyZe since we were talking about potential deadlocks with mutexes in this code, I took a look through it and it was originally designed in a way where deadlocks won't happen. The functions that lock the mutex don't call each other, and if (for example) getActiveControllers is called while switchControllers is being handled, it'll just block until switchControllers finishes.

for (const std::string& it : activate)
{
ControllersMap::iterator c = managed_controllers_.find(it);
if (c != managed_controllers_.end())
{ // controller belongs to this manager
request->start_controllers.push_back(c->second.name);
for (const auto& claimed_resource : c->second.claimed_interfaces)
for (const auto& required_resource : c->second.required_command_interfaces)
Copy link
Contributor

Choose a reason for hiding this comment

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

What if Controller A requires the position command interface for Joint 1 and Controller B requires the velocity command interface for Joint1. Will that be seen as a conflict here? I think it should be.

(Refer to the example here)

I think you will want to mark it as a conflict if both controllers have any command_interface for the same joint

Copy link
Contributor Author

@schornakj schornakj Nov 9, 2021

Choose a reason for hiding this comment

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

I investigated this, and when this function collects interface names they are modified here to remove the command type suffixes (/position, /velocity, etc.). This identifies conflicts between controllers that want to use different command types for the same joint.

I updated the PR to add a comment to be more detailed about what happens there. The implementation of the code is different than what I would have written (using std::transform to modify the names in-place through the return value from inserting into a map is a little unclear in my opinion) but in the interest of keeping this PR simple I won't change it here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, that's fine with me. Thanks for the comment.

@codecov
Copy link

codecov bot commented Nov 9, 2021

Codecov Report

Merging #785 (4e506ba) into main (812a805) will increase coverage by 0.56%.
The diff coverage is 88.41%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #785      +/-   ##
==========================================
+ Coverage   54.88%   55.43%   +0.56%     
==========================================
  Files         196      196              
  Lines       21359    21395      +36     
==========================================
+ Hits        11720    11858     +138     
+ Misses       9639     9537     -102     
Impacted Files Coverage Δ
...oveit_servo/include/moveit_servo/collision_check.h 100.00% <ø> (ø)
...veit_servo/include/moveit_servo/servo_parameters.h 75.00% <ø> (ø)
...eit_core/robot_trajectory/src/robot_trajectory.cpp 54.16% <58.83%> (+29.49%) ⬆️
moveit_ros/moveit_servo/src/servo_node.cpp 69.39% <75.00%> (-0.17%) ⬇️
...include/moveit/robot_trajectory/robot_trajectory.h 96.11% <100.00%> (+10.06%) ⬆️
moveit_ros/moveit_servo/src/collision_check.cpp 85.25% <100.00%> (-0.23%) ⬇️
moveit_ros/moveit_servo/src/servo_calcs.cpp 68.86% <100.00%> (-0.51%) ⬇️
moveit_ros/moveit_servo/src/servo_parameters.cpp 70.11% <100.00%> (+0.63%) ⬆️
...rajectory_processing/src/ruckig_traj_smoothing.cpp 80.62% <0.00%> (-4.08%) ⬇️
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f96c84c...4e506ba. Read the comment docs.

@JafarAbdi JafarAbdi merged commit 54c6e08 into ros-planning:main Nov 10, 2021
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

3 participants