ros2 argument in lauch.py
I have a launch file with ROS1 as below. I want to wirte it with ros2 launch.py. How to write it with ros2 ?
<launch>
<arg name="camera_type_tel" default="astrapro" doc="camera type [astrapro, astra,d435]"/>
<include file="$(find camera_driver_transfer)/launch/$(arg camera_type_tel).launch">
</include>
</launch>
I want to run the camer launch file with argument , not use the string(d435_launch.py). I wirte it as below: but when I run it ,it is error! how can I do ?
import os
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import (DeclareLaunchArgument, GroupAction,
IncludeLaunchDescription)
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import LaunchConfiguration
def generate_launch_description():
# Get the launch directory
camera_driver_transfer_dir = get_package_share_directory('camera_driver_transfer')
camera_type_tel = LaunchConfiguration('camera_type_tel')
declare_camera_type_tel = DeclareLaunchArgument(
'camera_type_tel',
default_value='d435',
choices=['d435', 'astra_pro'],
description='camera type')
camera_type_launch = camera_type_tel+'_launch.py'
# Specify the actions
camera_group = GroupAction([
IncludeLaunchDescription(
PythonLaunchDescriptionSource(os.path.join(camera_driver_transfer_dir, 'launch', camera_type_launch))) #this is error
#PythonLaunchDescriptionSource(os.path.join(camera_driver_transfer_dir, 'launch', 'd435_launch.py'))) #this is ok
])
# Create the launch description and populate
ld = LaunchDescription()
ld.add_action(declare_camera_type_tel)
ld.add_action(camera_group)
return ld
What type of error are you receiving? Please also add the information from the terminal. This line:
camera_type_launch = camera_type_tel+'_launch.py'
looks incorrect to me, where did you find such use ofDeclareLaunchArgument
as a string to concatenate? Are you sure it is a string? The later error may come from this.yes, you are right. I want to get the result of DeclareLaunchArgument as sting type.But it seens it has not. I don't know how to do it. Have you a good way to implement this feature on ROS2?
I think this question answers how you can get it as a string: https://answers.ros.org/question/3963...