Skip to content

Commit

Permalink
[ControllerInterface] Improve the prefix name check for the chainable…
Browse files Browse the repository at this point in the history
… controllers (#2038)

---------

Co-authored-by: Christoph Fröhlich <[email protected]>
  • Loading branch information
saikishor and christophfroehlich authored Feb 12, 2025
1 parent c302212 commit 465e5d0
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions controller_interface/src/chainable_controller_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@ 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()) != 0)
{
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 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.";
throw std::runtime_error(error_msg);
}
auto state_interface = std::make_shared<hardware_interface::StateInterface>(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
Expand Down Expand Up @@ -137,19 +137,20 @@ 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()) != 0)
{
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 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.";
throw std::runtime_error(error_msg);
}

hardware_interface::CommandInterface::SharedPtr reference_interface =
std::make_shared<hardware_interface::CommandInterface>(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
Expand Down

0 comments on commit 465e5d0

Please sign in to comment.