Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the prefix name check for the chainable controllers #2038

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
christophfroehlich marked this conversation as resolved.
Show resolved Hide resolved
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
Loading