Skip to content

Commit

Permalink
undo prefix_ -> prefix (HWInfo) and Command-/StateIntefaceSharedPtr
Browse files Browse the repository at this point in the history
  • Loading branch information
mamueluth committed Jan 26, 2024
1 parent 720e11f commit 95b31ee
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 53 deletions.
4 changes: 2 additions & 2 deletions hardware_interface/include/hardware_interface/actuator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ class Actuator final
const rclcpp_lifecycle::State & error();

HARDWARE_INTERFACE_PUBLIC
std::vector<StateInterfaceSharedPtr> export_state_interfaces();
std::vector<std::shared_ptr<StateInterface>> export_state_interfaces();

HARDWARE_INTERFACE_PUBLIC
std::vector<CommandInterfaceSharedPtr> export_command_interfaces();
std::vector<std::shared_ptr<CommandInterface>> export_command_interfaces();

HARDWARE_INTERFACE_PUBLIC
return_type prepare_command_mode_switch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod
* \return vector of state interfaces
*/
[[deprecated(
"Replaced by vector<StateInterfaceSharedPtr> on_export_state_interfaces() method. "
"Replaced by vector<std::shared_ptr<StateInterface>> on_export_state_interfaces() method. "
"Exporting is "
"handled "
"by the Framework.")]] virtual std::vector<StateInterface>
Expand All @@ -166,9 +166,9 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod
*
* \return vector of shared pointers to the created and stored StateInterfaces
*/
virtual std::vector<StateInterfaceSharedPtr> on_export_state_interfaces()
virtual std::vector<std::shared_ptr<StateInterface>> on_export_state_interfaces()
{
std::vector<StateInterfaceSharedPtr> state_interfaces;
std::vector<std::shared_ptr<StateInterface>> state_interfaces;
state_interfaces.reserve(joint_state_interfaces_.size());

for (const auto & [name, descr] : joint_state_interfaces_)
Expand All @@ -193,7 +193,7 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod
* \return vector of state interfaces
*/
[[deprecated(
"Replaced by vector<CommandInterfaceSharedPtr> on_export_command_interfaces() method. "
"Replaced by vector<std::shared_ptr<CommandInterface>> on_export_command_interfaces() method. "
"Exporting is "
"handled "
"by the Framework.")]] virtual std::vector<CommandInterface>
Expand All @@ -211,9 +211,9 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod
*
* \return vector of shared pointers to the created and stored CommandInterfaces
*/
virtual std::vector<CommandInterfaceSharedPtr> on_export_command_interfaces()
virtual std::vector<std::shared_ptr<CommandInterface>> on_export_command_interfaces()
{
std::vector<CommandInterfaceSharedPtr> command_interfaces;
std::vector<std::shared_ptr<CommandInterface>> command_interfaces;
command_interfaces.reserve(joint_command_interfaces_.size());

for (const auto & [name, descr] : joint_command_interfaces_)
Expand Down Expand Up @@ -330,8 +330,8 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod
std::map<std::string, InterfaceDescription> joint_state_interfaces_;
std::map<std::string, InterfaceDescription> joint_command_interfaces_;

std::unordered_map<std::string, StateInterfaceSharedPtr> actuator_states_;
std::unordered_map<std::string, CommandInterfaceSharedPtr> actuator_commands_;
std::unordered_map<std::string, std::shared_ptr<StateInterface>> actuator_states_;
std::unordered_map<std::string, std::shared_ptr<CommandInterface>> actuator_commands_;

rclcpp_lifecycle::State lifecycle_state_;
};
Expand Down
6 changes: 1 addition & 5 deletions hardware_interface/include/hardware_interface/handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Handle
}

explicit Handle(const InterfaceDescription & interface_description)
: prefix_name_(interface_description.prefix_name_),
: prefix_name_(interface_description.prefix_name),
interface_name_(interface_description.interface_info.name)
{
// As soon as multiple datatypes are used in HANDLE_DATATYPE
Expand Down Expand Up @@ -136,8 +136,6 @@ class StateInterface : public Handle
using Handle::Handle;
};

