scan_to_pcl.cpp
Go to the documentation of this file.
00001 #include <iostream>
00002 #include <fstream>
00003 #include <chrono>
00004 #include <algorithm>
00005 #include <iterator>
00006 
00007 #include <pcl/point_types.h>
00008 #include <sensor_msgs/PointCloud2.h>
00009 #include <pcl_conversions/pcl_conversions.h>
00010 #include <tf/transform_listener.h>
00011 #include "pcl_ros/transforms.h"
00012 
00013 #include <ros/ros.h>
00014 #include <pcl_ros/point_cloud.h>
00015 #include <visualization_msgs/Marker.h>
00016 #include <geometry_msgs/Pose.h>
00017 #include <tf/transform_broadcaster.h>
00018 #include "laser_geometry/laser_geometry.h"
00019 
00020 
00021 using namespace std;
00022 // using namespace std::chrono;
00023 
00024 ros::Publisher pcl_from_scan;
00025 
00026 typedef pcl::PointCloud<pcl::PointXYZ> PointCloud;
00027 laser_geometry::LaserProjection projector;
00028 
00029 void hokuyo_callbacks(const sensor_msgs::LaserScan::ConstPtr& scan_in)
00030 {
00031     sensor_msgs::PointCloud2 cloud;
00032     projector.projectLaser(*scan_in, cloud);
00033 
00034     // Publish the new point cloud.
00035     cloud.header.frame_id = "/laser";
00036     cloud.header.stamp = scan_in->header.stamp;
00037     pcl_from_scan.publish(cloud);
00038 }
00039 
00040 int main(int argc, char **argv) {
00041     ros::init(argc, argv, "laserScan_to_pointcloud");
00042     ros::NodeHandle nh;
00043 
00044     ros::Subscriber hokuyo_sub;
00045     hokuyo_sub = nh.subscribe<sensor_msgs::LaserScan>("/hokuyo_filtered", 1, hokuyo_callbacks);
00046 
00047     
00048     pcl_from_scan = nh.advertise<PointCloud>("hokuyo_points", 1);
00049 
00050     while (ros::ok())
00051     {
00052         ros::spin();
00053     }
00054 
00055     nh.shutdown();          
00056     return 0;
00057 }


spin_hokuyo
Author(s):
autogenerated on Sat Jun 8 2019 20:41:35