Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow separate launch composition #77

Merged
merged 5 commits into from
Dec 4, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ __pycache__
.mypy_cache
.pytest_cache
.flake8

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: delete unnecessary change.

30 changes: 24 additions & 6 deletions launch_ros/launch_ros/actions/load_composable_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@

from typing import List
from typing import Optional
from typing import Text
from typing import Union

import composition_interfaces.srv

from launch.action import Action
from launch.launch_context import LaunchContext
import launch.logging
from launch.utilities import ensure_argument_type
from launch.some_substitutions_type import SomeSubstitutionsType
from launch.some_substitutions_type import SomeSubstitutionsType_types_tuple
from launch.utilities import normalize_to_list_of_substitutions
from launch.utilities import perform_substitutions
from launch.utilities import ensure_argument_type
from launch.utilities import is_a_subclass

from .composable_node_container import ComposableNodeContainer

Expand All @@ -39,7 +45,7 @@ def __init__(
self,
*,
composable_node_descriptions: List[ComposableNode],
target_container: ComposableNodeContainer,
target_container: Union[SomeSubstitutionsType, ComposableNodeContainer],
ivanpauno marked this conversation as resolved.
Show resolved Hide resolved
**kwargs,
) -> None:
"""
Expand All @@ -57,13 +63,14 @@ def __init__(
"""
ensure_argument_type(
target_container,
ComposableNodeContainer,
list(SomeSubstitutionsType_types_tuple) + [ComposableNodeContainer],
'target_container',
'LoadComposableNodes'
)
oceanusxiv marked this conversation as resolved.
Show resolved Hide resolved
super().__init__(**kwargs)
self.__composable_node_descriptions = composable_node_descriptions
self.__target_container = target_container
self.__final_target_container_name = None # type: Optional[Text]
self.__logger = launch.logging.get_logger(__name__)

def _load_node(
Expand Down Expand Up @@ -128,11 +135,11 @@ def _load_node(
self.__logger.error(
"Failed to load node '{}' of type '{}' in container '{}': {}".format(
response.full_node_name if response.full_node_name else request.node_name,
request.plugin_name, self.__target_container.node_name, response.error_message
request.plugin_name, self.__final_target_container_name, response.error_message
)
)
self.__logger.info("Loaded node '{}' in container '{}'".format(
response.full_node_name, self.__target_container.node_name
response.full_node_name, self.__final_target_container_name
))

def _load_in_sequence(
Expand Down Expand Up @@ -161,10 +168,21 @@ def execute(
context: LaunchContext
) -> Optional[List[Action]]:
"""Execute the action."""
# resolve target container node name

if is_a_subclass(self.__target_container, ComposableNodeContainer):
self.__final_target_container_name = self.__target_container.node_name
elif isinstance(self.__target_container, SomeSubstitutionsType_types_tuple):
subs = normalize_to_list_of_substitutions(self.__target_container)
self.__final_target_container_name = perform_substitutions(context, subs)
oceanusxiv marked this conversation as resolved.
Show resolved Hide resolved
else:
self.__logger.error('target container is neither a ComposableNodeContainer nor a SubstitutionType')
return

# Create a client to load nodes in the target container.
self.__rclpy_load_node_client = context.locals.launch_ros_node.create_client(
composition_interfaces.srv.LoadNode, '{}/_container/load_node'.format(
self.__target_container.node_name
self.__final_target_container_name
)
)
# Assume user has configured `LoadComposableNodes` to happen after container action
Expand Down