Advertisement
Guest User

navigation_launch.py

a guest
Jul 30th, 2023
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.66 KB | None | 0 0
  1. # Copyright (c) 2018 Intel Corporation
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14.  
  15. import os
  16.  
  17. from ament_index_python.packages import get_package_share_directory
  18.  
  19. from launch import LaunchDescription
  20. from launch.actions import DeclareLaunchArgument, SetEnvironmentVariable
  21. from launch.substitutions import LaunchConfiguration
  22. from launch_ros.actions import Node
  23. from nav2_common.launch import RewrittenYaml
  24.  
  25.  
  26. def generate_launch_description():
  27. # Get the launch directory
  28. bringup_dir = get_package_share_directory('nav2_bringup')
  29.  
  30. namespace = LaunchConfiguration('namespace')
  31. use_sim_time = LaunchConfiguration('use_sim_time')
  32. autostart = LaunchConfiguration('autostart')
  33. params_file = LaunchConfiguration('params_file')
  34.  
  35. lifecycle_nodes = ['controller_server',
  36. 'planner_server',
  37. 'recoveries_server',
  38. 'bt_navigator',
  39. 'waypoint_follower']
  40.  
  41. # Map fully qualified names to relative ones so the node's namespace can be prepended.
  42. # In case of the transforms (tf), currently, there doesn't seem to be a better alternative
  43. # https://github.com/ros/geometry2/issues/32
  44. # https://github.com/ros/robot_state_publisher/pull/30
  45. # TODO(orduno) Substitute with `PushNodeRemapping`
  46. # https://github.com/ros2/launch_ros/issues/56
  47. remappings = [('/tf', 'tf'),
  48. ('/tf_static', 'tf_static')]
  49.  
  50. # Create our own temporary YAML files that include substitutions
  51. param_substitutions = {
  52. 'use_sim_time': use_sim_time,
  53. 'autostart': autostart}
  54.  
  55. configured_params = RewrittenYaml(
  56. source_file=params_file,
  57. root_key=namespace,
  58. param_rewrites=param_substitutions,
  59. convert_types=True)
  60.  
  61. return LaunchDescription([
  62. # Set env var to print messages to stdout immediately
  63. SetEnvironmentVariable('RCUTILS_LOGGING_BUFFERED_STREAM', '1'),
  64.  
  65. DeclareLaunchArgument(
  66. 'namespace', default_value='',
  67. description='Top-level namespace'),
  68.  
  69. DeclareLaunchArgument(
  70. 'use_sim_time', default_value='true',
  71. description='Use simulation (Gazebo) clock if true'),
  72.  
  73. DeclareLaunchArgument(
  74. 'autostart', default_value='true',
  75. description='Automatically startup the nav2 stack'),
  76.  
  77. DeclareLaunchArgument(
  78. 'params_file',
  79. default_value=os.path.join(bringup_dir, 'params', 'truck_nav2_params.yaml'),
  80. description='Full path to the ROS2 parameters file to use'),
  81.  
  82. Node(
  83. package='nav2_controller',
  84. executable='controller_server',
  85. output='screen',
  86. parameters=[configured_params],
  87. remappings=remappings),
  88.  
  89. Node(
  90. package='nav2_planner',
  91. executable='planner_server',
  92. name='planner_server',
  93. output='screen',
  94. parameters=[configured_params],
  95. remappings=remappings),
  96.  
  97. Node(
  98. package='nav2_recoveries',
  99. executable='recoveries_server',
  100. name='recoveries_server',
  101. output='screen',
  102. parameters=[configured_params],
  103. remappings=remappings),
  104.  
  105. Node(
  106. package='nav2_bt_navigator',
  107. executable='bt_navigator',
  108. name='bt_navigator',
  109. output='screen',
  110. parameters=[configured_params],
  111. remappings=remappings),
  112.  
  113. Node(
  114. package='nav2_waypoint_follower',
  115. executable='waypoint_follower',
  116. name='waypoint_follower',
  117. output='screen',
  118. parameters=[configured_params],
  119. remappings=remappings),
  120.  
  121. Node(
  122. package='nav2_lifecycle_manager',
  123. executable='lifecycle_manager',
  124. name='lifecycle_manager_navigation',
  125. output='screen',
  126. parameters=[{'use_sim_time': use_sim_time},
  127. {'autostart': autostart},
  128. {'node_names': lifecycle_nodes}]),
  129.  
  130. ])
  131.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement