利用深度攝像頭生成仿鐳射資料並構建地圖
阿新 • • 發佈:2019-02-09
前提:
1.本教程確保你已經成功安裝了kinect 或者xtion深度相機的驅動,能夠正常使用。驅動安裝可參考我的部落格http://www.cnblogs.com/zxouxuewei/p/5271939.html
2.你已經具有一臺能夠手動或者自動移動的平臺,將你的深度相機真確安裝在移動平臺上。(如下圖片是我自己製作的移動平臺,以後會對介面做詳細的描述)
一。使用kinect深度相機將點雲資料轉換為鐳射資料
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