{"id":142,"date":"2026-04-05T18:59:35","date_gmt":"2026-04-05T10:59:35","guid":{"rendered":"https:\/\/374969782.xyz\/?p=142"},"modified":"2026-04-07T13:18:17","modified_gmt":"2026-04-07T05:18:17","slug":"ros2%e5%ad%a6%e4%b9%a0%e8%ae%b0%e5%bd%95%ef%bc%887%ef%bc%89-%e5%8f%82%e6%95%b0","status":"publish","type":"post","link":"https:\/\/374969782.xyz\/index.php\/2026\/04\/05\/ros2%e5%ad%a6%e4%b9%a0%e8%ae%b0%e5%bd%95%ef%bc%887%ef%bc%89-%e5%8f%82%e6%95%b0\/","title":{"rendered":"ROS2\u5b66\u4e60\u8bb0\u5f55\uff087\uff09-\u53c2\u6570"},"content":{"rendered":"\n<p>\u53c2\u6570\u662fROS\u673a\u5668\u4eba\u7cfb\u7edf\u4e2d\u7684\u5168\u5c40\u5b57\u5178\uff0c\u53ef\u4ee5\u8fd0\u884c\u591a\u4e2a\u8282\u70b9\u4e2d\u5171\u4eab\u6570\u636e\u3002<\/p>\n\n\n\n<p>\u6bd4\u5982\u5728\u673a\u5668\u89c6\u89c9\u8bc6\u522b\u7684\u65f6\u5019\uff0c\u6709\u5f88\u591a\u53c2\u6570\u90fd\u4f1a\u5f71\u54cd\u89c6\u89c9\u8bc6\u522b\u7684\u6548\u679c\u3002<\/p>\n\n\n\n<p>\u5728ROS\u7cfb\u7edf\u4e2d\uff0c\u53c2\u6570\u662f\u4ee5<strong>\u5168\u5c40\u5b57\u5178<\/strong>\u7684\u5f62\u6001\u5b58\u5728\u7684\uff0c\u4ec0\u4e48\u53eb\u5b57\u5178\uff1f\u5c31\u50cf\u771f\u5b9e\u7684\u5b57\u5178\u4e00\u6837\uff0c\u7531\u540d\u79f0\u548c\u6570\u503c\u7ec4\u6210\uff0c\u4e5f\u53eb\u505a\u952e\u548c\u503c\uff0c\u5408\u6210<strong>\u952e\u503c<\/strong>\u3002\u6216\u8005\u6211\u4eec\u4e5f\u53ef\u4ee5\u7406\u89e3\u4e3a\uff0c\u5c31\u50cf\u7f16\u7a0b\u4e2d\u7684\u53c2\u6570\u4e00\u6837\uff0c\u6709\u4e00\u4e2a\u53c2\u6570\u540d \uff0c\u7136\u540e\u8ddf\u4e00\u4e2a\u7b49\u53f7\uff0c\u540e\u8fb9\u5c31\u662f\u53c2\u6570\u503c\u4e86\uff0c\u5728\u4f7f\u7528\u7684\u65f6\u5019\uff0c\u8bbf\u95ee\u8fd9\u4e2a\u53c2\u6570\u540d\u5373\u53ef\u3002<\/p>\n\n\n\n<p>\u5728ROS2\u4e2d\uff0c\u53c2\u6570\u7684\u7279\u6027\u975e\u5e38\u4e30\u5bcc\uff0c\u6bd4\u5982\u67d0\u4e00\u4e2a\u8282\u70b9\u5171\u4eab\u4e86\u4e00\u4e2a\u53c2\u6570\uff0c\u5176\u4ed6\u8282\u70b9\u90fd\u53ef\u4ee5\u8bbf\u95ee\uff0c\u5982\u679c\u67d0\u4e00\u4e2a\u8282\u70b9\u5bf9\u53c2\u6570\u8fdb\u884c\u4e86\u4fee\u6539\uff0c\u5176\u4ed6\u8282\u70b9\u4e5f\u6709\u529e\u6cd5\u7acb\u523b\u77e5\u9053\uff0c\u4ece\u800c\u83b7\u53d6\u6700\u65b0\u7684\u6570\u503c\uff0c\u53ef\u52a8\u6001\u76d1\u63a7\u3002\u5728<strong>\u53c2\u6570\u7684\u9ad8\u7ea7\u7f16\u7a0b<\/strong>\u4e2d\uff0c\u53ef\u80fd\u4f1a\u7528\u5230\u3002<\/p>\n\n\n\n<p>\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u67e5\u8be2\u5f53\u524d\u7cfb\u7edf\u4e2d\u6709\u54ea\u4e9b\u53c2\u6570\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ros2 param list<\/code><\/pre>\n\n\n\n<p>\u8fd8\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u7684\u65b9\u6cd5\u66f4\u8fdb\u4e00\u6b65\u64cd\u63a7\u6307\u5b9a\u53c2\u6570\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ros2 param describe turtlesim background_b   # \u67e5\u770b\u67d0\u4e2a\u53c2\u6570\u7684\u63cf\u8ff0\u4fe1\u606f\nros2 param get turtlesim background_b        # \u67e5\u8be2\u67d0\u4e2a\u53c2\u6570\u7684\u503c\nros2 param set turtlesim background_b 10     # \u4fee\u6539\u67d0\u4e2a\u53c2\u6570\u7684\u503c<\/code><\/pre>\n\n\n\n<p>\u4e00\u4e2a\u4e00\u4e2a\u67e5\u8be2\/\u4fee\u6539\u53c2\u6570\u592a\u9ebb\u70e6\u4e86\uff0c\u4e0d\u5982\u8bd5\u4e00\u8bd5\u53c2\u6570\u6587\u4ef6\uff0cROS\u4e2d\u7684\u53c2\u6570\u6587\u4ef6\u4f7f\u7528yaml\u683c\u5f0f\uff0c\u53ef\u4ee5\u5728param\u547d\u4ee4\u540e\u8fb9\u8ddfdump\u5b50\u547d\u4ee4\uff0c\u5c06\u67d0\u4e2a\u8282\u70b9\u7684\u53c2\u6570\u90fd\u4fdd\u5b58\u5230\u6587\u4ef6\u4e2d\uff0c\u6216\u8005\u901a\u8fc7load\u547d\u4ee4\u4e00\u6b21\u6027\u52a0\u8f7d\u67d0\u4e2a\u53c2\u6570\u6587\u4ef6\u4e2d\u7684\u6240\u6709\u5185\u5bb9\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ros2 param dump turtlesim >> turtlesim.yaml  # \u5c06\u67d0\u4e2a\u8282\u70b9\u7684\u53c2\u6570\u4fdd\u5b58\u5230\u53c2\u6570\u6587\u4ef6\u4e2d\nros2 param load turtlesim turtlesim.yaml     # \u4e00\u6b21\u6027\u52a0\u8f7d\u67d0\u4e00\u4e2a\u6587\u4ef6\u4e2d\u7684\u6240\u6709\u53c2\u6570<\/code><\/pre>\n\n\n\n<p>\u5728\u4ee3\u7801\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7rclpy\u7684\u4e00\u4e9b\u5e93\u51fd\u6570\uff0c\u64cd\u4f5c\u53c2\u6570\u3002\u4e00\u4e2a\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\n\nclass ParameterNode(Node):\n    def __init__(self, name):\n        super().__init__(name)                                    # ROS2\u8282\u70b9\u7236\u7c7b\u521d\u59cb\u5316\n        self.timer = self.create_timer(2, self.timer_callback)    # \u521b\u5efa\u4e00\u4e2a\u5b9a\u65f6\u5668\uff08\u5355\u4f4d\u4e3a\u79d2\u7684\u5468\u671f\uff0c\u5b9a\u65f6\u6267\u884c\u7684\u56de\u8c03\u51fd\u6570\uff09\n        self.declare_parameter('robot_name', 'mbot')       # \u521b\u5efa\u4e00\u4e2a\u53c2\u6570\uff0c\u5e76\u8bbe\u7f6e\u53c2\u6570\u7684\u9ed8\u8ba4\u503c\n\n    def timer_callback(self):                                  # \u521b\u5efa\u5b9a\u65f6\u5668\u5468\u671f\u6267\u884c\u7684\u56de\u8c03\u51fd\u6570\n        robot_name_param = self.get_parameter('robot_name').get_parameter_value().string_value   # \u4eceROS2\u7cfb\u7edf\u4e2d\u8bfb\u53d6\u53c2\u6570\u7684\u503c\n\n        self.get_logger().info('Hello %s!' % robot_name_param)     # \u8f93\u51fa\u65e5\u5fd7\u4fe1\u606f\uff0c\u6253\u5370\u8bfb\u53d6\u5230\u7684\u53c2\u6570\u503c\n\n        new_name_param = rclpy.parameter.Parameter('robot_name',   # \u91cd\u65b0\u5c06\u53c2\u6570\u503c\u8bbe\u7f6e\u4e3a\u6307\u5b9a\u503c\n                            rclpy.Parameter.Type.STRING, 'mbot')\n        all_new_parameters = &#91;new_name_param]\n        self.set_parameters(all_new_parameters)      # \u5c06\u91cd\u65b0\u521b\u5efa\u7684\u53c2\u6570\u5217\u8868\u53d1\u9001\u7ed9ROS2\u7cfb\u7edf\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 = ParameterNode(\"param_declare\")            # \u521b\u5efaROS2\u8282\u70b9\u5bf9\u8c61\u5e76\u8fdb\u884c\u521d\u59cb\u5316\n    rclpy.spin(node)                                 # \u5faa\u73af\u7b49\u5f85ROS2\u9000\u51fa\n    node.destroy_node()                              # \u9500\u6bc1\u8282\u70b9\u5bf9\u8c61\n    rclpy.shutdown()                                 # \u5173\u95edROS2 Python\u63a5\u53e3<\/code><\/pre>\n\n\n\n<p>\u8be5\u7c7b\u7ee7\u627f\u81earclpy.node\u7c7b\uff0c\u81ea\u5e26declare_parameter()\u65b9\u6cd5\u8bbe\u7f6e\u53c2\u6570\u3002\u6b64\u5916\u8fd8\u53ef\u4ee5\u91c7\u7528rclpy.parameter\u5e93\u64cd\u4f5c\u53c2\u6570\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u53c2\u6570\u662fROS\u673a\u5668\u4eba\u7cfb\u7edf\u4e2d\u7684\u5168\u5c40\u5b57\u5178\uff0c\u53ef\u4ee5\u8fd0\u884c\u591a\u4e2a\u8282\u70b9\u4e2d\u5171\u4eab\u6570\u636e\u3002 \u6bd4\u5982\u5728\u673a\u5668\u89c6\u89c9\u8bc6\u522b\u7684\u65f6\u5019\uff0c\u6709\u5f88\u591a\u53c2\u6570\u90fd\u4f1a\u5f71\u54cd [&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-142","post","type-post","status-publish","format-standard","hentry","category-ros2"],"_links":{"self":[{"href":"https:\/\/374969782.xyz\/index.php\/wp-json\/wp\/v2\/posts\/142","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=142"}],"version-history":[{"count":2,"href":"https:\/\/374969782.xyz\/index.php\/wp-json\/wp\/v2\/posts\/142\/revisions"}],"predecessor-version":[{"id":145,"href":"https:\/\/374969782.xyz\/index.php\/wp-json\/wp\/v2\/posts\/142\/revisions\/145"}],"wp:attachment":[{"href":"https:\/\/374969782.xyz\/index.php\/wp-json\/wp\/v2\/media?parent=142"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/374969782.xyz\/index.php\/wp-json\/wp\/v2\/categories?post=142"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/374969782.xyz\/index.php\/wp-json\/wp\/v2\/tags?post=142"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}