Gazebo | Ignition | Community
Ask Your Question

Subscribe to Gazebo Plugin Topic

asked 2020-06-10 17:37:20 -0600

tasuminagorashi gravatar image

I have a sdf file where I put Gazebo IMU plugin. The gazebo topic is ~/turtlebot/rack/imu_sensor/imu . How can I create a ROS2 node that subscribes to that Gazebo topic?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-06-22 05:49:47 -0600

ahcorde gravatar image


you should: - create a gazebo::transport::Node to subscribe the Gazebo topic - create a ROS 2 node and create the gith publisher. - In the callback you need to fill the ROS 2 message with the Gazebo IMU message.

Here you can a find a snippet of how to implement this idea.

gazebo_ros::Node::SharedPtr ros_node;

rclcpp::Publisher<sensor_msgs::msg::Imu>::SharedPtr imu_pub;

gazebo::transport::NodePtr gz_node;

// Function is called everytime a message is received.
void cb(ConstImuPtr &_msg)
  gazebo_msgs::msg::IMU imu_msg;

 // fill imu_msg message based on _msg



int main(int argc, char ** argv)
  // Load gazebo
  gazebo::client::setup(argc, argv);

  if (!rclcpp::is_initialized()) {
    rclcpp::init(argc, argv);
    ros_node = gazebo_ros::Node::Get();
  } else {
    ros_node = gazebo_ros::Node::Get();

  imu_pub = ros_node->create_publisher<sensor_msgs::msg::Imu>("/turtlebot/rack/imu_sensor/imu", rclcpp::SensorDataQoS(rclcpp::KeepLast(1)));

  // Gazebo transport
  gz_node = gazebo::transport::NodePtr(new gazebo::transport::Node());

  // Listen to Gazebo world_stats topic
  gazebo::transport::SubscriberPtr sub = gz_node->Subscribe("~/turtlebot/rack/imu_sensor/imu", cb);

  while (true)

  // Make sure to shut everything down.
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2020-06-10 17:37:20 -0600

Seen: 173 times

Last updated: Jun 22 '20