mujoco_ros_utils
ImagePublisher.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <ros/ros.h>
4 
5 #include <mujoco/mjdata.h>
6 #include <mujoco/mjmodel.h>
7 #include <mujoco/mjrender.h>
8 #include <mujoco/mjtnum.h>
9 #include <mujoco/mjvisualize.h>
10 
11 #include <GLFW/glfw3.h>
12 #include <string>
13 
14 namespace MujocoRosUtils
15 {
16 
19 {
20 public:
22  static void RegisterPlugin();
23 
29  static ImagePublisher * Create(const mjModel * m, mjData * d, int plugin_id);
30 
31 public:
33  ImagePublisher(ImagePublisher &&) = default;
34 
39  void reset(const mjModel * m, int plugin_id);
40 
46  void compute(const mjModel * m, mjData * d, int plugin_id);
47 
49  void free();
50 
51 protected:
64  ImagePublisher(const mjModel * m,
65  mjData * d,
66  int sensor_id,
67  const std::string & frame_id,
68  std::string color_topic_name,
69  std::string depth_topic_name,
70  std::string info_topic_name,
71  int height,
72  int width,
73  mjtNum publish_rate);
74 
75 protected:
77  int sensor_id_ = -1;
78 
80  int camera_id_ = -1;
81 
83  std::string frame_id_;
84 
86  int publish_skip_ = 0;
87 
89  int sim_cnt_ = 0;
90 
93  unsigned char * color_buffer_;
94  float * depth_buffer_;
95  unsigned char * color_buffer_flipped_;
98 
101  mjvScene scene_;
102  mjvCamera camera_;
103  mjvOption option_;
104  mjrContext context_;
105  mjrRect viewport_;
106  GLFWwindow * window_;
108 
111  std::shared_ptr<ros::NodeHandle> nh_;
112  ros::Publisher color_pub_;
113  ros::Publisher depth_pub_;
114  ros::Publisher info_pub_;
116 };
117 
118 } // namespace MujocoRosUtils
MujocoRosUtils::ImagePublisher::depth_buffer_
float * depth_buffer_
Definition: ImagePublisher.h:94
MujocoRosUtils::ImagePublisher::frame_id_
std::string frame_id_
Frame ID of topics header or TF parent.
Definition: ImagePublisher.h:83
MujocoRosUtils::ImagePublisher::RegisterPlugin
static void RegisterPlugin()
Register plugin.
Definition: ImagePublisher.cpp:13
MujocoRosUtils::ImagePublisher::publish_skip_
int publish_skip_
Iteration interval to skip ROS publish.
Definition: ImagePublisher.h:86
MujocoRosUtils::ImagePublisher::Create
static ImagePublisher * Create(const mjModel *m, mjData *d, int plugin_id)
Create an instance.
Definition: ImagePublisher.cpp:74
MujocoRosUtils::ImagePublisher::camera_
mjvCamera camera_
Definition: ImagePublisher.h:102
MujocoRosUtils::ImagePublisher::reset
void reset(const mjModel *m, int plugin_id)
Reset.
Definition: ImagePublisher.cpp:265
MujocoRosUtils::ImagePublisher::option_
mjvOption option_
Definition: ImagePublisher.h:103
MujocoRosUtils::ImagePublisher::viewport_
mjrRect viewport_
Definition: ImagePublisher.h:105
MujocoRosUtils::ImagePublisher::sim_cnt_
int sim_cnt_
Iteration count of simulation.
Definition: ImagePublisher.h:89
MujocoRosUtils::ImagePublisher::window_
GLFWwindow * window_
Definition: ImagePublisher.h:106
MujocoRosUtils::ImagePublisher::scene_
mjvScene scene_
Definition: ImagePublisher.h:101
MujocoRosUtils::ImagePublisher::color_pub_
ros::Publisher color_pub_
Definition: ImagePublisher.h:112
MujocoRosUtils::ImagePublisher::compute
void compute(const mjModel *m, mjData *d, int plugin_id)
Compute.
Definition: ImagePublisher.cpp:271
MujocoRosUtils::ImagePublisher::free
void free()
Free buffer.
Definition: ImagePublisher.cpp:362
MujocoRosUtils::ImagePublisher::nh_
std::shared_ptr< ros::NodeHandle > nh_
Definition: ImagePublisher.h:111
MujocoRosUtils::ImagePublisher::info_pub_
ros::Publisher info_pub_
Definition: ImagePublisher.h:114
MujocoRosUtils::ImagePublisher::camera_id_
int camera_id_
Camera ID.
Definition: ImagePublisher.h:80
MujocoRosUtils::ImagePublisher::depth_pub_
ros::Publisher depth_pub_
Definition: ImagePublisher.h:113
MujocoRosUtils::ImagePublisher::context_
mjrContext context_
Definition: ImagePublisher.h:104
MujocoRosUtils::ImagePublisher::color_buffer_
unsigned char * color_buffer_
Definition: ImagePublisher.h:93
MujocoRosUtils::ImagePublisher::color_buffer_flipped_
unsigned char * color_buffer_flipped_
Definition: ImagePublisher.h:95
MujocoRosUtils::ImagePublisher
Plugin to publish topics of color and depth images.
Definition: ImagePublisher.h:18
MujocoRosUtils::ImagePublisher::sensor_id_
int sensor_id_
Sensor ID.
Definition: ImagePublisher.h:77
MujocoRosUtils::ImagePublisher::ImagePublisher
ImagePublisher(ImagePublisher &&)=default
Copy constructor.
MujocoRosUtils::ImagePublisher::depth_buffer_flipped_
float * depth_buffer_flipped_
Definition: ImagePublisher.h:96
MujocoRosUtils
Definition: ActuatorCommand.cpp:7