Ask Your Question
0

Execute loops in multiple nodes at the same time?

asked 2012-02-07 12:01:08 -0500

gavinmachine gravatar image

Hello,

I have a system that has two ROS nodes, each with a while loop that waits for a certain amount of time to pass. However, when the first node enters its loop, the rest of the system freezes waiting for the loop to complete.

The question: Is there a way to execute my ROS system so that several nodes can run at the same time, even with loops running within? Perhaps the solution lies with threading or parallelism?

Thanks!

edit retag flag offensive close merge delete

Comments

The only thing I've thought of is to use the ros::Rate loop_rate to slow the loops down. This seems to work, but I'm not sure if it's an optimal solution.
gavinmachine gravatar imagegavinmachine ( 2012-02-07 12:47:07 -0500 )edit
What is "the rest of the system"? Is the node that's locking up expected to execute any callbacks while it's waiting? Why not use one of the system sleep functions instead of a while loop?
ahendrix gravatar imageahendrix ( 2012-02-07 18:08:52 -0500 )edit

3 Answers

Sort by » oldest newest most voted
1

answered 2012-02-07 17:12:01 -0500

Each ROS node is a single process (see first sentence in the Nodes documentation), so what you describe should not happen. Have you actually tried what you describe or is it just a description of what you assume would happen? Being two separate processes, two nodes already run in parallel and one will not block the other (apart from some special cases on could probably construct somehow).

edit flag offensive delete link more
0

answered 2012-02-08 01:06:12 -0500

DimitriProsser gravatar image

If you're trying to wait a certain amount of time before proceeding, I would suggest that you do it asynchronously so that you don't block any loops. This can be achieved in ROS through timers.

Once a timer expires, it throws an event that is handled in a callback function. In this way, you can simply have a loop that runs all of your updates, but when the timer expires, command will jump to handle the callback function, and then will immediately return to your main loop. This way, you're not blocking your main loop while you wait for a certain period of time. You can see here for more information on event-driven programming.

edit flag offensive delete link more
0

answered 2012-02-07 18:34:53 -0500

I agree with Stefan answer. In any case if (as you said) are considering the thread level parallelism then you should consider use the nodelets: http://www.ros.org/wiki/nodelet

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

Stats

Asked: 2012-02-07 12:01:08 -0500

Seen: 1,415 times

Last updated: Feb 08 '12