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

Rosbag play & publisher-subscriber in ROS Indigo

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

user_123 gravatar image

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

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::init(argc,argv,"subscriber1");
        ros::NodeHandle node_;
        ros::Subscriber sub1=node_.subscribe("base_scan",1000,laser_callback);
        ros::spin();
        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

Comments

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 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
1

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

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

Comments

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 -0600 )edit
0

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

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 http://wiki.ros.org/ROS/NetworkSetup
  3. Run your node. If you use roslaunch, do remember to add output="screen" flag.
edit flag offensive delete link more

Comments

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 -0600 )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 -0600 )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 -0600 )edit

Question Tools

3 followers

Stats

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

Seen: 916 times

Last updated: Jun 02 '17