Nav2极简笔记01-安装与试用

举报
zhangrelay 发表于 2021/08/25 23:22:40 2021/08/25
【摘要】 安装 功能包: ros-foxy-navigation2ros-foxy-nav2-bringupros-foxy-turtlebot3* 推荐使用新立得,例如nav2的地图服务器: 图形化安装适合初学者入门!   选择需要的包下载安装即可。 源码编译: github中navigation2,按照官网流程说明...

安装

功能包:

  • ros-foxy-navigation2
  • ros-foxy-nav2-bringup
  • ros-foxy-turtlebot3*

推荐使用新立得,例如nav2的地图服务器:

图形化安装适合初学者入门!

 

选择需要的包下载安装即可。

源码编译:

github中navigation2,按照官网流程说明配置安装,文档更新较快,为避免误导,不再赘述。


  
  1. ros@ros:~/RobCode/navigation2$ colcon build
  2. Starting >>> nav2_common
  3. Starting >>> nav_2d_msgs
  4. Starting >>> nav2_gazebo_spawner
  5. Finished <<< nav2_common [0.68s]
  6. Starting >>> nav2_msgs
  7. Starting >>> nav2_voxel_grid
  8. Finished <<< nav2_gazebo_spawner [0.72s]
  9. Finished <<< nav_2d_msgs [14.3s]
  10. Starting >>> dwb_msgs
  11. Finished <<< nav2_voxel_grid [33.6s]
  12. Finished <<< dwb_msgs [29.2s]
  13. Finished <<< nav2_msgs [53.0s]
  14. Starting >>> nav2_util
  15. [Processing: nav2_util]
  16. Finished <<< nav2_util [34.1s]
  17. Starting >>> nav_2d_utils
  18. Starting >>> nav2_behavior_tree
  19. Starting >>> nav2_lifecycle_manager
  20. Starting >>> nav2_map_server
  21. Starting >>> nav2_amcl
  22. Starting >>> nav2_waypoint_follower
  23. Finished <<< nav_2d_utils [19.4s]
  24. Finished <<< nav2_waypoint_follower [30.0s]
  25. Finished <<< nav2_lifecycle_manager [33.4s]
  26. Starting >>> nav2_rviz_plugins
  27. Finished <<< nav2_map_server [1min 1s]
  28. Starting >>> nav2_costmap_2d
  29. Finished <<< nav2_amcl [1min 7s]
  30. Finished <<< nav2_rviz_plugins [58.3s]
  31. [Processing: nav2_behavior_tree, nav2_costmap_2d]
  32. [Processing: nav2_behavior_tree, nav2_costmap_2d]
  33. Finished <<< nav2_behavior_tree [2min 58s]
  34. Starting >>> nav2_bt_navigator
  35. Finished <<< nav2_costmap_2d [2min 21s]
  36. Starting >>> nav2_core
  37. Starting >>> costmap_queue
  38. Finished <<< nav2_core [4.58s]
  39. Starting >>> dwb_core
  40. Starting >>> nav2_controller
  41. Starting >>> nav2_navfn_planner
  42. Starting >>> nav2_planner
  43. Starting >>> nav2_recoveries
  44. Starting >>> nav2_regulated_pure_pursuit_controller
  45. Finished <<< nav2_bt_navigator [51.2s]
  46. Starting >>> smac_planner
  47. Finished <<< costmap_queue [45.9s]
  48. Finished <<< nav2_navfn_planner [57.8s]
  49. Finished <<< dwb_core [57.9s]
  50. Starting >>> dwb_critics
  51. Starting >>> dwb_plugins
  52. Finished <<< nav2_planner [1min 15s]
  53. Finished <<< nav2_regulated_pure_pursuit_controller [1min 17s]
  54. [Processing: dwb_critics, dwb_plugins, nav2_controller, nav2_recoveries, smac_planner]
  55. Finished <<< dwb_plugins [54.7s]
  56. Finished <<< nav2_controller [2min 4s]
  57. Finished <<< dwb_critics [1min 8s]
  58. Starting >>> nav2_dwb_controller
  59. Finished <<< nav2_dwb_controller [2.32s]
  60. Finished <<< nav2_recoveries [2min 14s]
  61. Finished <<< smac_planner [2min 17s]
  62. Starting >>> navigation2
  63. Finished <<< navigation2 [1.05s]
  64. Starting >>> nav2_bringup
  65. Finished <<< nav2_bringup [1.19s]
  66. Starting >>> nav2_system_tests
  67. [Processing: nav2_system_tests]
  68. [Processing: nav2_system_tests]
  69. [Processing: nav2_system_tests]
  70. Finished <<< nav2_system_tests [1min 58s]
  71. Summary: 31 packages finished [9min 34s]
  72. ros@ros:~/RobCode/navigation2$

示例

测试安装后,是否能够正常使用(ros2-foxy为例)。

