在ROS中点云的数据类型在ROS中表示点云的数据结构有: sensor_msgs::PointCloud sensor_msgs::PointCloud2 pcl::PointCloud关于PCL在ros的数据的结构,具体的介绍可查 看 wiki.ros.org/pcl/Overview关于sensor_msgs::PointCloud2 和 pcl::PointCloud之间的转换使用pcl::fromROSMsg 和 pcl::toROSMsg sensor_msgs::PointCloud 和 sensor_msgs::PointCloud2之间的转换使用sensor_msgs::convertPointCloud2ToPointCloud 和sensor_msgs::convertPointCloudToPointCloud2.那么如何在ROS中使用PCL呢?
(1)在建立的包下的CMakeLists.txt文件下添加依赖项在package.xml文件里添加:<build_depend>libpcl-all-dev</build_depend>
<run_depend>libpcl-all</run_depend>在src文件夹下新建.cpp文件
#include <ros/ros.h>
// PCL specific includes
#include <sensor_msgs/PointCloud2.h>
#include <pcl_conversions/pcl_conversions.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
ros::Publisher pub;
void
cloud_cb (const sensor_msgs::PointCloud2ConstPtr& input)
{
// Create a container for the data.
sensor_msgs::PointCloud2 output;
// Do data processing here…
output = *input;
// Publish the data.
pub.publish (output);
}
int
main (int argc, char** argv)
{
// Initialize ROS
ros::init (argc, argv, “my_pcl_tutorial”);
ros::NodeHandle nh;
ros::Subscriber sub = nh.subscribe (“input”, 1, cloud_cb);
pub = nh.advertise<sensor_msgs::PointCloud2> (“output”, 1);
// Spin
ros::spin ();
}在 CMakeLists.txt 文件中添加: add_executable(example src/example.cpp)
target_link_libraries(example ${catkin_LIBRARIES})catkin_make之后生成可执行文件,运行以下命令 roslaunch openni_launch openni.launch 这是打开kinect发布的命令
$ rosrun ros_slam example input:=/camera/depth/points //运行我们生成的文件
运行RV