Skip to content

Commit

Permalink
fix the sorting logic for complex and large use-cases (fixes #1170)
Browse files Browse the repository at this point in the history
  • Loading branch information
saikishor committed Nov 27, 2023
1 parent 16cdd84 commit 2e32546
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion controller_manager/src/controller_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2444,7 +2444,15 @@ bool ControllerManager::controller_sorting(
(is_controller_active(ctrl_b.c) || is_controller_inactive(ctrl_b.c))))
{
if (is_controller_active(ctrl_a.c) || is_controller_inactive(ctrl_a.c)) return true;
return false;
// When both the controllers are inactive, do not change their initial order
auto ctrl_a_it = std::find_if(
controllers.begin(), controllers.end(),
std::bind(controller_name_compare, std::placeholders::_1, ctrl_a.info.name));
auto ctrl_b_it = std::find_if(
controllers.begin(), controllers.end(),
std::bind(controller_name_compare, std::placeholders::_1, ctrl_b.info.name));
return std::distance(controllers.begin(), ctrl_a_it) <
std::distance(controllers.begin(), ctrl_b_it);
}

const std::vector<std::string> cmd_itfs = ctrl_a.c->command_interface_configuration().names;
Expand All @@ -2453,8 +2461,25 @@ bool ControllerManager::controller_sorting(
{
// The case of the controllers that don't have any command interfaces. For instance,
// joint_state_broadcaster
// If the controller b is also under the same condition, then maintain their initial order
if (ctrl_b.c->command_interface_configuration().names.empty() || !ctrl_b.c->is_chainable())
{
auto ctrl_a_it = std::find_if(
controllers.begin(), controllers.end(),
std::bind(controller_name_compare, std::placeholders::_1, ctrl_a.info.name));
auto ctrl_b_it = std::find_if(
controllers.begin(), controllers.end(),
std::bind(controller_name_compare, std::placeholders::_1, ctrl_b.info.name));
return std::distance(controllers.begin(), ctrl_a_it) <
std::distance(controllers.begin(), ctrl_b_it);
}
return true;
}
else if (ctrl_b.c->command_interface_configuration().names.empty() || !ctrl_b.c->is_chainable())
{
// If only the controller b is a broadcaster or non chainable type , then swap the controllers
return false;
}
else
{
auto following_ctrls = get_following_controller_names(ctrl_a.info.name, controllers);
Expand Down

0 comments on commit 2e32546

Please sign in to comment.