# Как запустить одним launch файлом несколько других launch файлов

В ROS2 вы можете запускать несколько launch-файлов из разных пакетов с помощью `IncludeLaunchDescription` и `LaunchDescription`. Вот пример launch-файла, который запускает другие launch-файлы:

#### Пример `main_launch.py` (Python-стиль)

```python
from launch import LaunchDescription
from launch.actions import IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from ament_index_python.packages import get_package_share_directory
import os

def generate_launch_description():
    # Получаем пути к launch-файлам других пакетов
    pkg1_launch_dir = os.path.join(get_package_share_directory('package1_name'), 'launch')
    pkg2_launch_dir = os.path.join(get_package_share_directory('package2_name'), 'launch')

    # Включаем первый launch-файл
    launch_file1 = IncludeLaunchDescription(
        PythonLaunchDescriptionSource(os.path.join(pkg1_launch_dir, 'launch_file1.py'))
    )

    # Включаем второй launch-файл
    launch_file2 = IncludeLaunchDescription(
        PythonLaunchDescriptionSource(os.path.join(pkg2_launch_dir, 'launch_file2.py'))
    )

    return LaunchDescription([
        launch_file1,
        launch_file2,
        # Можно добавить другие launch-файлы или ноды
    ])
```

#### Альтернативный вариант в XML-стиле (`main_launch.xml`)

```xml
<launch>
    <include file="$(find-pkg-share package1_name)/launch/launch_file1.py"/>
    <include file="$(find-pkg-share package2_name)/launch/launch_file2.xml"/>
</launch>
```

#### Важные моменты:

1. Убедитесь, что все пакеты, на которые вы ссылаетесь, установлены и доступны через `get_package_share_directory`
2. Вы можете передавать аргументы в дочерние launch-файлы:

```python
launch_file1 = IncludeLaunchDescription(
    PythonLaunchDescriptionSource(...),
    launch_arguments={'arg_name': 'value'}.items()
)
```

3. Для XML launch-файлов используйте `<include>` с указанием полного пути

#### Как запустить:

```bash
ros2 launch your_package_name main_launch.py
```

Где `your_package_name` - имя вашего пакета, содержащего этот launch-файл.


---

# 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://alice-and-alex-docs.gitbook.io/alice_and_alex_docs/ros2-development/kak-zapustit-odnim-launch-failom-neskolko-drugikh-launch-failov.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.
