Skip to content

Commit ba58074

Browse files
Fix controller sorting issue while loading large number of controllers (#1180) (#1186)
(cherry picked from commit d68cc22) Co-authored-by: Sai Kishor Kothakota <[email protected]>
1 parent 8695bdf commit ba58074

File tree

2 files changed

+507
-2
lines changed

2 files changed

+507
-2
lines changed

controller_manager/src/controller_manager.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ controller_interface::return_type ControllerManager::configure_controller(
692692
to = from;
693693

694694
// Reordering the controllers
695-
std::sort(
695+
std::stable_sort(
696696
to.begin(), to.end(),
697697
std::bind(
698698
&ControllerManager::controller_sorting, this, std::placeholders::_1, std::placeholders::_2,
@@ -2292,7 +2292,16 @@ bool ControllerManager::controller_sorting(
22922292
{
22932293
// The case of the controllers that don't have any command interfaces. For instance,
22942294
// joint_state_broadcaster
2295-
return true;
2295+
// If the controller b is also under the same condition, then maintain their initial order
2296+
if (ctrl_b.c->command_interface_configuration().names.empty() || !ctrl_b.c->is_chainable())
2297+
return false;
2298+
else
2299+
return true;
2300+
}
2301+
else if (ctrl_b.c->command_interface_configuration().names.empty() || !ctrl_b.c->is_chainable())
2302+
{
2303+
// If only the controller b is a broadcaster or non chainable type , then swap the controllers
2304+
return false;
22962305
}
22972306
else
22982307
{

0 commit comments

Comments
 (0)