Ask Your Question
1

Running Python launch files with arguments

asked 2021-02-23 10:20:24 -0600

NotARobot gravatar image

updated 2021-02-24 10:28:44 -0600

Greetings. Is there a way to use arguments within launch files written in Python?

I have found the possibilities offered by roslaunch, however I was wondering how to achieve the same effect in Python launch files.

To be more specific I want to create a number of robots for simulation purposes. For this I would like to supply a list of pose coordinates, spawning the corresponding number of robots at the respective poses.

In order to achieve this I plan to iterate in the launch file to create separate namespaces for each robot before spawning them.

Therefore, is there a way to pass some command line arguments like ros2 launch my_sim_bringup multiple_robots.launch -x 0 -y 0 -z 0 ?

Could I define generate_launch_description like this def generate_launch_description(my_arg), as I would do with any Python function to achieve this behavior?

I am very sorry for asking such basic questions, but the documentation regarding the Python launch system is lacking.


EDIT: Doing further research I found: ros2 access current LaunchConfiguration, Access launch argument in LaunchFile ROS2 as well as ROS2: How to pass arguments from one launch file to a child launch file. But to be frank, I don't get it.

Using the method proposed by these links I have implemented in my launch file:

ld = LaunchDescription()    
robot_positions = DeclareLaunchArgument(
            'positions',
            default_value="000",
        )
ld.add_action(robot_positions)

as well as

positions = LaunchConfiguration('positions', default="000")

Now I was lead to belief that it was possible to use command line arguments or superordinate launch files to supply the values. Something like this for command line ros2 launch my_sim_bringup multiple_robots.launch positions:=000

However, positions does not hold the string "000", rather a LaunchConfiguration object, which as far as I can see it in launch_configuration.py has no getter functions for retrieving the value.

edit retag flag offensive close merge delete

Comments

Please have a look at this answer. Maybe it helps you.

destogl gravatar image destogl  ( 2021-03-11 10:02:55 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-05-27 11:28:16 -0600

NotARobot gravatar image

Thank you for your answer destogl. I have to confess the solution I was looking for is very trivial and is more generic to Python.

I have solved the problem by using argv to get the desired effect.

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

4 followers

Stats

Asked: 2021-02-23 10:20:24 -0600

Seen: 179 times

Last updated: May 27