Skip to content

Commit

Permalink
Use create_own_container
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Agüero <caguero@openrobotics.org>
  • Loading branch information
caguero committed Oct 1, 2024
1 parent a2adf04 commit f0f63b3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
4 changes: 3 additions & 1 deletion ros_gz_bridge/launch/ros_gz_bridge.launch
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
<arg name="bridge_name" />
<arg name="config_file" />
<arg name="container_name" default="ros_gz_container" />
<arg name="create_own_container" default="False" />
<arg name="namespace" default="" />
<arg name="use_composition" default="True" />
<arg name="use_composition" default="False" />
<arg name="use_respawn" default="False" />
<arg name="log_level" default="info" />
<ros_gz_bridge
bridge_name="$(var bridge_name)"
config_file="$(var config_file)"
container_name="$(var container_name)"
create_own_container="$(var create_own_container)"
namespace="$(var namespace)"
use_composition="$(var use_composition)"
use_respawn="$(var use_respawn)"
Expand Down
14 changes: 7 additions & 7 deletions ros_gz_bridge/launch/ros_gz_bridge.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def generate_launch_description():
bridge_name = LaunchConfiguration('bridge_name')
config_file = LaunchConfiguration('config_file')
container_name = LaunchConfiguration('container_name')
start_container = LaunchConfiguration('start_container')
create_own_container = LaunchConfiguration('create_own_container')
namespace = LaunchConfiguration('namespace')
use_composition = LaunchConfiguration('use_composition')
use_respawn = LaunchConfiguration('use_respawn')
Expand All @@ -47,8 +47,8 @@ def generate_launch_description():
description='Name of container that nodes will load in if use composition',
)

declare_start_container_cmd = DeclareLaunchArgument(
'start_container',
declare_create_own_container_cmd = DeclareLaunchArgument(
'create_own_container',
default_value='False',
description='Whether to start a ROS container when using composition',
)
Expand All @@ -58,7 +58,7 @@ def generate_launch_description():
)

declare_use_composition_cmd = DeclareLaunchArgument(
'use_composition', default_value='True', description='Use composed bringup if True'
'use_composition', default_value='False', description='Use composed bringup if True'
)

declare_use_respawn_cmd = DeclareLaunchArgument(
Expand Down Expand Up @@ -89,7 +89,7 @@ def generate_launch_description():
)

load_composable_nodes_with_container = ComposableNodeContainer(
condition=IfCondition(PythonExpression([use_composition, ' and ', start_container])),
condition=IfCondition(PythonExpression([use_composition, ' and ', create_own_container])),
name=LaunchConfiguration('container_name'),
namespace='',
package='rclcpp_components',
Expand All @@ -108,7 +108,7 @@ def generate_launch_description():
)

load_composable_nodes_without_container = LoadComposableNodes(
condition=IfCondition(PythonExpression([use_composition, ' and not ', start_container])),
condition=IfCondition(PythonExpression([use_composition, ' and not ', create_own_container])),
target_container=container_name,
composable_node_descriptions=[
ComposableNode(
Expand All @@ -130,7 +130,7 @@ def generate_launch_description():
ld.add_action(declare_bridge_name_cmd)
ld.add_action(declare_config_file_cmd)
ld.add_action(declare_container_name_cmd)
ld.add_action(declare_start_container_cmd)
ld.add_action(declare_create_own_container_cmd)
ld.add_action(declare_namespace_cmd)
ld.add_action(declare_use_composition_cmd)
ld.add_action(declare_use_respawn_cmd)
Expand Down
14 changes: 13 additions & 1 deletion ros_gz_bridge/ros_gz_bridge/actions/ros_gz_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ def __init__(
bridge_name: SomeSubstitutionsType,
config_file: SomeSubstitutionsType,
container_name: Optional[SomeSubstitutionsType] = 'ros_gz_container',
create_own_container: Optional[SomeSubstitutionsType] = 'False',
namespace: Optional[SomeSubstitutionsType] = '',
use_composition: Optional[SomeSubstitutionsType] = 'True',
use_composition: Optional[SomeSubstitutionsType] = 'False',
use_respawn: Optional[SomeSubstitutionsType] = 'False',
log_level: Optional[SomeSubstitutionsType] = 'info',
**kwargs
Expand All @@ -52,6 +53,7 @@ def __init__(
:param: bridge_name Name of ros_gz_bridge node
:param: config_file YAML config file.
:param: container_name Name of container that nodes will load in if use composition.
:param: create_own_container Whether to start a ROS container when using composition.
:param: namespace Top-level namespace.
:param: use_composition Use composed bringup if True.
:param: use_respawn Whether to respawn if a node crashes (when composition is disabled).
Expand All @@ -61,6 +63,7 @@ def __init__(
self.__bridge_name = bridge_name
self.__config_file = config_file
self.__container_name = container_name
self.__create_own_container = create_own_container
self.__namespace = namespace
self.__use_composition = use_composition
self.__use_respawn = use_respawn
Expand All @@ -83,6 +86,10 @@ def parse(cls, entity: Entity, parser: Parser):
'container_name', data_type=str,
optional=True)

create_own_container = entity.get_attr(
'create_own_container', data_type=str,
optional=True)

namespace = entity.get_attr(
'namespace', data_type=str,
optional=True)
Expand Down Expand Up @@ -111,6 +118,10 @@ def parse(cls, entity: Entity, parser: Parser):
container_name = parser.parse_substitution(container_name)
kwargs['container_name'] = container_name

if isinstance(create_own_container, str):
create_own_container = parser.parse_substitution(create_own_container)
kwargs['create_own_container'] = create_own_container

if isinstance(namespace, str):
namespace = parser.parse_substitution(namespace)
kwargs['namespace'] = namespace
Expand Down Expand Up @@ -139,6 +150,7 @@ def execute(self, context: LaunchContext) -> Optional[List[Action]]:
launch_arguments=[('bridge_name', self.__bridge_name),
('config_file', self.__config_file),
('container_name', self.__container_name),
('create_own_container', self.__create_own_container),
('namespace', self.__namespace),
('use_composition', self.__use_composition),
('use_respawn', self.__use_respawn),
Expand Down

0 comments on commit f0f63b3

Please sign in to comment.