rviz可视化点云_ROS 可视化(一): 发布PointCloud2点云数据到Rviz

本文介绍了如何在ROS环境中创建并发布PointCloud2类型的点云数据到rviz进行可视化。首先,需要在package.xml中添加对pcl_ros的依赖,并在CMakeLists.txt中配置相关库。然后,通过编写测试代码生成随机点云数据,将其转换为ROS消息类型,并使用ros::Publisher发布。最后,在rviz中订阅这个话题即可观察到点云的实时可视化效果。
摘要由CSDN通过智能技术生成

1. 相关依赖

package.xml 需要添加对 pcl_ros 包的依赖

2. CMakeLists.txt

find_package(PCL REQUIRED)

include_directories(include${PCL_INCLUDE_DIRS})

link_directories(${PCL_LIBRARY_DIRS})

add_executable(pcl_create src/pcl_create.cpp)

target_link_libraries(pcl_create ${catkin_LIBRARIES} ${PCL_LIBRARIES})

2. 测试代码

#include

#include

#include

#include

main (int argc, char **argv)

{

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

ros::NodeHandle nh;

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

pcl::PointCloud<: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";

ros::Rate loop_rate(1);

while (ros::ok())

{

pcl_pub.publish(output);

ros::spinOnce();

loop_rate.sleep();

}

return 0;

}

原文:https://www.cnblogs.com/lvchaoshun/p/9961112.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值