ros2 launch or python3 foo.launch.py
I see several example launch files which implement a main, instead of just returning a launch description. Example from ros2/launch/ros repo: https://github.com/ros2/launch_ros/blob/master/launch_ros/examples/lifecycle_pub_sub_launch.py
Is there a guideline which variant to prefer? Are there any advantages in using the ros2 launch variant?
edit: This seems to be a conceptual question. From what i can see, the deciding part that makes the nodes run is the following:
ls = launch.LaunchService(argv=argv)
ls.include_launch_description(ld)
return ls.run()
It should be easy to include other LaunchDescriptions
from other launch files like so:
client_launch = IncludeLaunchDescription(
PythonLaunchDescriptionSource([share_dir, '/launch/client.launch.py']),
launch_arguments={}.items()
)
I dont see an advantage in letting the ros2 launch system take over the LaunchService
, when you lose quite some functionality by not defining your own main.
For example:
- printing the introspection of the launch file
- performing tasks after starting the nodes, like calling services
What am I missing that the creators of ros2 launch thought of?
Asked by highmax1234 on 2021-05-12 02:45:14 UTC
Answers
From what I've seen the ros2 launch <pkg> <launch_file>
method is the "proper" way of doing it. If I had to guess I would say that the example you linked is structured as-such so as to make it self-contained in some way.
As for problems... You might run into weird issues if/when you start trying to reference launch descriptions within each other. E.g. you have a launch file for Node A, one for Node B, and another for Node C. Then you have a "master" launch file that imports some combination of each, and perhaps adds a few other things on top like log levels or miscellaneous ROS command line arguments. I can't say you'll 100% run into problems with the latter approach of using python3
, but with the former approach with ros2 launch
you'll definitely have no weird behaviors crop-up.
Asked by Spectre on 2021-05-12 04:06:13 UTC
Comments