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/macros.hpp"
31#include "rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp"
32#include "rclcpp_lifecycle/state.hpp"
33#include "zenbedded_schema/interface_schema.hpp"
34
35namespace zenbedded
36{
37using CallbackReturn = rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn;
38
40{
41public:
42 RCLCPP_SHARED_PTR_DEFINITIONS(ZenbeddedHardware)
43
44 CallbackReturn on_init(
45 const hardware_interface::HardwareComponentInterfaceParams & params) override;
46
47 std::vector<hardware_interface::StateInterface> export_state_interfaces() override;
48
49 std::vector<hardware_interface::CommandInterface> export_command_interfaces() override;
50
51 CallbackReturn on_activate(const rclcpp_lifecycle::State & previous_state) override;
52
53 CallbackReturn on_deactivate(const rclcpp_lifecycle::State & previous_state) override;
54
55 hardware_interface::return_type read(
56 const rclcpp::Time & time, const rclcpp::Duration & period) override;
57
58 hardware_interface::return_type write(
59 const rclcpp::Time & time, const rclcpp::Duration & period) override;
60
61private:
62 std::unique_ptr<zenoh::Session> session_;
63
64 InterfaceSchema schema_;
65
66 // Lock-free state buffer
68 std::vector<uint8_t> command_buffer_;
69
70 // Zenoh sub/pub
71 std::unique_ptr<zenoh::Subscriber<void>> state_sub_;
72 std::unique_ptr<zenoh::Publisher> command_pub_;
73
74 std::vector<double> hw_commands_;
75 std::vector<double> hw_states_;
76 std::string zenoh_endpoint_;
77 std::string zenoh_mode_;
78 std::string state_topic_;
79 std::string command_topic_;
80};
81
82} // namespace zenbedded
83
84#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:40
std::vector< hardware_interface::StateInterface > export_state_interfaces() override
Exports all state interfaces for this hardware interface.
Definition zenbedded_hardware.cpp:83
std::vector< hardware_interface::CommandInterface > export_command_interfaces() override
Exports all command interfaces for this hardware interface.
Definition zenbedded_hardware.cpp:94
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:153
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:167