Skip to content

Commit e9c2669

Browse files
committed
adapt to new changes and remove some rebase artefacts
1 parent 3a53368 commit e9c2669

14 files changed

+105
-104
lines changed

controller_interface/include/controller_interface/chainable_controller_interface.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,7 @@ class ChainableControllerInterface : public ControllerInterfaceBase
5959
bool is_chainable() const final;
6060

6161
CONTROLLER_INTERFACE_PUBLIC
62-
std::vector<hardware_interface::StateInterface> export_state_interfaces() final;
63-
64-
CONTROLLER_INTERFACE_PUBLIC
65-
std::vector<hardware_interface::StateInterface> export_state_interfaces() final;
62+
std::vector<std::shared_ptr<hardware_interface::StateInterface>> export_state_interfaces() final;
6663

6764
CONTROLLER_INTERFACE_PUBLIC
6865
std::vector<std::shared_ptr<hardware_interface::CommandInterface>> export_reference_interfaces()

controller_interface/include/controller_interface/controller_interface.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class ControllerInterface : public controller_interface::ControllerInterfaceBase
4747
* \returns empty list.
4848
*/
4949
CONTROLLER_INTERFACE_PUBLIC
50-
std::vector<hardware_interface::StateInterface> export_state_interfaces() final;
50+
std::vector<std::shared_ptr<hardware_interface::StateInterface>> export_state_interfaces() final;
5151

5252
/**
5353
* Controller has no reference interfaces.

controller_interface/include/controller_interface/controller_interface_base.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ class ControllerInterfaceBase : public rclcpp_lifecycle::node_interfaces::Lifecy
231231
* \returns list of state interfaces for preceding controllers.
232232
*/
233233
CONTROLLER_INTERFACE_PUBLIC
234-
virtual std::vector<hardware_interface::StateInterface> export_state_interfaces() = 0;
234+
virtual std::vector<std::shared_ptr<hardware_interface::StateInterface>>
235+
export_state_interfaces() = 0;
235236

