63 lines
1.9 KiB
Python
63 lines
1.9 KiB
Python
"""
|
|
Mission executor launch file.
|
|
Selects config based on env argument at launch time.
|
|
|
|
Usage:
|
|
ros2 launch rov_mission mission.launch.py # dev config (default)
|
|
ros2 launch rov_mission mission.launch.py env:=field # field config
|
|
"""
|
|
from launch import LaunchDescription
|
|
from launch.actions import DeclareLaunchArgument, OpaqueFunction
|
|
from launch.substitutions import LaunchConfiguration
|
|
from launch_ros.actions import Node
|
|
from ament_index_python.packages import get_package_share_directory
|
|
import os
|
|
|
|
|
|
def _launch_with_config(context, *args, **kwargs):
|
|
"""Resolve env argument and return node with correct config file."""
|
|
pkg_dir = get_package_share_directory('rov_mission')
|
|
|
|
# Evaluate env argument at launch time
|
|
env = LaunchConfiguration('env').perform(context)
|
|
|
|
config_file = os.path.join(pkg_dir, 'config', f'{env}.yaml')
|
|
|
|
if not os.path.exists(config_file):
|
|
raise FileNotFoundError(
|
|
f'Config file not found: {config_file}. '
|
|
f'Valid environments: dev, field'
|
|
)
|
|
|
|
return [
|
|
Node(
|
|
package='rov_mission',
|
|
executable='mission_executor',
|
|
name='mission_executor',
|
|
output='screen',
|
|
parameters=[config_file],
|
|
respawn=True,
|
|
respawn_delay=5.0,
|
|
),
|
|
Node(
|
|
package='rov_mission',
|
|
executable='cockpit_bridge',
|
|
name='cockpit_bridge',
|
|
output='screen',
|
|
respawn=True,
|
|
respawn_delay=5.0,
|
|
)
|
|
]
|
|
|
|
|
|
def generate_launch_description():
|
|
"""Launch mission executor with environment-specific config."""
|
|
return LaunchDescription([
|
|
DeclareLaunchArgument(
|
|
'env',
|
|
default_value='dev',
|
|
description='Deployment environment: dev, field'
|
|
),
|
|
OpaqueFunction(function=_launch_with_config),
|
|
])
|