{"id":447,"date":"2026-09-30T13:39:17","date_gmt":"2026-09-30T05:39:17","guid":{"rendered":"https:\/\/geocommunity.vip\/?p=447"},"modified":"2026-10-01T18:35:28","modified_gmt":"2026-10-01T10:35:28","slug":"lidar-in-ros2","status":"publish","type":"post","link":"https:\/\/geocommunity.vip\/index.php\/2026\/09\/30\/lidar-in-ros2\/","title":{"rendered":"\u6fc0\u5149\u96f7\u8fbe\u5728ROS2\u4e2d\u7684\u4f7f\u7528"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">\u4e00\u3001ROS2\u4e2d\u7684\u6fc0\u5149\u96f7\u8fbe\u6570\u636e<\/h1>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-36-1024x768.png\" alt=\"\" class=\"wp-image-448\" style=\"width:658px;height:auto\" srcset=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-36-1024x768.png 1024w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-36-300x225.png 300w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-36-768x576.png 768w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-36.png 1448w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">1\u3001\u6fc0\u5149\u96f7\u8fbe\u7684\u8bdd\u9898\u540d\u79f0<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">ROS2\u4e2d\u7684\u6fc0\u5149\u96f7\u8fbe\u7684\u8282\u70b9\u4f1a\u5728\u6307\u5b9a\u540d\u79f0\u7684\u8bdd\u9898\u91cc\u53d1\u5e03\u6d88\u606f\u3002\u8bdd\u9898\u540d\u79f0\u5728REP-138\uff08\u6fc0\u5149\u96f7\u8fbe LaserScan \u7684\u901a\u7528\u8bdd\u9898\u3001\u53c2\u6570\u548c\u8bca\u65ad\u4fe1\u606f\u89c4\u8303\u3002\uff09\u63a8\u8350\u4e3a\u201c\/scan\u201d\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2\u3001\u6fc0\u5149\u96f7\u8fbe\u7684\u6d88\u606f\u5305\u683c\u5f0f<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>Header header<\/td><td>header\u4e2d\u7684timestamp\uff08\u65f6\u95f4\u6233\uff09\u8868\u793a\u672c\u6b21\u626b\u63cf\u4e2d\u63a5\u6536\u5230\u7b2c\u4e00\u675f\u6d4b\u8ddd\u6fc0\u5149\u53cd\u5c04\u4fe1\u53f7\u7684\u65f6\u95f4\u3002<br>header\u4e2d\u7684frame_id\u6307\u660e\u4e86\u6fc0\u5149\u96f7\u8fbe\u7684\u57fa\u51c6\u5750\u6807\u7cfb\u3002<\/td><\/tr><tr><td>float32 angle_min<\/td><td>\u626b\u63cf\u7684\u8d77\u59cb\u89d2\u5ea6\uff08\u5f27\u5ea6\uff09<\/td><\/tr><tr><td>float32 angle_max<\/td><td>\u626b\u63cf\u7684\u7ec8\u6b62\u89d2\u5ea6\uff08\u5f27\u5ea6\uff09<\/td><\/tr><tr><td>float32 angle_increment<\/td><td>\u76f8\u90bb\u4e24\u6b21\u6d4b\u8ddd\u7684\u65cb\u8f6c\u5939\u89d2\uff08\u5f27\u5ea6\uff09<\/td><\/tr><tr><td>float32 time_increment<\/td><td>\u76f8\u90bb\u4e24\u6b21\u6d4b\u8ddd\u7684\u65f6\u95f4\u5dee\uff08\u79d2\uff09<\/td><\/tr><tr><td>float32 scan_time<\/td><td>\u4e24\u6b21\u626b\u63cf\u7684\u8d77\u59cb\u65f6\u95f4\u5dee\uff08\u79d2\uff09- \u626b\u4e00\u5708\u8981\u591a\u4e45<\/td><\/tr><tr><td>float32 range_min<\/td><td>\u6709\u6548\u6d4b\u8ddd\u8303\u56f4\u7684\u6700\u5c0f\u8ddd\u79bb\uff08\u7c73\uff09<\/td><\/tr><tr><td>float32 range_max<\/td><td>\u6709\u6548\u6d4b\u8ddd\u8303\u56f4\u7684\u6700\u5927\u8ddd\u79bb\uff08\u7c73\uff09<\/td><\/tr><tr><td>float32[] ranges<\/td><td>\u672c\u6b21\u626b\u63cf\u7684\u6240\u6709\u6d4b\u8ddd\u503c\uff08\u7c73\uff09<\/td><\/tr><tr><td>float32[] intensities<\/td><td>\u6240\u6709\u6d4b\u8ddd\u7684\u8fd4\u56de\u4fe1\u53f7\u5f3a\u5ea6<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\">\u4e8c\u3001\u5728Rviz2\u4e2d\u67e5\u770b\u6fc0\u5149\u96f7\u8fbe\u6570\u636e<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Rviz2 = ROS Visualization tool 2\uff0c\u662f\u4e00\u4e2a\u56fe\u5f62\u5316\u5de5\u5177\uff0c\u53ef\u4ee5\u76f4\u89c2\u5730\u67e5\u770b\u4f20\u611f\u5668\u7684\u6570\u636e\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u8fc7<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>source ~\/ros2_ws\/install\/setup.bash\nrviz2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u542f\u52a8\u56fe\u5f62\u754c\u9762\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u6839\u636e\u9700\u8981\u6765\u914d\u7f6e\u4e00\u4e9b\u53c2\u6570\uff0c\u6bd4\u5982\u201c\u5355\u51fb\u754c\u9762\u5de6\u4e0b\u89d2\u7684[Add]\u6309\u94ae\uff0c\u5728\u5f39\u51fa\u7684\u5bf9\u8bdd\u6846\u4e2d\u9009\u62e9[LaserScan]\u3002\u5728RViz2\u7684\u5de6\u4fa7\u663e\u793a\u9879\u76ee\u91cc\u5c55\u5f00[LaserScan]\u3002\u5c06\u5176\u4e2d\u7684\u96f7\u8fbe\u6570\u636e\u8bdd\u9898[Topic]\u8bbe\u7f6e\u4e3a\u201c\/scan\u201d\uff0c\u5c06\u70b9\u4e91\u5c3a\u5bf8[Size(m)]\u4fee\u6539\u4e3a\u201c0.03\u201d\u3002\u201d<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u53c2\u6570\u914d\u7f6e\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u8fdb\u884c\u5f53\u524d\u914d\u7f6e\u6587\u4ef6\u7684\u4fdd\u5b58\uff08\u201cSava Config As\u201d\uff09\uff0c\u4fdd\u5b58\u6587\u4ef6\u7684\u540e\u7f00\u4e3arviz\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53\u4e0b\u6b21\u542f\u52a8Rviz2\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>source ~\/ros2_ws\/install\/setup.bash\nrviz2 -d \u8def\u5f84\u540d\u79f0<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5176\u4e2d\u201c-d\u201d\u8868\u793a\u4ece\u6587\u4ef6\u4e2d\u52a0\u8f7dRViz2\u7684\u754c\u9762\u914d\u7f6e\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u5e38\uff0c\u4e3a\u4e86\u914d\u5408\u5176\u4ed6\u8282\u70b9\u4e00\u540c\u542f\u52a8\uff0c\u4e5f\u53ef\u4ee5\u5728Launch\u6587\u4ef6\u4e2d\uff0c\u63d0\u524d\u914d\u7f6e\u597dRviz\u542f\u52a8\u6307\u4ee4\u7b49\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u4e09\u3001\u6fc0\u5149\u96f7\u8fbe\u6570\u636e\u83b7\u53d6<\/h1>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"906\" src=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-37-1024x906.png\" alt=\"\" class=\"wp-image-449\" style=\"aspect-ratio:1.1302752293577982;width:419px;height:auto\" srcset=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-37-1024x906.png 1024w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-37-300x266.png 300w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-37-768x680.png 768w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-37.png 1333w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">1\u3001\u7f16\u5199\u6fc0\u5149\u96f7\u8fbe\u6570\u636e\u83b7\u53d6\u7a0b\u5e8f<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\uff081\uff09\u521b\u5efa\u8f6f\u4ef6\u5305<\/h3>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1021\" height=\"663\" src=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-38.png\" alt=\"\" class=\"wp-image-450\" style=\"aspect-ratio:1.5400040104271104;width:676px;height:auto\" srcset=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-38.png 1021w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-38-300x195.png 300w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-38-768x499.png 768w\" sizes=\"auto, (max-width: 1021px) 100vw, 1021px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">\uff082\uff09\u7f16\u5199\u8282\u70b9\u4ee3\u7801<\/h3>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"563\" src=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-39-1024x563.png\" alt=\"\" class=\"wp-image-452\" style=\"aspect-ratio:1.8188584768413574;width:782px;height:auto\" srcset=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-39-1024x563.png 1024w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-39-300x165.png 300w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-39-768x422.png 768w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-39.png 1287w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\u610f\uff1alidar_data.cpp\u5728\u6587\u4ef6\u5939src\u4e0b\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2\u3001\u8bbe\u7f6e\u7f16\u8bd1\u89c4\u5219<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u8282\u70b9\u6e90\u7801\u7684\u7f16\u8bd1\u89c4\u5219\u5199\u5728lidar_pkg\u7684CMakeList.txt\u6587\u4ef6\u91cc\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"956\" height=\"432\" src=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-40.png\" alt=\"\" class=\"wp-image-453\" style=\"aspect-ratio:2.212983163874367;width:680px;height:auto\" srcset=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-40.png 956w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-40-300x136.png 300w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-40-768x347.png 768w\" sizes=\"auto, (max-width: 956px) 100vw, 956px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">3\u3001\u4fee\u6539\u8f6f\u4ef6\u5305\u4fe1\u606f<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"542\" src=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/\u7c98\u8d34\u7684\u56fe\u50cf-5.png\" alt=\"\" class=\"wp-image-454\" style=\"aspect-ratio:1.5959625946266884;width:580px;height:auto\" srcset=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/\u7c98\u8d34\u7684\u56fe\u50cf-5.png 865w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/\u7c98\u8d34\u7684\u56fe\u50cf-5-300x188.png 300w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/\u7c98\u8d34\u7684\u56fe\u50cf-5-768x481.png 768w\" sizes=\"auto, (max-width: 865px) 100vw, 865px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">4\u3001\u7f16\u8bd1\u8f6f\u4ef6\u5305<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"335\" height=\"224\" src=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-41.png\" alt=\"\" class=\"wp-image-455\" srcset=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-41.png 335w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-41-300x201.png 300w\" sizes=\"auto, (max-width: 335px) 100vw, 335px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">hh \u5728\u5de5\u4f5c\u73af\u5883\u7684\u4e09\u4e2a\u8f6f\u4ef6\u5305\u90fd\u88ab\u7f16\u8bd1\u4e86\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u56db\u3001\u9879\u76ee\u6709\u5173\/scan\u67b6\u6784<\/h1>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"769\" src=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-44-1024x769.png\" alt=\"\" class=\"wp-image-459\" style=\"aspect-ratio:1.3316159714653721;width:643px;height:auto\" srcset=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-44-1024x769.png 1024w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-44-300x225.png 300w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-44-768x577.png 768w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-44.png 1447w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\">\u4e94\u3001\u57fa\u4e8e\u6fc0\u5149\u96f7\u8fbe\u7684\u907f\u969c\u5b9e\u73b0<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u907f\u969c\u7a0b\u5e8f\u539f\u7406\u3002\u7a0b\u5e8f\u4f1a\u8ba2\u9605\u6fc0\u5149\u96f7\u8fbe\u6570\u636e\u7684\u201c\/scan\u201d\u8bdd\u9898\uff0c\u4ece\u4e2d\u63a5\u6536\u6fc0\u5149\u96f7\u8fbe\u8282\u70b9\u53d1\u6765\u7684sensor_msgs::LaserScan\u7c7b\u578b\u6d88\u606f\u5305\uff0c\u5e76\u89e3\u6790\u51fa\u96f7\u8fbe\u6d4b\u8ddd\u503c\u3002\u6839\u636e\u96f7\u8fbe\u6d4b\u8ddd\u503c\u8ba9\u673a\u5668\u4eba\u505a\u51fa\u53cd\u5e94\uff1a\u524d\u65b9\u6ca1\u6709\u969c\u788d\u7269\u5c31\u524d\u8fdb\uff0c\u524d\u65b9\u9047\u5230\u969c\u788d\u7269\u5c31\u8f6c\u5411\u3002\u5c06\u6839\u636e\u6d4b\u8ddd\u503c\u8ba1\u7b97\u51fa\u6765\u7684\u901f\u5ea6\u503c\u6253\u5305\u6210geometry_msgs::Twist\u7c7b\u578b\u7684\u6d88\u606f\u5305\uff0c\u53d1\u5e03\u5230\u201c\/cmd_vel\u201d\u8bdd\u9898\u4e2d\u3002\u673a\u5668\u4eba\u5e95\u76d8\u8282\u70b9\u4f1a\u4ece\u201c\/cmd_vel\u201d\u8bdd\u9898\u83b7\u53d6\u901f\u5ea6\u6570\u503c\u5e76\u6267\u884c\uff0c\u4ee5\u6b64\u6765\u5b9e\u73b0\u673a\u5668\u4eba\u7684\u907f\u969c\u884c\u4e3a\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"616\" src=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-45-1024x616.png\" alt=\"\" class=\"wp-image-461\" style=\"width:677px;height:auto\" srcset=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-45-1024x616.png 1024w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-45-300x181.png 300w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-45-768x462.png 768w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-45.png 1075w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">1\u3001\u7f16\u5199\u6fc0\u5149\u96f7\u8fbe\u907f\u969c\u7a0b\u5e8f<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"683\" src=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-46-1024x683.png\" alt=\"\" class=\"wp-image-462\" style=\"aspect-ratio:1.4992888417882142;width:684px;height:auto\" srcset=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-46-1024x683.png 1024w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-46-300x200.png 300w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-46-768x512.png 768w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-46.png 1536w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;rclcpp\/rclcpp.hpp&gt;\n#include &lt;sensor_msgs\/msg\/laser_scan.hpp&gt;\n#include &lt;geometry_msgs\/msg\/twist.hpp&gt;\n\nstd::shared_ptr&lt;rclcpp::Node&gt; node;\n\/\/ \u53d1\u9001\u901f\u5ea6\u6307\u4ee4\u7684\u53d1\u5e03\u8005\nrclcpp::Publisher&lt;geometry_msgs::msg::Twist&gt;::SharedPtr cmd_vel_pub;\n\n\/\/ \u5bf9\u673a\u5668\u4eba\u8f6c\u5411\u65f6\u95f4\u8fdb\u884c\u8ba1\u6570\nint nCount = 0;\n\nvoid LidarCallback(const sensor_msgs::msg::LaserScan::SharedPtr msg)\n{\n    int nNum = msg-&gt;ranges.size(); \/\/ \u83b7\u53d6\u6fc0\u5149\u96f7\u8fbe\u626b\u63cf\u6570\u636e\u7684\u6570\u91cf\n    int nMid = nNum \/ 2; \/\/ \u8ba1\u7b97\u4e2d\u95f4\u7d22\u5f15\n    float fMidRange = msg-&gt;ranges&#91;nMid]; \/\/ \u83b7\u53d6\u4e2d\u95f4\u7d22\u5f15\u5bf9\u5e94\u7684\u8ddd\u79bb\u503c\n    RCLCPP_INFO(node-&gt;get_logger(), \"Mid Range: %f\", fMidRange); \/\/ \u6253\u5370\u4e2d\u95f4\u8ddd\u79bb\u503c\n\n    if (nCount &gt; 0)\n    {\n        nCount--;\n        return;\n    }\n\n    geometry_msgs::msg::Twist cmd_vel_msg;\n    if (fMidRange &lt; 1.5f) \/\/ \u5982\u679c\u4e2d\u95f4\u8ddd\u79bb\u5c0f\u4e8e1.5\u7c73\uff0c\u8868\u793a\u524d\u65b9\u6709\u969c\u788d\u7269\n    {\n        cmd_vel_msg.angular.z = 0.3; \/\/ \u8bbe\u7f6e\u89d2\u901f\u5ea6\u4e3a0.5\u5f27\u5ea6\/\u79d2\uff0c\u5411\u5de6\u8f6c\n        nCount = 100; \/\/ \u8bbe\u7f6e\u8ba1\u6570\u5668\uff0c\u8868\u793a\u9700\u8981\u8f6c\u5411\u7684\u65f6\u95f4\n    }\n    else\n    {\n        cmd_vel_msg.linear.x = 0.1; \/\/ \u8bbe\u7f6e\u7ebf\u901f\u5ea6\u4e3a0.1\u7c73\/\u79d2\uff0c\u5411\u524d\u79fb\u52a8\n    }\n    cmd_vel_pub-&gt;publish(cmd_vel_msg);\n}\n\nint main(int argc, char *argv&#91;])\n{\n    rclcpp::init(argc, argv); \/\/ \u521d\u59cb\u5316ROS2\u5ba2\u6237\u7aef\u5e93\n    node = std::make_shared&lt;rclcpp::Node&gt;(\"lidar_behavior_node\"); \/\/ \u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u201clidar_behavior_node\u201d\u7684\u8282\u70b9\n    \n    \/\/ \u521b\u5efa\u4e00\u4e2a\u53d1\u5e03\u8005\uff0c\u53d1\u5e03\u540d\u4e3a\u201c\/cmd_vel\u201d\u7684\u901f\u5ea6\u6307\u4ee4\u8bdd\u9898\n    cmd_vel_pub = node-&gt;create_publisher&lt;geometry_msgs::msg::Twist&gt;(\"\/cmd_vel\", 10);\n\n    auto subscription = node-&gt;create_subscription&lt;sensor_msgs::msg::LaserScan&gt;(\n        \"\/scan\", 10, LidarCallback); \/\/ \u521b\u5efa\u4e00\u4e2a\u8ba2\u9605\u8005\uff0c\u8ba2\u9605\u540d\u4e3a\u201c\/scan\u201d\u7684\u6fc0\u5149\u96f7\u8fbe\u626b\u63cf\u6570\u636e\u8bdd\u9898\uff0c\u5e76\u6307\u5b9a\u56de\u8c03\u51fd\u6570\n\n    rclcpp::spin(node); \/\/ \u8fdb\u5165\u5faa\u73af\uff0c\u7b49\u5f85\u56de\u8c03\u51fd\u6570\u88ab\u89e6\u53d1\n    rclcpp::shutdown(); \/\/ \u5173\u95edROS2\u5ba2\u6237\u7aef\u5e93\n    return 0; \/\/ \u8fd4\u56de0\u8868\u793a\u7a0b\u5e8f\u6b63\u5e38\u7ed3\u675f\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u7a0b\u5e8f\u903b\u8f91\u56fe\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"683\" src=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-47-1024x683.png\" alt=\"\" class=\"wp-image-464\" style=\"aspect-ratio:1.4992888417882142;width:692px;height:auto\" srcset=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-47-1024x683.png 1024w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-47-300x200.png 300w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-47-768x512.png 768w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-47.png 1536w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">2\u3001\u8bbe\u7f6e\u7f16\u8bd1\u89c4\u5219<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"641\" height=\"347\" src=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-48.png\" alt=\"\" class=\"wp-image-466\" style=\"aspect-ratio:1.84729697547035;width:539px;height:auto\" srcset=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-48.png 641w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-48-300x162.png 300w\" sizes=\"auto, (max-width: 641px) 100vw, 641px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">3\u3001\u4fee\u6539\u8f6f\u4ef6\u5305\u4fe1\u606f<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"399\" height=\"27\" src=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-49.png\" alt=\"\" class=\"wp-image-467\" srcset=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-49.png 399w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-49-300x20.png 300w\" sizes=\"auto, (max-width: 399px) 100vw, 399px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">4\u3001\u7f16\u8bd1\u8f6f\u4ef6\u5305<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"343\" height=\"241\" src=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-50.png\" alt=\"\" class=\"wp-image-468\" srcset=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-50.png 343w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-50-300x211.png 300w\" sizes=\"auto, (max-width: 343px) 100vw, 343px\" \/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\">\u516d\u3001\u9879\u76ee\u6709\u5173\u907f\u969c\u67b6\u6784PLAN<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6838\u5fc3\uff1aPi\u540e\u7aef\u4e0d\u9700\u8981 \/scan\uff0c\u5b83\u6709\u7684\u662f\u539f\u59cb\u6570\u636e\u3002<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-51-1024x576.png\" alt=\"\" class=\"wp-image-469\" style=\"aspect-ratio:1.77683765203596;width:696px;height:auto\" srcset=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-51-1024x576.png 1024w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-51-300x169.png 300w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-51-768x432.png 768w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-51-1536x864.png 1536w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/09\/image-51.png 1672w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th class=\"has-text-align-left\" data-align=\"left\">\u907f\u969c\u8981\u505a\u7684\u4e8b<\/th><th class=\"has-text-align-left\" data-align=\"left\">\u5728 ROS \u91cc\u5bf9\u5e94\u4ec0\u4e48<\/th><th class=\"has-text-align-left\" data-align=\"left\">\u5728\u6211\u7684\u540e\u7aef\u91cc\u5bf9\u5e94\u4ec0\u4e48<\/th><\/tr><\/thead><tbody><tr><td class=\"has-text-align-left\" data-align=\"left\">\u62ff\u5230\u626b\u63cf\u6570\u636e<\/td><td class=\"has-text-align-left\" data-align=\"left\">\u8ba2\u9605 \/scan<\/td><td class=\"has-text-align-left\" data-align=\"left\">lidar_controller.latest_revolution()<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">\u89e3\u6790\u51fa\u8ddd\u79bb<\/td><td class=\"has-text-align-left\" data-align=\"left\">\u89e3\u6790\u6d88\u606f\u91cc\u7684\u6570\u7ec4<\/td><td class=\"has-text-align-left\" data-align=\"left\">frame[&#8216;pts&#8217;] \u91cc\u5c31\u662f [\u89d2\u5ea6, \u8ddd\u79bb, \u8d28\u91cf]<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">\u8f93\u51fa\u901f\u5ea6\u6307\u4ee4<\/td><td class=\"has-text-align-left\" data-align=\"left\">\u53d1\u5e03 \/cmd_vel\uff08\u673a\u5668\u4eba\u8282\u70b9\u62ff\u5230\u540e\uff0c\u7f16\u5199\u9a71\u52a8\u7535\u673a\u7a0b\u5e8f\uff0c\u5b9e\u73b0\u907f\u969c\u3002\uff09<\/td><td class=\"has-text-align-left\" data-align=\"left\">motor_controller.drive(angle, speed)\uff08drive\u51fd\u6570\u76f4\u63a5\u7f16\u5199\u9a71\u52a8\u7535\u673a\u7a0b\u5e8f\uff0c\u5b9e\u73b0\u907f\u969c\u3002\uff09<\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001ROS2\u4e2d\u7684\u6fc0\u5149\u96f7\u8fbe\u6570\u636e 1\u3001\u6fc0\u5149\u96f7\u8fbe\u7684\u8bdd\u9898\u540d\u79f0 ROS2\u4e2d\u7684\u6fc0\u5149\u96f7\u2026<\/p>\n","protected":false},"author":1,"featured_media":471,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,8,3],"tags":[],"class_list":["post-447","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-slam","category-8","category-3"],"_links":{"self":[{"href":"https:\/\/geocommunity.vip\/index.php\/wp-json\/wp\/v2\/posts\/447","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/geocommunity.vip\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/geocommunity.vip\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/geocommunity.vip\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/geocommunity.vip\/index.php\/wp-json\/wp\/v2\/comments?post=447"}],"version-history":[{"count":8,"href":"https:\/\/geocommunity.vip\/index.php\/wp-json\/wp\/v2\/posts\/447\/revisions"}],"predecessor-version":[{"id":475,"href":"https:\/\/geocommunity.vip\/index.php\/wp-json\/wp\/v2\/posts\/447\/revisions\/475"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/geocommunity.vip\/index.php\/wp-json\/wp\/v2\/media\/471"}],"wp:attachment":[{"href":"https:\/\/geocommunity.vip\/index.php\/wp-json\/wp\/v2\/media?parent=447"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/geocommunity.vip\/index.php\/wp-json\/wp\/v2\/categories?post=447"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/geocommunity.vip\/index.php\/wp-json\/wp\/v2\/tags?post=447"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}