object oriented programming in ROS
Hello guys,
I have the following question regarding the architecture of a ROS application.
"How can i implement object oriented programming in a ROS structure"
First A little bit of background: I have taken the lead in an existing ROS project. I am fairly new to ROS but i have used a few years ago.
For my application i have two industrial robot arms that are both controlled via the movegroup interface (python). One of the robots has a camera that detects some objects. Dependent on the output of the camera the robots perform movements. The work that has been done so far (in the current structure).
We have multiple nodes that communicate with each other using topics such as: /request, /reply, /error
nodes:
- /Robot1
- /Robot2
- /Camera
In the launch file, all nodes are run.
Now another approach i have been looking into is more of an object oriented approach: In a robot class i define all robot functions (with functionality to the move_group). Same is done for the camera class.
Next I make a main class that calls the functions using a state machine like so (of course a simplified version):
Main():
robot1 = Robot()
robot2 = Robot()
camera = Camera()robot1.move_to_home()
robot2.move_to_home()
result = camera.get_data()
In the latter way i do not need the request reply and error communication via topics (those are handled within the class itself and communicate with each other using a reference to the main)
Now my question: Which of these two ways is preferred? Also is there any place to find the best practices or Way of Working on ROS programming?
Thanks in advance
In the latter way i do not need the request reply and error communication via topics (those are handled within the class itself and communicate with each other using a reference to the main)
You are proposing building a single monolithic app that runs on a single host, does not use nodes and does not use publish/subscribe? In my opinion, this new thing would no longer be "ROS".
Your comment makes sense. In my example i described a simplified example. What i meant is the following: I will no longer use request reply and error communication via topics, but topics are being used for other things like /camera/result, robot/position, etc. Your comment about no using nodes interests me, since indeed if i use one main program (node) and add child objects in it, i will not initiate multiple nodes and thus only have one node active (apart from some standard robot/camera nodes e.g. moveit).