Skip to content

Commit cab9d52

Browse files
committed
adapt controller interfaces for distributed chained control
1 parent 14a2c07 commit cab9d52

File tree

5 files changed

+86
-1
lines changed

5 files changed

+86
-1
lines changed

controller_interface/include/controller_interface/chainable_controller_interface.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ class ChainableControllerInterface : public ControllerInterfaceBase
5757
CONTROLLER_INTERFACE_PUBLIC
5858
std::vector<hardware_interface::CommandInterface> export_reference_interfaces() final;
5959

60+
CONTROLLER_INTERFACE_PUBLIC
61+
std::vector<hardware_interface::DistributedCommandInterface>
62+
export_distributed_reference_interfaces() final;
63+
6064
CONTROLLER_INTERFACE_PUBLIC
6165
bool set_chained_mode(bool chained_mode) final;
6266

@@ -75,6 +79,15 @@ class ChainableControllerInterface : public ControllerInterfaceBase
7579
*/
7680
virtual std::vector<hardware_interface::CommandInterface> on_export_reference_interfaces() = 0;
7781

82+
// Only for fast poc should be pure virtual
83+
/**
84+
* Default returns emtpy list, so that not every chainable controller has to be updated for poc.
85+
*
86+
* \returns empty list.
87+
*/
88+
virtual std::vector<hardware_interface::DistributedCommandInterface>
89+
on_export_distributed_reference_interfaces();
90+
7891
/// Virtual method that each chainable controller should implement to switch chained mode.
7992
/**
8093
* Each chainable controller implements this methods to switch between "chained" and "external"

controller_interface/include/controller_interface/controller_interface.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,22 @@ class ControllerInterface : public controller_interface::ControllerInterfaceBase
4343
bool is_chainable() const final;
4444

4545
/**
46-
* Controller has no reference interfaces.
46+
* Controller has no distributed reference interfaces.
4747
*
4848
* \returns empty list.
4949
*/
5050
CONTROLLER_INTERFACE_PUBLIC
5151
std::vector<hardware_interface::CommandInterface> export_reference_interfaces() final;
5252

53+
/**
54+
* Controller has no reference interfaces.
55+
*
56+
* \returns empty list.
57+
*/
58+
CONTROLLER_INTERFACE_PUBLIC
59+
std::vector<hardware_interface::DistributedCommandInterface>
60+
export_distributed_reference_interfaces() final;
61+
5362
/**
5463
* Controller is not chainable, therefore no chained mode can be set.
5564
*

controller_interface/include/controller_interface/controller_interface_base.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,16 @@ class ControllerInterfaceBase : public rclcpp_lifecycle::node_interfaces::Lifecy
197197
CONTROLLER_INTERFACE_PUBLIC
198198
virtual std::vector<hardware_interface::CommandInterface> export_reference_interfaces() = 0;
199199

200+
/**
201+
* Export interfaces for a chainable controller that can be used as command interface of other
202+
* controllers if controller is distributed.
203+
*
204+
* \returns list of distributed command interfaces for preceding controllers.
205+
*/
206+
CONTROLLER_INTERFACE_PUBLIC
207+
virtual std::vector<hardware_interface::DistributedCommandInterface>
208+
export_distributed_reference_interfaces() = 0;
209+
200210
/**
201211
* Set chained mode of a chainable controller. This method triggers internal processes to switch
202212
* a chainable controller to "chained" mode and vice-versa. Setting controller to "chained" mode

controller_interface/src/chainable_controller_interface.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "controller_interface/chainable_controller_interface.hpp"
1616

17+
#include <exception>
1718
#include <vector>
1819

1920
#include "hardware_interface/types/lifecycle_state_names.hpp"
@@ -44,6 +45,46 @@ return_type ChainableControllerInterface::update(
4445
return ret;
4546
}
4647

48+
std::vector<hardware_interface::DistributedCommandInterface>
49+
ChainableControllerInterface::export_distributed_reference_interfaces()
50+
{
51+
auto reference_interfaces = on_export_distributed_reference_interfaces();
52+
53+
// check if the "reference_interfaces_" variable is resized to number of interfaces
54+
if (reference_interfaces_.size() != reference_interfaces.size())
55+
{
56+
// TODO(destogl): Should here be "FATAL"? It is fatal in terms of controller but not for the
57+
// framework
58+
RCLCPP_FATAL(
59+
get_node()->get_logger(),
60+
"The internal storage for reference values 'reference_interfaces_' variable has size '%zu', "
61+
"but it is expected to have the size '%zu' equal to the number of exported reference "
62+
"interfaces. No reference interface will be exported. Please correct and recompile "
63+
"the controller with name '%s' and try again.",
64+
reference_interfaces_.size(), reference_interfaces.size(), get_node()->get_name());
65+
reference_interfaces.clear();
66+
}
67+
68+
// check if the names of the reference interfaces begin with the controller's name
69+
for (const auto & interface : reference_interfaces)
70+
{
71+
if (interface.get_prefix_name() != get_node()->get_name())
72+
{
73+
RCLCPP_FATAL(
74+
get_node()->get_logger(),
75+
"The name of the interface '%s' does not begin with the controller's name. This is "
76+
"mandatory "
77+
" for reference interfaces. No reference interface will be exported. Please correct and "
78+
"recompile the controller with name '%s' and try again.",
79+
interface.get_name().c_str(), get_node()->get_name());
80+
reference_interfaces.clear();
81+
break;
82+
}
83+
}
84+
85+
return reference_interfaces;
86+
}
87+
4788
std::vector<hardware_interface::CommandInterface>
4889
ChainableControllerInterface::export_reference_interfaces()
4990
{
@@ -111,6 +152,12 @@ bool ChainableControllerInterface::set_chained_mode(bool chained_mode)
111152

112153
bool ChainableControllerInterface::is_in_chained_mode() const { return in_chained_mode_; }
113154

155+
std::vector<hardware_interface::DistributedCommandInterface>
156+
ChainableControllerInterface::on_export_distributed_reference_interfaces()
157+
{
158+
return {};
159+
}
160+
114161
bool ChainableControllerInterface::on_set_chained_mode(bool /*chained_mode*/) { return true; }
115162

116163
} // namespace controller_interface

controller_interface/src/controller_interface.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ std::vector<hardware_interface::CommandInterface> ControllerInterface::export_re
3333
return {};
3434
}
3535

36+
std::vector<hardware_interface::DistributedCommandInterface>
37+
ControllerInterface::export_distributed_reference_interfaces()
38+
{
39+
return {};
40+
}
41+
3642
bool ControllerInterface::set_chained_mode(bool /*chained_mode*/) { return false; }
3743

3844
bool ControllerInterface::is_in_chained_mode() const { return false; }

0 commit comments

Comments
 (0)