#include <sensor_msgs/LaserScan.h>
void callback(const sensor_msgs::LaserScan& msg)
{
size_t size = msg.ranges.size();
double min_distance = 1.5;//避障距离1.5米
for (unsigned int i = 0; i < size; ++i)
{
if (msg.ranges[i] < min_distance) {
return;
}
}
}
int main(int argc, char** argv)
{
ros::init(argc, argv, "scan_node"); //初始化节点
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("/scan", 1, callback); //订阅话题
ros::Duration(1.0).sleep();
ros::spin();
return 0;
}
ROS-订阅激光数据
最新推荐文章于 2024-06-06 17:55:57 发布