How to organize packages in a workspace

Hi,

While I practice, I will create so many packages.
Could I create subfolders to make groups of some packages in src directory?
If I do, what do I have to change?

Thanks

Yes, you can create a parent directory with packages inside, so ti would be:

~/ros2_ws/src/[parent_directory]/pkg_1

You don’t have to change anything unless you set hard-coded paths in one of those packages (which you shouldn’t).

However, you might have to delete compilation folders and recompile after reorganizing.

1 Like

Yes, you can have multiple Packages inside a directory Sub Directory in your catkin_ws/src directory.
For Example, when you clone a Github directory, there are many packages inside a single parent directory.
https://github.com/munn33b/my-robotic-arm

Each package will have own its own CMakesList.txt file, that will be automatically recognized byCatkin Build Tool and compiled. So, each package inside parent directory should have its own CMakesList.txt and package.xml file.

2 Likes

You can organize your ROS packages within sub folders in the src directory of your workspace. This can help you maintain a more structured and organized workspace, especially as the number of packages grows.
In the src directory which is located in your workspace , you can create packages with different names.
Take for example , you want to create a localization and navigation node . These can have different packages . The locatlization node can be based in packageA while the navigation node can be based in packageB. Each package packageA and packageB will have its own CMakeLists.txt and package.xml files, and they can be built independently. The organization makes it easier to manage and understand the project structure, especially as it grows in complexity.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.