ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Rosbag play & publisher-subscriber in ROS Indigo

asked 2017-06-01 02:15:47 -0500

user_123 gravatar image

updated 2017-06-01 06:25:30 -0500

I want to play the contents of a bag file in one machine, and get the details by subscribing to specific topics on another machine.The ROS master is running in the first machine. In another terminal of the first machine, I have played the bagfile, using rosbag play --clock basic_localization_stage.bag. In the second machine, I have written a simple code of subscriber as follows-

#include "ros/ros.h"
#include "ros/console.h"
#include "sensor_msgs/LaserScan.h"
#include "tf/tfMessage.h"

void laser_callback(const sensor_msgs::LaserScan::ConstPtr& msg)
        ROS_INFO("\nI heard in topic base_scan %f",msg->scan_time);

int main(int argc,char ** argv)
        ros::NodeHandle node_;
        ros::Subscriber sub1=node_.subscribe("base_scan",1000,laser_callback);
        return 0;

But even after subscribing, I am not getting any output in second machine terminal. The rosbag play command publishes on base_scan & tf topics,but if the node is subscribed to base_scan topic, it is not showing any output.

edit retag flag offensive close merge delete


Please some one help with a solution whether it is possible or not...

user_123 gravatar image user_123  ( 2017-06-01 06:25:58 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2017-06-02 04:21:53 -0500

angeltop gravatar image

When one uses more than one machine, the following exports are necessary:

  1. Machine 1: export ROS_MASTER_URI=http://MACHINE_1_IP:11311 export ROS_IP=MACHINE_1_IP
  2. Machine 2: export ROS_MASTER_URI=http://MACHINE_1_IP:11311 export ROS_IP=MACHINE_2_IP
  3. Machine 3: export ROS_MASTER_URI=http://MACHINE_1_IP:11311 export ROS_IP=MACHINE_3_IP

Note that these commands should be in your bashrc or execute them on every terminal before any ros command(rosrun, roslaunch, rostopic etc). I hope this helps

edit flag offensive delete link more


Thank you, it worked after setting this ROS_IP and ROS_MASTER_URI....

user_123 gravatar image user_123  ( 2017-06-02 05:14:41 -0500 )edit

answered 2017-06-01 11:48:16 -0500

DavidN gravatar image

It is totally normal to write a node subscribing to data published from a bag. For your case, I suggest you do the following steps to make sure you have the correct set up:

  1. Play the bag on the 1st machine (where ROS MASTER is running), assuming the scan topic has the name of base_scan
  2. In the 2nd machine, dont run your node just yet. Run the following command to make sure the 2nd machine can receive the messages from the 1st machine: rostopic echo /base_scan . If you don't see any data after running this command, that means something wrong with your multi-machine setup. I suggest you fix this by following
  3. Run your node. If you use roslaunch, do remember to add output="screen" flag.
edit flag offensive delete link more


As suggested by you,after running rostopic echo /base_scan in the second machine, it is not giving any data on the screen, but running rostopic list it is giving a list like /base_scan, /tf, /rosout etc, which means the multi machine setup is established correctly.

user_123 gravatar image user_123  ( 2017-06-02 01:06:35 -0500 )edit

Since tge topiclist has appeared, I'm not sure where the problem lies, please help with a solution. Thank you.

user_123 gravatar image user_123  ( 2017-06-02 01:07:21 -0500 )edit

After step 1, do you see any message when running rostopic echo /base_scan in the first machine?

DavidN gravatar image DavidN  ( 2017-06-02 11:14:44 -0500 )edit

Question Tools



Asked: 2017-06-01 02:15:47 -0500

Seen: 885 times

Last updated: Jun 02 '17