ros2_control - galactic
Loading...
Searching...
No Matches
joint_state_topic_hardware_interface.hpp
1// Copyright 2025 ros2_control Development Team
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/* Author: Jafar Abdi */
16
17#pragma once
18
19// C++
20#include <memory>
21#include <string>
22
23// ROS
24#include <hardware_interface/system_interface.hpp>
25#include <hardware_interface/types/hardware_component_interface_params.hpp>
26#include <rclcpp/node.hpp>
27#include <rclcpp/publisher.hpp>
28#include <rclcpp/subscription.hpp>
29
30#include <sensor_msgs/msg/joint_state.hpp>
31
32namespace joint_state_topic_hardware_interface
33{
34using CallbackReturn = rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn;
35
37{
38public:
39 CallbackReturn on_init(const hardware_interface::HardwareComponentInterfaceParams& params) override;
40
41 hardware_interface::return_type read(const rclcpp::Time& time, const rclcpp::Duration& period) override;
42
43 hardware_interface::return_type write(const rclcpp::Time& /*time*/, const rclcpp::Duration& /*period*/) override;
44
45private:
46 rclcpp::Subscription<sensor_msgs::msg::JointState>::SharedPtr topic_based_joint_states_subscriber_;
47 rclcpp::Publisher<sensor_msgs::msg::JointState>::SharedPtr topic_based_joint_commands_publisher_;
48 sensor_msgs::msg::JointState latest_joint_state_;
49 bool sum_wrapped_joint_states_{ false };
50
51 // If the difference between the current joint state and joint command is less than this value,
52 // the joint command will not be published.
53 double trigger_joint_command_threshold_ = 1e-5;
54};
55
56} // namespace joint_state_topic_hardware_interface
Virtual Class to implement when integrating a complex system into ros2_control.
Definition system_interface.hpp:68
virtual return_type read()=0
Read the current state values from the actuator.
virtual return_type write()=0
Write the current command values to the actuator.
Definition joint_state_topic_hardware_interface.hpp:37