Ask Your Question

Ros threading to have multiple processes?

asked 2014-01-21 09:44:38 -0500

Phorce gravatar image

updated 2014-01-28 17:06:33 -0500

ngrennan gravatar image

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?


edit retag flag offensive close merge delete


Do you want to do 1) and 2) repeatedly, or just once? In any case try checking out the suggestion by @ahendrix.

demmeln gravatar image demmeln  ( 2014-01-21 11:48:01 -0500 )edit

3 Answers

Sort by ยป oldest newest most voted

answered 2014-01-21 22:19:22 -0500

dornhege gravatar image

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).

edit flag offensive delete link more

answered 2014-01-21 10:30:53 -0500

ahendrix gravatar image

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

edit flag offensive delete link more

answered 2014-01-22 00:48:16 -0500

Hamid Didari gravatar image


I think this Link is helpful for you

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: 2014-01-21 09:44:38 -0500

Seen: 170 times

Last updated: Jan 22 '14