{"id":154,"date":"2026-04-10T17:41:26","date_gmt":"2026-04-10T09:41:26","guid":{"rendered":"https:\/\/374969782.xyz\/?p=154"},"modified":"2026-04-10T17:41:27","modified_gmt":"2026-04-10T09:41:27","slug":"ros2%e5%ad%a6%e4%b9%a0%e8%ae%b0%e5%bd%95%ef%bc%8810%ef%bc%89-launch","status":"publish","type":"post","link":"https:\/\/374969782.xyz\/index.php\/2026\/04\/10\/ros2%e5%ad%a6%e4%b9%a0%e8%ae%b0%e5%bd%95%ef%bc%8810%ef%bc%89-launch\/","title":{"rendered":"ROS2\u5b66\u4e60\u8bb0\u5f55\uff0810\uff09-launch"},"content":{"rendered":"\n<p><strong>Launch\u542f\u52a8\u6587\u4ef6<\/strong>\u53ef\u4ee5\u4e00\u6b21\u6027\u542f\u52a8\u591a\u4e2a\u8282\u70b9\u6587\u4ef6\uff0c\u662fROS\u7cfb\u7edf\u4e2d\u591a\u8282\u70b9\u542f\u52a8\u4e0e\u914d\u7f6e\u7684\u4e00\u79cd\u811a\u672c\u3002<\/p>\n\n\n\n<p><strong>ROS2\u4e2d\u7684Launch\u6587\u4ef6\u5c31\u662f\u57fa\u4e8ePython\u63cf\u8ff0\u7684<\/strong>\uff0c\u5176\u6838\u5fc3\u76ee\u7684\u662f<strong>\u542f\u52a8\u8282\u70b9<\/strong>\uff0c\u6211\u4eec\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u7684\u5404\u79cd\u53c2\u6570\uff0c\u5728Launch\u6587\u4ef6\u4e2d\uff0c\u901a\u8fc7\u7c7b\u4f3c\u8fd9\u6837\u7684\u5f88\u591a\u4ee3\u7801\u6a21\u7248\uff0c\u4e5f\u53ef\u4ee5\u8fdb\u884c\u914d\u7f6e\uff0c\u751a\u81f3\u8fd8\u53ef\u4ee5\u4f7f\u7528Python\u539f\u6709\u7684\u7f16\u7a0b\u529f\u80fd\uff0c\u5927\u5927\u4e30\u5bcc\u4e86\u542f\u52a8\u8fc7\u7a0b\u4e2d\u7684\u591a\u6837\u5316\u914d\u7f6e\u3002\u5b83\u5c31\u50cf\u7c98\u5408\u5242\u4e00\u6837\uff0c\u53ef\u4ee5\u81ea\u7531\u7ec4\u88c5\u548c\u914d\u7f6e\u5404\u4e2a\u8282\u70b9\u3002<\/p>\n\n\n\n<p>\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u5185\u4f7f\u7528ros2\u4e2d\u7684launch\u547d\u4ee4\u6765\u542f\u52a8\u4e00\u4e2alaunch\u6587\u4ef6\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ros2 launch learning_launch simple.launch.py<\/code><\/pre>\n\n\n\n<p>\u8be5launch\u6587\u4ef6\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from launch import LaunchDescription           # launch\u6587\u4ef6\u7684\u63cf\u8ff0\u7c7b\nfrom launch_ros.actions import Node            # \u8282\u70b9\u542f\u52a8\u7684\u63cf\u8ff0\u7c7b\n\ndef generate_launch_description():             # \u81ea\u52a8\u751f\u6210launch\u6587\u4ef6\u7684\u51fd\u6570\n    return LaunchDescription(&#91;                 # \u8fd4\u56delaunch\u6587\u4ef6\u7684\u63cf\u8ff0\u4fe1\u606f\n        Node(                                  # \u914d\u7f6e\u4e00\u4e2a\u8282\u70b9\u7684\u542f\u52a8\uff0c\u5c31\u662f\u8fd0\u884c\u8fd9\u6837\u4e00\u4e2a\u8282\u70b9\n            package='learning_topic',          # \u8282\u70b9\u6240\u5728\u7684\u529f\u80fd\u5305\n            executable='topic_helloworld_pub', # \u8282\u70b9\u7684\u53ef\u6267\u884c\u6587\u4ef6\n        ),\n        Node(                                  # \u914d\u7f6e\u4e00\u4e2a\u8282\u70b9\u7684\u542f\u52a8\n            package='learning_topic',          # \u8282\u70b9\u6240\u5728\u7684\u529f\u80fd\u5305\n            executable='topic_helloworld_sub', # \u8282\u70b9\u7684\u53ef\u6267\u884c\u6587\u4ef6\u540d\n        ),\n    ])<\/code><\/pre>\n\n\n\n<p>\u6211\u4eec\u4f7f\u7528ros2\u547d\u4ee4\u5728\u7ec8\u7aef\u4e2d\u542f\u52a8\u8282\u70b9\u65f6\uff0c\u8fd8\u53ef\u4ee5\u5728\u547d\u4ee4\u540e\u914d\u7f6e\u4e00\u4e9b\u4f20\u5165\u7a0b\u5e8f\u7684\u53c2\u6570\uff0c\u4f7f\u7528launch\u6587\u4ef6\u4e00\u6837\u53ef\u4ee5\u505a\u5230\u3002<\/p>\n\n\n\n<p>\u4f20\u9012\u5176\u4ed6\u53c2\u6570\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import os\n\nfrom ament_index_python.packages import get_package_share_directory # \u67e5\u8be2\u529f\u80fd\u5305\u8def\u5f84\u7684\u65b9\u6cd5\n\nfrom launch import LaunchDescription    # launch\u6587\u4ef6\u7684\u63cf\u8ff0\u7c7b\nfrom launch_ros.actions import Node     # \u8282\u70b9\u542f\u52a8\u7684\u63cf\u8ff0\u7c7b\n\n\ndef generate_launch_description():      # \u81ea\u52a8\u751f\u6210launch\u6587\u4ef6\u7684\u51fd\u6570\n   rviz_config = os.path.join(          # \u627e\u5230\u914d\u7f6e\u6587\u4ef6\u7684\u5b8c\u6574\u8def\u5f84\n      get_package_share_directory('learning_launch'),\n      'rviz',\n      'turtle_rviz.rviz'\n      )\n\n   return LaunchDescription(&#91;           # \u8fd4\u56delaunch\u6587\u4ef6\u7684\u63cf\u8ff0\u4fe1\u606f\n      Node(                             # \u914d\u7f6e\u4e00\u4e2a\u8282\u70b9\u7684\u542f\u52a8\n         package='rviz2',               # \u8282\u70b9\u6240\u5728\u7684\u529f\u80fd\u5305\n         executable='rviz2',            # \u8282\u70b9\u7684\u53ef\u6267\u884c\u6587\u4ef6\u540d\n         name='rviz2',                  # \u5bf9\u8282\u70b9\u91cd\u65b0\u547d\u540d\uff0c\u4e0d\u7528\u521d\u59cb\u5316\u8282\u70b9\u65f6\u7684\u9ed8\u8ba4\u540d\n                                        # \u4f1a\u66ff\u6362\u6389\u8282\u70b9\u7a0b\u5e8f\u5185\u672c\u8eab\u521d\u59cb\u5316\u8bbe\u5b9a\u7684\u540d\u5b57\n                                     # \u4ee5\u6253\u5f00\u591a\u4e2a\u76f8\u540c\u8282\u70b9\u65f6\u533a\u5206\u540d\u5b57\uff08ros2\u4e0d\u5141\u8bb8\u540c\u540d\u8282\u70b9\uff09\n         arguments=&#91;'-d', rviz_config]  # \u52a0\u8f7d\u547d\u4ee4\u884c\u53c2\u6570\n      )\n   ])\n\n<\/code><\/pre>\n\n\n\n<p>config\u90e8\u5206\u5c31\u662f\u5229\u7528\u4e86python\u4ee3\u7801\u7684\u7279\u6027\uff0c\u914d\u7f6e\u4e86\u5177\u4f53\u53d8\u91cf\u8def\u5f84\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>launch\u8fd8\u53ef\u4ee5\u5b9e\u73b0<strong>\u8d44\u6e90\u91cd\u6620\u5c04<\/strong>\uff0c\u5728\u4f7f\u7528\u522b\u4eba\u4ee3\u7801\u7684\u65f6\u5019\uff0c\u5bf9\u7c7b\u4f3c\u7684\u8d44\u6e90\u91cd\u65b0\u547d\u540d\uff0c\u63d0\u9ad8\u8f6f\u4ef6\u7684\u590d\u7528\u6027\u3002\u5982\u4e0b\uff0c\u65f6\u501f\u52a9turtle\u7684\u4e00\u4e2alaunch\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from launch import LaunchDescription      # launch\u6587\u4ef6\u7684\u63cf\u8ff0\u7c7b\nfrom launch_ros.actions import Node       # \u8282\u70b9\u542f\u52a8\u7684\u63cf\u8ff0\u7c7b\n\ndef generate_launch_description():        # \u81ea\u52a8\u751f\u6210launch\u6587\u4ef6\u7684\u51fd\u6570\n    return LaunchDescription(&#91;            # \u8fd4\u56delaunch\u6587\u4ef6\u7684\u63cf\u8ff0\u4fe1\u606f\n        Node(                             # \u914d\u7f6e\u4e00\u4e2a\u8282\u70b9\u7684\u542f\u52a8\n            package='turtlesim',          # \u8282\u70b9\u6240\u5728\u7684\u529f\u80fd\u5305\n            namespace='turtlesim1',       # \u8282\u70b9\u6240\u5728\u7684\u547d\u540d\u7a7a\u95f4\n            executable='turtlesim_node',  # \u8282\u70b9\u7684\u53ef\u6267\u884c\u6587\u4ef6\u540d\n            name='sim'                    # \u5bf9\u8282\u70b9\u91cd\u65b0\u547d\u540d\n        ),\n        Node(                             # \u914d\u7f6e\u4e00\u4e2a\u8282\u70b9\u7684\u542f\u52a8\n            package='turtlesim',          # \u8282\u70b9\u6240\u5728\u7684\u529f\u80fd\u5305\n            namespace='turtlesim2',       # \u8282\u70b9\u6240\u5728\u7684\u547d\u540d\u7a7a\u95f4\n            executable='turtlesim_node',  # \u8282\u70b9\u7684\u53ef\u6267\u884c\u6587\u4ef6\u540d\n            name='sim'                    # \u5bf9\u8282\u70b9\u91cd\u65b0\u547d\u540d\n        ),\n        Node(                             # \u914d\u7f6e\u4e00\u4e2a\u8282\u70b9\u7684\u542f\u52a8\n            package='turtlesim',          # \u8282\u70b9\u6240\u5728\u7684\u529f\u80fd\u5305\n            executable='mimic',           # \u8282\u70b9\u7684\u53ef\u6267\u884c\u6587\u4ef6\u540d\n            name='mimic',                 # \u5bf9\u8282\u70b9\u91cd\u65b0\u547d\u540d\n            remappings=&#91;                  # \u8d44\u6e90\u91cd\u6620\u5c04\u5217\u8868\n                ('\/input\/pose', '\/turtlesim1\/turtle1\/pose'),         # \u5c06\/input\/pose\u8bdd\u9898\u540d\u4fee\u6539\u4e3a\/turtlesim1\/turtle1\/pose\n                ('\/output\/cmd_vel', '\/turtlesim2\/turtle1\/cmd_vel'),  # \u5c06\/output\/cmd_vel\u8bdd\u9898\u540d\u4fee\u6539\u4e3a\/turtlesim2\/turtle1\/cmd_vel\n            ]\n        )\n    ])\n<\/code><\/pre>\n\n\n\n<p>namespace\u548cc++\u7684\u547d\u540d\u7a7a\u95f4\u7c7b\u4f3c\uff0c\u4f1a\u5728\u8282\u70b9\u7684\u540d\u5b57\u524d\u6dfb\u52a0\u4e00\u4e2a\u7236\u76ee\u5f55\u3002\u6b64\u65f6\u901a\u8fc7<code>ros2 topic list<\/code>\u67e5\u770b\u8bdd\u9898\u53ef\u4ee5\u770b\u5230\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/parameter_events\n\/rosout\n\/turtlesim1\/turtle1\/cmd_vel\n\/turtlesim1\/turtle1\/color_sensor\n\/turtlesim1\/turtle1\/pose\n\/turtlesim2\/turtle1\/cmd_vel\n\/turtlesim2\/turtle1\/color_sensor\n\/turtlesim2\/turtle1\/pose<\/code><\/pre>\n\n\n\n<p>\u4ece\u547d\u540d\u7a7a\u95f4\u89d2\u5ea6\u907f\u514d\u4e86\u8282\u70b9\u91cd\u540d\u95ee\u9898\uff08ros2\u4e0d\u5141\u8bb8\u540c\u540d\u8282\u70b9\u5b58\u5728\uff09\u3002<\/p>\n\n\n\n<p>mimic\u8282\u70b9\u7684\u4f5c\u7528\u662f\u5b9e\u73b0\u4e00\u4e2a\u6d77\u9f9f\u7684\u4f4d\u7f6e\u53d8\u6210\u53e6\u4e00\u4e2a\u6d77\u9f9f\u7684\u6307\u4ee4\uff0c\u672c\u8eab\u8ba2\u9605\u8bdd\u9898<code>\/input\/pose<\/code>\u5e76\u63a5\u6536\u53d7\u4e00\u4e2a\u6d77\u9f9f\u8fd0\u52a8\u540e\u7684\u4f4d\u7f6e\u53c2\u6570\uff0c\u7136\u540e\u518d\u5c06\u8fd9\u4e9b\u53c2\u6570\u53d1\u5e03\u5230\u8bdd\u9898<code>\/output\/cmd_vel<\/code>\u3002remappings\u53c2\u6570\u5219\u662f\u5bf9\u8d44\u6e90\u7684\u91cd\u6620\u5c04\uff0c\u5c06\u539f\u672c\u8ba2\u9605\u7684\u8bdd\u9898\u548c\u53d1\u5e03\u7684\u8bdd\u9898\u5730\u5740\u90fd\u91cd\u5b9a\u5411\u4e86\u3002\u4e8e\u662f\u5b9e\u73b0\u4e86\uff0c\u7528turtlesim1\u547d\u540d\u7a7a\u95f4\u5185\u7684\u6d77\u9f9f\u4f4d\u7f6e\u63a7\u5236turtlesim2\u547d\u540d\u7a7a\u95f4\u5185\u7684\u6d77\u9f9f\u4f4d\u7f6e\u3002<\/p>\n\n\n\n<p>\u5728\u4f7f\u7528\u522b\u4eba\u7684\u4ee3\u7801\u65f6\uff0c\u82e5\u522b\u4eba\u4ee3\u7801\u8bbe\u7f6e\u7684\u8282\u70b9\u540d\u3001\u8bdd\u9898\u540d\u7b49\u4e0d\u9002\u5408\u81ea\u5df1\u7684\u9879\u76ee\u65f6\uff0c\u53ef\u4ee5\u7528\u8fd9\u79cd\u65b9\u6cd5\u53bb\u8c03\u6574\uff0c\u4e5f\u4e0d\u9700\u8981\u4fee\u6539\u6e90\u7801\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u901a\u8fc7launch\u8fd8\u53ef\u4ee5\u4fee\u6539\u4e00\u4e9b\u6267\u884c\u53c2\u6570\uff0c\u4ecd\u4e3e\u6d77\u9f9f\u4f8b\u5b50\uff0c\u4fee\u6539\u5176\u6253\u5f00\u65f6\u7684\u80cc\u666f\u989c\u8272\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from launch import LaunchDescription                   # launch\u6587\u4ef6\u7684\u63cf\u8ff0\u7c7b\nfrom launch.actions import DeclareLaunchArgument       # \u58f0\u660elaunch\u6587\u4ef6\u5185\u4f7f\u7528\u7684Argument\u7c7b\nfrom launch.substitutions import LaunchConfiguration, TextSubstitution\n\nfrom launch_ros.actions import Node                    # \u8282\u70b9\u542f\u52a8\u7684\u63cf\u8ff0\u7c7b\n\n\ndef generate_launch_description():                     # \u81ea\u52a8\u751f\u6210launch\u6587\u4ef6\u7684\u51fd\u6570\n   background_r_launch_arg = DeclareLaunchArgument(\n      'background_r', default_value=TextSubstitution(text='0')     # \u521b\u5efa\u4e00\u4e2aLaunch\u6587\u4ef6\u5185\u53c2\u6570\uff08arg\uff09background_r\n   )\n   background_g_launch_arg = DeclareLaunchArgument(\n      'background_g', default_value=TextSubstitution(text='84')    # \u521b\u5efa\u4e00\u4e2aLaunch\u6587\u4ef6\u5185\u53c2\u6570\uff08arg\uff09background_g\n   )\n   background_b_launch_arg = DeclareLaunchArgument(\n      'background_b', default_value=TextSubstitution(text='122')   # \u521b\u5efa\u4e00\u4e2aLaunch\u6587\u4ef6\u5185\u53c2\u6570\uff08arg\uff09background_b\n   )\n\n   return LaunchDescription(&#91;                                      # \u8fd4\u56delaunch\u6587\u4ef6\u7684\u63cf\u8ff0\u4fe1\u606f\n      background_r_launch_arg,                                     # \u8c03\u7528\u4ee5\u4e0a\u521b\u5efa\u7684\u53c2\u6570\uff08arg\uff09\n      background_g_launch_arg,\n      background_b_launch_arg,\n      Node(                                                        # \u914d\u7f6e\u4e00\u4e2a\u8282\u70b9\u7684\u542f\u52a8\n         package='turtlesim',\n         executable='turtlesim_node',                              # \u8282\u70b9\u6240\u5728\u7684\u529f\u80fd\u5305\n         name='sim',                                               # \u5bf9\u8282\u70b9\u91cd\u65b0\u547d\u540d\n         parameters=&#91;{                                             # ROS\u53c2\u6570\u5217\u8868\n            'background_r': LaunchConfiguration('background_r'),   # \u521b\u5efa\u53c2\u6570background_r\n            'background_g': LaunchConfiguration('background_g'),   # \u521b\u5efa\u53c2\u6570background_g\n            'background_b': LaunchConfiguration('background_b'),   # \u521b\u5efa\u53c2\u6570background_b\n         }]\n      ),\n   ])\n<\/code><\/pre>\n\n\n\n<p>LaunchConfiguration\u662f\u53bb\u7cfb\u7edf\u5185\u8bfb\u53d6\u53c2\u6570\u7684\u503c\uff08background_r\u3001background_g\u3001background_b\u53c2\u6570\uff09\uff0c\u8fd9\u51e0\u4e2a\u53c2\u6570\u7684\u503c\u5219\u662f\u4e0a\u9762\u7684\u4ee3\u7801\u8fdb\u884c\u5b9a\u4e49\u7684\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>background_r_launch_arg = DeclareLaunchArgument(\n      'background_r', default_value=TextSubstitution(text='0')     # \u521b\u5efa\u4e00\u4e2aLaunch\u6587\u4ef6\u5185\u53c2\u6570\uff08arg\uff09background_r\n   )<\/code><\/pre>\n\n\n\n<p>LaunchDescription\u751f\u6210launch\u63cf\u8ff0\u4fe1\u606f\u7684\u65f6\u5019\u518d\u4f20\u9012\u5165<code>background_r_launch_arg<\/code>\u7b49\u4e09\u4e2a\u53c2\u6570\u4ee5\u5b9e\u73b0\u4fdd\u5b58\u548c\u8c03\u7528\u3002<\/p>\n\n\n\n<p>\u4f20\u5165\u8fd9\u4e09\u4e2a\u53c2\u6570\u8fd8\u662f\u663e\u5f97\u6709\u4e9b\u5197\u4f59\uff0c\u5728launch\u5185\u53ef\u4ee5\u7528yaml\u914d\u7f6e\u6587\u4ef6\u5b8c\u6210\u53c2\u6570\u4f20\u9012\u7684\u914d\u7f6e\uff0c\u4e0a\u8ff0\u4ee3\u7801\u53ef\u4f18\u5316\u4e3a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import os\n\nfrom ament_index_python.packages import get_package_share_directory  # \u67e5\u8be2\u529f\u80fd\u5305\u8def\u5f84\u7684\u65b9\u6cd5\n\nfrom launch import LaunchDescription   # launch\u6587\u4ef6\u7684\u63cf\u8ff0\u7c7b\nfrom launch_ros.actions import Node    # \u8282\u70b9\u542f\u52a8\u7684\u63cf\u8ff0\u7c7b\n\n\ndef generate_launch_description():     # \u81ea\u52a8\u751f\u6210launch\u6587\u4ef6\u7684\u51fd\u6570\n   config = os.path.join(              # \u627e\u5230\u53c2\u6570\u6587\u4ef6\u7684\u5b8c\u6574\u8def\u5f84\n      get_package_share_directory('learning_launch'),\n      'config',\n      'turtlesim.yaml'\n      )\n\n   return LaunchDescription(&#91;          # \u8fd4\u56delaunch\u6587\u4ef6\u7684\u63cf\u8ff0\u4fe1\u606f\n      Node(                            # \u914d\u7f6e\u4e00\u4e2a\u8282\u70b9\u7684\u542f\u52a8\n         package='turtlesim',          # \u8282\u70b9\u6240\u5728\u7684\u529f\u80fd\u5305\n         executable='turtlesim_node',  # \u8282\u70b9\u7684\u53ef\u6267\u884c\u6587\u4ef6\u540d\n         namespace='turtlesim2',       # \u8282\u70b9\u6240\u5728\u7684\u547d\u540d\u7a7a\u95f4\n         name='sim',                   # \u5bf9\u8282\u70b9\u91cd\u65b0\u547d\u540d\n         parameters=&#91;config]           # \u52a0\u8f7d\u53c2\u6570\u6587\u4ef6\n      )\n   ])\n<\/code><\/pre>\n\n\n\n<p>\u5bf9\u5e94\u7684<code>turtlesim.yaml<\/code>\u6587\u4ef6\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/turtlesim2\/sim:\n   ros__parameters:\n      background_b: 0\n      background_g: 0\n      background_r: 0\n<\/code><\/pre>\n\n\n\n<p>\u7b2c\u4e00\u884c\u7684<code>\/turtlesim2\/sim<\/code>\u5bf9\u5e94\u547d\u540d\u7a7a\u95f4\uff0c\u4e0d\u53ef\u968f\u610f\u4fee\u6539\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u5728\u590d\u6742\u7684\u673a\u5668\u4eba\u7cfb\u7edf\u4e2d\uff0claunch\u6587\u4ef6\u4e5f\u4f1a\u6709\u5f88\u591a\uff0c\u6b64\u65f6\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u7c7b\u4f3c\u7f16\u7a0b\u4e2d\u7684include\u673a\u5236\uff0c\u8ba9launch\u6587\u4ef6\u4e92\u76f8\u5305\u542b\u3002\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import os\n\nfrom ament_index_python.packages import get_package_share_directory  # \u67e5\u8be2\u529f\u80fd\u5305\u8def\u5f84\u7684\u65b9\u6cd5\n\nfrom launch import LaunchDescription                 # launch\u6587\u4ef6\u7684\u63cf\u8ff0\u7c7b\nfrom launch.actions import IncludeLaunchDescription  # \u8282\u70b9\u542f\u52a8\u7684\u63cf\u8ff0\u7c7b\nfrom launch.launch_description_sources import PythonLaunchDescriptionSource\nfrom launch.actions import GroupAction               # launch\u6587\u4ef6\u4e2d\u7684\u6267\u884c\u52a8\u4f5c\nfrom launch_ros.actions import PushRosNamespace      # ROS\u547d\u540d\u7a7a\u95f4\u914d\u7f6e\n\ndef generate_launch_description():                   # \u81ea\u52a8\u751f\u6210launch\u6587\u4ef6\u7684\u51fd\u6570\n   parameter_yaml = IncludeLaunchDescription(  # \u627e\u5230\u5e76\u5305\u542b\u6307\u5b9a\u8def\u5f84\u4e0b\u7684\u53e6\u5916\u4e00\u4e2alaunch\u6587\u4ef6\n      PythonLaunchDescriptionSource(&#91;os.path.join(\n         get_package_share_directory('learning_launch'), 'launch'),\n         '\/parameters_nonamespace.launch.py'])\n      )\n\n   parameter_yaml_with_namespace = GroupAction(      # \u5bf9\u6307\u5b9alaunch\u6587\u4ef6\u4e2d\u542f\u52a8\u7684\u529f\u80fd\u52a0\u4e0a\u547d\u540d\u7a7a\u95f4\uff0c\u5373\u5728\u5176\u524d\u9762\u52a0\u4e00\u4e2a\u7236\u76ee\u5f55\uff0c\u907f\u514d\u539f\u672c\u7684\u547d\u540d\u548c\u5f53\u524dlaunch\u7684\u547d\u540d\u51b2\u7a81\n      actions=&#91;\n         PushRosNamespace('turtlesim2'),\n         parameter_yaml]\n      )\n\n   return LaunchDescription(&#91;                        # \u8fd4\u56delaunch\u6587\u4ef6\u7684\u63cf\u8ff0\u4fe1\u606f\n      parameter_yaml_with_namespace                  # return\u5f97\u5230launch\u63cf\u8ff0\u7684\u65f6\u5019\u4f1a\u5f97\u5230\u4e0a\u9762\u914d\u7f6e\u7684parameter_yaml_with_namespace\n   ])<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u6700\u540e\uff0c\u6240\u6709\u7684launch\u6587\u4ef6\u90fd\u5fc5\u987b\u62f7\u8d1d\u5230install\u7684\u5b89\u88c5\u7a7a\u95f4\u5185\u3002\u4e3a\u4e86\u5b9e\u73b0\u8fd9\u4e2a\uff0c\u5fc5\u987b\u5728<code>setup.py<\/code>\u914d\u7f6e\u6587\u4ef6\u7684data_files\u90e8\u5206\u91cc\u6dfb\u52a0\u5982\u4e0b\u5185\u5bb9\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>(os.path.join('share', package_name, 'launch'), glob(os.path.join('launch', '*.launch.py'))),\n(os.path.join('share', package_name, 'config'), glob(os.path.join('config', '*.*'))),\n(os.path.join('share', package_name, 'rviz'), glob(os.path.join('rviz', '*.*'))),<\/code><\/pre>\n\n\n\n<p>\u5b8c\u6574\u7684setup.py\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from setuptools import setup\nimport os\nfrom glob import glob\n\npackage_name = 'learning_launch'\n\nsetup(\n    name=package_name,\n    version='0.0.0',\n    packages=&#91;package_name],\n    data_files=&#91;\n        ('share\/ament_index\/resource_index\/packages',\n            &#91;'resource\/' + package_name]),\n        ('share\/' + package_name, &#91;'package.xml']),\n        (os.path.join('share', package_name, 'launch'), glob(os.path.join('launch', '*.launch.py'))),\n        (os.path.join('share', package_name, 'config'), glob(os.path.join('config', '*.*'))),\n        (os.path.join('share', package_name, 'rviz'), glob(os.path.join('rviz', '*.*'))),\n    ],\n    install_requires=&#91;'setuptools'],\n    zip_safe=True,\n    maintainer='hcx',\n    maintainer_email='huchunxu@guyuehome.com',\n    description='TODO: Package description',\n    license='TODO: License declaration',\n    tests_require=&#91;'pytest'],\n    entry_points={\n        'console_scripts': &#91;\n        ],\n    },\n)\n<\/code><\/pre>\n\n\n\n<p>\u8fd9\u6837\u914d\u7f6e\u540e\uff0ccolcon\u7f16\u8bd1\u65f6\u624d\u4f1a\u5c06launch\u6587\u4ef6\u62f7\u8d1d\u5230install\u6587\u4ef6\u5939\u5185\uff0c\u5728\u8fd0\u884c\u65f6\u627e\u5230\u5e76\u6210\u529f\u8fd0\u884c\u3002\u5426\u5219\u867d\u7136\u53ef\u4ee5\u6b63\u5e38\u7f16\u8bd1\uff0c\u4f46\u8fd0\u884c\u65f6\u4f1a\u65e0\u6cd5\u627e\u5230\u76f8\u5e94\u6587\u4ef6\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Launch\u542f\u52a8\u6587\u4ef6\u53ef\u4ee5\u4e00\u6b21\u6027\u542f\u52a8\u591a\u4e2a\u8282\u70b9\u6587\u4ef6\uff0c\u662fROS\u7cfb\u7edf\u4e2d\u591a\u8282\u70b9\u542f\u52a8\u4e0e\u914d\u7f6e\u7684\u4e00\u79cd\u811a\u672c\u3002 ROS2\u4e2d\u7684Lau [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-154","post","type-post","status-publish","format-standard","hentry","category-ros2"],"_links":{"self":[{"href":"https:\/\/374969782.xyz\/index.php\/wp-json\/wp\/v2\/posts\/154","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/374969782.xyz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/374969782.xyz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/374969782.xyz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/374969782.xyz\/index.php\/wp-json\/wp\/v2\/comments?post=154"}],"version-history":[{"count":8,"href":"https:\/\/374969782.xyz\/index.php\/wp-json\/wp\/v2\/posts\/154\/revisions"}],"predecessor-version":[{"id":163,"href":"https:\/\/374969782.xyz\/index.php\/wp-json\/wp\/v2\/posts\/154\/revisions\/163"}],"wp:attachment":[{"href":"https:\/\/374969782.xyz\/index.php\/wp-json\/wp\/v2\/media?parent=154"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/374969782.xyz\/index.php\/wp-json\/wp\/v2\/categories?post=154"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/374969782.xyz\/index.php\/wp-json\/wp\/v2\/tags?post=154"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}