Robotics StackExchange | Archived questions

Best practice: File/directory structure for multiple larger nodes in one package

This question addresses a general best-practice question; I'll use the project I'm currently working on as an example.

I am working on a ROS2 project in which a simulated cargo-drone (node: dronesimulator; outputs drone position on a topic, no graphics) is controlled from a operator-input node (node: dronecontroller) and is visualized with a separate graphics node (node: drone_graphics). I'm using ROS2 Galactic and program in C++ in Ubuntu.

All nodes are solely for this project; no 'generic' nodes involved which can be used for a different project. Also, the nodes are so large that, by good C++ practice, each should be split in several .cpp and .h files.

Based on the tutorials (especially the publisher/subscriber one, https://docs.ros.org/en/galactic/Tutorials/Writing-A-Simple-Cpp-Publisher-And-Subscriber.html) I think that all these nodes should be in one package. Following the guidelines of the tutorial, all .cpp files will end up in the same directory, being my_ws/src/cargo_drone/src. It is unclear what to do with the .h files, but I guess that my_ws/src/cargo_drone/include would be an appropriate place.

However, I don't like the fact that .cpp files (and .h files) of different executables are mixed up into one giant directory. There must be more structured way, isn't it?

My questions are:

Asked by Gijs van Oort on 2022-03-07 04:25:35 UTC

Comments

Just wanted to say "hi" ;)

Asked by gvdhoorn on 2022-03-07 12:10:25 UTC

Hi Gijs, I's so nice to see you here again! I had already noticed that you are quite active with ROS, and was wondering if you'd see my question.. So, yes dus! Best, Gijs

Asked by Gijs van Oort on 2022-03-07 17:52:56 UTC

Answers

Well, package architecture depends mostly on you, having subdirectories inside src directory (and include as well) is also an option. When creating new projects I usually follow how biggest ROS projects such as Moveit2 or Nav2 are structured. Splitting code between different packages usually comes when the project becomes large enough so that the code can be categorized by its desired functions (such as path planning, graphical display, etc.)

Asked by Serafadam on 2022-03-16 17:44:58 UTC

Comments