Ask Your Question
0

Access launch argument in LaunchFile ROS2

asked 2019-12-26 12:40:47 -0600

relffok gravatar image

updated 2019-12-26 12:42:11 -0600

Hi, I've been trying to Use my Launch Arguments inside of my Launch File for further purposes. So I can declare it by using launch.actions.DeclareLaunchArgument( 'param1', default_value="defaultString") and access it later using launch.substitutions.LaunchConfiguration( 'param1') to pass it to a node or whatever. The type of this element is a launch.substitutions.launch_configuration.LaunchConfiguration object.

Now I want to use the content of this argument as a string for building filepaths for example. I know several functions are able to interpret the LaunchConfiguration object but I specifically to read it as a string. I have not found a way to do so. As I need to access multiple arguments several times, I am looking for a simple implementation.

Any ideas? Thanks!

(I am working with ROS2 Dashing)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-12-31 10:27:41 -0600

guru_florida gravatar image

updated 2019-12-31 10:29:17 -0600

I don't believe you can access the argument during building of the description. I think you can still do what you want though as far as building paths based on an argument by passing in an array and have the path concat'd at run time.

For example, I want to specify the underlying hardware launch file as an argument. If I give the argument hardware:=rpi1 then my main launch file will include launch file rpi1.launch.py instead of the default hardware.launch.py in it's launch description:

Import required modules:

from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import ThisLaunchFileDir, LaunchConfiguration

Declare the launch argument, then use the launch argument in a build-path statement to include my parameterized launch file:

launch_desc.add_action( launch.actions.DeclareLaunchArgument('hardware', default_value='hardware') )
launch_desc.add_action( IncludeLaunchDescription(PythonLaunchDescriptionSource([ThisLaunchFileDir(),'/',LaunchConfiguration('hardware'), '.launch.py'])) )
edit flag offensive delete link more

Comments

Thanks for your answer. I did know the possibility using an array. Unfortunately I need to access the arguments as a string type because the LaunchConfiguration element can only be read by launch action functions and I want to use them with other functions as well.

I can't believe that this is not possible yet because I feel its a very basic and handy action to use.

relffok gravatar imagerelffok ( 2020-01-02 11:48:04 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2019-12-26 12:40:47 -0600

Seen: 48 times

Last updated: Dec 31 '19