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

Simplify namespaced bringups and multirobot sim #4715

Merged
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
22 changes: 2 additions & 20 deletions nav2_bringup/launch/bringup_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from launch_ros.actions import Node
from launch_ros.actions import PushROSNamespace
from launch_ros.descriptions import ParameterFile
from nav2_common.launch import ReplaceString, RewrittenYaml
from nav2_common.launch import RewrittenYaml


def generate_launch_description():
Expand All @@ -39,7 +39,6 @@ def generate_launch_description():

# Create the launch configuration variables
namespace = LaunchConfiguration('namespace')
use_namespace = LaunchConfiguration('use_namespace')
slam = LaunchConfiguration('slam')
map_yaml_file = LaunchConfiguration('map')
use_sim_time = LaunchConfiguration('use_sim_time')
Expand All @@ -58,16 +57,6 @@ def generate_launch_description():
# https://github.com/ros2/launch_ros/issues/56
remappings = [('/tf', 'tf'), ('/tf_static', 'tf_static')]

# Only it applys when `use_namespace` is True.
# '<robot_namespace>' keyword shall be replaced by 'namespace' launch argument
# in config file 'nav2_multirobot_params.yaml' as a default & example.
# User defined config file should contain '<robot_namespace>' keyword for the replacements.
params_file = ReplaceString(
source_file=params_file,
replacements={'<robot_namespace>': ('/', namespace)},
condition=IfCondition(use_namespace),
)

