原創博客:轉載請表明出處:http://www.cnblogs.com/zxouxuewei/
前提:
1.本教程確保你已經成功安裝了kinect 或者xtion深度相機的驅動,能夠正常使用。驅動安裝可參考我的博客http://www.cnblogs.com/zxouxuewei/p/5271939.html
2.你已經具有一台能夠手動或者自動移動的平台,將你的深度相機真確安裝在移動平台上。(如下圖片是我自己制作的移動平台,以后會對接口做詳細的描述)
一。使用kinect深度相機將點雲數據轉換為激光數據
1.下載源碼測試源碼,pointcloud_to_laserscan:https://github.com/ros-perception/pointcloud_to_laserscan
2.解壓到你的ros工作空間路徑中。
3.使用catkin_make編譯功能包。
4.功能包路徑:ROS_PACKAGE_PATH=/root/catkin_rs/src/pointcloud_laserscan:$ROS_PACKAGE_PATH
5.分析launch文件,修改使其在自己的平台上可用。(修改以下提示)
<?xml version="1.0"?> <launch> <arg name="camera" default="camera" /> <!-- start sensor--> <include file="$(find openni_launch)/launch/openni.launch"> #由於我們使用的kinect,openni2已近不支持了。所以用openni <arg name="camera" default="$(arg camera)"/> </include> <!-- run pointcloud_to_laserscan node --> <node pkg="pointcloud_to_laserscan" type="pointcloud_to_laserscan_node" name="pointcloud_to_laserscan"> #節點名稱可以更改為自己想要的 <remap from="cloud_in" to="$(arg camera)/depth_registered/points_processed"/> #話題名稱也可以更改,不過在rviz中要明白該訂閱那個話題 <remap from="scan" to="$(arg camera)/scan"/> <rosparam> target_frame: camera_link transform_tolerance: 0.01 min_height: 0.0 max_height: 1.0 angle_min: -1.5708 # -M_PI/2 angle_max: 1.5708 # M_PI/2 angle_increment: 0.087 # M_PI/360.0 scan_time: 0.3333 range_min: 0.45 range_max: 4.0 use_inf: true # Concurrency level, affects number of pointclouds queued for processing and number of threads used # 0 : Detect number of cores # 1 : Single threaded # 2->inf : Parallelism level concurrency_level: 1 </rosparam> </node> </launch>
分析:首先啟動openni_launch中的深度相機。定義節點名稱為:pointcloud_to_laserscan。發布話題的名稱定義等等;
6.運行launch文件 啟動深度相機節點:
roslaunch pointcloud_to_laserscan sample_node.launch(如果有如下信息,證明是正常的)
[ INFO] [1458635459.179868847]: Initializing nodelet with 4 worker threads. [ INFO] [1458635462.234383165]: Number devices connected: 1 [ INFO] [1458635462.234515193]: 1. device on bus 001:28 is a SensorKinect (2ae) from PrimeSense (45e) with serial id 'A00366803996050A' [ INFO] [1458635462.235427900]: Searching for device with index = 1 [ INFO] [1458635462.415296355]: Opened 'SensorKinect' on bus 1:28 with serial number 'A00366803996050A' [ INFO] [1458635462.973510398]: rgb_frame_id = 'camera_rgb_optical_frame' [ INFO] [1458635462.973599301]: depth_frame_id = 'camera_depth_optical_frame'
7.在rviz視圖中查看點雲以及仿的激光數據:
rviz
8.查看節點圖
rqt_graph
二.利用深度相機仿激光數據創建地圖
1.下載hector_slam_example:下載地址,編譯(cmake)好之后,記住需要將這個文件加入ros工作空間路徑中。 2.
Install the dependency packages:
rosdep install hector_slam_example
3.在啟動之前如果你用的是kinect,那就請你修改一下launch文件吧。
<include file="$(find openni_launch)/launch/openni.launch"> #由於我們使用的kinect,openni2已近不支持了。所以用openni
然后就是oslaunch
roslaunch hector_slam_example hector_openni.launch
只需要讓移動平台移動就可以去構建地圖了,當然這里面用的生成模擬激光的方法是depthimage_to_laserscan節點,但是要求KINECT要相對穩定,並且盡量水平放置。
4.查看節點:
rqt_graph