{"id":320,"date":"2025-04-18T00:41:17","date_gmt":"2025-04-17T16:41:17","guid":{"rendered":"http:\/\/cennum.top\/?p=320"},"modified":"2025-06-04T23:30:09","modified_gmt":"2025-06-04T15:30:09","slug":"nav2_bringup","status":"publish","type":"post","link":"https:\/\/cennum.top\/index.php\/2025\/04\/18\/nav2_bringup\/","title":{"rendered":"nav2\u5b98\u65b9bringup\u542f\u52a8"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">1.\u521b\u5efapy\u529f\u80fd\u5305<\/h4>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">2.\u5728\u8be5\u529f\u80fd\u5305\u4e0b\u521b\u5efalaunch\u6587\u4ef6\u5939<\/h4>\n\n\n\n<p>\u521b\u5efa\u4e00\u4e2astart_nav2.launch.py\u6587\u4ef6<\/p>\n\n\n\n<p>\u5199\u5165\u4ee5\u4e0b\u5185\u5bb9\uff0c<\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-8-background-color has-background\"><code>import os\nimport launch\nimport launch_ros\nfrom ament_index_python.packages import get_package_share_directory\nfrom launch.launch_description_sources import PythonLaunchDescriptionSource\n\n\ndef generate_launch_description():\n    # \u83b7\u53d6\u4e0e\u62fc\u63a5\u9ed8\u8ba4\u8def\u5f84\n    cyberdog_nav2_dir = get_package_share_directory(\n        'cyberdog_nav2')\n    nav2_bringup_dir = get_package_share_directory('nav2_bringup')\n    rviz_config_dir = os.path.join(\n        nav2_bringup_dir, 'rviz', 'nav2_default_view.rviz')\n    \n    # \u521b\u5efa Launch \u914d\u7f6e\n    use_sim_time = launch.substitutions.LaunchConfiguration(\n        'use_sim_time', default='true')\n    map_yaml_path = launch.substitutions.LaunchConfiguration(\n        'map', default=os.path.join(cyberdog_nav2_dir, 'maps', 'map1.yaml'))\n    nav2_param_path = launch.substitutions.LaunchConfiguration(\n        'params_file', default=os.path.join(cyberdog_nav2_dir, 'config', 'nav2_params.yaml'))\n\n    return launch.LaunchDescription(&#91;\n        # \u58f0\u660e\u65b0\u7684 Launch \u53c2\u6570\n        launch.actions.DeclareLaunchArgument('use_sim_time', default_value=use_sim_time,\n                                             description='Use simulation (Gazebo) clock if true'),\n        launch.actions.DeclareLaunchArgument('map', default_value=map_yaml_path,\n                                             description='Full path to map file to load'),\n        launch.actions.DeclareLaunchArgument('params_file', default_value=nav2_param_path,\n                                             description='Full path to param file to load'),\n\n        launch.actions.IncludeLaunchDescription(\n            PythonLaunchDescriptionSource(\n                &#91;nav2_bringup_dir, '\/launch', '\/bringup_launch.py']),\n            # \u4f7f\u7528 Launch \u53c2\u6570\u66ff\u6362\u539f\u6709\u53c2\u6570\n            launch_arguments={\n                'map': map_yaml_path,\n                'use_sim_time': use_sim_time,\n                'params_file': nav2_param_path}.items(),\n        ),\n        launch_ros.actions.Node(\n            package='rviz2',\n            executable='rviz2',\n            name='rviz2',\n            arguments=&#91;'-d', rviz_config_dir],\n            parameters=&#91;{'use_sim_time': use_sim_time}],\n            output='screen'),\n    ])\n<\/code><\/pre>\n\n\n\n<p>\u6ce8\u610f\u4fee\u6539\u8def\u5f84\uff0c\u6587\u4ef6\u540d\u7b49\u4f60\u81ea\u5b9a\u4e49\u7684\u4e1c\u897f<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">3.\u5728\u529f\u80fd\u5305\u4e0b\u521b\u5efamaps\u6587\u4ef6\u5939\u7528\u4e8e\u5b58\u653e\u5730\u56fe\u7684.pgm\u548c.yaml\u6587\u4ef6<\/h4>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">4.\u5728\u529f\u80fd\u5305\u4e0b\u521b\u5efaconfig\u6587\u4ef6\u5939<\/h4>\n\n\n\n<p>\u7528\u4e8e\u5b58\u653enav2\u5b98\u65b9nav2_params.yaml\uff0c\u4fbf\u4e8e\u4fee\u6539\uff0c\u8be5\u6587\u4ef6\u8bf7\u524d\u5f80nav2\u5b98\u65b9github\u590d\u5236<\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-8-background-color has-background\"><code>https:&#47;&#47;github.com\/ros-navigation\/navigation2\/blob\/main\/nav2_bringup\/params\/nav2_params.yaml<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">5.\u4fee\u6539setup.py<\/h4>\n\n\n\n<p>\u4fee\u6539setup.py\uff0c\u5c06\u529f\u80fd\u5305\u4e0b\u7684launch\u6587\u4ef6\u5939\uff0cmaps\u6587\u4ef6\u5939\uff0cconfig\u6587\u4ef6\u5939\u590d\u5236\u5230\u5de5\u4f5c\u7a7a\u95f4\/install\/share\u76ee\u5f55\u4e0b<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">6.\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u673a\u5668\u4eba\u4fee\u6539nav2_params.yaml\u4e2d\u7684\u5185\u5bb9<\/h4>\n\n\n\n<p>nav2_params.yaml\u4e2d\u53ef\u4ee5\u5f88\u65b9\u4fbf\u4fee\u6539bringup\u4e2d\u7684\u6240\u6709\u53c2\u6570\uff0c\u901a\u8fc7start_nav2.launch.py\u6765\u628anav2_params.yaml\u4f20\u9012\u7ed9bringup<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1.\u521b\u5efapy\u529f\u80fd\u5305 2.\u5728\u8be5\u529f\u80fd\u5305\u4e0b\u521b\u5efalaunc &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,30],"tags":[],"class_list":["post-320","post","type-post","status-publish","format-standard","hentry","category-linux","category-ros2"],"_links":{"self":[{"href":"https:\/\/cennum.top\/index.php\/wp-json\/wp\/v2\/posts\/320","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cennum.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cennum.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cennum.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cennum.top\/index.php\/wp-json\/wp\/v2\/comments?post=320"}],"version-history":[{"count":3,"href":"https:\/\/cennum.top\/index.php\/wp-json\/wp\/v2\/posts\/320\/revisions"}],"predecessor-version":[{"id":517,"href":"https:\/\/cennum.top\/index.php\/wp-json\/wp\/v2\/posts\/320\/revisions\/517"}],"wp:attachment":[{"href":"https:\/\/cennum.top\/index.php\/wp-json\/wp\/v2\/media?parent=320"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cennum.top\/index.php\/wp-json\/wp\/v2\/categories?post=320"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cennum.top\/index.php\/wp-json\/wp\/v2\/tags?post=320"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}