Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions launch_ros/launch_ros/actions/composable_node_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from typing import Optional

from launch.action import Action
from launch.actions import RegisterEventHandler
from launch.event_handlers.on_process_start import OnProcessStart
from launch.launch_context import LaunchContext
from launch.some_substitutions_type import SomeSubstitutionsType

Expand Down Expand Up @@ -61,10 +63,20 @@ def execute(self, context: LaunchContext) -> Optional[List[Action]]:
load_actions = None # type: Optional[List[Action]]
if self.__composable_node_descriptions is not None:
from .load_composable_nodes import LoadComposableNodes
load_actions = [LoadComposableNodes(
composable_node_descriptions=self.__composable_node_descriptions,
target_container=self
)]
# Perform load action once the container has started.
load_actions = [
RegisterEventHandler(
event_handler=OnProcessStart(
target_action=self,
on_start=[
LoadComposableNodes(
composable_node_descriptions=self.__composable_node_descriptions,
target_container=self
)
]
)
)
]
container_actions = super().execute(context) # type: Optional[List[Action]]
if container_actions is not None and load_actions is not None:
return container_actions + load_actions
Expand Down
24 changes: 5 additions & 19 deletions launch_ros/launch_ros/actions/load_composable_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
import composition_interfaces.srv

from launch.action import Action
from launch.actions import RegisterEventHandler
from launch.event_handlers.on_process_start import OnProcessStart
from launch.events.process import ProcessStarted
from launch.launch_context import LaunchContext
import launch.logging
from launch.utilities import ensure_argument_type
Expand Down Expand Up @@ -51,6 +48,9 @@ def __init__(
The container node is expected to provide a `~/_container/load_node` service for
loading purposes.
Loading will be performed sequentially.
When executed, this action will block until the container's load service is available.
Make sure any LoadComposableNode action is executed only after its container processes
has started.

:param composable_node_descriptions: descriptions of composable nodes to be loaded
:param target_container: the container to load the nodes into
Expand Down Expand Up @@ -156,15 +156,6 @@ def _load_in_sequence(
)
)

def _on_container_start(
self,
event: ProcessStarted,
context: LaunchContext
) -> Optional[List[Action]]:
"""Load nodes on container process start."""
self._load_in_sequence(self.__composable_node_descriptions, context)
return None

def execute(
self,
context: LaunchContext
Expand All @@ -176,10 +167,5 @@ def execute(
self.__target_container.node_name
)
)
# Perform load action once the container has started.
return [RegisterEventHandler(
event_handler=OnProcessStart(
target_action=self.__target_container,
on_start=self._on_container_start,
)
)]
# Assume user has configured `LoadComposableNodes` to happen after container action
self._load_in_sequence(self.__composable_node_descriptions, context)