Software architecture for sequential execution of two ROS nodes
This question is regarding the best programming practices while heavily using ROS. I am trying to achieve sequential execution of two ROS nodes. I have a depth camera mounted on a moving robot. The camera works on ROS CPP and robot works on ROS Python.
Below is the sequential execution plan-
- Command the robot to move robot little bit.
- Stop the robot.
- Once the robot is stopped, take a picture from the camera.
- Process the picture. The processing is time-consuming and takes around few seconds.
- Once processing is done, the robot is commanded to move next.
- The cycle repeats.
The above execution could be done quickly if the camera and robot operate on the same programming language.
At present, I have defined two ROS topics. I have one publisher and one subscriber inside robot node, and similarly, I have another publisher and subscriber inside camera node. However, it is getting complicated to debug. I believe, there should be a more natural way in ROS to handle such scenarios.'
I want to know how to achieve sequential execution of two ROS nodes in this scenario.
PS: The code snippet wasn't provided since it is too long to put here. However, I tried to convey the approach I have implemented. Sorry for such a long post!
Asked by ravijoshi on 2018-06-08 10:32:01 UTC
Answers
For this kind of problem, I would go with a state machine, for example : smach
with 3 state : 'plan waypoint', 'move to waypoint' and 'process picture'
and you design your state machine like this : "plan" > "move" > "process" >> repeat
each state will call a service or action implemented in ROS nodes.
The most difficult thing with this approach would be to have the correct balance between having simple states and having a simple state machine :
- Too much states will lead to simple states code, so easily understandable, but a complex state machine
- A too simple state machine will lead to complex state
But this is my point of view, there is no best pattern for this kind of problem I think.
Asked by lmathieu on 2018-06-08 16:13:28 UTC
Comments