ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Ros threading to have multiple processes?

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

Phorce gravatar image

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

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?

Thanks

edit retag flag offensive close merge delete

Comments

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 -0600 )edit

3 Answers

Sort by ยป oldest newest most voted
2

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

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) {
    ros::spinOnce();
    loop_rate.sleep();
}

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
1

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

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
0

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

Hamid Didari gravatar image

Hi

I think this Link is helpful for you

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-01-21 09:44:38 -0600

Seen: 260 times

Last updated: Jan 22 '14