获取激光雷达数据

从激光雷达获得距离

搭建turtlebot仿真环境
下载

sudo apt-get install ros-kinetic-turtlebot*

配置环境

sudo apt-get install ros-kinetic-joy*

将turtlebot包复制到已有工程后,编译

catkin_make

测试

roslaunch turtlebot_gazebo turtlebot_world.launch
激光雷达

性能指标参考链接
ROS中雷达的数据格式使用rosmsg show sensor_msgs/LaserScan查看
数据结构如下:

std_msgs/Header header
//ros中典型的头文件,由,seq,时间戳,id构成
angle-min:
//开始扫描的角度
angle-max:
//结束扫描的角度
angle-increment:
//每次扫描增加的角度
time-increment: 
//测量的时间间隔
scan-time 
//扫描的时间间隔
range-min
//测距的最小值
range-max
//测距的最大值
ranges:
//ranges是一个浮点数组,每个数组成员代表着激光传感器返回的距离
//转一周的测量数据一共360个
//ranges,intensities数组大小应该是根据 angle_min: angle_max: 
//angle_increment: 0.0174532923847 算出来的个数,并不是固定长度。
//size = (angle_max-angle_min)/angle_increment
intensities:
//与设备有关,强度数组长度360

见下图(来自于参考链接):
获取激光雷达数据_第1张图片
使用

rostopic echo /scan -n1

查看传感器数据如下:

header: 
  seq: 65
  stamp: 
    secs: 368
    nsecs: 280000000
  frame_id: "/camera_depth_frame"
angle_min: -0.521567881107
angle_max: 0.524276316166
angle_increment: 0.00163668883033
time_increment: 0.0
scan_time: 0.0329999998212
range_min: 0.449999988079
range_max: 10.0
ranges: [nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, 1.290791392326355, 1.289928674697876, 1.2890713214874268, 1.2882193326950073, 1.2873724699020386, 1.2865309715270996, 1.2856947183609009, 1.2848633527755737, 1.2840372323989868, 1.2864514589309692, 1.2912418842315674, 1.2960647344589233, 1.300920844078064, 1.3058099746704102, 1.3107328414916992, 1.3156895637512207, 1.3206802606582642, 1.330765962600708, 1.335861325263977, 1.3409922122955322, 1.3461588621139526, 1.351361632347107, 1.3566008806228638, 1.361877202987671, 1.3671903610229492, 1.3725413084030151, 1.3779300451278687, 1.383357286453247, 1.38882315158844, 1.3998721837997437, 1.4054561853408813, 1.411080241203308, 1.4167450666427612, 1.4224507808685303, 1.4281978607177734, 1.4339866638183594, 1.4398177862167358, 1.4456913471221924, 1.4516080617904663, 1.463572382926941, 1.4696208238601685, 1.475714087486267, 1.481852650642395, 1.488036870956421, 1.494267463684082, 1.500544548034668, 1.5068689584732056, 1.5196610689163208, 1.526129961013794, 1.532647967338562, 1.5392156839370728, 1.5458334684371948, 1.552502155303955, 1.5592221021652222, 1.5659937858581543, 1.579695224761963, 1.5866259336471558, 1.5936105251312256, 1.6006501913070679, 1.6077449321746826, 1.6148957014083862, 1.622102975845337, 1.63668954372406, 1.6440702676773071, 1.6515098810195923, 1.6554276943206787, 1.6547038555145264, 1.6532713174819946, 1.6525623798370361, 1.6518583297729492, 1.6511592864990234, 1.6504650115966797, 1.6497756242752075, 1.6484113931655884, 1.6477361917495728, 1.6470659971237183, 1.6464004516601562, 1.6457396745681763, 1.6444319486618042, 1.6437851190567017, 1.643142819404602, 1.6425050497055054, 1.6418719291687012, 1.6412433385849, 1.6399997472763062, 1.6393845081329346, 1.6387739181518555, 1.6381676197052002, 1.6375658512115479, 1.6369683742523193]
intensities: []
激光雷达测距原理

1.三角测距参考链接
激光照射到被测物体表面后产生反射,反射光通过光学透镜成像在CCD传感器上。
获取激光雷达数据_第2张图片
2 TOF测距
激光器发射一个激光脉冲,并由计时器记录下发出的时间,回返光由接收器接收并距离下时间,两个时间相减,得到“飞行时间”,再由光速计算出距离。

订阅雷达数据

代码如下,

#include "ros/ros.h"
#include 
#include    
#include 


void laserCallback(const sensor_msgs::LaserScan::ConstPtr& msg)
{
    std::vector ranges=msg->ranges;
    std::cout<< ranges.size()<<" ";

    std::cout<< msg->header.stamp<<" ";
    std::cout<< msg->header.frame_id<<" ";
    std::cout<< msg->angle_min<<" ";
    std::cout<< msg->angle_max<<" ";
	std::cout<< msg->angle_increment<<" ";
	std::cout<< msg->time_increment<<" ";
	std::cout<< "dis_ranges:"<<  msg->range_min<<" ";
	std::cout<< msg->range_max<<" ";
	std::cout<< msg->ranges[0]<<" ";
    std::cout<<"\n";
}
int main(int argc, char **argv)
{

    ros::init(argc, argv, "sub_laser");
    ros::NodeHandle nh;
    ros::Subscriber sub = nh.subscribe("/scan", 1, laserCallback);
    ros::spin();

    return 0;
}

再修改Cmakelist.txt和Package.xml,将sensor_message 和cpp文件加入。步骤略。

你可能感兴趣的:(学习)