mujoco_ros_utils
PosePublisher.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <geometry_msgs/msg/pose_stamped.hpp>
4 #include <geometry_msgs/msg/transform_stamped.hpp>
5 #include <geometry_msgs/msg/twist_stamped.hpp>
6 #include <rclcpp/rclcpp.hpp>
7 #include <tf2_ros/transform_broadcaster.h>
8 
9 #include <mujoco/mjdata.h>
10 #include <mujoco/mjmodel.h>
11 #include <mujoco/mjtnum.h>
12 #include <mujoco/mjvisualize.h>
13 
14 #include <string>
15 
16 namespace MujocoRosUtils
17 {
18 
21 {
22 public:
24  static void RegisterPlugin();
25 
31  static PosePublisher * Create(const mjModel * m, mjData * d, int plugin_id);
32 
33 public:
36 
41  void reset(const mjModel * m, int plugin_id);
42 
48  void compute(const mjModel * m, mjData * d, int plugin_id);
49 
50 protected:
62  PosePublisher(const mjModel * m,
63  mjData * d,
64  int sensor_id,
65  const std::string & frame_id,
66  const std::string & pose_topic_name,
67  const std::string & vel_topic_name,
68  mjtNum publish_rate,
69  bool output_tf,
70  const std::string & tf_child_frame_id);
71 
72 protected:
74  int sensor_id_ = -1;
75 
77  int body_id_ = -1;
78 
80  rclcpp::Node::SharedPtr nh_;
81 
83  rclcpp::Publisher<geometry_msgs::msg::PoseStamped>::SharedPtr pose_pub_;
84 
86  rclcpp::Publisher<geometry_msgs::msg::TwistStamped>::SharedPtr vel_pub_;
87 
89  std::unique_ptr<tf2_ros::TransformBroadcaster> tf_br_;
90 
92  std::string frame_id_;
93 
95  std::string pose_topic_name_;
96 
98  std::string vel_topic_name_;
99 
101  int publish_skip_ = 0;
102 
104  bool output_tf_ = false;
105 
107  std::string tf_child_frame_id_;
108 
110  int sim_cnt_ = 0;
111 };
112 
113 } // namespace MujocoRosUtils
Plugin to publish topics or broadcast TF of pose and velocity of the body.
Definition: PosePublisher.h:21
static void RegisterPlugin()
Register plugin.
std::string frame_id_
Frame ID of topics header or TF parent.
Definition: PosePublisher.h:92
std::string vel_topic_name_
Topic name of velocity.
Definition: PosePublisher.h:98
std::string tf_child_frame_id_
Child frame ID for TF.
rclcpp::Node::SharedPtr nh_
ROS node handle.
Definition: PosePublisher.h:80
void reset(const mjModel *m, int plugin_id)
Reset.
PosePublisher(PosePublisher &&)=default
Copy constructor.
std::string pose_topic_name_
Topic name of pose.
Definition: PosePublisher.h:95
rclcpp::Publisher< geometry_msgs::msg::PoseStamped >::SharedPtr pose_pub_
ROS publisher for pose.
Definition: PosePublisher.h:83
int publish_skip_
Iteration interval to skip ROS publish.
std::unique_ptr< tf2_ros::TransformBroadcaster > tf_br_
TF broadcaster.
Definition: PosePublisher.h:89
static PosePublisher * Create(const mjModel *m, mjData *d, int plugin_id)
Create an instance.
void compute(const mjModel *m, mjData *d, int plugin_id)
Compute.
bool output_tf_
Whether to broadcast TF.
rclcpp::Publisher< geometry_msgs::msg::TwistStamped >::SharedPtr vel_pub_
ROS publisher for velocity.
Definition: PosePublisher.h:86
int sim_cnt_
Iteration count of simulation.