ROS 可视化(一): 发布PointCloud2点云数据到Rviz
生活随笔
收集整理的這篇文章主要介紹了
ROS 可视化(一): 发布PointCloud2点云数据到Rviz
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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 <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";
ros::Rate loop_rate(1);
while (ros::ok())
{
pcl_pub.publish(output);
ros::spinOnce();
loop_rate.sleep();
}
return 0;
}
總結
以上是生活随笔為你收集整理的ROS 可视化(一): 发布PointCloud2点云数据到Rviz的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php Spreadsheet 导出,P
- 下一篇: linux加密框架 crypto 通用算