Atlas Robotics
Lesson 10/11 · about 6 min

Watch on YouTube ↗Watch on Facebook ↗

Package structure

Package is the smallest packaging and distribution unit of ROS 2: code, launch file, configuration file (YAML), and a metadata file package.xml declaring name, version, dependencies, together in one folder.

Each package builds and installs independently via colcon, and can be declared as a dependency by another package (like atlas_control depends on atlas_description) without knowing how it is implemented internally — just knowing what executable, launch file or interface it provides. ROS 2 has two main package types: ament_python (pure Python code, like ros2_basics) and ament_cmake (C++ or mixed); This lesson focuses on ament_python because that's the type you write the most when you first learn.

Directory tree of ros2_basics

Click on the folder name to open/close, like the Explorer panel in VS Code:

ros2_basics/
  • package.xml # name, version, dependencies
  • setup.py # declare executable (console_scripts)
  • setup.cfg
  • resource/
    • ros2_basics # empty file, just to mark for ament
  • ros2_basics/ — real Python code
    • sensor_publisher.py
    • data_logger.py
  • launch/
    • demo.launch.py

Key point: executable must be declared

It's not enough to write a Python file. ros2 run only finds items declared in setup.py:

entry_points={
    'console_scripts': [
        'sensor_publisher = ros2_basics.sensor_publisher:main',
    ],
},

Add a new node but forget this line, ros2 run will say executable not found, even though the file is still there. This is a very common mistake when starting out.

Workflow

cd ~/atlas_sim
colcon build --packages-select ros2_basics
source install/setup.bash
ros2 run ros2_basics sensor_publisher

colcon build put the code in folder install/. The command source install/setup.bash tells the terminal where the package is located. Forgetting the source step is the most common mistake.

Package structure · Module 1: ROS 2 Core Concepts — Atlas Robotics