关闭

ROS_PCL+Rviz创建点云并三维显示

2248人阅读 评论(0) 收藏 举报
分类:

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

2.代码.cpp

#include<ros/ros.h>
#include<pcl/point_cloud.h>
#include<pcl_conversions/pcl_conversions.h>
#include<sensor_msgs/PointCloud2.h>

main (int argc, char **argv)
{
  ros::init (argc, argv, "pcl_create");
  ros::NodeHandle nh;
  ros::Publisher pcl_pub = nh.advertise<sensor_msgs::PointCloud2> ("pcl_output", 1);
  pcl::PointCloud<pcl::PointXYZ> cloud;
  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


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:258017次
    • 积分:4856
    • 等级:
    • 排名:第6258名
    • 原创:218篇
    • 转载:89篇
    • 译文:0篇
    • 评论:119条
    最新评论