impossible to register messages in a bag file
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; msg.data = "end of loop"; chatter_pub.publish(msg); //ROS_INFO("Message sent: %s",msg.data.c_str()); while(chatter_pub.getNumSubscribers()==0){ ros::spinOnce(); } //sleep(10); loop_rate.sleep(); ROS_INFO("Message sent: %s",msg.data.c_str()); 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.
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?
... moreover i can't see the usual messages count down on screen, as it happens when i play bag files one by one