# Launch File

Launch files are used to launch a large system with many executables where an executable may contain multiple nodes. From a computing perspective, nodes or executables form a graph because the philosophy of ROS2 is to have independent modules that focus on a single responsibility. The communication between nodes are supported through message passing. From a launch process perspective, the executables and launch files form a tree structure.

<figure><img src="/files/yta2qvMREyZsapLNUulF" alt=""><figcaption></figcaption></figure>

Suppose we have a main launch file for our project `learn-launch-file`. This launch file can launch nodes/executables of the project learn-launch-file and run launch files in other projects. A more concrete example is presented below:<br>

<figure><img src="/files/jYxekQRy6VihzrOMRPQC" alt=""><figcaption></figcaption></figure>

The syntax are different for these two types of tasks. To launch a node, we use the `Node` class. For example:

```python
from launch_ros.actions import Node
robot_state_publisher = Node(
    package="robot_state_publisher",
    executable="robot_state_publisher",
    name="my_robot_state_publisher",
    output="both",
    parameters=[
        {"use_sim_time": True},
        {"robot_description": robot_model_description},
    ]
)

rviz = Node(
    package="rviz2",
    executable="rviz2",
    condition=IfCondition(LaunchConfiguration("rviz")),
    arguments=["-d", path.join(bringup_package, "config", "slam_and_nav_v1.rviz")]
)
```

To run another launch file inside our current launch file, we use `IncludeLaunchDescription` and `PythonLaunchDescriptionSource`. For example:

```
from launch.actions import IncludeLaunchDescription
from launch.conditions import IfCondition
from launch.launch_description_sources import PythonLaunchDescriptionSource

slam_toolbox = IncludeLaunchDescription(
    PythonLaunchDescriptionSource(path.join(get_package_share_directory("slam_toolbox"), "launch", "online_async_launch.py")),
    launch_arguments={
        'use_sim_time': "True",
        'slam_params_file': PathJoinSubstitution([bringup_package, "config", "mapper_params_online_async.yaml"])
    }.items(),
)
```

{% hint style="warning" %}
The parameters for specifying the arguments are different. Use arguments for a node and launch\_arguments for a launch file.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.learnros2.com/ros/ros2-building-blocks/launch-file.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
