fix: mission launch file now correctly loads env-specific config at launch time
This commit is contained in:
parent
4b1766255a
commit
c3a8b4bc77
@ -1,30 +1,52 @@
|
||||
"""Mission executor launch file."""
|
||||
"""
|
||||
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
|
||||
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 generate_launch_description():
|
||||
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')
|
||||
|
||||
env_arg = DeclareLaunchArgument(
|
||||
'env', default_value='dev',
|
||||
description='Deployment environment: dev, field'
|
||||
)
|
||||
# Evaluate env argument at launch time
|
||||
env = LaunchConfiguration('env').perform(context)
|
||||
|
||||
env = LaunchConfiguration('env')
|
||||
config_file = os.path.join(pkg_dir, 'config', f'{env}.yaml')
|
||||
|
||||
return LaunchDescription([
|
||||
env_arg,
|
||||
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',
|
||||
# Config selected by env argument at launch time
|
||||
parameters=[config_file],
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
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),
|
||||
])
|
||||
|
||||
Loading…
Reference in New Issue
Block a user