Skip to content

Commit

Permalink
hal_hw_interface: Update for Humble ros2_control
Browse files Browse the repository at this point in the history
PR 503 changes a bunch of stuff.
ros-controls/ros2_control#503

`ros2_control` distro `hardware_interface` package dropped the
`hardware_interface/base_interface.hpp` header.  Notes say to replace
`hardware_interface::BaseInterface<hardware_interface::SystemInterface>`
with `hardware_interface::SystemInterface`

    In file included from [...]/hal_ros_control/hal_hw_interface/src/hal_system_interface.cpp:39:
    [...]/hal_ros_control/hal_hw_interface/include/hal_hw_interface/hal_system_interface.hpp:48:10: fatal error: hardware_interface/base_interface.hpp: No such file or directory
       48 | #include "hardware_interface/base_interface.hpp"
          |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    compilation terminated.
    gmake[2]: *** [CMakeFiles/hal_system_interface.dir/build.make:76: CMakeFiles/hal_system_interface.dir/src/hal_system_interface.cpp.o] Error 1

Notes also say to rename `configure()` to `on_init()` and change
return type to `CallbackReturn`.  Replace `on_init()`
`return_type::ERROR` with `CallbackReturn::ERROR`.
  • Loading branch information
zultron committed Apr 7, 2023
1 parent 4c1a0a8 commit 5b338f7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
#include <unordered_map>

#include "hardware_interface/handle.hpp"
#include "hardware_interface/base_interface.hpp"
#include "hardware_interface/system_interface.hpp"
#include "rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp"
#include "rclcpp_lifecycle/state.hpp"
Expand Down Expand Up @@ -100,16 +99,15 @@ namespace hal_system_interface
* [1]: https://github.com/PickNikRobotics/ros_control_boilerplate
*/

class HalSystemInterface : public hardware_interface::BaseInterface<
hardware_interface::SystemInterface>
class HalSystemInterface : public hardware_interface::SystemInterface
{
public:
// Define aliases and static functions for using the Class with shared_ptrs
RCLCPP_SHARED_PTR_DEFINITIONS(HalSystemInterface);

HAL_HW_INTERFACE_PUBLIC
hardware_interface::return_type
configure(const hardware_interface::HardwareInfo& info) override;
CallbackReturn
on_init(const hardware_interface::HardwareInfo& info) override;

HAL_HW_INTERFACE_PUBLIC
std::vector<hardware_interface::StateInterface>
Expand All @@ -130,10 +128,10 @@ class HalSystemInterface : public hardware_interface::BaseInterface<
// const std::vector<std::string> & /*stop_interfaces*/) override;

HAL_HW_INTERFACE_PUBLIC
hardware_interface::return_type start() override;
CallbackReturn on_activate();

HAL_HW_INTERFACE_PUBLIC
hardware_interface::return_type stop() override;
CallbackReturn on_deactivate();

HAL_HW_INTERFACE_PUBLIC
hardware_interface::return_type read(const rclcpp::Time & time, const rclcpp::Duration & period) override;
Expand Down
18 changes: 9 additions & 9 deletions hal_hw_interface/src/hal_system_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ void HalSystemInterface::init_state_interface(const std::string joint_name,
.handle_storage = 0.0 };
}

hardware_interface::return_type
HalSystemInterface::configure(const hardware_interface::HardwareInfo& info)
CallbackReturn
HalSystemInterface::on_init(const hardware_interface::HardwareInfo& info)
{
if (configure_default(info) != hardware_interface::return_type::OK)
if (hardware_interface::SystemInterface::on_init(info) != CallbackReturn::SUCCESS)
{
return hardware_interface::return_type::ERROR;
return CallbackReturn::ERROR;
}

HAL_ROS_INFO_NAMED(LOG_NAME, "Initializing HAL hardware interface");
Expand Down Expand Up @@ -149,7 +149,7 @@ HalSystemInterface::configure(const hardware_interface::HardwareInfo& info)

HAL_ROS_INFO_NAMED(LOG_NAME, "Initialized HAL pins");

return hardware_interface::return_type::OK;
return CallbackReturn::SUCCESS;
} // configure()

std::vector<hardware_interface::StateInterface>
Expand Down Expand Up @@ -190,16 +190,16 @@ hardware_interface::return_type HalSystemInterface::write([[maybe_unused]] const
return hardware_interface::return_type::OK;
}

hardware_interface::return_type HalSystemInterface::start()
CallbackReturn HalSystemInterface::on_activate()
{
HAL_ROS_INFO_NAMED(LOG_NAME, "Starting HAL system interface");
return hardware_interface::return_type::OK;
return CallbackReturn::SUCCESS;
}

hardware_interface::return_type HalSystemInterface::stop()
CallbackReturn HalSystemInterface::on_deactivate()
{
HAL_ROS_INFO_NAMED(LOG_NAME, "Stopping HAL system interface");
return hardware_interface::return_type::OK;
return CallbackReturn::SUCCESS;
}

} // namespace hal_system_interface
Expand Down

0 comments on commit 5b338f7

Please sign in to comment.