hawonlee / Conductor-Software

This software uses the Robot Operating System to coordinate four independent modules that compose the Virtual Dosimeter.
1 stars 0 forks source link

SpinOnce to be used in the Monte Carlo loop #2

Open andreubs opened 3 years ago

andreubs commented 3 years ago

https://github.com/hawonlee/Conductor-Software/blob/e1e55306f4f37b49829d1678cbffae49025ffcc6/hello_world/scripts/publisher.cpp#L78

http://wiki.ros.org/roscpp/Overview/Callbacks%20and%20Spinning

Looks like the SpinOnce() function will let us run the Monte Carlo after receiving the message, without locking the flow of the execution like spin() does.

hawonlee commented 3 years ago

The alternative to spin() in the conductor node allows for more control over the execution. The messages received in this node can then be published to a topic that the Monte Carlo node is subscribed to. The SpinOnce() function in the Monte Carlo node will allow the messages to be received and used in order.

hawonlee commented 3 years ago

The following link has examples of a ROS subscriber and publisher in c++: http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber%28c%2B%2B%29. The examples use spin(), which can be replaced with an infinite loop that contains spinOnce(). The spinOnce() will call the callback methods when messages have been published to the topic (http://wiki.ros.org/roscpp/Overview/Callbacks%20and%20Spinning#:~:text=ros%3A%3AspinOnce()%20will,at%20that%20point%20in%20time.&text=1%20%23include%20%3Cros%2Fcallback_queue.,-h%3E%202%203).