mujoco_ros_utils
ImagePublisher.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <rclcpp/rclcpp.hpp>
4 #include <sensor_msgs/msg/camera_info.hpp>
5 #include <sensor_msgs/msg/image.hpp>
6 
7 #include <mujoco/mjdata.h>
8 #include <mujoco/mjmodel.h>
9 #include <mujoco/mjrender.h>
10 #include <mujoco/mjtnum.h>
11 #include <mujoco/mjvisualize.h>
12 
13 #include <GLFW/glfw3.h>
14 #include <string>
15 
16 namespace MujocoRosUtils
17 {
18 
21 {
22 public:
24  static void RegisterPlugin();
25 
31  static ImagePublisher * 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 
51  void free();
52 
53 protected:
66  ImagePublisher(const mjModel * m,
67  mjData * d,
68  int sensor_id,
69  const std::string & frame_id,
70  std::string color_topic_name,
71  std::string depth_topic_name,
72  std::string info_topic_name,
73  int height,
74  int width,
75  mjtNum publish_rate);
76 
77 protected:
79  int sensor_id_ = -1;
80 
82  int camera_id_ = -1;
83 
85  std::string frame_id_;
86 
88  int publish_skip_ = 0;
89 
91  int sim_cnt_ = 0;
92 
95  unsigned char * color_buffer_;
96  float * depth_buffer_;
97  unsigned char * color_buffer_flipped_;
100 
103  mjvScene scene_;
104  mjvCamera camera_;
105  mjvOption option_;
106  mjrContext context_;
107  mjrRect viewport_;
108  GLFWwindow * window_;
110 
113  rclcpp::Node::SharedPtr nh_;
114  rclcpp::Publisher<sensor_msgs::msg::Image>::SharedPtr color_pub_;
115  rclcpp::Publisher<sensor_msgs::msg::Image>::SharedPtr depth_pub_;
116  rclcpp::Publisher<sensor_msgs::msg::CameraInfo>::SharedPtr info_pub_;
118 };
119 
120 } // namespace MujocoRosUtils
Plugin to publish topics of color and depth images.
void compute(const mjModel *m, mjData *d, int plugin_id)
Compute.
int publish_skip_
Iteration interval to skip ROS publish.
unsigned char * color_buffer_flipped_
rclcpp::Publisher< sensor_msgs::msg::Image >::SharedPtr color_pub_
rclcpp::Publisher< sensor_msgs::msg::Image >::SharedPtr depth_pub_
ImagePublisher(ImagePublisher &&)=default
Copy constructor.
rclcpp::Publisher< sensor_msgs::msg::CameraInfo >::SharedPtr info_pub_
int sim_cnt_
Iteration count of simulation.
std::string frame_id_
Frame ID of topics header or TF parent.
static void RegisterPlugin()
Register plugin.
void reset(const mjModel *m, int plugin_id)
Reset.
rclcpp::Node::SharedPtr nh_
static ImagePublisher * Create(const mjModel *m, mjData *d, int plugin_id)
Create an instance.