ros2_control - kilted
Loading...
Searching...
No Matches
free_joint_state_publisher_plugin.hpp
1// Copyright 2026 PAL Robotics S.L.
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 MUJOCO_ROS2_CONTROL_PLUGINS__FREE_JOINT_STATE_PUBLISHER_PLUGIN_HPP_
16#define MUJOCO_ROS2_CONTROL_PLUGINS__FREE_JOINT_STATE_PUBLISHER_PLUGIN_HPP_
17
18#include <memory>
19#include <string>
20#include <vector>
21
22#include <mujoco_ros2_control_msgs/msg/free_joint_state_array.hpp>
23#include <rclcpp/rclcpp.hpp>
24#include <realtime_tools/realtime_publisher.hpp>
25
26#include "mujoco_ros2_control_plugins/mujoco_ros2_control_plugins_base.hpp"
27
29{
30
54{
55public:
57 ~FreeJointStatePublisherPlugin() override = default;
58
59 bool init(rclcpp::Node::SharedPtr node, const mjModel* model, mjData* data) override;
60 void update_write(const mjModel* model, mjData* data) override;
61 void cleanup() override;
62
63private:
64 using FreeJointStateArray = mujoco_ros2_control_msgs::msg::FreeJointStateArray;
65
67 struct FreeJointEntry
68 {
69 int body_id{ -1 };
70 std::string body_name;
71 int qpos_adr{ -1 };
72 int qvel_adr{ -1 };
73 };
74
77 bool collect_free_joint_entries(const std::vector<std::string>& body_names);
78
80 int resolve_frame_id(const std::string& frame_id) const;
81
82 rclcpp::Node::SharedPtr node_;
83 rclcpp::Logger logger_{ rclcpp::get_logger("FreeJointStatePublisherPlugin") };
84
85 const mjModel* model_{ nullptr };
86
87 rclcpp::Publisher<FreeJointStateArray>::SharedPtr publisher_raw_;
88 std::unique_ptr<realtime_tools::RealtimePublisher<FreeJointStateArray>> publisher_;
89
90 std::vector<FreeJointEntry> entries_;
91
93 int frame_body_id_{ -1 };
94 std::string effective_frame_id_;
95
96 rclcpp::Duration publish_period_{ 0, 0 };
97 rclcpp::Time last_publish_time_{ 0, 0, RCL_ROS_TIME };
98
100 FreeJointStateArray message_;
101};
102
103} // namespace mujoco_ros2_control_plugins
104
105#endif // MUJOCO_ROS2_CONTROL_PLUGINS__FREE_JOINT_STATE_PUBLISHER_PLUGIN_HPP_
Plugin that publishes the pose and velocity of every MuJoCo free-joint body (or a user-selected subse...
Definition free_joint_state_publisher_plugin.hpp:54
void update_write(const mjModel *model, mjData *data) override
Called once per write() cycle, on the control thread, after the hardware interface has staged the con...
Definition free_joint_state_publisher_plugin.cpp:150
void cleanup() override
Cleanup the plugin.
Definition free_joint_state_publisher_plugin.cpp:229
bool init(rclcpp::Node::SharedPtr node, const mjModel *model, mjData *data) override
Initialize the plugin.
Definition free_joint_state_publisher_plugin.cpp:81
Base class for MuJoCo ROS 2 control plugins.
Definition mujoco_ros2_control_plugins_base.hpp:52
Definition mujoco_ros2_control_plugins_base.hpp:22