Skip to main content
ClaudeWave
Skill200 repo starsupdated 4d ago

ROS2 Launch & Configuration

Clean Architecture compatible ROS2 launch files and parameter management (Python)

Install in Claude Code
Copy
git clone --depth 1 https://github.com/harunkurtdev/ros2-claude-code-template /tmp/ros2-launch-configuration && cp -r /tmp/ros2-launch-configuration/.claude/skills/ros2_launch_config ~/.claude/skills/ros2-launch-configuration
Then start a new Claude Code session; the skill loads automatically.

SKILL.md

# ROS2 Launch & Configuration Skill

This skill provides a guide for creating modular and reusable ROS2 launch files, which are written in Python for both C++ and Python nodes.

## Launch File Structure

```
packages/
└── robot_core/
    └── launch/
        ├── robot_launch.py          # Main launch file
        ├── sensors_launch.py        # Sensor subsystem
        ├── navigation_launch.py     # Navigation subsystem
        └── includes/
            ├── common.py            # Common functions
            └── defaults.py          # Default values
```

## Basic Launch File Template

```python
#!/usr/bin/env python3
"""
Launch file: robot_launch.py
Description: Main robot system launch file
"""

import os
from ament_index_python.packages import get_package_share_directory

from launch import LaunchDescription
from launch.actions import (
    DeclareLaunchArgument,
    IncludeLaunchDescription,
    GroupAction,
    SetEnvironmentVariable,
    LogInfo
)
from launch.conditions import IfCondition, UnlessCondition
from launch.substitutions import (
    LaunchConfiguration,
    PathJoinSubstitution
)
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch_ros.actions import Node, SetParameter
from launch_ros.substitutions import FindPackageShare


def generate_launch_description():
    """Generate launch description."""

    # Package paths
    pkg_robot_core = get_package_share_directory('robot_core')

    # Launch arguments
    declared_arguments = [
        DeclareLaunchArgument(
            'robot_name',
            default_value='robot_1',
            description='Robot namespace'
        ),
        DeclareLaunchArgument(
            'use_sim',
            default_value='false',
            description='Use simulation mode'
        ),
        DeclareLaunchArgument(
            'config_file',
            default_value=os.path.join(pkg_robot_core, 'config', 'params.yaml'),
            description='Path to parameter file'
        ),
    ]

    # Configurations
    robot_name = LaunchConfiguration('robot_name')
    use_sim = LaunchConfiguration('use_sim')
    config_file = LaunchConfiguration('config_file')

    # Environment setup
    env_setup = [
        SetEnvironmentVariable('RCUTILS_COLORIZED_OUTPUT', '1'),
    ]

    # Global parameters
    global_params = SetParameter(name='use_sim_time', value=use_sim)

    # C++ Node Example
    cpp_node = Node(
        package='robot_cpp_pkg',
        executable='robot_controller_cpp', # Name of the C++ executable in CMakeLists.txt
        name='controller',
        namespace=robot_name,
        parameters=[config_file],
        output='screen'
    )

    # Python Node Example
    py_node = Node(
        package='robot_py_pkg',
        executable='sensor_node.py', # Name of the script or entry point
        name='sensors',
        namespace=robot_name,
        parameters=[config_file],
        output='screen',
        condition=UnlessCondition(use_sim)
    )

    return LaunchDescription(
        declared_arguments +
        env_setup +
        [global_params, cpp_node, py_node]
    )
```

## Parameter File Structure (YAML)

```yaml
# config/params.yaml
/**:
  ros__parameters:
    # Global parameters
    use_sim_time: false
    log_level: "info"

robot_state:
  ros__parameters:
    # Robot state node parameters
    update_rate: 100.0
    frame_id: "base_link"

    # Nested parameters
    position_filter:
      type: "kalman"
      process_noise: 0.01

navigation:
  ros__parameters:
    max_velocity: 1.5
    planner:
      type: "astar"
```

## Loading Parameters in C++

