mujoco_ros_utils
SensorPublisher.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/mjtnum.h>
8 #include <mujoco/mjvisualize.h>
9 
10 #include <string>
11 
12 namespace MujocoRosUtils
13 {
14 
17 {
18 public:
20  typedef enum MessageType_
21  {
23  MsgScalar = 0,
24 
27 
30 
33  } MessageType;
34 
35 public:
37  static void RegisterPlugin();
38 
44  static SensorPublisher * Create(const mjModel * m, mjData * d, int plugin_id);
45 
46 public:
48  SensorPublisher(SensorPublisher &&) = default;
49 
54  void reset(const mjModel * m, int plugin_id);
55 
61  void compute(const mjModel * m, mjData * d, int plugin_id);
62 
63 protected:
73  SensorPublisher(const mjModel * m,
74  mjData * d,
75  int sensor_id,
76  MessageType msg_type,
77  const std::string & frame_id,
78  const std::string & topic_name,
79  mjtNum publish_rate);
80 
81 protected:
83  int sensor_id_ = -1;
84 
87 
89  std::string frame_id_;
90 
92  std::string topic_name_;
93 
95  std::shared_ptr<ros::NodeHandle> nh_;
96 
98  ros::Publisher pub_;
99 
101  int publish_skip_ = 0;
102 
104  int sim_cnt_ = 0;
105 };
106 
107 } // namespace MujocoRosUtils
MujocoRosUtils::SensorPublisher::nh_
std::shared_ptr< ros::NodeHandle > nh_
ROS node handle.
Definition: SensorPublisher.h:95
MujocoRosUtils::SensorPublisher::SensorPublisher
SensorPublisher(SensorPublisher &&)=default
Copy constructor.
MujocoRosUtils::SensorPublisher::msg_type_
MessageType msg_type_
Type of ROS message.
Definition: SensorPublisher.h:86
MujocoRosUtils::SensorPublisher::frame_id_
std::string frame_id_
Frame ID of message header.
Definition: SensorPublisher.h:89
MujocoRosUtils::SensorPublisher::MsgScalar
@ MsgScalar
Scalar.
Definition: SensorPublisher.h:23
MujocoRosUtils::SensorPublisher::topic_name_
std::string topic_name_
Topic name.
Definition: SensorPublisher.h:92
MujocoRosUtils::SensorPublisher::MessageType
enum MujocoRosUtils::SensorPublisher::MessageType_ MessageType
Type of ROS message.
MujocoRosUtils::SensorPublisher::pub_
ros::Publisher pub_
ROS publisher.
Definition: SensorPublisher.h:98
MujocoRosUtils::SensorPublisher::compute
void compute(const mjModel *m, mjData *d, int plugin_id)
Compute.
Definition: SensorPublisher.cpp:211
MujocoRosUtils::SensorPublisher::sim_cnt_
int sim_cnt_
Iteration count of simulation.
Definition: SensorPublisher.h:104
MujocoRosUtils::SensorPublisher::publish_skip_
int publish_skip_
Iteration interval to skip ROS publish.
Definition: SensorPublisher.h:101
MujocoRosUtils::SensorPublisher::reset
void reset(const mjModel *m, int plugin_id)
Reset.
Definition: SensorPublisher.cpp:205
MujocoRosUtils::SensorPublisher::MsgPoint
@ MsgPoint
Point.
Definition: SensorPublisher.h:26
MujocoRosUtils::SensorPublisher::MsgVector3
@ MsgVector3
3D vector
Definition: SensorPublisher.h:29
MujocoRosUtils::SensorPublisher::sensor_id_
int sensor_id_
Sensor ID.
Definition: SensorPublisher.h:83
MujocoRosUtils::SensorPublisher::RegisterPlugin
static void RegisterPlugin()
Register plugin.
Definition: SensorPublisher.cpp:15
MujocoRosUtils::SensorPublisher
Plugin to publish sensor data.
Definition: SensorPublisher.h:16
MujocoRosUtils::SensorPublisher::MsgQuaternion
@ MsgQuaternion
Quaternion.
Definition: SensorPublisher.h:32
MujocoRosUtils
Definition: ActuatorCommand.cpp:7
MujocoRosUtils::SensorPublisher::MessageType_
MessageType_
Type of ROS message.
Definition: SensorPublisher.h:20
MujocoRosUtils::SensorPublisher::Create
static SensorPublisher * Create(const mjModel *m, mjData *d, int plugin_id)
Create an instance.
Definition: SensorPublisher.cpp:74