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

Use opaque function to allow for remapping of scan topics #293

Merged
merged 2 commits into from
Nov 1, 2023
Merged
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
64 changes: 40 additions & 24 deletions turtlebot4_navigation/launch/nav2.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,52 +18,68 @@
from ament_index_python.packages import get_package_share_directory

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, GroupAction, IncludeLaunchDescription
from launch.actions import (
DeclareLaunchArgument,
GroupAction,
IncludeLaunchDescription,
OpaqueFunction
)
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import LaunchConfiguration, PathJoinSubstitution

from launch_ros.actions import PushRosNamespace
from launch_ros.actions import PushRosNamespace, SetRemap


ARGUMENTS = [
DeclareLaunchArgument('use_sim_time', default_value='false',
choices=['true', 'false'],
description='Use sim time'),
DeclareLaunchArgument('params_file',
default_value=PathJoinSubstitution([
get_package_share_directory('turtlebot4_navigation'),
'config',
'nav2.yaml'
]),
description='Nav2 parameters'),
DeclareLaunchArgument('namespace', default_value='',
description='Robot namespace')
]


def generate_launch_description():
pkg_turtlebot4_navigation = get_package_share_directory('turtlebot4_navigation')
def launch_setup(context, *args, **kwargs):
pkg_nav2_bringup = get_package_share_directory('nav2_bringup')

nav2_params_arg = DeclareLaunchArgument(
'params_file',
default_value=PathJoinSubstitution(
[pkg_turtlebot4_navigation, 'config', 'nav2.yaml']),
description='Nav2 parameters')

namespace_arg = DeclareLaunchArgument(
'namespace',
default_value='',
description='Robot namespace')

nav2_params = LaunchConfiguration('params_file')
namespace = LaunchConfiguration('namespace')
use_sim_time = LaunchConfiguration('use_sim_time')

namespace_str = namespace.perform(context)
if (namespace_str and not namespace_str.startswith('/')):
namespace_str = '/' + namespace_str

launch_nav2 = PathJoinSubstitution(
[pkg_nav2_bringup, 'launch', 'navigation_launch.py'])

nav2 = GroupAction([
PushRosNamespace(namespace),
SetRemap(namespace_str + '/global_costmap/scan', namespace_str + '/scan'),
SetRemap(namespace_str + '/local_costmap/scan', namespace_str + '/scan'),

IncludeLaunchDescription(
PythonLaunchDescriptionSource(
PathJoinSubstitution(
[pkg_nav2_bringup, 'launch', 'navigation_launch.py'])),
launch_arguments={'use_sim_time': use_sim_time,
'use_composition': 'False',
'params_file': LaunchConfiguration('params_file')}.items()),
PythonLaunchDescriptionSource(launch_nav2),
launch_arguments=[
('use_sim_time', use_sim_time),
('params_file', nav2_params.perform(context)),
('use_composition', 'False'),
('namespace', namespace_str)
]
),
])

return [nav2]


def generate_launch_description():
ld = LaunchDescription(ARGUMENTS)
ld.add_action(nav2_params_arg)
ld.add_action(namespace_arg)
ld.add_action(nav2)
ld.add_action(OpaqueFunction(function=launch_setup))
return ld
Loading