```cpp
// Within a ROS2 Node
void load_parameters() {
    this->declare_parameter("update_rate", 10.0);
    this->declare_parameter("position_filter.type", "default");

    double rate = this->get_parameter("update_rate").as_double();
    std::string filter_type = this->get_parameter("position_filter.type").as_string();

    RCLCPP_INFO(this->get_logger(), "Rate: %f, Filter: %s", rate, filter_type.c_str());
}
```

## Lifecycle Node Launch integration

```python
from launch_ros.actions import LifecycleNode
from launch_ros.events.lifecycle import ChangeState
from lifecycle_msgs.msg import Transition
from launch.actions import EmitEvent, RegisterEventHandler
from launch.event_handlers import OnProcessStart

def generate_launch_description():
    # ...
    driver_node = LifecycleNode(
        package='robot_drivers',
        executable='lidar_driver',
        name='lidar',
        namespace='',
        output='screen'
    )

    # Auto-configure on start
    configure_event = RegisterEventHandler(
        OnProcessStart(
            target_action=driver_node,
            on_start=[
                EmitEvent(event=ChangeState(
                    lifecycle_node_matcher=lambda n: n == driver_node,
                    transition_id=Transition.TRANSITION_CONFIGURE,
                )),
            ]
        )
    )

    return LaunchDescription([driver_node, configure_event])
```
behaviortree-reviewerSubagent

Use proactively before opening a PR that adds or changes BehaviorTree.CPP nodes or BehaviorTree.ROS2 wrappers (RosActionNode/RosServiceNode/RosTopicPub/SubNode, TreeExecutionServer). Reviews a diff against BT.CPP v4 conventions — node base-class choice, non-blocking ticks, ports/blackboard typing, factory/plugin registration, XML v4, and the ROS 2 wrapper contract. Returns a punch list with file:line anchors, not a rewrite.

clean-arch-architectSubagent

Use when a design decision touches Clean Architecture boundaries in a ROS 2 project — which layer a new behaviour belongs to, whether a port belongs in domain or application, whether a new node should be lifecycle-managed, whether to compose nodes or split packages. Returns an architectural recommendation with trade-offs, not implementation.

ecs-architectSubagent

Use when a design decision touches the gz-sim ECS — where new state should live, which system phase should write it, how to avoid coupling, whether to add a component vs. a member variable, whether a new system should be split or merged with an existing one. Returns an architectural recommendation with trade-offs, not implementation.

gz-style-reviewerSubagent

Use proactively before opening any gz-sim PR. Reviews a diff against the project's C++17 style, ECS conventions, plugin registration patterns, CMake structure, test placement, Migration.md / Changelog.md expectations, and pre-commit configuration. Returns a punch list, not a rewrite.

ros2-controllers-reviewerSubagent

Use proactively before opening a PR that adds or changes a ros2_control controller, broadcaster, or hardware component (incl. URDF <ros2_control> bringup). Reviews a diff against ros2_controllers / ros2_control_demos conventions — controller & hardware lifecycle, command/state interface configuration, real-time safety of update()/read()/write(), generate_parameter_library usage, pluginlib registration, chainable-controller correctness, URDF wiring, and tests. Returns a punch list with file:line anchors, not a rewrite.

ros2-style-reviewerSubagent

Use proactively before opening any ROS 2 / Nav 2 PR. Reviews a diff against this template's Clean Architecture, ROS 2 communication, lifecycle, testing, and Nav 2 plugin conventions. Returns a punch list with file:line anchors, not a rewrite.

vda5050-reviewerSubagent

Use proactively before opening a PR that touches a VDA 5050 connector / fleet bridge. Reviews a diff against VDA 5050 v3.0.0 protocol compliance (topics, QoS, header rules, base/horizon, action state machine, schema validation) and the template's Clean Architecture for the MQTT↔Nav 2 bridge. Returns a punch list with file:line anchors, not a rewrite.

buildSlash Command

Build the colcon workspace (optionally a single package) and report the outcome.