Skip to content

Commit

Permalink
export_interfaces_2() virtual for custom interface export
Browse files Browse the repository at this point in the history
  • Loading branch information
mamueluth committed Jan 29, 2024
1 parent a7db21d commit 5e4118b
Show file tree
Hide file tree
Showing 6 changed files with 281 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,20 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod
return {};
}

/**
* Override this method to export custom StateInterfaces which are not defined in the URDF file.
*
* Note method name is going to be changed to export_state_interfaces() as soon as the deprecated
* version is removed.
*
* \return vector of shared pointers to the created and stored StateInterfaces
*/
virtual std::vector<std::shared_ptr<StateInterface>> export_state_interfaces_2()
{
// return empty vector by default.
return {};
}

/**
* Default implementation for exporting the StateInterfaces. The StateInterfaces are created
* according to the InterfaceDescription. The memory accessed by the controllers and hardware is
Expand All @@ -168,7 +182,7 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod
*/
virtual std::vector<std::shared_ptr<StateInterface>> on_export_state_interfaces()
{
std::vector<std::shared_ptr<StateInterface>> state_interfaces;
std::vector<std::shared_ptr<StateInterface>> state_interfaces = export_state_interfaces_2();
state_interfaces.reserve(joint_state_interfaces_.size());

for (const auto & [name, descr] : joint_state_interfaces_)
Expand Down Expand Up @@ -204,6 +218,20 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod
return {};
}

/**
* Override this method to export custom CommandInterfaces which are not defined in the URDF file.
*
* Note method name is going to be changed to export_command_interfaces() as soon as the
* deprecated version is removed.
*
* \return vector of shared pointers to the created and stored StateInterfaces
*/
virtual std::vector<std::shared_ptr<CommandInterface>> export_command_interfaces_2()
{
// return empty vector by default.
return {};
}

/**
* Default implementation for exporting the CommandInterfaces. The CommandInterfaces are created
* according to the InterfaceDescription. The memory accessed by the controllers and hardware is
Expand All @@ -213,7 +241,8 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod
*/
virtual std::vector<std::shared_ptr<CommandInterface>> on_export_command_interfaces()
{
std::vector<std::shared_ptr<CommandInterface>> command_interfaces;
std::vector<std::shared_ptr<CommandInterface>> command_interfaces =
export_command_interfaces_2();
command_interfaces.reserve(joint_command_interfaces_.size());

for (const auto & [name, descr] : joint_command_interfaces_)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ struct InterfaceInfo
std::string max;
/// (Optional) Initial value of the interface.
std::string initial_value;
/// (Optional) The datatype of the interface, e.g. "bool", "int". Used by GPIOs.
/// (Optional) The datatype of the interface, e.g. "bool", "int".
std::string data_type;
/// (Optional) If the handle is an array, the size of the array. Used by GPIOs.
/// (Optional) If the handle is an array, the size of the array.
int size;
};

Expand Down Expand Up @@ -118,11 +118,6 @@ struct InterfaceDescription
*/
std::string prefix_name;

/**
* What type of component is exported: joint, sensor or gpio
*/
std::string component_type;

/**
* Information about the Interface type (position, velocity,...) as well as limits and so on.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,20 @@ class SensorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
return {};
}

/**
* Override this method to export custom StateInterfaces which are not defined in the URDF file.
*
* Note method name is going to be changed to export_state_interfaces() as soon as the deprecated
* version is removed.
*
* \return vector of shared pointers to the created and stored StateInterfaces
*/
virtual std::vector<std::shared_ptr<StateInterface>> export_state_interfaces_2()
{
// return empty vector by default.
return {};
}

/**
* Default implementation for exporting the StateInterfaces. The StateInterfaces are created
* according to the InterfaceDescription. The memory accessed by the controllers and hardware is
Expand All @@ -152,7 +166,7 @@ class SensorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
*/
virtual std::vector<std::shared_ptr<StateInterface>> on_export_state_interfaces()
{
std::vector<std::shared_ptr<StateInterface>> state_interfaces;
std::vector<std::shared_ptr<StateInterface>> state_interfaces = export_state_interfaces_2();
state_interfaces.reserve(sensor_state_interfaces_.size());

for (const auto & [name, descr] : sensor_state_interfaces_)
Expand Down
37 changes: 33 additions & 4 deletions hardware_interface/include/hardware_interface/system_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,30 @@ class SystemInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
return {};
}

/**
* Override this method to export custom StateInterfaces which are not defined in the URDF file.
*
* Note method name is going to be changed to export_state_interfaces() as soon as the deprecated
* version is removed.
*
* \return vector of shared pointers to the created and stored StateInterfaces
*/
virtual std::vector<std::shared_ptr<StateInterface>> export_state_interfaces_2()
{
// return empty vector by default.
return {};
}

/**
* Default implementation for exporting the StateInterfaces. The StateInterfaces are created
* according to the InterfaceDescription. The memory accessed by the controllers and hardware is
* assigned here and resides in the system_interface.
*
* \return vector of shared pointers to the created and stored StateInterfaces
*/
virtual std::vector<std::shared_ptr<StateInterface>> on_export_state_interfaces()
std::vector<std::shared_ptr<StateInterface>> on_export_state_interfaces()
{
std::vector<std::shared_ptr<StateInterface>> state_interfaces;
std::vector<std::shared_ptr<StateInterface>> state_interfaces = export_state_interfaces_2();
state_interfaces.reserve(
joint_state_interfaces_.size() + sensor_state_interfaces_.size() +
gpio_state_interfaces_.size());
Expand Down Expand Up @@ -237,16 +251,31 @@ class SystemInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
return {};
}

/**
* Override this method to export custom CommandInterfaces which are not defined in the URDF file.
*
* Note method name is going to be changed to export_command_interfaces() as soon as the
* deprecated version is removed.
*
* \return vector of shared pointers to the created and stored StateInterfaces
*/
virtual std::vector<std::shared_ptr<CommandInterface>> export_command_interfaces_2()
{
// return empty vector by default.
return {};
}

/**
* Default implementation for exporting the CommandInterfaces. The CommandInterfaces are created
* according to the InterfaceDescription. The memory accessed by the controllers and hardware is
* assigned here and resides in the system_interface.
*
* \return vector of shared pointers to the created and stored CommandInterfaces
*/
virtual std::vector<std::shared_ptr<CommandInterface>> on_export_command_interfaces()
std::vector<std::shared_ptr<CommandInterface>> on_export_command_interfaces()
{
std::vector<std::shared_ptr<CommandInterface>> command_interfaces;
std::vector<std::shared_ptr<CommandInterface>> command_interfaces =
export_command_interfaces_2();
command_interfaces.reserve(joint_command_interfaces_.size() + gpio_command_interfaces_.size());

for (const auto & [name, descr] : joint_command_interfaces_)
Expand Down
Loading

0 comments on commit 5e4118b

Please sign in to comment.