How does python launch file works in ros2?
I Used to work on ROS1 8 months ago and it was quite easy to work with launch files. Now I am working with ros2 after all these months and even after referring to many resources I am unable to create a launch file which can launch a simple empty gazebo world in ignition citadel. I am using ros2 foxy and I want to create a project in it which requires many things but I am not able to launch a simple world in gazebo. So I want to ask if anyone could explain me how launch file is created, how it works in ros2 foxy and how I can launch a simple empty world in gazebo ignition citadel. Even referring to any proper resource would be a great help
I have already tried creating a launch file for talker and listener but m unable to help myself for this one.
Thank You in advance
Just to draw attention to it (as I don't see it mentioned often in the context of "ROS 2 launch files"): you don't have to use Python-based launch files in ROS 2. The XML syntax is still supported. Especially for simpler launch files (loading some nodes, setting some parameters), I would not necessarily recommend using Python-based launch files.
The
.launch.py
files were/are intended for more complex scenarios where the "power of a full programming language" would be helpful. Declarative systems can only do so much, and sometimes an imperative approach is just easier. That's when you want to use Python.For a simple system where you're looking to just launch some nodes, I'd suggest to stick to the XML version of ROS 2 launch files. And you can mix-and-match Python and XML launch files.
The only 'good' documentation on it I know would ...(more)
Thank you for addressing my concern. I am working to develop a swarm robotics project and right now in initial phase I am developing and configuring a single bot and then will go on communication between those bots and on collective decision making and for that I think going with python file might be beneficial for me (I might be wrong please correct me if I am). And my main concern is that I am unable to get lunch directory in share folder of install directory by colcon build, so I think I have not understood the basic of launch file for ros2 correctly. Can you help me out with anything for that? Thank you again :)
will the "communication" and "collective decision making" be implemented in the launch file, or in the nodes?
Probably the nodes.
Unless you want to implement (parts of) system runtime management (ie: managed nodes) in your launch file (which gets complex really, really quickly), I'd not expect any logic in the launch files themselves, but in the nodes.