Ask Your Question
1

How to properly structure a ROS package?

asked 2020-11-03 05:30:38 -0500

Py gravatar image

updated 2020-11-03 05:50:42 -0500

My ROS package is beginning to get complicated with multiple folders for various aspects of functionality. However, I am unsure whether I have structured the package correctly. I am unsure whether my urdf and config folders should be placed outside of src and whether the nodes defined in Python scripts should be organised into a sub-folder (scripts) within src.

Here's what I have so far:

catkin_ws/src/my_package
│
├── cmake-build-debug
│   └── *LOTS OF SUB-FOLDERS & FILES*
├── include
│   └── my_package
│       └── *EMPTY*
├── venv
│   └── *LOTS OF SUB-FOLDERS & FILES*
├── launch
│   ├── all_nodes.launch
│   └── robot_simulation.launch
├── src
│   ├── config
│   │   ├── config_a.lua
│   │   └── config_b.rviz
│   ├── scripts
│   │   ├── __init__.py
│   │   ├── node_a.py
│   │   ├── node_b.py
│   │   ├── node_c.py
│   │   ├── node_d.py
│   │   ├── node_e.sh
│   │   └── node_f.sh
│   ├── urdf
│   │   ├── robot.urdf.xacro
│   │   ├── robot_plugins.gazebo
│   │   ├── mounts
│   │   │   ├── mount_a.urdf.xacro
│   │   │   ├── mount_b.urdf.xacro
│   │   │   └── mount_c.urdf.xacro
│   │   └── sensors.urdf.xacro
│   ├── gui
│   │   ├── index.html
│   │   └── main.js
│   └── worlds
│       └── area.world
├── CMakeLists.txt
├── package.xml
├── README.md
└── requirements.txt

Does this look right?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
4

answered 2020-11-03 05:57:05 -0500

gvdhoorn gravatar image

updated 2020-11-06 11:04:56 -0500

No, I would not layout things as you have. Particularly src should be reserved for source code only (ie: Python, C++, etc).

No configuration files, no URDF nor Xacro, no Gazebo worlds, etc.

My ROS package is beginning to get complicated with multiple folders for various aspects of functionality.

As a high-level comment: try to separate things a bit. You seem to treat my_package as a mini workspace almost. It's not.

Why not create a my_package_gui, my_package_gazebo and my_package_description package? Packages are almost free, so separate things as much as possible. Decrease coupling, separate concerns and delegate responsibilities.


There are various Q&As on ROS Answers about recommended package layout.

The ROS wiki also has a few pages which go into this, most notable wiki/Packages. It doesn't prescribe a particular layout, but does give some examples of common folders and where they are expected to be relative to a package's root.

An often referenced 3rd party resource on the topic of best practices is leggedrobotics/ros_best_practices. The section File/Folder Structure for Packages shows an often used example.

One thing to keep in mind: this structure is mostly for humans, as roslaunch and rosrun fi don't care where you've placed your binaries / executable scripts. They'll crawl the complete package and its sub directories. There are certainly things which must be in a certain location (such as the manifest and build script), but the rest is not important.

And an observation:

catkin_ws/src/my_package
│
...
├── venv
...

Personally I would not place a Python venv inside the src space of a Catkin workspace, but you may have good reason to do so. You may want to look at tools such as catkin_virtualenv to manage this instead.


Edit: and I just noticed this:

catkin_ws/src/my_package
│
├── cmake-build-debug
..

What is cmake-build-debug? Are you doing in-source builds with cmake directly?

I would expect build artefacts to only exist in the build space of your Catkin workspace.

edit flag offensive delete link more

Comments

1

Finally: as these are mostly conventions for humans, they tend to be subjective (ie: linked to preferences of whoever wrote them). Ask 100 developers this same question and you'll get a lot of different answers.

gvdhoorn gravatar image gvdhoorn  ( 2020-11-03 05:58:11 -0500 )edit

Fantastic! This has helped me re-structure. Thanks for the guidance. It turns out that the cmake-build-debug folder had been put in src by my IDE CLion, which was just incorrectly configured. The only thing I'm struggling with now is the Python venv folder. I like the idea of all this being handled using catkin_virtualenv but I can't seem to get it working. I usually create a virtual environment through the CLion GUI. If I just located the environment somewhere else would that be better? If so, where would you recommend?

Py gravatar image Py  ( 2020-11-04 06:40:33 -0500 )edit

I like the idea of all this being handled using catkin_virtualenv but I can't seem to get it working

I would suggest you post a new question about the catkin_virtualenv problem.

For now this seems like it has answered your (initial) question, so please mark the question as answered by ticking the checkmark to the left of the answer.

gvdhoorn gravatar image gvdhoorn  ( 2020-11-06 10:56:06 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-11-03 05:30:38 -0500

Seen: 150 times

Last updated: Nov 06 '20