Skip to content

Commit d68cc22

Browse files
authored
Fix controller sorting issue while loading large number of controllers (ros-controls#1180)
1 parent 587dffb commit d68cc22

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
@@ -777,7 +777,7 @@ controller_interface::return_type ControllerManager::configure_controller(
777777
to = from;
778778

779779
// Reordering the controllers
780-
std::sort(
780+
std::stable_sort(
781781
to.begin(), to.end(),
782782
std::bind(
783783
&ControllerManager::controller_sorting, this, std::placeholders::_1, std::placeholders::_2,
@@ -2453,7 +2453,16 @@ bool ControllerManager::controller_sorting(
24532453
{
24542454
// The case of the controllers that don't have any command interfaces. For instance,
24552455
// joint_state_broadcaster
2456-
return true;
2456+
// If the controller b is also under the same condition, then maintain their initial order
2457+
if (ctrl_b.c->command_interface_configuration().names.empty() || !ctrl_b.c->is_chainable())
2458+
return false;
2459+
else
2460+
return true;
2461+
}
2462+
else if (ctrl_b.c->command_interface_configuration().names.empty() || !ctrl_b.c->is_chainable())
2463+
{
2464+
// If only the controller b is a broadcaster or non chainable type , then swap the controllers
2465+
return false;
24572466
}
24582467
else
24592468
{

0 commit comments

Comments
 (0)