In Aerostack2, we use YAML configuration files to pass parameters to the nodes. To facilitate parameter configuration, utilities have been developed that allow setting parameters individually.
Adding launch utilities allows users to set parameters via a configuration file and through parameters, following this order:
Default configuration file in the package config folder.
Custom configuration file specified in the launch command (e.g., config_file:=path/to/file.yaml).
Custom parameters specified in the launch command (e.g., param:=100).
So that, the launcher can be called with:
No arguments -> uses the default config file.
A parameter file argument -> parameters in the file override the parameters in the default config file.
A parameter name -> overrides both the default and custom config file parameter value.
Implementation Considerations
The following code shows how to use the launch utilities in a launch file:
import as2_core.launch_param_utils as as2_utils
# Generate the launch description
[
# Declare launch arguments
DeclareLaunchArgument(...),
# Declare config file argument and parameter in file arguments
*as2_utils.declare_launch_arguments(
'config_file_param_name',
default_value=custom_config_file_path,
description='Your description'
),
# Declare the node
Node(
package='pkg_name',
executable='pkg_name_node',
parameters=[
# Add configuration file parameter to the node
*as2_utils.launch_configuration('config_file', default_value=custom_config_file),
{
# Rest of the parameters
'param_name': LaunchConfiguration('param_name'),
}
]
)
]
Example:
import os
from ament_index_python.packages import get_package_share_directory
import as2_core.launch_param_utils as as2
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch_ros.actions import Node
from launch.substitutions import LaunchConfiguration
def generate_launch_description():
"""Entrypoint."""
# Get default platform configuration file
package_folder = get_package_share_directory('pkg_name')
custom_config_file = os.path.join(package_folder, 'config/custom_config_file.yaml')
return LaunchDescription([
DeclareLaunchArgument('use_sim_time', default_value='false'),
*as2.declare_launch_arguments(
'config_file',
default_value=custom_config_file,
description='Configuration file'
),
Node(
package='pkg_name',
executable='pkg_name_node',
parameters=[
*as2.launch_configuration('config_file', default_value=custom_config_file),
{
'use_sim_time': LaunchConfiguration('use_sim_time'),
}
]
)
])
Note: Use os.path.join rather than PathJoinSubstitution to avoid issues with show args.
_Note: When declaring a string which content is a number, must use: " 'numbervalue' "Note: When declaring a launch argument, if adding two config files with the same parameter name, the parameter will retain the value from the first declaration.
You can test the launch file with the following command:
ros2 launch pkg_name launch_file_name.py -s
The -sargument will show the launch file arguments and their default values. The config file path argument and parameter in file arguments should be shown in the output.
Current implementation in Aerostack2
Current aerostack2 packages that have been migrated to ament_lint_auto:
as2_alphanumericviewer (don't have config file)_
[x] as2_behaviors_motion
[x] as2_behaviors_perception
as2_behaviorsplatform (don't have config file)_
as2_behaviors_trajectorygeneration (don't have config file)_
as2_gazeboassets (don't have config file)_
as2_gazebo_classicassets (don't have config file)_
as2_keyboardteleoperation (don't have config file)_
Feature Description
In Aerostack2, we use YAML configuration files to pass parameters to the nodes. To facilitate parameter configuration, utilities have been developed that allow setting parameters individually.
Adding launch utilities allows users to set parameters via a configuration file and through parameters, following this order:
So that, the launcher can be called with:
Implementation Considerations
The following code shows how to use the launch utilities in a launch file:
Example:
Note: Use
os.path.join
rather thanPathJoinSubstitution
to avoid issues with show args. _Note: When declaring a string which content is a number, must use: " 'numbervalue' " Note: When declaring a launch argument, if adding two config files with the same parameter name, the parameter will retain the value from the first declaration.You can test the launch file with the following command:
ros2 launch pkg_name launch_file_name.py -s
The
-s
argument will show the launch file arguments and their default values. The config file path argument and parameter in file arguments should be shown in the output.Current implementation in Aerostack2
Current aerostack2 packages that have been migrated to ament_lint_auto:
External packages: