Ask Your Question

impossible to register messages in a bag file

asked 2012-12-19 01:56:01 -0500

Jaco gravatar image

Hi all,
I wrote a c++ script to send messages to a certain topic:

#include "std_msgs/String.h"
#include "ros/ros.h"

int main(int argc, char **argv){
    ros::init(argc, argv,"end_bag");
    ros::NodeHandle n;

    ros::Publisher chatter_pub = n.advertise<std_msgs::string>("/end",1000);
    ros::Rate loop_rate(10);

    std_msgs::String msg; = "end of loop";

    //ROS_INFO("Message sent: %s",;
    ROS_INFO("Message sent: %s",;
    return 0;

From a shell, I started recording messages sent to topic /end :

rosbag record -O end /end 

After sending of the messages, I analyzed bag file and I didn't find anything inside it. Do you have any idea why this happens? I tried also to substitute the while in the code with while(1) but no messages is received as well.

Thanks for support.

edit retag flag offensive close merge delete


thanks for answer. code fortunately compiles, it was just a copy-paste error. anyway, your answer was helpful. it works. after that, i played two bag files by writing rosbag play subset.bag end.bag. the execution of first bag file should last 3.45 mins but it seems not to finish. do you know reason?

Jaco gravatar image Jaco  ( 2012-12-19 03:57:22 -0500 )edit

... moreover i can't see the usual messages count down on screen, as it happens when i play bag files one by one

Jaco gravatar image Jaco  ( 2012-12-19 03:58:24 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2012-12-19 02:02:31 -0500

Lorenz gravatar image

I doubt that the code above would compile. Your advertise call specifies type std_msgs::string, the correct type is std_msgs::String though. Please read the support guidelines before posting. Always copy-paste code and tag your questions.

You publish before rosbag or any other node could register. A quick fix would be either to use a latched topic or publish right after the while loop that checks for the number of publishers to be 0.

To use a latched topic, use the following advertise call:

ros::Publisher chatter_pub = n.advertise<std_msgs::String>("/end", 1000, true);
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2012-12-19 01:56:01 -0500

Seen: 96 times

Last updated: Dec 19 '12