⚠️Important Note
(below is an example)
ros2_ws/ <-- Your ROS2 workspace
├── build/ <-- Auto-generated when you colcon build
├── install/ <-- Built install files (executables, setups)
├── log/ <-- Build/test logs
└── src/ <-- Workspace src (contains multiple packages)
├── turtlesim/ <-- Example package from ROS
│ ├── package.xml
│ ├── CMakeLists.txt
│ ├── include/turtlesim/ <-- headers (C++)
│ └── src/ <-- code for turtlesim
│ └── turtlesim_node.cpp
│
├── my_package/ <-- Your custom package
│ ├── package.xml
│ ├── CMakeLists.txt
│ ├── include/my_package/ <-- headers for your code
│ └── src/ <-- your source code
│ └── my_node.cpp
│
└── another_pkg/ <-- Maybe a Python package
├── package.xml
├── setup.py
└── another_pkg/ <-- Python module
└── my_node.py
cd ~/ros2_ws/src
Use ros2 pkg create
with build type (ament_cmake
for C++, ament_python
for Python):
ros2 pkg create --build-type ament_cmake my_package
This makes a new folder with:
package.xml
→ metadata (name, maintainer, dependencies).CMakeLists.txt
→ build instructions.src/
→ where you put your source code.include/
(for C++ headers).