⚠️Important Note

  1. workspace src is where packages live
  2. package src is where the source codes live

(below is an example)

📂 Full Workspace 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

🚀 How to Create a ROS2 Package

📦 Package

1. Go to your workspace

cd ~/ros2_ws/src

2. Create a new package

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: