Skip to content

Commit eebc602

Browse files
committed
change exporting of state_publishers and command_forwarders
1 parent cab9d52 commit eebc602

File tree

2 files changed

+93
-22
lines changed

2 files changed

+93
-22
lines changed

controller_manager/include/controller_manager/controller_manager.hpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,20 @@ class ControllerManager : public rclcpp::Node
240240
std::shared_ptr<controller_manager_msgs::srv::RegisterSubControllerManager::Response> response);
241241

242242
CONTROLLER_MANAGER_PUBLIC
243-
void create_hardware_state_publishers();
243+
void register_sub_controller_manager_references_srv_cb(
244+
const std::shared_ptr<
245+
controller_manager_msgs::srv::RegisterSubControllerManagerReferences::Request>
246+
request,
247+
std::shared_ptr<controller_manager_msgs::srv::RegisterSubControllerManagerReferences::Response>
248+
response);
249+
250+
CONTROLLER_MANAGER_PUBLIC
251+
void create_hardware_state_publishers(
252+
const std::vector<std::string> & state_interfaces_to_export);
244253

245254
CONTROLLER_MANAGER_PUBLIC
246-
void create_hardware_command_forwarders();
255+
void create_hardware_command_forwarders(
256+
const std::vector<std::string> & command_interfaces_to_export);
247257

248258
CONTROLLER_MANAGER_PUBLIC
249259
void register_sub_controller_manager();
@@ -464,6 +474,9 @@ class ControllerManager : public rclcpp::Node
464474
bool sub_controller_manager_ = false;
465475
bool central_controller_manager_ = false;
466476
bool use_multiple_nodes_ = false;
477+
std::vector<std::string> command_interfaces_to_export_ = std::vector<std::string>({});
478+
std::vector<std::string> state_interfaces_to_export_ = std::vector<std::string>({});
479+
467480
// TODO(Manuel): weak_ptr would probably be a better choice. This way has to be checked
468481
// if pointer points to an object. Don't like the nullptr thing and implicit checks
469482
// associated with it ... (create on distributed Handles and StatePublisher/CommandForwarder)

controller_manager/src/controller_manager.cpp

Lines changed: 78 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,6 @@ void ControllerManager::get_and_initialize_distributed_parameters()
378378
distributed_interfaces_publish_period_ =
379379
std::chrono::milliseconds(distributed_interfaces_publish_period);
380380
}
381-
382381
else
383382
{
384383
RCLCPP_WARN(
@@ -392,6 +391,36 @@ void ControllerManager::get_and_initialize_distributed_parameters()
392391
get_logger(), "'use_multiple_nodes' parameter not set, using default value:%s",
393392
use_multiple_nodes_ ? "true" : "false");
394393
}
394+
395+
if (!get_parameter("export_command_interfaces", command_interfaces_to_export_))
396+
{
397+
RCLCPP_WARN(
398+
get_logger(),
399+
"'export_command_interfaces' parameter not set, going to export all available command "
400+
"interfaces");
401+
}
402+
403+
if (!get_parameter("export_state_interfaces", state_interfaces_to_export_))
404+
{
405+
RCLCPP_WARN(
406+
get_logger(),
407+
"'export_state_interfaces' parameter not set, going to export all available command "
408+
"interfaces");
409+
}
410+
411+
if (!get_parameter("sub_controller_manager", sub_controller_manager_))
412+
{
413+
RCLCPP_WARN(
414+
get_logger(), "'sub_controller_manager' parameter not set, using default value:%s",
415+
sub_controller_manager_ ? "true" : "false");
416+
}
417+
418+
if (!get_parameter("use_multiple_nodes", use_multiple_nodes_))
419+
{
420+
RCLCPP_WARN(
421+
get_logger(), "'use_multiple_nodes' parameter not set, using default value:%s",
422+
use_multiple_nodes_ ? "true" : "false");
423+
}
395424
}
396425

397426
void ControllerManager::configure_controller_manager()
@@ -469,8 +498,26 @@ void ControllerManager::init_distributed_sub_controller_manager()
469498
}
470499
}
471500

