Skip to content

Commit ee1e2e1

Browse files
Fix the controller sorting bug when the interfaces are not configured (fixes #1164) (#1165) (#1166)
(cherry picked from commit 75e7efd) Co-authored-by: Sai Kishor Kothakota <[email protected]>
1 parent b9cdcfe commit ee1e2e1

File tree

3 files changed

+57
-4
lines changed

3 files changed

+57
-4
lines changed

controller_manager/src/controller_manager.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ std::vector<std::string> get_following_controller_names(
154154

155155
return following_controllers;
156156
}
157+
// If the controller is not configured, return empty
158+
if (!(is_controller_active(controller_it->c) || is_controller_inactive(controller_it->c)))
159+
return following_controllers;
157160
const auto cmd_itfs = controller_it->c->command_interface_configuration().names;
158161
for (const auto & itf : cmd_itfs)
159162
{
@@ -212,6 +215,8 @@ std::vector<std::string> get_preceding_controller_names(
212215
}
213216
for (const auto & ctrl : controllers)
214217
{
218+
// If the controller is not configured, then continue
219+
if (!(is_controller_active(ctrl.c) || is_controller_inactive(ctrl.c))) continue;
215220
auto cmd_itfs = ctrl.c->command_interface_configuration().names;
216221
for (const auto & itf : cmd_itfs)
217222
{
@@ -2273,6 +2278,14 @@ bool ControllerManager::controller_sorting(
22732278
const ControllerSpec & ctrl_a, const ControllerSpec & ctrl_b,
22742279
const std::vector<controller_manager::ControllerSpec> & controllers)
22752280
{
2281+
// If the neither of the controllers are configured, then return false
2282+
if (!((is_controller_active(ctrl_a.c) || is_controller_inactive(ctrl_a.c)) &&
2283+
(is_controller_active(ctrl_b.c) || is_controller_inactive(ctrl_b.c))))
2284+
{
2285+
if (is_controller_active(ctrl_a.c) || is_controller_inactive(ctrl_a.c)) return true;
2286+
return false;
2287+
}
2288+
22762289
const std::vector<std::string> cmd_itfs = ctrl_a.c->command_interface_configuration().names;
22772290
const std::vector<std::string> state_itfs = ctrl_a.c->state_interface_configuration().names;
22782291
if (cmd_itfs.empty() || !ctrl_a.c->is_chainable())

controller_manager/test/test_chainable_controller/test_chainable_controller.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,33 @@ TestChainableController::TestChainableController()
3232
controller_interface::InterfaceConfiguration
3333
TestChainableController::command_interface_configuration() const
3434
{
35-
return cmd_iface_cfg_;
35+
if (
36+
get_state().id() == lifecycle_msgs::msg::State::PRIMARY_STATE_INACTIVE ||
37+
get_state().id() == lifecycle_msgs::msg::State::PRIMARY_STATE_ACTIVE)
38+
{
39+
return cmd_iface_cfg_;
40+
}
41+
else
42+
{
43+
throw std::runtime_error(
44+
"Can not get command interface configuration until the controller is configured.");
45+
}
3646
}
3747

3848
controller_interface::InterfaceConfiguration
3949
TestChainableController::state_interface_configuration() const
4050
{
41-
return state_iface_cfg_;
51+
if (
52+
get_state().id() == lifecycle_msgs::msg::State::PRIMARY_STATE_INACTIVE ||
53+
get_state().id() == lifecycle_msgs::msg::State::PRIMARY_STATE_ACTIVE)
54+
{
55+
return state_iface_cfg_;
56+
}
57+
else
58+
{
59+
throw std::runtime_error(
60+
"Can not get state interface configuration until the controller is configured.");
61+
}
4262
}
4363

4464
controller_interface::return_type TestChainableController::update_reference_from_subscribers()

controller_manager/test/test_controller/test_controller.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,32 @@ TestController::TestController()
2929

3030
controller_interface::InterfaceConfiguration TestController::command_interface_configuration() const
3131
{
32-
return cmd_iface_cfg_;
32+
if (
33+
get_state().id() == lifecycle_msgs::msg::State::PRIMARY_STATE_INACTIVE ||
34+
get_state().id() == lifecycle_msgs::msg::State::PRIMARY_STATE_ACTIVE)
35+
{
36+
return cmd_iface_cfg_;
37+
}
38+
else
39+
{
40+
throw std::runtime_error(
41+
"Can not get command interface configuration until the controller is configured.");
42+
}
3343
}
3444

3545
controller_interface::InterfaceConfiguration TestController::state_interface_configuration() const
3646
{
37-
return state_iface_cfg_;
47+
if (
48+
get_state().id() == lifecycle_msgs::msg::State::PRIMARY_STATE_INACTIVE ||
49+
get_state().id() == lifecycle_msgs::msg::State::PRIMARY_STATE_ACTIVE)
50+
{
51+
return state_iface_cfg_;
52+
}
53+
else
54+
{
55+
throw std::runtime_error(
56+
"Can not get state interface configuration until the controller is configured.");
57+
}
3858
}
3959

4060
controller_interface::return_type TestController::update(

0 commit comments

Comments
 (0)