How to define the execution of a sequence of launch actions within the ROS2 launch system
Greetings. Is there a way to manage the the execution order of my nodes within a launch file? Furthermore is there such a way for imported launch files and their nodes.
These questions relay to the use-case of spawning and controlling a robot with ros2_control and MoveIt2. The execution order would be roughly something like:
Top Level .launch file (sequence in cardinals)
|- 1. gzserver (IncludeLaunchDescription)
|- 2. Robot .launch file (IncludeLaunchDescription)
| 2.1. robot_state_publisher (Node)
| 2.2. ros2_control specific .launch file (IncludeLaunchDescription)
| 2.3. MoveIt specific .launch file (IncludeLaunchDescription)
| 2.4. spawn_entity (Node)
|- 3. Simulation .launch file (IncludeLaunchDescription)
| 3.1. Gazebo environment spawning (IncludeLaunchDescription)
|- 4. RViz .launch file (IncludeLaunchDescription)
As a beginner within the launch system I am unaware to achieve this. I am aware that the order of adding the launch actions does not have a controllable effect and that there are event handlers for delays within the launch system. However, the event handlers seem unable to achieve the desired outcome. Also many of the 'common' nodes do not yet inherit form rclcpp_lifecycle::LifecycleNode
, since it is still in development.
Certainly a better versed ROS developer can point me to a solution, because it seems to be a somewhat common use-case.
Why do the event handlers not achieve the desired outcome?
Also, if you're using
gazebo_ros2_control
you should launchspawn_entity
before your controllers. Since the controller manager fromgazebo_ros2_control
is inside your URDF and doesn't start unless you spawn the robot. You might need to move 2.4 to be 2.1.5 so to speak, if I'm remembering correctly.I'm also not sure what the difference between 1 and 3 is. Are you first launching Gazebo and then adding the world after?
Since the launch files are nested via inclusion I can not reference nodes from the included launch files on a higher level, or I am not mistaken? As far as I know the event handlers are able to look for on_exit or on_execution_complete events and others, from nodes but for this the events have to be registered in the launch file which starts the node. - Sorry, I am guessing a lot since I find the official documentation to shallow for such a case.
Oh I did not know I have to spawn it first, thank you! - I thought
spawn_entity
only spawns it within Gazebo, because with the publishing its already visible within RViz.I do not have a Gazebo world to load. I want to spawn all necessary entities with the launch system, because this will become the virtual prototype of a modular test system with a fluctuating number of ...(more)