rviz可视化点云_ROS_PCL+Rviz创建点云并三维显示

1.程序包的配置等参照 第一个PCL程序

2.代码.cpp

#include#include#include#includemain (int argc, char **argv)

{

ros::init (argc, argv, "pcl_create");

ros::NodeHandle nh;

ros::Publisher pcl_pub = nh.advertise("pcl_output", 1);

pcl::PointCloudcloud;

sensor_msgs::PointCloud2 output;

// Fill in the cloud data

cloud.width = 100;

cloud.height = 1;

cloud.points.resize(cloud.width * cloud.height);

for (size_t i = 0; i < cloud.points.size(); ++i)

{

cloud.points[i].x = 1024 * rand () / (RAND_MAX + 1.0f);

cloud.points[i].y = 1024 * rand () / (RAND_MAX + 1.0f);

cloud.points[i].z = 1024 * rand () / (RAND_MAX + 1.0f);

}

//Convert the cloud to ROS message

pcl::toROSMsg(cloud, output);

output.header.frame_id = "odom";//this has been done in order to be able to visualize our PointCloud2 message on the RViz visualizer

ros::Rate loop_rate(1);

while (ros::ok())

{

pcl_pub.publish(output);

ros::spinOnce();

loop_rate.sleep();

}

return 0;

}

3.编译

cd catkin_ws

source devel/setup.bash

catkin_make

4.运行

roscore

rosrun imgpcl pcl_create

rosrun rviz rviz

5.Rviz的配置

点击Add,添加pointcloud2,

Fixed  Frame设置为odom.

Topic 设置为/pcl_output

你可能感兴趣的:(rviz可视化点云)