hanshuning的专栏

说你想说的话,做你想做的事 你不应为落井下石者暗自苦恼 而应为那些爱你的人努力向上 就算孤独如荒原狼 一个人也要像一支队伍一样 不气馁,有态度,爱自由...

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

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


阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hanshuning/article/details/52346189
个人分类: PCL ROS
上一篇ubuntu_Light Table字体及相关设置及使用
下一篇ROS_PCl_加载PCD点云数据文件与接收点云并保存
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