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 2 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
.vscode
wjwwood marked this conversation as resolved.
Show resolved Hide resolved
27 changes: 16 additions & 11 deletions launch_ros/launch_ros/actions/load_composable_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@

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.utilities import normalize_to_list_of_substitutions
from launch.utilities import perform_substitutions

from .composable_node_container import ComposableNodeContainer
Expand All @@ -39,7 +42,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 @@ -55,15 +58,10 @@ def __init__(
:param composable_node_descriptions: descriptions of composable nodes to be loaded
:param target_container: the container to load the nodes into
"""
ensure_argument_type(
target_container,
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 +126,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 +159,17 @@ def execute(
context: LaunchContext
) -> Optional[List[Action]]:
"""Execute the action."""
# resolve target container node name
if isinstance(self.__target_container, ComposableNodeContainer):
oceanusxiv marked this conversation as resolved.
Show resolved Hide resolved
self.__final_target_container_name = self.__target_container.node_name
else: # TODO: maybe should do better type checking here
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

# 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