using StateInterfaceSharedPtr = std::shared_ptr<StateInterface>;

class CommandInterface : public Handle
{
public:
Expand All @@ -158,8 +156,6 @@ class CommandInterface : public Handle
using Handle::Handle;
};

using CommandInterfaceSharedPtr = std::shared_ptr<CommandInterface>;

} // namespace hardware_interface

#endif // HARDWARE_INTERFACE__HANDLE_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ struct TransmissionInfo
*/
struct InterfaceDescription
{
InterfaceDescription(const std::string & prefix_name, const InterfaceInfo & interface_info_in)
: prefix_name_(prefix_name), interface_info(interface_info_in)
InterfaceDescription(const std::string & prefix_name_in, const InterfaceInfo & interface_info_in)
: prefix_name(prefix_name_in), interface_info(interface_info_in)
{
}

/**
* Name of the interface defined by the user.
*/
std::string prefix_name_;
std::string prefix_name;

/**
* What type of component is exported: joint, sensor or gpio
Expand All @@ -128,7 +128,7 @@ struct InterfaceDescription
*/
InterfaceInfo interface_info;

std::string get_name() const { return prefix_name_ + "/" + interface_info.name; }
std::string get_name() const { return prefix_name + "/" + interface_info.name; }

std::string get_interface_type() const { return interface_info.name; }
};
Expand Down
2 changes: 1 addition & 1 deletion hardware_interface/include/hardware_interface/sensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Sensor final
const rclcpp_lifecycle::State & error();

HARDWARE_INTERFACE_PUBLIC
std::vector<StateInterfaceSharedPtr> export_state_interfaces();
std::vector<std::shared_ptr<StateInterface>> export_state_interfaces();

HARDWARE_INTERFACE_PUBLIC
std::string get_name() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class SensorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
* \return vector of state interfaces
*/
[[deprecated(
"Replaced by vector<StateInterfaceSharedPtr> on_export_state_interfaces() method. "
"Replaced by vector<std::shared_ptr<StateInterface>> on_export_state_interfaces() method. "
"Exporting is handled "
"by the Framework.")]] virtual std::vector<StateInterface>
export_state_interfaces()
Expand All @@ -150,9 +150,9 @@ class SensorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
*
* \return vector of shared pointers to the created and stored StateInterfaces
*/
virtual std::vector<StateInterfaceSharedPtr> on_export_state_interfaces()
virtual std::vector<std::shared_ptr<StateInterface>> on_export_state_interfaces()
{
std::vector<StateInterfaceSharedPtr> state_interfaces;
std::vector<std::shared_ptr<StateInterface>> state_interfaces;
state_interfaces.reserve(sensor_state_interfaces_.size());

for (const auto & [name, descr] : sensor_state_interfaces_)
Expand Down Expand Up @@ -212,7 +212,7 @@ class SensorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI

std::map<std::string, InterfaceDescription> sensor_state_interfaces_;

std::unordered_map<std::string, StateInterfaceSharedPtr> sensor_states_;
std::unordered_map<std::string, std::shared_ptr<StateInterface>> sensor_states_;

rclcpp_lifecycle::State lifecycle_state_;
};
Expand Down
4 changes: 2 additions & 2 deletions hardware_interface/include/hardware_interface/system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ class System final
const rclcpp_lifecycle::State & error();

HARDWARE_INTERFACE_PUBLIC
std::vector<StateInterfaceSharedPtr> export_state_interfaces();
std::vector<std::shared_ptr<StateInterface>> export_state_interfaces();

HARDWARE_INTERFACE_PUBLIC
std::vector<CommandInterfaceSharedPtr> export_command_interfaces();
std::vector<std::shared_ptr<CommandInterface>> export_command_interfaces();

