Introduction to ros2 file structure
ROS 2 (Robot Operating System 2) uses a modular file structure to organize packages, which are the fundamental units of software in a ROS 2 workspace. Each package typically contains code, configuration files, and metadata required for building and running a specific functionality like a sensor driver, algorithm, or robot control logic. A typical package directory includes files such as package.xml (metadata about the package like name, dependencies, and version) and CMakeLists.txt (used by CMake to build the package). Source code is often stored in src/, and ROS-specific resources like launch files, message definitions, and parameters are placed in launch/, msg/, or config/ folders respectively.
The workspace itself usually follows a structure where all packages are stored inside a src/ directory, and it is built using tools like colcon. After building, the install/, build/, and log/ directories are generated to store the built files, intermediate files, and logs. This structure makes it easy to manage dependencies, test individual components, and scale projects across multiple robots or teams. ROS 2's structure promotes reusable, modular, and maintainable robot software development.
The standard file structure is shown below:
ros2_ws/ # Root workspace directory
├── src/ # Source folder for all packages
│ └── my_robot_pkg/ # Example ROS 2 package
│ ├── CMakeLists.txt # Build instructions using CMake
│ ├── package.xml # Package metadata and dependencies
│ ├── launch/ # Launch files for running nodes
│ │ └── my_robot_launch.py
│ ├── config/ # YAML or other config files
│ │ └── params.yaml
│ ├── msg/ # Custom message definitions (optional)
│ │ └── MyData.msg
│ ├── srv/ # Custom service definitions (optional)
│ │ └── Compute.srv
│ ├── include/ # C++ header files (for C++ packages)
│ │ └── my_robot_pkg/
│ └── src/ # Source code (Python or C++)
│ └── my_robot_node.py
├── build/ # Auto-generated build files (after colcon build)
├── install/ # Installed executables and resources
└── log/ # Build and runtime logs
Follow this video fro more info and to get in-depth understanding on ros2 work-space creation and structure