1- #!/usr/bin/env python3
2-
3- # Copyright 2023 Universidad Politécnica de Madrid
1+ # Copyright 2024 Universidad Politécnica de Madrid
42#
53# Redistribution and use in source and binary forms, with or without
64# modification, are permitted provided that the following conditions are met:
2725# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2826# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2927# POSSIBILITY OF SUCH DAMAGE.
28+
3029"""Launch Pixhawk platform node."""
3130
32- __authors__ = 'Miguel Fernández Cortizas, Rafael Pérez Seguí'
33- __copyright__ = 'Copyright (c) 2022 Universidad Politécnica de Madrid'
31+ __authors__ = 'Miguel Fernández Cortizas, Rafael Pérez Seguí, Pedro Arias Pérez '
32+ __copyright__ = 'Copyright (c) 2024 Universidad Politécnica de Madrid'
3433__license__ = 'BSD-3-Clause'
3534
35+ import os
36+
37+ from ament_index_python .packages import get_package_share_directory
38+ from as2_core .declare_launch_arguments_from_config_file import DeclareLaunchArgumentsFromConfigFile
39+ from as2_core .launch_configuration_from_config_file import LaunchConfigurationFromConfigFile
3640from launch import LaunchDescription
3741from launch .actions import DeclareLaunchArgument
38- from launch .substitutions import EnvironmentVariable , LaunchConfiguration , PathJoinSubstitution
42+ from launch .substitutions import EnvironmentVariable , LaunchConfiguration
3943from launch_ros .actions import Node
40- from launch_ros .substitutions import FindPackageShare
4144
4245
4346def generate_launch_description ():
4447 """Entrypoint."""
45- control_modes = PathJoinSubstitution ([
46- FindPackageShare ('as2_platform_pixhawk' ),
47- 'config' , 'control_modes.yaml'
48- ])
49-
50- platform_config_file = PathJoinSubstitution ([
51- FindPackageShare ('as2_platform_pixhawk' ),
52- 'config' , 'platform_config_file.yaml'
53- ])
48+ package_folder = get_package_share_directory ('as2_platform_pixhawk' )
49+ control_modes = os .path .join (package_folder , 'config/control_modes.yaml' )
50+ platform_config_file = os .path .join (package_folder , 'config/platform_config_file.yaml' )
5451
5552 return LaunchDescription ([
5653 DeclareLaunchArgument ('namespace' ,
@@ -60,10 +57,9 @@ def generate_launch_description():
6057 DeclareLaunchArgument ('control_modes_file' ,
6158 default_value = control_modes ,
6259 description = 'Platform control modes file' ),
63- DeclareLaunchArgument ('platform_config_file' ,
64- default_value = platform_config_file ,
65- description = 'Platform configuration file' ),
66-
60+ DeclareLaunchArgumentsFromConfigFile (
61+ name = 'platform_config_file' , source_file = platform_config_file ,
62+ description = 'Platform configuration file' ),
6763 Node (
6864 package = 'as2_platform_pixhawk' ,
6965 executable = 'as2_platform_pixhawk_node' ,
@@ -75,7 +71,10 @@ def generate_launch_description():
7571 {
7672 'control_modes_file' : LaunchConfiguration ('control_modes_file' ),
7773 },
78- LaunchConfiguration ('platform_config_file' )
74+ LaunchConfiguration ('platform_config_file' ),
75+ LaunchConfigurationFromConfigFile (
76+ 'platform_config_file' ,
77+ default_file = platform_config_file ),
7978 ]
8079 )
8180 ])
0 commit comments