How to notify that a bag file has been completely played? [closed]
Hello everyone.
I built a bag file that, every time is played, sends messaged to two topics. I start bag playing from keyboard:
rosbag play -r 2 subset.bag
On the other side, there's a simple program receiving messages from both topics and calling right functions in a specified class to manage them according to their nature:
int main(int argc, char **argv){ stage_listener sl; char buffer [1024]; while(1){ int i = fscanf(stdin,"%s",buffer); if(strcmp("exit",buffer) == 0) exit(0); else if(strcmp("num_nodes",buffer) == 0){ printf("\nOdometry nodes: %i\nScan nodes: %i\n",sl.numOdom(),sl.numScan()); //int b = (*sl).numOdom(); } else if(strcmp("listen",buffer) == 0){ ROS_INFO("Activating topics listening...\n"); ros::init(argc,argv, "listener"); ros::NodeHandle n_odom, n_scan; ros::Subscriber sub_odom = n_odom.subscribe("/odom", 1000, &stage_listener::addOdomNode, &sl); ros::Subscriber sub_scan = n_scan.subscribe("/base_scan", 1000, &stage_listener::addScanNode, &sl); ros::spin(); ROS_INFO("Listening activity completed"); } else{ ROS_INFO("Command not found\n"); } } }
The receiver stands waiting for messages after executing instruction
ros::spin();
The problem is that receiver doesn't know when all messages have been sent and keeps waiting, without regaining control and proceeding in executing subsequent instructions. I want, after the end of messages in bag file, main() function to regain control and print on screen by instruction
ROS_INFO("Listening activity completed");
Then, a new execution of while(1) must start, in such a way new commands can be inserted from keyboard through instruction
int i = fscanf(stdin,"%s",buffer);
Is there a way to break ros::spin() loop when there are no more messages to be received?
Thanks for help.
Can you more fully explain what you're trying to do? At the surface level it sounds like you need service calls if you care about control/sequence..
i edited file, i hope this will help to explain better my problem
If the program is called with "listen" then it subscribes to /odom and /base_scan.. and you'd like it to stop when the data is done?
yes, exactly