From 4c1187541ebdb12afdfeeb4a75600b4933065614 Mon Sep 17 00:00:00 2001 From: Sai Kishor Kothakota Date: Wed, 5 Feb 2025 15:03:58 +0100 Subject: [PATCH 1/3] Improve the prefix name check for the chainable controllers --- .../src/chainable_controller_interface.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/controller_interface/src/chainable_controller_interface.cpp b/controller_interface/src/chainable_controller_interface.cpp index 409578be9b..1f55896b9c 100644 --- a/controller_interface/src/chainable_controller_interface.cpp +++ b/controller_interface/src/chainable_controller_interface.cpp @@ -57,7 +57,7 @@ ChainableControllerInterface::export_state_interfaces() // check if the names of the controller state interfaces begin with the controller's name for (const auto & interface : state_interfaces) { - if (interface.get_prefix_name() != get_node()->get_name()) + if (interface.get_prefix_name().find(get_node()->get_name()) == std::string::npos) { std::string error_msg = "The prefix of the interface '" + interface.get_prefix_name() + @@ -68,7 +68,7 @@ ChainableControllerInterface::export_state_interfaces() throw std::runtime_error(error_msg); } auto state_interface = std::make_shared(interface); - const auto interface_name = state_interface->get_interface_name(); + const auto interface_name = state_interface->get_name(); auto [it, succ] = exported_state_interfaces_.insert({interface_name, state_interface}); // either we have name duplicate which we want to avoid under all circumstances since interfaces // need to be uniquely identify able or something else really went wrong. In any case abort and @@ -137,7 +137,7 @@ ChainableControllerInterface::export_reference_interfaces() const auto ref_interface_size = reference_interfaces.size(); for (auto & interface : reference_interfaces) { - if (interface.get_prefix_name() != get_node()->get_name()) + if (interface.get_prefix_name().find(get_node()->get_name()) == std::string::npos) { std::string error_msg = "The name of the interface " + interface.get_name() + " does not begin with the controller's name. This is mandatory for " @@ -149,7 +149,7 @@ ChainableControllerInterface::export_reference_interfaces() hardware_interface::CommandInterface::SharedPtr reference_interface = std::make_shared(std::move(interface)); - const auto interface_name = reference_interface->get_interface_name(); + const auto interface_name = reference_interface->get_name(); // check the exported interface name is unique auto [it, succ] = exported_reference_interfaces_.insert({interface_name, reference_interface}); // either we have name duplicate which we want to avoid under all circumstances since interfaces From 1f735ce5fa7f401a296ad65d9a697b7d9b9a48ed Mon Sep 17 00:00:00 2001 From: Sai Kishor Kothakota Date: Thu, 6 Feb 2025 00:00:10 +0100 Subject: [PATCH 2/3] fix the error message --- .../src/chainable_controller_interface.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/controller_interface/src/chainable_controller_interface.cpp b/controller_interface/src/chainable_controller_interface.cpp index 1f55896b9c..461331632c 100644 --- a/controller_interface/src/chainable_controller_interface.cpp +++ b/controller_interface/src/chainable_controller_interface.cpp @@ -61,7 +61,7 @@ ChainableControllerInterface::export_state_interfaces() { std::string error_msg = "The prefix of the interface '" + interface.get_prefix_name() + - "' does not equal the controller's name '" + get_node()->get_name() + + "' should contain the controller's name '" + get_node()->get_name() + "'. This is mandatory for state interfaces. No state interface will be exported. Please " "correct and recompile the controller with name '" + get_node()->get_name() + "' and try again."; @@ -139,11 +139,11 @@ ChainableControllerInterface::export_reference_interfaces() { if (interface.get_prefix_name().find(get_node()->get_name()) == std::string::npos) { - std::string error_msg = "The name of the interface " + interface.get_name() + - " does not begin with the controller's name. This is mandatory for " - "reference interfaces. Please " - "correct and recompile the controller with name " + - get_node()->get_name() + " and try again."; + std::string error_msg = "The prefix of the interface '" + interface.get_prefix_name() + + "' should contain the controller's name '" + get_node()->get_name() + + "'. This is mandatory for reference interfaces. Please correct and " + "recompile the controller with name '" + + get_node()->get_name() + "' and try again."; throw std::runtime_error(error_msg); } From 7c99ca4412fcf0d34bd03c292e9b18d74736d381 Mon Sep 17 00:00:00 2001 From: Sai Kishor Kothakota Date: Thu, 6 Feb 2025 00:09:03 +0100 Subject: [PATCH 3/3] Check that the prefix starts with the controller name exclusively --- .../src/chainable_controller_interface.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/controller_interface/src/chainable_controller_interface.cpp b/controller_interface/src/chainable_controller_interface.cpp index 461331632c..c03b056845 100644 --- a/controller_interface/src/chainable_controller_interface.cpp +++ b/controller_interface/src/chainable_controller_interface.cpp @@ -57,11 +57,11 @@ ChainableControllerInterface::export_state_interfaces() // check if the names of the controller state interfaces begin with the controller's name for (const auto & interface : state_interfaces) { - if (interface.get_prefix_name().find(get_node()->get_name()) == std::string::npos) + if (interface.get_prefix_name().find(get_node()->get_name()) != 0) { std::string error_msg = "The prefix of the interface '" + interface.get_prefix_name() + - "' should contain the controller's name '" + get_node()->get_name() + + "' should begin with the controller's name '" + get_node()->get_name() + "'. This is mandatory for state interfaces. No state interface will be exported. Please " "correct and recompile the controller with name '" + get_node()->get_name() + "' and try again."; @@ -137,10 +137,11 @@ ChainableControllerInterface::export_reference_interfaces() const auto ref_interface_size = reference_interfaces.size(); for (auto & interface : reference_interfaces) { - if (interface.get_prefix_name().find(get_node()->get_name()) == std::string::npos) + if (interface.get_prefix_name().find(get_node()->get_name()) != 0) { std::string error_msg = "The prefix of the interface '" + interface.get_prefix_name() + - "' should contain the controller's name '" + get_node()->get_name() + + "' should begin with the controller's name '" + + get_node()->get_name() + "'. This is mandatory for reference interfaces. Please correct and " "recompile the controller with name '" + get_node()->get_name() + "' and try again.";