Is it possible to refer to the actions defined in a different launch?
Hello, I'd like to know whether it's possible to refer to the actions defined in launch A, from launch B.
For example, considering the case of: - start publisher after 5 seconds wait - launch subscriber after publisher started
pubsub.launch.py
from launch import LaunchDescription
from launch.actions import RegisterEventHandler
from launch.actions.timer_action import TimerAction
from launch.event_handlers import OnProcessStart
from launch_ros.actions import Node
def generate_launch_description():
publisher = Node(
package="examples_rclcpp_minimal_publisher",
executable="publisher_lambda",
output="screen",
)
launch_publisher_after_timer = TimerAction(period=5.0, actions=[publisher])
subscriber = Node(
package="examples_rclcpp_minimal_subscriber",
executable="subscriber_lambda",
output="screen",
)
subscriber_handler = RegisterEventHandler(
event_handler=OnProcessStart(
target_action=publisher,
on_start=[
subscriber,
],
)
)
return LaunchDescription([launch_publisher_after_timer, subscriber_handler])
This of course works as expected. However, if I split this into two launch files, sub.launch.py doesn't work correctly. (I know my usage is wrong.)
pub.launch.py
(imports are omitted)
def generate_launch_description():
publisher = Node(
package="examples_rclcpp_minimal_publisher",
executable="publisher_lambda",
output="screen",
)
launch_publisher_after_timer = TimerAction(period=5.0, actions=[publisher])
return LaunchDescription([launch_publisher_after_timer])
sub.launch.py
(imports are omitted)
def generate_launch_description():
publisher = Node(
package="examples_rclcpp_minimal_publisher",
executable="publisher_lambda",
output="screen",
)
subscriber = Node(
package="examples_rclcpp_minimal_subscriber",
executable="subscriber_lambda",
output="screen",
)
subscriber_handler = RegisterEventHandler(
event_handler=OnProcessStart(
target_action=publisher,
on_start=[
subscriber,
],
)
)
return LaunchDescription([subscriber_handler])
pubsub.launch.xml
<launch>
<include file="./pub.launch.py"/>
<include file="./sub.launch.py"/>
</launch>
So my question is, can I use publisher
Node defined in pub.launch.py
as target_action
in sub.launch.py
?
I guess it's possible if there is a method to iterate all actions defined in other launch files and then filter by name.
Thank you in advance.