ROS kinetic环境使用Realsense D435i获取三维点云并存为.pcd文件
- 使用的环境为ubuntu16.04,AMD64。配置arm架构工控机环境的话,最好另外找资源。
二进制安装D435的SDK
下载intel Realsense ROS工作空间
- 下载的版本号需要与intel Realsense SDK的版本号对应
- 下载链接:版本说明及下载。找到Assets点击source code下载工作空间。
- 通过realsense-viewer查看SDK的版本号,终端输入以下指令,启动可视化软件,比如我的软件左上角为intel realsense viewer V 2.43.0,表示版本号为2.43.0(具体版本号需要自己去查看)。
realsense-viewer
- 下载的source code放到home目录下的catkin_realsense中,若没有则自己新建。
- 注意:当编译工作空间不通过时,若提示缺少ddynamic-reconfigur,可通过以下方式安装
sudo apt install ros-kinetic-ddynamic-reconfigure
ROS下驱动D435i获得点云
- 编译完工作空间以后,需要将环境环境加入到**.bashrc**文件中。
echo "source ~/catkin_realsense/devel/setup.bash" >> ~/.bashrc
sudo apt install ros-kinetic-rgbd-launch
roslaunch realsense2_camera rs_rgbd.launch
订阅点云话题并保存为.pcd文件
- 订阅 /camera/depth_registered/points话题的信息,拿来后处理就行
#include <ros/ros.h>
#include <sensor_msgs/PointCloud2.h>
#include <pcl_conversions/pcl_conversions.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/PCLPointCloud2.h>
#include <pcl/filters/voxel_grid.h>
#include <iostream>
using namespace std;
ros::Publisher pub;
void cloud_cb (const sensor_msgs::PointCloud2ConstPtr& cloud_msg)
{
pcl::PCLPointCloud2* cloud = new pcl::PCLPointCloud2;
pcl::PCLPointCloud2ConstPtr cloudPtr(cloud);
pcl::PCLPointCloud2 cloud_filtered;
pcl::io::savePCDFile("./pointcloud_init.pcd", *cloud_msg);
cout<<"publish point_cloud height = "<<cloud_msg->height<<endl;
cout<<"publish point_cloud width = "<<cloud_msg->width<<endl;
}
int main (int argc, char** argv)
{
ros::init (argc, argv, "VoxelGrid");
ros::NodeHandle nh;
ros::Subscriber sub = nh.subscribe<sensor_msgs::PointCloud2> ("/camera/depth_registered/points", 1, cloud_cb);
ros::spin ();
}
使用plc_tool查看pcd文件
sudo apt install pcl-tools
- 终端输入以下指令,查看xxx.pcd文件,xxx为自己的文件名
pcl_viewer xxx.pcd
我的工作空间和代码更新链接