472-
create_hardware_state_publishers();
473-
create_hardware_command_forwarders();
501+
// export every interface by default
502+
if (state_interfaces_to_export_.empty())
503+
{
504+
// get all available state interfaces and export
505+
create_hardware_state_publishers(resource_manager_->available_state_interfaces());
506+
}
507+
else
508+
{
509+
create_hardware_state_publishers(state_interfaces_to_export_);
510+
}
511+
// export every interface by default
512+
if (command_interfaces_to_export_.empty())
513+
{
514+
// get all available command interfaces and export
515+
create_hardware_command_forwarders(resource_manager_->available_command_interfaces());
516+
}
517+
else
518+
{
519+
create_hardware_command_forwarders(command_interfaces_to_export_);
520+
}
474521
register_sub_controller_manager();
475522
}
476523

@@ -597,16 +644,18 @@ void ControllerManager::register_sub_controller_manager_srv_cb(
597644
<< sub_ctrl_mng_wrapper->get_name() << ">.");
598645
}
599646

600-
void ControllerManager::create_hardware_state_publishers()
647+
void ControllerManager::register_sub_controller_manager_references_srv_cb(
648+
const std::shared_ptr<
649+
controller_manager_msgs::srv::RegisterSubControllerManagerReferences::Request>
650+
request,
651+
std::shared_ptr<controller_manager_msgs::srv::RegisterSubControllerManagerReferences::Response>
652+
response)
601653
{
602-
std::vector<std::string> state_interfaces_to_export = std::vector<std::string>({});
603-
// export every interface by default
604-
if (!get_parameter("export_state_interfaces", state_interfaces_to_export))
605-
{
606-
// get all available state interfaces
607-
state_interfaces_to_export = resource_manager_->available_state_interfaces();
608-
}
654+
}
609655

656+
void ControllerManager::create_hardware_state_publishers(
657+
const std::vector<std::string> & state_interfaces_to_export)
658+
{
610659
for (const auto & state_interface : state_interfaces_to_export)
611660
{
612661
std::shared_ptr<distributed_control::StatePublisher> state_publisher;
@@ -643,16 +692,9 @@ void ControllerManager::create_hardware_state_publishers()
643692
}
644693
}
645694

646-
void ControllerManager::create_hardware_command_forwarders()
695+
void ControllerManager::create_hardware_command_forwarders(
696+
const std::vector<std::string> & command_interfaces_to_export)
647697
{
648-
std::vector<std::string> command_interfaces_to_export = std::vector<std::string>({});
649-
// export every interface by default
650-
if (!get_parameter("export_command_interfaces", command_interfaces_to_export))
651-
{
652-
// get all available command interfaces
653-
command_interfaces_to_export = resource_manager_->available_command_interfaces();
654-
}
655-
656698
for (auto const & command_interface : command_interfaces_to_export)
657699
{
658700
std::shared_ptr<distributed_control::CommandForwarder> command_forwarder;
@@ -1021,8 +1063,24 @@ controller_interface::return_type ControllerManager::configure_controller(
10211063
controller_name.c_str());
10221064
return controller_interface::return_type::ERROR;
10231065
}
1066+
// safe the name for later. Interfaces get moved so they are no longer available after they have been imported.
1067+
std::vector<std::string> reference_interfaces_names;
1068+
reference_interfaces_names.reserve(interfaces.size());
1069+
for (const auto & interface : interfaces)
1070+
{
1071+
reference_interfaces_names.push_back(interface.get_name());
1072+
}
1073+
10241074
resource_manager_->import_controller_reference_interfaces(controller_name, interfaces);
10251075

1076+
if (is_sub_controller_manager())
1077+
{
1078+
// export all of the just created reference interfaces by default
1079+
create_hardware_command_forwarders(reference_interfaces_names);
1080+
1081+
// TODO(Manuel) : register
1082+
}
1083+
10261084
// TODO(destogl): check and resort controllers in the vector
10271085
}
10281086

0 commit comments

Comments
 (0)