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

Extra parameter to start a container #616

Merged
merged 10 commits into from
Oct 14, 2024
37 changes: 33 additions & 4 deletions ros_gz_bridge/launch/ros_gz_bridge.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from launch.actions import DeclareLaunchArgument, GroupAction
from launch.conditions import IfCondition
from launch.substitutions import LaunchConfiguration, PythonExpression
from launch_ros.actions import LoadComposableNodes, Node
from launch_ros.actions import ComposableNodeContainer, LoadComposableNodes, Node
from launch_ros.descriptions import ComposableNode


Expand All @@ -27,6 +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')
namespace = LaunchConfiguration('namespace')
use_composition = LaunchConfiguration('use_composition')
use_respawn = LaunchConfiguration('use_respawn')
Expand All @@ -46,6 +47,12 @@ def generate_launch_description():
description='Name of container that nodes will load in if use composition',
)

declare_start_container_cmd = DeclareLaunchArgument(
'start_container',
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest changing this to create_own_container to make it a little more clear that this is not necessary for the bridge to work as a composable node. I would also add more to the description so users don't think they have to set this to True in order to get the benefits of composition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I renamed the new parameter as suggested and added to the launch action. I also changed the default value of use_composition to False. f0f63b3

default_value='False',
description='Whether to start a ROS container when using composition',
caguero marked this conversation as resolved.
Show resolved Hide resolved
)

declare_namespace_cmd = DeclareLaunchArgument(
'namespace', default_value='', description='Top-level namespace'
)
Expand Down Expand Up @@ -81,8 +88,27 @@ def generate_launch_description():
],
)

load_composable_nodes = LoadComposableNodes(
condition=IfCondition(use_composition),
load_composable_nodes_with_container = ComposableNodeContainer(
condition=IfCondition(PythonExpression([use_composition, ' and ', start_container])),
name=LaunchConfiguration('container_name'),
namespace='',
package='rclcpp_components',
executable='component_container',
composable_node_descriptions=[
ComposableNode(
package='ros_gz_bridge',
plugin='ros_gz_bridge::RosGzBridge',
name=bridge_name,
namespace=namespace,
parameters=[{'config_file': config_file}],
extra_arguments=[{'use_intra_process_comms': True}],
),
],
output='screen',
)

load_composable_nodes_without_container = LoadComposableNodes(
condition=IfCondition(PythonExpression([use_composition, ' and not ', start_container])),
target_container=container_name,
composable_node_descriptions=[
ComposableNode(
Expand All @@ -94,6 +120,7 @@ def generate_launch_description():
extra_arguments=[{'use_intra_process_comms': True}],
),
],
output='screen',
)

# Create the launch description and populate
Expand All @@ -103,12 +130,14 @@ 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_namespace_cmd)
ld.add_action(declare_use_composition_cmd)
ld.add_action(declare_use_respawn_cmd)
ld.add_action(declare_log_level_cmd)
# Add the actions to launch all of the bridge nodes
ld.add_action(load_nodes)
ld.add_action(load_composable_nodes)
ld.add_action(load_composable_nodes_with_container)
ld.add_action(load_composable_nodes_without_container)

return ld
Loading