ros2_control - humble
Loading...
Searching...
No Matches
zenbedded_hardware.hpp
1// Copyright 2026 kamal2730
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef ZENBEDDED_HARDWARE_INTERFACE__ZENBEDDED_HARDWARE_HPP_
16#define ZENBEDDED_HARDWARE_INTERFACE__ZENBEDDED_HARDWARE_HPP_
17
18#include <cstddef>
19#include <cstdint>
20#include <memory>
21#include <string>
22#include <vector>
23
24#include <realtime_tools/realtime_buffer.hpp>
25#include <zenoh.hxx>
26#include "hardware_interface/handle.hpp"
27#include "hardware_interface/hardware_info.hpp"
28#include "hardware_interface/system_interface.hpp"
29#include "hardware_interface/types/hardware_interface_return_values.hpp"
30#include "rclcpp/clock.hpp"
31#include "rclcpp/macros.hpp"
32#include "rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp"
33#include "rclcpp_lifecycle/state.hpp"
34#include "zenbedded_schema/interface_schema.hpp"
35
36namespace zenbedded
37{
38using CallbackReturn = rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn;
39
41{
42public:
43 RCLCPP_SHARED_PTR_DEFINITIONS(ZenbeddedHardware)
44
45 CallbackReturn on_init(
46 const hardware_interface::HardwareComponentInterfaceParams & params) override;
47
48 std::vector<hardware_interface::StateInterface> export_state_interfaces() override;
49
50 std::vector<hardware_interface::CommandInterface> export_command_interfaces() override;
51
52 CallbackReturn on_activate(const rclcpp_lifecycle::State & previous_state) override;
53
54 CallbackReturn on_deactivate(const rclcpp_lifecycle::State & previous_state) override;
55
56 hardware_interface::return_type read(
57 const rclcpp::Time & time, const rclcpp::Duration & period) override;
58
59 hardware_interface::return_type write(
60 const rclcpp::Time & time, const rclcpp::Duration & period) override;
61
62private:
63 std::unique_ptr<zenoh::Session> session_;
64
65 InterfaceSchema schema_;
66
67 // Lock-free state buffer
69 std::vector<uint8_t> command_buffer_;
70
71 // Zenoh sub/pub
72 std::unique_ptr<zenoh::Subscriber<void>> state_sub_;
73 std::unique_ptr<zenoh::Publisher> command_pub_;
74
75 std::vector<double> hw_commands_;
76 std::vector<double> hw_states_;
77 std::string zenoh_endpoint_;
78 std::string zenoh_mode_;
79 std::string state_topic_;
80 std::string command_topic_;
81 rclcpp::Clock steady_clock_{RCL_STEADY_TIME};
82};
83
84} // namespace zenbedded
85
86#endif // ZENBEDDED_HARDWARE_INTERFACE__ZENBEDDED_HARDWARE_HPP_
Virtual Class to implement when integrating a complex system into ros2_control.
Definition system_interface.hpp:85
Definition realtime_buffer.hpp:44
Definition interface_schema.hpp:60
Definition zenbedded_hardware.hpp:41
std::vector< hardware_interface::StateInterface > export_state_interfaces() override
Exports all state interfaces for this hardware interface.
Definition zenbedded_hardware.cpp:96
std::vector< hardware_interface::CommandInterface > export_command_interfaces() override
Exports all command interfaces for this hardware interface.
Definition zenbedded_hardware.cpp:107
hardware_interface::return_type read(const rclcpp::Time &time, const rclcpp::Duration &period) override
Read the current state values from the actuator.
Definition zenbedded_hardware.cpp:182
hardware_interface::return_type write(const rclcpp::Time &time, const rclcpp::Duration &period) override
Write the current command values to the actuator.
Definition zenbedded_hardware.cpp:196