ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
2

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

asked 2022-03-07 03:25:35 -0600

Gijs van Oort gravatar image

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: drone_simulator; outputs drone position on a topic, no graphics) is controlled from a operator-input node (node: drone_controller) 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/Tuto...) 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:

  • What is best practice? Should the nodes (i.e., executables) indeed be grouped into one package, or not?
  • If so, where to put all .cpp and .h files (and possibly other resource files) so that it forms some sort of organized structure?
  • If not, what is the purpose of having packages and the ability to have multiple nodes in a package (or: when should nodes be grouped in a package and when not?)
edit retag flag offensive close merge delete

Comments

Just wanted to say "hi" ;)

gvdhoorn gravatar image gvdhoorn  ( 2022-03-07 11:10:25 -0600 )edit

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

Gijs van Oort gravatar image Gijs van Oort  ( 2022-03-07 16:52:56 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-03-16 17:44:58 -0600

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.)

edit flag offensive delete link more

Question Tools

3 followers

Stats

Asked: 2022-03-07 03:25:35 -0600

Seen: 860 times

Last updated: Mar 16 '22