1818from ament_index_python .packages import get_package_share_directory
1919
2020from launch import LaunchDescription
21- from launch .actions import DeclareLaunchArgument , GroupAction
21+ from launch .actions import DeclareLaunchArgument , GroupAction , OpaqueFunction
2222from launch .substitutions import LaunchConfiguration , PathJoinSubstitution
23- from launch_ros .actions import ComposableNodeContainer , PushRosNamespace
23+ from launch_ros .actions import ComposableNodeContainer , PushRosNamespace , SetRemap
2424from launch_ros .descriptions import ComposableNode
2525
2626from nav2_common .launch import RewrittenYaml
2727
2828
29- def generate_launch_description ():
30- pkg_turtlebot4_bringup = get_package_share_directory ('turtlebot4_bringup' )
31-
32- camera = LaunchConfiguration ('camera' )
33- params_file = LaunchConfiguration ('params_file' )
34- namespace = LaunchConfiguration ('namespace' )
35-
36- ARGUMENTS = [
29+ pkg_turtlebot4_bringup = get_package_share_directory ('turtlebot4_bringup' )
30+ camera = LaunchConfiguration ('camera' )
31+ params_file = LaunchConfiguration ('params_file' )
32+ namespace = LaunchConfiguration ('namespace' )
33+ ARGUMENTS = [
3734 DeclareLaunchArgument ('camera' , default_value = 'oakd_pro' ),
3835 DeclareLaunchArgument ('params_file' ,
3936 default_value = [PathJoinSubstitution (
@@ -42,13 +39,23 @@ def generate_launch_description():
4239 description = 'Robot namespace' )
4340 ]
4441
42+
43+ def launch_setup (context , * args , ** kwargs ):
44+ namespace_str = namespace .perform (context )
45+ if (namespace_str and not namespace_str .startswith ('/' )):
46+ namespace_str = '/' + namespace_str
47+
4548 namespaced_param_file = RewrittenYaml (
4649 source_file = params_file ,
4750 root_key = namespace ,
4851 param_rewrites = {},
49- convert_types = True )
52+ convert_types = True ,
53+ )
5054
51- node = ComposableNodeContainer (
55+ oakd = GroupAction ([
56+ PushRosNamespace (namespace ),
57+ SetRemap ('/diagnostics' , namespace_str + '/diagnostics' ),
58+ ComposableNodeContainer (
5259 name = 'oakd_container' ,
5360 namespace = namespace ,
5461 package = 'rclcpp_components' ,
@@ -63,13 +70,12 @@ def generate_launch_description():
6370 ],
6471 output = 'screen' ,
6572 )
73+ ])
6674
67- actions = [
68- PushRosNamespace (namespace ),
69- node
70- ]
71- oakd = GroupAction (actions )
75+ return [oakd ]
7276
77+
78+ def generate_launch_description ():
7379 ld = LaunchDescription (ARGUMENTS )
74- ld .add_action (oakd )
75- return ld
80+ ld .add_action (OpaqueFunction ( function = launch_setup ) )
81+ return ld
0 commit comments