mujoco_ros_utils
SensorPublisher.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <geometry_msgs/msg/point_stamped.hpp>
4 #include <geometry_msgs/msg/quaternion_stamped.hpp>
5 #include <geometry_msgs/msg/vector3_stamped.hpp>
6 #include <rclcpp/rclcpp.hpp>
7 
8 #include <mujoco/mjdata.h>
9 #include <mujoco/mjmodel.h>
10 #include <mujoco/mjtnum.h>
11 #include <mujoco/mjvisualize.h>
12 
13 #include <mujoco_ros_utils/msg/scalar_stamped.hpp>
14 #include <string>
15 
16 namespace MujocoRosUtils
17 {
18 
21 {
22 public:
24  typedef enum MessageType_
25  {
27  MsgScalar = 0,
28 
31 
34 
38 
39 public:
41  static void RegisterPlugin();
42 
48  static SensorPublisher * Create(const mjModel * m, mjData * d, int plugin_id);
49 
50 public:
53 
58  void reset(const mjModel * m, int plugin_id);
59 
65  void compute(const mjModel * m, mjData * d, int plugin_id);
66 
67 protected:
77  SensorPublisher(const mjModel * m,
78  mjData * d,
79  int sensor_id,
80  MessageType msg_type,
81  const std::string & frame_id,
82  const std::string & topic_name,
83  mjtNum publish_rate);
84 
85 protected:
87  int sensor_id_ = -1;
88 
91 
93  std::string frame_id_;
94 
96  std::string topic_name_;
97 
99  rclcpp::Node::SharedPtr nh_;
100 
102  rclcpp::PublisherBase::SharedPtr pub_;
103 
105  int publish_skip_ = 0;
106 
108  int sim_cnt_ = 0;
109 };
110 
111 } // namespace MujocoRosUtils
Plugin to publish sensor data.
std::string topic_name_
Topic name.
rclcpp::Node::SharedPtr nh_
ROS node handle.
SensorPublisher(SensorPublisher &&)=default
Copy constructor.
int publish_skip_
Iteration interval to skip ROS publish.
static void RegisterPlugin()
Register plugin.
static SensorPublisher * Create(const mjModel *m, mjData *d, int plugin_id)
Create an instance.
int sim_cnt_
Iteration count of simulation.
MessageType msg_type_
Type of ROS message.
std::string frame_id_
Frame ID of message header.
enum MujocoRosUtils::SensorPublisher::MessageType_ MessageType
Type of ROS message.
rclcpp::PublisherBase::SharedPtr pub_
ROS publisher.
void reset(const mjModel *m, int plugin_id)
Reset.
void compute(const mjModel *m, mjData *d, int plugin_id)
Compute.
MessageType_
Type of ROS message.