236237
/**
237238
* Set chained mode of a chainable controller. This method triggers internal processes to switch

controller_interface/src/chainable_controller_interface.cpp

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -44,52 +44,32 @@ return_type ChainableControllerInterface::update(
4444
return ret;
4545
}
4646

47-
std::vector<hardware_interface::StateInterface>
47+
std::vector<std::shared_ptr<hardware_interface::StateInterface>>
4848
ChainableControllerInterface::export_state_interfaces()
4949
{
5050
auto state_interfaces = on_export_state_interfaces();
51+
std::vector<std::shared_ptr<hardware_interface::StateInterface>> state_interfaces_ptrs_vec;
52+
state_interfaces_ptrs_vec.reserve(state_interfaces.size());
5153

5254
// check if the names of the controller state interfaces begin with the controller's name
53-
for (const auto & interface : state_interfaces)
55+
for (auto & interface : state_interfaces)
5456
{
5557
if (interface.get_prefix_name() != get_node()->get_name())
5658
{
57-
RCLCPP_FATAL(
58-
get_node()->get_logger(),
59-
"The name of the interface '%s' does not begin with the controller's name. This is "
59+
std::string error_msg =
60+
"The name of the interface '" + interface.get_name() +
61+
"' does not begin with the controller's name. This is "
6062
"mandatory for state interfaces. No state interface will be exported. Please "
61-
"correct and recompile the controller with name '%s' and try again.",
62-
interface.get_name().c_str(), get_node()->get_name());
63-
state_interfaces.clear();
64-
break;
63+
"correct and recompile the controller with name '" +
64+
get_node()->get_name() + "' and try again.";
65+
throw std::runtime_error(error_msg);
6566
}
66-
}
67-
68-
return state_interfaces;
69-
}
70-
71-
std::vector<std::shared_ptr<hardware_interface::CommandInterface>>
72-
ChainableControllerInterface::export_state_interfaces()
73-
{
74-
auto state_interfaces = on_export_state_interfaces();
7567

76-
// check if the names of the controller state interfaces begin with the controller's name
77-
for (const auto & interface : state_interfaces)
78-
{
79-
if (interface.get_prefix_name() != get_node()->get_name())
80-
{
81-
RCLCPP_FATAL(
82-
get_node()->get_logger(),
83-
"The name of the interface '%s' does not begin with the controller's name. This is "
84-
"mandatory for state interfaces. No state interface will be exported. Please "
85-
"correct and recompile the controller with name '%s' and try again.",
86-
interface.get_name().c_str(), get_node()->get_name());
87-
state_interfaces.clear();
88-
break;
89-
}
68+
state_interfaces_ptrs_vec.push_back(
69+
std::make_shared<hardware_interface::StateInterface>(interface));
9070
}
9171

92-
return state_interfaces;
72+
return state_interfaces_ptrs_vec;
9373
}
9474

9575
std::vector<std::shared_ptr<hardware_interface::CommandInterface>>
@@ -187,8 +167,8 @@ ChainableControllerInterface::on_export_state_interfaces()
187167
std::vector<hardware_interface::StateInterface> state_interfaces;
188168
for (size_t i = 0; i < exported_state_interface_names_.size(); ++i)
189169
{
190-
state_interfaces.emplace_back(hardware_interface::StateInterface(
191-
get_node()->get_name(), exported_state_interface_names_[i], &state_interfaces_values_[i]));
170+
state_interfaces.emplace_back(
171+
get_node()->get_name(), exported_state_interface_names_[i], &state_interfaces_values_[i]);
192172
}
193173
return state_interfaces;
194174
}

controller_interface/src/controller_interface.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ ControllerInterface::ControllerInterface() : ControllerInterfaceBase() {}
2222

2323
bool ControllerInterface::is_chainable() const { return false; }
2424

25-
std::vector<hardware_interface::StateInterface> ControllerInterface::export_state_interfaces()
25+
std::vector<std::shared_ptr<hardware_interface::StateInterface>>
26+
ControllerInterface::export_state_interfaces()
2627
{
2728
return {};
2829
}

controller_interface/test/test_chainable_controller_interface.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ TEST_F(ChainableControllerInterfaceTest, export_state_interfaces)
4747

4848
auto exported_state_interfaces = controller.export_state_interfaces();
4949

50-
ASSERT_EQ(reference_interfaces.size(), 1u);
51-
EXPECT_EQ(reference_interfaces[0]->get_prefix_name(), TEST_CONTROLLER_NAME);
52-
EXPECT_EQ(reference_interfaces[0]->get_interface_name(), "test_itf");
50+
ASSERT_THAT(exported_state_interfaces, SizeIs(1));
51+
EXPECT_EQ(exported_state_interfaces[0]->get_prefix_name(), TEST_CONTROLLER_NAME);
52+
EXPECT_EQ(exported_state_interfaces[0]->get_interface_name(), "test_state");
5353

54-
EXPECT_EQ(reference_interfaces[0]->get_value(), INTERFACE_VALUE);
54+
EXPECT_EQ(exported_state_interfaces[0]->get_value(), INTERFACE_VALUE);
5555
}
5656

5757
TEST_F(ChainableControllerInterfaceTest, export_reference_interfaces)
@@ -68,10 +68,10 @@ TEST_F(ChainableControllerInterfaceTest, export_reference_interfaces)
6868
auto reference_interfaces = controller.export_reference_interfaces();
6969

7070
ASSERT_THAT(reference_interfaces, SizeIs(1));
71-
EXPECT_EQ(reference_interfaces[0].get_prefix_name(), TEST_CONTROLLER_NAME);
72-
EXPECT_EQ(reference_interfaces[0].get_interface_name(), "test_itf");
71+
EXPECT_EQ(reference_interfaces[0]->get_prefix_name(), TEST_CONTROLLER_NAME);
72+
EXPECT_EQ(reference_interfaces[0]->get_interface_name(), "test_itf");
7373

74-
EXPECT_EQ(reference_interfaces[0].get_value(), INTERFACE_VALUE);
74+
EXPECT_EQ(reference_interfaces[0]->get_value(), INTERFACE_VALUE);
7575
}
7676

7777
TEST_F(ChainableControllerInterfaceTest, interfaces_prefix_is_not_node_name)
@@ -127,7 +127,7 @@ TEST_F(ChainableControllerInterfaceTest, setting_chained_mode)
127127

128128
EXPECT_TRUE(controller.set_chained_mode(true));
129129
EXPECT_TRUE(controller.is_in_chained_mode());
130-
EXPECT_EQ(exported_state_interfaces[0].get_value(), EXPORTED_STATE_INTERFACE_VALUE_IN_CHAINMODE);
130+
EXPECT_EQ(exported_state_interfaces[0]->get_value(), EXPORTED_STATE_INTERFACE_VALUE_IN_CHAINMODE);
131131

132132
controller.configure();
133133
EXPECT_TRUE(controller.set_chained_mode(false));

controller_manager/src/controller_manager.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -752,12 +752,13 @@ controller_interface::return_type ControllerManager::configure_controller(
752752
get_logger(),
753753
"Controller '%s' is chainable. Interfaces are being exported to resource manager.",
754754
controller_name.c_str());
755-
auto state_interfaces = controller->export_state_interfaces();
756-
std::vector<std::shared_ptr<hardware_interface::CommandInterface>> interfaces;
755+
std::vector<std::shared_ptr<hardware_interface::StateInterface>> state_interfaces;
756+
std::vector<std::shared_ptr<hardware_interface::CommandInterface>> ref_interfaces;
757757
try
758758
{
759-
interfaces = controller->export_reference_interfaces();
760-
if (interfaces.empty() && state_interfaces.empty())
759+
state_interfaces = controller->export_state_interfaces();
760+
ref_interfaces = controller->export_reference_interfaces();
761+
if (ref_interfaces.empty() && state_interfaces.empty())
761762
{
762763
// TODO(destogl): Add test for this!
763764
RCLCPP_ERROR(

hardware_interface/include/hardware_interface/actuator_interface.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod
120120
* \returns CallbackReturn::SUCCESS if required data are provided and can be parsed.
121121
* \returns CallbackReturn::ERROR if any error happens or data are missing.
122122
*/
123-
virtual CallbackReturn on_init(const HardwareInfo & /*hardware_info*/)
123+
virtual CallbackReturn on_init(const HardwareInfo & hardware_info)
124124
{
125125
info_ = hardware_info;
126126
import_state_interface_descriptions(info_);

hardware_interface/include/hardware_interface/resource_manager.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class HARDWARE_INTERFACE_PUBLIC ResourceManager
141141
* \param[in] interfaces list of controller's state interfaces as StateInterfaces.
142142
*/
143143
void import_controller_exported_state_interfaces(
144-
const std::string & controller_name, std::vector<StateInterface> & interfaces);
144+
const std::string & controller_name, std::vector<std::shared_ptr<StateInterface>> & interfaces);
145145

146146
/// Get list of exported tate interface of a controller.
147147
/**

hardware_interface/include/hardware_interface/sensor_interface.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class SensorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
120120
* \returns CallbackReturn::SUCCESS if required data are provided and can be parsed.
121121
* \returns CallbackReturn::ERROR if any error happens or data are missing.
122122
*/
123-
virtual CallbackReturn on_init(const HardwareInfo & /*hardware_info*/)
123+
virtual CallbackReturn on_init(const HardwareInfo & hardware_info)
124124
{
125125
info_ = hardware_info;
126126
import_state_interface_descriptions(info_);

0 commit comments

Comments
 (0)