{"id":60,"date":"2026-03-27T20:27:26","date_gmt":"2026-03-27T12:27:26","guid":{"rendered":"https:\/\/374969782.xyz\/?p=60"},"modified":"2026-04-05T18:08:46","modified_gmt":"2026-04-05T10:08:46","slug":"ros2%e5%ad%a6%e4%b9%a0%e8%ae%b0%e5%bd%95%ef%bc%882%ef%bc%89","status":"publish","type":"post","link":"https:\/\/374969782.xyz\/index.php\/2026\/03\/27\/ros2%e5%ad%a6%e4%b9%a0%e8%ae%b0%e5%bd%95%ef%bc%882%ef%bc%89\/","title":{"rendered":"ROS2\u5b66\u4e60\u8bb0\u5f55\uff082\uff09-\u8282\u70b9"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u8282\u70b9<\/h2>\n\n\n\n<p>\u8282\u70b9\u662f\u673a\u5668\u4eba\u5de5\u4f5c\u7684\u57fa\u672c\u5355\u5143\uff0c\u6bcf\u4e2a\u8282\u70b9\u90fd\u662f\u6267\u884c\u5177\u4f53\u4efb\u52a1\u7684\u8fdb\u7a0b\uff0c\u662f\u72ec\u7acb\u8fd0\u884c\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u672c\u8eab\u53ef\u4ee5\u4f7f\u7528\u4e0d\u540c\u7684\u7f16\u7a0b\u8bed\u8a00\u3002\u540c\u65f6\u4e5f\u6ee1\u8db3\u5206\u5e03\u5f0f\u7684\u8fd0\u884c\uff0c\u6bcf\u4e2a\u8282\u70b9\u53ef\u4ee5\u5404\u81ea\u90e8\u7f72\u5728\u4e0d\u540c\u7684\u786c\u4ef6\u8bbe\u5907\uff0c\u751a\u81f3\u4e91\u7aef\uff0c\u5177\u4f53\u901a\u8fc7\u8282\u70b9\u540d\u79f0\u6765\u7ba1\u7406\u3002<\/p>\n\n\n\n<p>\u542f\u52a8\u8282\u70b9\u7684\u65b9\u6cd5\u4e3a\uff0c\u5728\u547d\u4ee4\u884c\u5185\u8fd0\u884c\u5b8csource\u6e90\u7801\u540e\uff0c\u901a\u8fc7ros2\u547d\u4ee4\u7684\u5982\u4e0b\u8bed\u53e5\u542f\u52a8\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ros2 run &lt;\u5305\u540d&gt; &lt;\u5305\u5185\u53ef\u6267\u884c\u7a0b\u5e8f&gt;<\/code><\/pre>\n\n\n\n<p>run\u4e3aros2\u7684\u4e00\u4e2a\u6307\u4ee4\u3002<\/p>\n\n\n\n<p>\u81ea\u884c\u7f16\u5199\u8282\u70b9\u6e90\u7801\u65f6\uff0c\u9700\u8981\u5f15\u5165rclpy\u5e93\uff08ros2\u7684python\u63a5\u53e3\u5e93\uff09\uff0c\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import rclpy                                     # ROS2 Python\u63a5\u53e3\u5e93\nfrom rclpy.node import Node                      # ROS2 \u8282\u70b9\u7c7b\nimport time\n\ndef main(args=None):                             # ROS2\u8282\u70b9\u4e3b\u5165\u53e3main\u51fd\u6570\n    rclpy.init(args=args)                        # ROS2 Python\u63a5\u53e3\u521d\u59cb\u5316\n    node = Node(\"node_helloworld\")               # \u521b\u5efaROS2\u8282\u70b9\u5bf9\u8c61\u5e76\u8fdb\u884c\u521d\u59cb\u5316\n    \n    while rclpy.ok():                            # ROS2\u7cfb\u7edf\u662f\u5426\u6b63\u5e38\u8fd0\u884c,ctrl+c\u4e2d\u65ad\u540e\u8fd4\u56deFalse\n        node.get_logger().info(\"Hello World\")    # ROS2\u65e5\u5fd7\u8f93\u51fa\n        time.sleep(0.5)                          # \u4f11\u7720\u63a7\u5236\u5faa\u73af\u65f6\u95f4\n    \n    node.destroy_node()                          # \u9500\u6bc1\u8282\u70b9\u5bf9\u8c61    \n    rclpy.shutdown()                             # \u5173\u95edROS2 Python\u63a5\u53e3\n<\/code><\/pre>\n\n\n\n<p>\u6838\u5fc3\u4e3arclpy\u7684node\u7c7b\u6307\u5b9a\u8282\u70b9\uff0c\u5e76\u4f7f\u7528rclpy\u7684\u76f8\u5173\u65b9\u6cd5\u8fd0\u884cros2\u3002<\/p>\n\n\n\n<p>\u4e0a\u8ff0\u4ee3\u7801\u53ef\u4ee5\u4f18\u5316\u4e3a\u9762\u5411\u5bf9\u8c61\uff0c\u76f4\u63a5\u7ee7\u627fnode\u8282\u70b9\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import rclpy                                     # ROS2 Python\u63a5\u53e3\u5e93\nfrom rclpy.node import Node                      # ROS2 \u8282\u70b9\u7c7b\nimport time\n\nclass HelloWorldNode(Node):\n    def __init__(self, name):\n        super().__init__(name)                       # ROS2\u8282\u70b9\u7236\u7c7b\u521d\u59cb\u5316\n        while rclpy.ok():                            # ROS2\u7cfb\u7edf\u662f\u5426\u6b63\u5e38\u8fd0\u884c\n            self.get_logger().info(\"Hello World\")    # ROS2\u65e5\u5fd7\u8f93\u51fa\n            time.sleep(0.5)                          # \u4f11\u7720\u63a7\u5236\u5faa\u73af\u65f6\u95f4\n\ndef main(args=None):                                 # ROS2\u8282\u70b9\u4e3b\u5165\u53e3main\u51fd\u6570\n    rclpy.init(args=args)                            # ROS2 Python\u63a5\u53e3\u521d\u59cb\u5316\n    node = HelloWorldNode(\"node_helloworld_class\")   # \u521b\u5efaROS2\u8282\u70b9\u5bf9\u8c61\u5e76\u8fdb\u884c\u521d\u59cb\u5316\n    node.destroy_node()                              # \u9500\u6bc1\u8282\u70b9\u5bf9\u8c61\n    rclpy.shutdown()                                 # \u5173\u95edROS2 Python\u63a5\u53e3<\/code><\/pre>\n\n\n\n<details class=\"wp-block-details is-layout-flow wp-block-details-is-layout-flow\"><summary>\u7f16\u5199\u5b8c\u8282\u70b9\u7684\u6e90\u7801\u540e\uff0c\u8fd8\u9700\u5728setup.py\u6587\u4ef6\u5185\u914d\u7f6e\u53ef\u6267\u884c\u547d\u4ee4\u548c\u5bf9\u5e94\u7684\u51fd\u6570\u4f4d\u7f6e\uff0c\u5373\u914d\u7f6e\u7a0b\u5e8f\u5165\u53e3\u3002<\/summary>\n<p>setup.py\u662f\u7f16\u8bd1python\u5305\u65f6\u81ea\u52a8\u5728\u5305\u5185\u521b\u5efa\u7684\u6587\u4ef6\uff08c++\u5305\u6ca1\u6709\uff09\u3002<\/p>\n\n\n\n<p>\u5728setup.py\u6587\u4ef6\u672b\u627e\u5230\u540d\u4e3aentry_points\u7684\u5b57\u5178\uff0c\u914d\u7f6e\u5176&#8217;console_scripts&#8217;\u5143\u7d20\u5bf9\u5e94\u7684\u5217\u8868\uff0c\u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u5b57\u7b26\u4e32\u5f62\u5982\uff1a\u8282\u70b9\u547d\u4ee4\u540d = \u547d\u4ee4\u5bf9\u5e94\u51fd\u6570\u6240\u5728\u7684\u5177\u4f53\u4f4d\u7f6e\uff0c\u4f4d\u7f6e\u662f\u4ecesetup.py\u81ea\u5df1\u6240\u5728\u7684\u6587\u4ef6\u5939\u51fa\u53d1\u7684\uff0c\u5e76\u8981\u6307\u660e\u5177\u4f53\u54ea\u4e2a.py\u6587\u4ef6\u4e2d\u7684\u54ea\u4e2a\u51fd\u6570\u3002\u5177\u4f53\u4f8b\u5b50\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>entry_points={\n        'console_scripts': &#91;\n         'node_helloworld       = learning_node.node_helloworld:main',\n         'node_helloworld_class = learning_node.node_helloworld_class:main',\n         'node_object            = learning_node.node_object:main',\n         'node_object_webcam     = learning_node.node_object_webcam:main',\n        ],\n    }<\/code><\/pre>\n\n\n\n<p>\u7b2c\u4e00\u884c\u5b57\u7b26\u4e32\u5c31\u8868\u793a\uff0cnode_helloworld\u8282\u70b9\u6307\u4ee4\u7684\u6e90\u7801\u5728setup.py\u540c\u7ea7\u76ee\u5f55\u7684learning_node\u4e2d\uff0c\u5176\u4e2d\u7684node_helloworld.py\u6587\u4ef6\u5b9a\u4e49\u7684main\u65b9\u6cd5\u5373\u4e3a\u8be5\u8282\u70b9\u672c\u4f53\u3002<\/p>\n<\/details>\n\n\n\n<p><\/p>\n\n\n\n<p>\u5728\u547d\u4ee4\u884c\uff0cros2\u4e5f\u6709\u4e00\u4e9b\u7ba1\u7406\u8282\u70b9\u7684\u65b9\u6cd5\u3002<\/p>\n\n\n\n<p>\u67e5\u770b\u8282\u70b9\u5217\u8868\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ros2 node list<\/code><\/pre>\n\n\n\n<p>\u67e5\u770b\u8282\u70b9\u8be6\u60c5:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ros2 node info &lt;node_name&gt;<\/code><\/pre>\n\n\n\n<p>\u4ee5\u53ca\u4e0a\u9762\u63d0\u5230\u8fc7\u7684\u8fd0\u884c\u5355\u4e2a\u8282\u70b9\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ros2 run &lt;package_name&gt; &lt;executable_name&gt;<\/code><\/pre>\n\n\n\n<p>\u91cd\u547d\u540d\u8282\u70b9\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ros2 run &lt;package_name&gt; &lt;executable_name&gt; --ros-args --remap __node:=&lt;new_node_name&gt;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u8282\u70b9 \u8282\u70b9\u662f\u673a\u5668\u4eba\u5de5\u4f5c\u7684\u57fa\u672c\u5355\u5143\uff0c\u6bcf\u4e2a\u8282\u70b9\u90fd\u662f\u6267\u884c\u5177\u4f53\u4efb\u52a1\u7684\u8fdb\u7a0b\uff0c\u662f\u72ec\u7acb\u8fd0\u884c\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u672c\u8eab\u53ef\u4ee5\u4f7f\u7528\u4e0d\u540c\u7684\u7f16 [&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-60","post","type-post","status-publish","format-standard","hentry","category-ros2"],"_links":{"self":[{"href":"https:\/\/374969782.xyz\/index.php\/wp-json\/wp\/v2\/posts\/60","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=60"}],"version-history":[{"count":7,"href":"https:\/\/374969782.xyz\/index.php\/wp-json\/wp\/v2\/posts\/60\/revisions"}],"predecessor-version":[{"id":77,"href":"https:\/\/374969782.xyz\/index.php\/wp-json\/wp\/v2\/posts\/60\/revisions\/77"}],"wp:attachment":[{"href":"https:\/\/374969782.xyz\/index.php\/wp-json\/wp\/v2\/media?parent=60"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/374969782.xyz\/index.php\/wp-json\/wp\/v2\/categories?post=60"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/374969782.xyz\/index.php\/wp-json\/wp\/v2\/tags?post=60"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}