Rosanswers logo

So basically, what I want to have is this:

  1. Have ROS collect data, and process this data into a vector. (This is done)

  2. Once the data has been recorded, write the vector to a text file (Not done)

The problem that I have is, how do I stop ros from spinning? How can I then just simply run the function which writes the text to the file?

I've been thinking along the lines of threading, I create a thread that subscribes handles the callback function and another thread that handles writing to the text file. So in essence, the plan would be to have thread1 run for a set amount of time, then halt thread1 and begin to start thread2

Is this possible using ROS? And, is this the only method to solving the above?


Originally posted by Phorce on ROS Answers with karma: 97 on 2014-01-21

Post score: 0

Original comments

Comment by demmeln on 2014-01-21:
Do you want to do 1) and 2) repeatedly, or just once? In any case try checking out the suggestion by @ahendrix.


2 Answers 2


Rosanswers logo

If I understand your problem correctly, use ros::spinOnce() to manually spin. Somewhat along the lines of:

while(ros::ok() && !got_all_data) {

Alternatively if you want to collect all data first and write afterwards, just use ros::spin(); and write the file afterwards. Ctrl-C should stop the spinning. (You might want to test that before doing something critical).

Originally posted by dornhege with karma: 31395 on 2014-01-21

This answer was ACCEPTED on the original site

Post score: 2


Rosanswers logo

Why not record the data you're interested in to a bag file, and then process that bag file later using python bag API?

Originally posted by ahendrix with karma: 47576 on 2014-01-21

This answer was NOT ACCEPTED on the original site

Post score: 1


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.