HARDWARE_INTERFACE_PUBLIC
return_type prepare_command_mode_switch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class SystemInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
* \return vector of state interfaces
*/
[[deprecated(
"Replaced by vector<StateInterfaceSharedPtr> on_export_state_interfaces() method. "
"Replaced by vector<std::shared_ptr<StateInterface>> on_export_state_interfaces() method. "
"Exporting is handled "
"by the Framework.")]] virtual std::vector<StateInterface>
export_state_interfaces()
Expand All @@ -185,9 +185,9 @@ class SystemInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
*
* \return vector of shared pointers to the created and stored StateInterfaces
*/
virtual std::vector<StateInterfaceSharedPtr> on_export_state_interfaces()
virtual std::vector<std::shared_ptr<StateInterface>> on_export_state_interfaces()
{
std::vector<StateInterfaceSharedPtr> state_interfaces;
std::vector<std::shared_ptr<StateInterface>> state_interfaces;
state_interfaces.reserve(
joint_state_interfaces_.size() + sensor_state_interfaces_.size() +
gpio_state_interfaces_.size());
Expand Down Expand Up @@ -226,7 +226,7 @@ class SystemInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
* \return vector of state interfaces
*/
[[deprecated(
"Replaced by vector<CommandInterfaceSharedPtr> on_export_command_interfaces() method. "
"Replaced by vector<std::shared_ptr<CommandInterface>> on_export_command_interfaces() method. "
"Exporting is "
"handled "
"by the Framework.")]] virtual std::vector<CommandInterface>
Expand All @@ -244,9 +244,9 @@ class SystemInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
*
* \return vector of shared pointers to the created and stored CommandInterfaces
*/
virtual std::vector<CommandInterfaceSharedPtr> on_export_command_interfaces()
virtual std::vector<std::shared_ptr<CommandInterface>> on_export_command_interfaces()
{
std::vector<CommandInterfaceSharedPtr> command_interfaces;
std::vector<std::shared_ptr<CommandInterface>> command_interfaces;
command_interfaces.reserve(joint_command_interfaces_.size() + gpio_command_interfaces_.size());

for (const auto & [name, descr] : joint_command_interfaces_)
Expand Down Expand Up @@ -375,8 +375,8 @@ class SystemInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
std::map<std::string, InterfaceDescription> gpio_state_interfaces_;
std::map<std::string, InterfaceDescription> gpio_command_interfaces_;

std::unordered_map<std::string, StateInterfaceSharedPtr> system_states_;
std::unordered_map<std::string, CommandInterfaceSharedPtr> system_commands_;
std::unordered_map<std::string, std::shared_ptr<StateInterface>> system_states_;
std::unordered_map<std::string, std::shared_ptr<CommandInterface>> system_commands_;

rclcpp_lifecycle::State lifecycle_state_;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class DummyActuatorDefault : public hardware_interface::ActuatorInterface
{
std::string get_name() const override { return "DummyActuatorDefault"; }

std::vector<hardware_interface::StateInterfaceSharedPtr> on_export_state_interfaces() override
std::vector<std::shared_ptr<hardware_interface::StateInterface>> on_export_state_interfaces()
override
{
auto interfaces = hardware_interface::ActuatorInterface::on_export_state_interfaces();
auto unlisted_state_interface = std::make_shared<hardware_interface::StateInterface>(
Expand All @@ -68,7 +69,8 @@ class DummyActuatorDefault : public hardware_interface::ActuatorInterface
return interfaces;
}

std::vector<hardware_interface::CommandInterfaceSharedPtr> on_export_command_interfaces() override
std::vector<std::shared_ptr<hardware_interface::CommandInterface>> on_export_command_interfaces()
override
{
auto interfaces = hardware_interface::ActuatorInterface::on_export_command_interfaces();
auto unlisted_state_interface = std::make_shared<hardware_interface::CommandInterface>(
Expand Down Expand Up @@ -97,7 +99,8 @@ class DummySensorDefault : public hardware_interface::SensorInterface
{
std::string get_name() const override { return "DummySensorDefault"; }

std::vector<hardware_interface::StateInterfaceSharedPtr> on_export_state_interfaces() override
std::vector<std::shared_ptr<hardware_interface::StateInterface>> on_export_state_interfaces()
override
{
auto interfaces = hardware_interface::SensorInterface::on_export_state_interfaces();
auto unlisted_state_interface = std::make_shared<hardware_interface::StateInterface>(
Expand All @@ -120,7 +123,8 @@ class DummySystemDefault : public hardware_interface::SystemInterface
{
std::string get_name() const override { return "DummySystemDefault"; }

std::vector<hardware_interface::StateInterfaceSharedPtr> on_export_state_interfaces() override
std::vector<std::shared_ptr<hardware_interface::StateInterface>> on_export_state_interfaces()
override
{
auto interfaces = hardware_interface::SystemInterface::on_export_state_interfaces();
auto unlisted_state_interface = std::make_shared<hardware_interface::StateInterface>(
Expand All @@ -132,7 +136,8 @@ class DummySystemDefault : public hardware_interface::SystemInterface
return interfaces;
}

std::vector<hardware_interface::CommandInterfaceSharedPtr> on_export_command_interfaces() override
std::vector<std::shared_ptr<hardware_interface::CommandInterface>> on_export_command_interfaces()
override
{
auto interfaces = hardware_interface::SystemInterface::on_export_command_interfaces();
auto unlisted_state_interface = std::make_shared<hardware_interface::CommandInterface>(
Expand Down
28 changes: 14 additions & 14 deletions hardware_interface/test/test_component_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,11 +685,11 @@ TEST_F(TestComponentParser, parse_joint_state_interface_descriptions_from_hardwa

const auto joint_state_descriptions =
parse_joint_state_interface_descriptions_from_hardware_info(control_hardware[0]);
EXPECT_EQ(joint_state_descriptions[0].prefix_name_, "joint1");
EXPECT_EQ(joint_state_descriptions[0].prefix_name, "joint1");
EXPECT_EQ(joint_state_descriptions[0].get_interface_type(), "position");
EXPECT_EQ(joint_state_descriptions[0].get_name(), "joint1/position");

EXPECT_EQ(joint_state_descriptions[1].prefix_name_, "joint2");
EXPECT_EQ(joint_state_descriptions[1].prefix_name, "joint2");
EXPECT_EQ(joint_state_descriptions[1].get_interface_type(), "position");
EXPECT_EQ(joint_state_descriptions[1].get_name(), "joint2/position");
}
Expand All @@ -704,13 +704,13 @@ TEST_F(TestComponentParser, parse_joint_command_interface_descriptions_from_hard

const auto joint_command_descriptions =
parse_joint_command_interface_descriptions_from_hardware_info(control_hardware[0]);
EXPECT_EQ(joint_command_descriptions[0].prefix_name_, "joint1");
EXPECT_EQ(joint_command_descriptions[0].prefix_name, "joint1");
EXPECT_EQ(joint_command_descriptions[0].get_interface_type(), "position");
EXPECT_EQ(joint_command_descriptions[0].get_name(), "joint1/position");
EXPECT_EQ(joint_command_descriptions[0].interface_info.min, "-1");
EXPECT_EQ(joint_command_descriptions[0].interface_info.max, "1");

EXPECT_EQ(joint_command_descriptions[1].prefix_name_, "joint2");
EXPECT_EQ(joint_command_descriptions[1].prefix_name, "joint2");
EXPECT_EQ(joint_command_descriptions[1].get_interface_type(), "position");
EXPECT_EQ(joint_command_descriptions[1].get_name(), "joint2/position");
EXPECT_EQ(joint_command_descriptions[1].interface_info.min, "-1");
Expand All @@ -726,17 +726,17 @@ TEST_F(TestComponentParser, parse_sensor_state_interface_descriptions_from_hardw

const auto sensor_state_descriptions =
parse_sensor_state_interface_descriptions_from_hardware_info(control_hardware[0]);
EXPECT_EQ(sensor_state_descriptions[0].prefix_name_, "sensor1");
EXPECT_EQ(sensor_state_descriptions[0].prefix_name, "sensor1");
EXPECT_EQ(sensor_state_descriptions[0].get_interface_type(), "roll");
EXPECT_EQ(sensor_state_descriptions[0].get_name(), "sensor1/roll");
EXPECT_EQ(sensor_state_descriptions[1].prefix_name_, "sensor1");
EXPECT_EQ(sensor_state_descriptions[1].prefix_name, "sensor1");
EXPECT_EQ(sensor_state_descriptions[1].get_interface_type(), "pitch");
EXPECT_EQ(sensor_state_descriptions[1].get_name(), "sensor1/pitch");
EXPECT_EQ(sensor_state_descriptions[2].prefix_name_, "sensor1");
EXPECT_EQ(sensor_state_descriptions[2].prefix_name, "sensor1");
EXPECT_EQ(sensor_state_descriptions[2].get_interface_type(), "yaw");
EXPECT_EQ(sensor_state_descriptions[2].get_name(), "sensor1/yaw");

EXPECT_EQ(sensor_state_descriptions[3].prefix_name_, "sensor2");
EXPECT_EQ(sensor_state_descriptions[3].prefix_name, "sensor2");
EXPECT_EQ(sensor_state_descriptions[3].get_interface_type(), "image");
EXPECT_EQ(sensor_state_descriptions[3].get_name(), "sensor2/image");
}
Expand All @@ -751,17 +751,17 @@ TEST_F(TestComponentParser, parse_gpio_state_interface_descriptions_from_hardwar

const auto gpio_state_descriptions =
parse_gpio_state_interface_descriptions_from_hardware_info(control_hardware[0]);
EXPECT_EQ(gpio_state_descriptions[0].prefix_name_, "flange_analog_IOs");
EXPECT_EQ(gpio_state_descriptions[0].prefix_name, "flange_analog_IOs");
EXPECT_EQ(gpio_state_descriptions[0].get_interface_type(), "analog_output1");
EXPECT_EQ(gpio_state_descriptions[0].get_name(), "flange_analog_IOs/analog_output1");
EXPECT_EQ(gpio_state_descriptions[1].prefix_name_, "flange_analog_IOs");
EXPECT_EQ(gpio_state_descriptions[1].prefix_name, "flange_analog_IOs");
EXPECT_EQ(gpio_state_descriptions[1].get_interface_type(), "analog_input1");
EXPECT_EQ(gpio_state_descriptions[1].get_name(), "flange_analog_IOs/analog_input1");
EXPECT_EQ(gpio_state_descriptions[2].prefix_name_, "flange_analog_IOs");
EXPECT_EQ(gpio_state_descriptions[2].prefix_name, "flange_analog_IOs");
EXPECT_EQ(gpio_state_descriptions[2].get_interface_type(), "analog_input2");
EXPECT_EQ(gpio_state_descriptions[2].get_name(), "flange_analog_IOs/analog_input2");

EXPECT_EQ(gpio_state_descriptions[3].prefix_name_, "flange_vacuum");
EXPECT_EQ(gpio_state_descriptions[3].prefix_name, "flange_vacuum");
EXPECT_EQ(gpio_state_descriptions[3].get_interface_type(), "vacuum");
EXPECT_EQ(gpio_state_descriptions[3].get_name(), "flange_vacuum/vacuum");
}
Expand All @@ -776,11 +776,11 @@ TEST_F(TestComponentParser, parse_gpio_command_interface_descriptions_from_hardw

const auto gpio_state_descriptions =
parse_gpio_command_interface_descriptions_from_hardware_info(control_hardware[0]);
EXPECT_EQ(gpio_state_descriptions[0].prefix_name_, "flange_analog_IOs");
EXPECT_EQ(gpio_state_descriptions[0].prefix_name, "flange_analog_IOs");
EXPECT_EQ(gpio_state_descriptions[0].get_interface_type(), "analog_output1");
EXPECT_EQ(gpio_state_descriptions[0].get_name(), "flange_analog_IOs/analog_output1");

EXPECT_EQ(gpio_state_descriptions[1].prefix_name_, "flange_vacuum");
EXPECT_EQ(gpio_state_descriptions[1].prefix_name, "flange_vacuum");
EXPECT_EQ(gpio_state_descriptions[1].get_interface_type(), "vacuum");
EXPECT_EQ(gpio_state_descriptions[1].get_name(), "flange_vacuum/vacuum");
}

0 comments on commit 95b31ee

Please sign in to comment.