configured_params = ParameterFile(
SteveMacenski marked this conversation as resolved.
Show resolved Hide resolved
RewrittenYaml(
source_file=params_file,
Expand All @@ -86,12 +75,6 @@ def generate_launch_description():
'namespace', default_value='', description='Top-level namespace'
)

declare_use_namespace_cmd = DeclareLaunchArgument(
'use_namespace',
default_value='false',
description='Whether to apply a namespace to the navigation stack',
)

declare_slam_cmd = DeclareLaunchArgument(
'slam', default_value='False', description='Whether run a SLAM'
)
Expand Down Expand Up @@ -142,7 +125,7 @@ def generate_launch_description():
# Specify the actions
bringup_cmd_group = GroupAction(
[
PushROSNamespace(condition=IfCondition(use_namespace), namespace=namespace),
PushROSNamespace(namespace),
Node(
condition=IfCondition(use_composition),
name='nav2_container',
Expand Down Expand Up @@ -207,7 +190,6 @@ def generate_launch_description():

# Declare the launch options
ld.add_action(declare_namespace_cmd)
ld.add_action(declare_use_namespace_cmd)
ld.add_action(declare_slam_cmd)
ld.add_action(declare_map_yaml_cmd)
ld.add_action(declare_use_sim_time_cmd)
Expand Down
6 changes: 2 additions & 4 deletions nav2_bringup/launch/cloned_multi_tb3_simulation_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def generate_launch_description():
declare_params_file_cmd = DeclareLaunchArgument(
'params_file',
default_value=os.path.join(
bringup_dir, 'params', 'nav2_multirobot_params_all.yaml'
bringup_dir, 'params', 'nav2_params.yaml'
),
description='Full path to the ROS2 parameters file to use for all launched nodes',
)
Expand All @@ -93,7 +93,7 @@ def generate_launch_description():

declare_rviz_config_file_cmd = DeclareLaunchArgument(
'rviz_config',
default_value=os.path.join(bringup_dir, 'rviz', 'nav2_namespaced_view.rviz'),
default_value=os.path.join(bringup_dir, 'rviz', 'nav2_default_view.rviz'),
description='Full path to the RVIZ config file to use.',
)

Expand Down Expand Up @@ -144,7 +144,6 @@ def generate_launch_description():
condition=IfCondition(use_rviz),
launch_arguments={
'namespace': TextSubstitution(text=robot_name),
'use_namespace': 'True',
'rviz_config': rviz_config_file,
}.items(),
),
Expand All @@ -154,7 +153,6 @@ def generate_launch_description():
),
launch_arguments={
'namespace': robot_name,
'use_namespace': 'True',
'map': map_yaml_file,
'use_sim_time': 'True',
'params_file': params_file,
Expand Down
42 changes: 1 addition & 41 deletions nav2_bringup/launch/rviz_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, EmitEvent, RegisterEventHandler
from launch.conditions import IfCondition, UnlessCondition
from launch.event_handlers import OnProcessExit
from launch.events import Shutdown
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from nav2_common.launch import ReplaceString


def generate_launch_description():
Expand All @@ -32,7 +30,6 @@ def generate_launch_description():

# Create the launch configuration variables
namespace = LaunchConfiguration('namespace')
use_namespace = LaunchConfiguration('use_namespace')
rviz_config_file = LaunchConfiguration('rviz_config')
use_sim_time = LaunchConfiguration('use_sim_time')

Expand All @@ -46,12 +43,6 @@ def generate_launch_description():
),
)

declare_use_namespace_cmd = DeclareLaunchArgument(
'use_namespace',
default_value='false',
description='Whether to apply a namespace to the navigation stack',
)

declare_rviz_config_file_cmd = DeclareLaunchArgument(
'rviz_config',
default_value=os.path.join(bringup_dir, 'rviz', 'nav2_default_view.rviz'),
Expand All @@ -65,68 +56,37 @@ def generate_launch_description():

# Launch rviz
start_rviz_cmd = Node(
condition=UnlessCondition(use_namespace),
package='rviz2',
executable='rviz2',
namespace=namespace,
arguments=['-d', rviz_config_file],
output='screen',
parameters=[{'use_sim_time': use_sim_time}],
)

namespaced_rviz_config_file = ReplaceString(
source_file=rviz_config_file,
replacements={'<robot_namespace>': ('/', namespace)},
)

start_namespaced_rviz_cmd = Node(
condition=IfCondition(use_namespace),
package='rviz2',
executable='rviz2',
namespace=namespace,
arguments=['-d', namespaced_rviz_config_file],
parameters=[{'use_sim_time': use_sim_time}],
output='screen',
remappings=[
('/map', 'map'),
('/tf', 'tf'),
('/tf_static', 'tf_static'),
('/goal_pose', 'goal_pose'),
('/clicked_point', 'clicked_point'),
('/initialpose', 'initialpose'),
],
)

exit_event_handler = RegisterEventHandler(
condition=UnlessCondition(use_namespace),
event_handler=OnProcessExit(
target_action=start_rviz_cmd,
on_exit=EmitEvent(event=Shutdown(reason='rviz exited')),
),
)

exit_event_handler_namespaced = RegisterEventHandler(
condition=IfCondition(use_namespace),
event_handler=OnProcessExit(
target_action=start_namespaced_rviz_cmd,
on_exit=EmitEvent(event=Shutdown(reason='rviz exited')),
),
)

# Create the launch description and populate
ld = LaunchDescription()

# Declare the launch options
ld.add_action(declare_namespace_cmd)
ld.add_action(declare_use_namespace_cmd)
ld.add_action(declare_rviz_config_file_cmd)
ld.add_action(declare_use_sim_time_cmd)

# Add any conditioned actions
ld.add_action(start_rviz_cmd)
ld.add_action(start_namespaced_rviz_cmd)

# Add other nodes and processes we need
ld.add_action(exit_event_handler)
ld.add_action(exit_event_handler_namespaced)

return ld
10 changes: 0 additions & 10 deletions nav2_bringup/launch/tb3_loopback_simulation.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def generate_launch_description():

# Create the launch configuration variables
namespace = LaunchConfiguration('namespace')
use_namespace = LaunchConfiguration('use_namespace')
map_yaml_file = LaunchConfiguration('map')
params_file = LaunchConfiguration('params_file')
autostart = LaunchConfiguration('autostart')
Expand All @@ -61,12 +60,6 @@ def generate_launch_description():
'namespace', default_value='', description='Top-level namespace'
)

declare_use_namespace_cmd = DeclareLaunchArgument(
'use_namespace',
default_value='false',
description='Whether to apply a namespace to the navigation stack',
)

declare_map_yaml_cmd = DeclareLaunchArgument(
'map',
default_value=os.path.join(bringup_dir, 'maps', 'tb3_sandbox.yaml'),
Expand Down Expand Up @@ -134,7 +127,6 @@ def generate_launch_description():
condition=IfCondition(use_rviz),
launch_arguments={
'namespace': namespace,
'use_namespace': use_namespace,
'use_sim_time': 'True',
'rviz_config': rviz_config_file,
}.items(),
Expand All @@ -144,7 +136,6 @@ def generate_launch_description():
PythonLaunchDescriptionSource(os.path.join(launch_dir, 'bringup_launch.py')),
launch_arguments={
'namespace': namespace,
'use_namespace': use_namespace,
'map': map_yaml_file,
'use_sim_time': 'True',
'params_file': params_file,
Expand Down Expand Up @@ -203,7 +194,6 @@ def generate_launch_description():

# Declare the launch options
ld.add_action(declare_namespace_cmd)
ld.add_action(declare_use_namespace_cmd)
ld.add_action(declare_map_yaml_cmd)
ld.add_action(declare_params_file_cmd)
ld.add_action(declare_autostart_cmd)
Expand Down
10 changes: 0 additions & 10 deletions nav2_bringup/launch/tb3_simulation_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def generate_launch_description():
# Create the launch configuration variables
slam = LaunchConfiguration('slam')
namespace = LaunchConfiguration('namespace')
use_namespace = LaunchConfiguration('use_namespace')
map_yaml_file = LaunchConfiguration('map')
use_sim_time = LaunchConfiguration('use_sim_time')
params_file = LaunchConfiguration('params_file')
Expand Down Expand Up @@ -77,12 +76,6 @@ def generate_launch_description():
'namespace', default_value='', description='Top-level namespace'
)

declare_use_namespace_cmd = DeclareLaunchArgument(
'use_namespace',
default_value='false',
description='Whether to apply a namespace to the navigation stack',
)

declare_slam_cmd = DeclareLaunchArgument(
'slam', default_value='False', description='Whether run a SLAM'
)
Expand Down Expand Up @@ -186,7 +179,6 @@ def generate_launch_description():
condition=IfCondition(use_rviz),
launch_arguments={
'namespace': namespace,
'use_namespace': use_namespace,
'use_sim_time': use_sim_time,
'rviz_config': rviz_config_file,
}.items(),
Expand All @@ -196,7 +188,6 @@ def generate_launch_description():
PythonLaunchDescriptionSource(os.path.join(launch_dir, 'bringup_launch.py')),
launch_arguments={
'namespace': namespace,
'use_namespace': use_namespace,
'slam': slam,
'map': map_yaml_file,
'use_sim_time': use_sim_time,
Expand Down Expand Up @@ -255,7 +246,6 @@ def generate_launch_description():

# Declare the launch options
ld.add_action(declare_namespace_cmd)
ld.add_action(declare_use_namespace_cmd)
ld.add_action(declare_slam_cmd)
ld.add_action(declare_map_yaml_cmd)
ld.add_action(declare_use_sim_time_cmd)
Expand Down
10 changes: 0 additions & 10 deletions nav2_bringup/launch/tb4_loopback_simulation.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def generate_launch_description():

# Create the launch configuration variables
namespace = LaunchConfiguration('namespace')
use_namespace = LaunchConfiguration('use_namespace')
map_yaml_file = LaunchConfiguration('map')
params_file = LaunchConfiguration('params_file')
autostart = LaunchConfiguration('autostart')
Expand All @@ -61,12 +60,6 @@ def generate_launch_description():
'namespace', default_value='', description='Top-level namespace'
)

declare_use_namespace_cmd = DeclareLaunchArgument(
'use_namespace',
default_value='false',
description='Whether to apply a namespace to the navigation stack',
)

declare_map_yaml_cmd = DeclareLaunchArgument(
'map',
default_value=os.path.join(bringup_dir, 'maps', 'depot.yaml'), # Try warehouse.yaml!
Expand Down Expand Up @@ -132,7 +125,6 @@ def generate_launch_description():
condition=IfCondition(use_rviz),
launch_arguments={
'namespace': namespace,
'use_namespace': use_namespace,
'use_sim_time': 'True',
'rviz_config': rviz_config_file,
}.items(),
Expand All @@ -142,7 +134,6 @@ def generate_launch_description():
PythonLaunchDescriptionSource(os.path.join(launch_dir, 'bringup_launch.py')),
launch_arguments={
'namespace': namespace,
'use_namespace': use_namespace,
'map': map_yaml_file,
'use_sim_time': 'True',
'params_file': params_file,
Expand Down Expand Up @@ -210,7 +201,6 @@ def generate_launch_description():

# Declare the launch options
ld.add_action(declare_namespace_cmd)
ld.add_action(declare_use_namespace_cmd)
ld.add_action(declare_map_yaml_cmd)
ld.add_action(declare_params_file_cmd)
ld.add_action(declare_autostart_cmd)
Expand Down
10 changes: 0 additions & 10 deletions nav2_bringup/launch/tb4_simulation_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def generate_launch_description():
# Create the launch configuration variables
slam = LaunchConfiguration('slam')
namespace = LaunchConfiguration('namespace')
use_namespace = LaunchConfiguration('use_namespace')
map_yaml_file = LaunchConfiguration('map')
use_sim_time = LaunchConfiguration('use_sim_time')
params_file = LaunchConfiguration('params_file')
Expand Down Expand Up @@ -81,12 +80,6 @@ def generate_launch_description():
'namespace', default_value='', description='Top-level namespace'
)

declare_use_namespace_cmd = DeclareLaunchArgument(
'use_namespace',
default_value='false',
description='Whether to apply a namespace to the navigation stack',
)

declare_slam_cmd = DeclareLaunchArgument(
'slam', default_value='False', description='Whether run a SLAM'
)
Expand Down Expand Up @@ -187,7 +180,6 @@ def generate_launch_description():
condition=IfCondition(use_rviz),
launch_arguments={
'namespace': namespace,
'use_namespace': use_namespace,
'use_sim_time': use_sim_time,
'rviz_config': rviz_config_file,
}.items(),
Expand All @@ -197,7 +189,6 @@ def generate_launch_description():
PythonLaunchDescriptionSource(os.path.join(launch_dir, 'bringup_launch.py')),
launch_arguments={
'namespace': namespace,
'use_namespace': use_namespace,
'slam': slam,
'map': map_yaml_file,
'use_sim_time': use_sim_time,
Expand Down Expand Up @@ -261,7 +252,6 @@ def generate_launch_description():

# Declare the launch options
ld.add_action(declare_namespace_cmd)
ld.add_action(declare_use_namespace_cmd)
ld.add_action(declare_slam_cmd)
ld.add_action(declare_map_yaml_cmd)
ld.add_action(declare_use_sim_time_cmd)
Expand Down
Loading
Loading