功能包


  
  1. source /opt/ros/foxy/setup.bash
  2. export TURTLEBOT3_MODEL=waffle
  3. export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:/opt/ros/foxy/share/turtlebot3_gazebo/models

路径依据实际情况,稍有不同。

源码编译

source /home/ros/RobCode/navigation2/install/setup.bash 

 

运行

ros2 launch nav2_bringup tb3_simulation_launch.py
 

设置初始位置(2D Pose Estimate):

 

在rviz2中加入机器人模型(RobotModel),调整TF大小:

 

使用目标(Navigation2 Goal)设置终点,看效果如何?

 

 

定位思考:

 

 

如何提高定位精度呢?


tb3_simulation_launch.py(Intel)


  
  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. """This is all-in-one launch script intended for use by nav2 developers."""
  15. import os
  16. from ament_index_python.packages import get_package_share_directory
  17. from launch import LaunchDescription
  18. from launch.actions import DeclareLaunchArgument, ExecuteProcess, IncludeLaunchDescription
  19. from launch.conditions import IfCondition
  20. from launch.launch_description_sources import PythonLaunchDescriptionSource
  21. from launch.substitutions import LaunchConfiguration, PythonExpression
  22. from launch_ros.actions import Node
  23. def generate_launch_description():
  24. # Get the launch directory
  25. bringup_dir = get_package_share_directory('nav2_bringup')
  26. launch_dir = os.path.join(bringup_dir, 'launch')
  27. # Create the launch configuration variables
  28. slam = LaunchConfiguration('slam')
  29. namespace = LaunchConfiguration('namespace')
  30. use_namespace = LaunchConfiguration('use_namespace')
  31. map_yaml_file = LaunchConfiguration('map')
  32. use_sim_time = LaunchConfiguration('use_sim_time')
  33. params_file = LaunchConfiguration('params_file')
  34. default_bt_xml_filename = LaunchConfiguration('default_bt_xml_filename')
  35. autostart = LaunchConfiguration('autostart')
  36. # Launch configuration variables specific to simulation
  37. rviz_config_file = LaunchConfiguration('rviz_config_file')
  38. use_simulator = LaunchConfiguration('use_simulator')
  39. use_robot_state_pub = LaunchConfiguration('use_robot_state_pub')
  40. use_rviz = LaunchConfiguration('use_rviz')
  41. headless = LaunchConfiguration('headless')
  42. world = LaunchConfiguration('world')
  43. # Map fully qualified names to relative ones so the node's namespace can be prepended.
  44. # In case of the transforms (tf), currently, there doesn't seem to be a better alternative
  45. # https://github.com/ros/geometry2/issues/32
  46. # https://github.com/ros/robot_state_publisher/pull/30
  47. # TODO(orduno) Substitute with `PushNodeRemapping`
  48. # https://github.com/ros2/launch_ros/issues/56
  49. remappings = [('/tf', 'tf'),
  50. ('/tf_static', 'tf_static')]
  51. # Declare the launch arguments
  52. declare_namespace_cmd = DeclareLaunchArgument(
  53. 'namespace',
  54. default_value='',
  55. description='Top-level namespace')
  56. declare_use_namespace_cmd = DeclareLaunchArgument(
  57. 'use_namespace',
  58. default_value='false',
  59. description='Whether to apply a namespace to the navigation stack')
  60. declare_slam_cmd = DeclareLaunchArgument(
  61. 'slam',
  62. default_value='False',
  63. description='Whether run a SLAM')
  64. declare_map_yaml_cmd = DeclareLaunchArgument(
  65. 'map',
  66. default_value=os.path.join(bringup_dir, 'maps', 'turtlebot3_world.yaml'),
  67. description='Full path to map file to load')
  68. declare_use_sim_time_cmd = DeclareLaunchArgument(
  69. 'use_sim_time',
  70. default_value='true',
  71. description='Use simulation (Gazebo) clock if true')
  72. declare_params_file_cmd = DeclareLaunchArgument(
  73. 'params_file',
  74. default_value=os.path.join(bringup_dir, 'params', 'nav2_params.yaml'),
  75. description='Full path to the ROS2 parameters file to use for all launched nodes')
  76. declare_bt_xml_cmd = DeclareLaunchArgument(
  77. 'default_bt_xml_filename',
  78. default_value=os.path.join(
  79. get_package_share_directory('nav2_bt_navigator'),
  80. 'behavior_trees', 'navigate_w_replanning_and_recovery.xml'),
  81. description='Full path to the behavior tree xml file to use')
  82. declare_autostart_cmd = DeclareLaunchArgument(
  83. 'autostart', default_value='true',
  84. description='Automatically startup the nav2 stack')
  85. declare_rviz_config_file_cmd = DeclareLaunchArgument(
  86. 'rviz_config_file',
  87. default_value=os.path.join(bringup_dir, 'rviz', 'nav2_default_view.rviz'),
  88. description='Full path to the RVIZ config file to use')
  89. declare_use_simulator_cmd = DeclareLaunchArgument(
  90. 'use_simulator',
  91. default_value='True',
  92. description='Whether to start the simulator')
  93. declare_use_robot_state_pub_cmd = DeclareLaunchArgument(
  94. 'use_robot_state_pub',
  95. default_value='True',
  96. description='Whether to start the robot state publisher')
  97. declare_use_rviz_cmd = DeclareLaunchArgument(
  98. 'use_rviz',
  99. default_value='True',
  100. description='Whether to start RVIZ')
  101. declare_simulator_cmd = DeclareLaunchArgument(
  102. 'headless',
  103. default_value='False',
  104. description='Whether to execute gzclient)')
  105. declare_world_cmd = DeclareLaunchArgument(
  106. 'world',
  107. # TODO(orduno) Switch back once ROS argument passing has been fixed upstream
  108. # https://github.com/ROBOTIS-GIT/turtlebot3_simulations/issues/91
  109. # default_value=os.path.join(get_package_share_directory('turtlebot3_gazebo'),
  110. # 'worlds/turtlebot3_worlds/waffle.model'),
  111. default_value=os.path.join(bringup_dir, 'worlds', 'waffle.model'),
  112. description='Full path to world model file to load')
  113. # Specify the actions
  114. start_gazebo_server_cmd = ExecuteProcess(
  115. condition=IfCondition(use_simulator),
  116. cmd=['gzserver', '-s', 'libgazebo_ros_init.so', world],
  117. cwd=[launch_dir], output='screen')
  118. start_gazebo_client_cmd = ExecuteProcess(
  119. condition=IfCondition(PythonExpression([use_simulator, ' and not ', headless])),
  120. cmd=['gzclient'],
  121. cwd=[launch_dir], output='screen')
  122. urdf = os.path.join(bringup_dir, 'urdf', 'turtlebot3_waffle.urdf')
  123. start_robot_state_publisher_cmd = Node(
  124. condition=IfCondition(use_robot_state_pub),
  125. package='robot_state_publisher',
  126. executable='robot_state_publisher',
  127. name='robot_state_publisher',
  128. namespace=namespace,
  129. output='screen',
  130. parameters=[{'use_sim_time': use_sim_time}],
  131. remappings=remappings,
  132. arguments=[urdf])
  133. rviz_cmd = IncludeLaunchDescription(
  134. PythonLaunchDescriptionSource(os.path.join(launch_dir, 'rviz_launch.py')),
  135. condition=IfCondition(use_rviz),
  136. launch_arguments={'namespace': '',
  137. 'use_namespace': 'False',
  138. 'rviz_config': rviz_config_file}.items())
  139. bringup_cmd = IncludeLaunchDescription(
  140. PythonLaunchDescriptionSource(os.path.join(launch_dir, 'bringup_launch.py')),
  141. launch_arguments={'namespace': namespace,
  142. 'use_namespace': use_namespace,
  143. 'slam': slam,
  144. 'map': map_yaml_file,
  145. 'use_sim_time': use_sim_time,
  146. 'params_file': params_file,
  147. 'default_bt_xml_filename': default_bt_xml_filename,
  148. 'autostart': autostart}.items())
  149. # Create the launch description and populate
  150. ld = LaunchDescription()
  151. # Declare the launch options
  152. ld.add_action(declare_namespace_cmd)
  153. ld.add_action(declare_use_namespace_cmd)
  154. ld.add_action(declare_slam_cmd)
  155. ld.add_action(declare_map_yaml_cmd)
  156. ld.add_action(declare_use_sim_time_cmd)
  157. ld.add_action(declare_params_file_cmd)
  158. ld.add_action(declare_bt_xml_cmd)
  159. ld.add_action(declare_autostart_cmd)
  160. ld.add_action(declare_rviz_config_file_cmd)
  161. ld.add_action(declare_use_simulator_cmd)
  162. ld.add_action(declare_use_robot_state_pub_cmd)
  163. ld.add_action(declare_use_rviz_cmd)
  164. ld.add_action(declare_simulator_cmd)
  165. ld.add_action(declare_world_cmd)
  166. # Add any conditioned actions
  167. ld.add_action(start_gazebo_server_cmd)
  168. ld.add_action(start_gazebo_client_cmd)
  169. # Add the actions to launch all of the navigation nodes
  170. ld.add_action(start_robot_state_publisher_cmd)
  171. ld.add_action(rviz_cmd)
  172. ld.add_action(bringup_cmd)
  173. return ld

文章来源: zhangrelay.blog.csdn.net,作者:zhangrelay,版权归原作者所有,如需转载,请联系作者。

原文链接:zhangrelay.blog.csdn.net/article/details/119899279

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。