scanConverter.cpp
Go to the documentation of this file.
00001 #include <math.h>
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 #include <ros/ros.h>
00005 
00006 #include <sensor_msgs/LaserScan.h>
00007 
00008 #include "pointDefinition.h"
00009 
00010 const double PI = 3.1415926;
00011 
00012 const double minAngle = -1.57079637051;
00013 const double increAngle = 0.00436332309619;
00014 const int increNum = 720;
00015 
00016 pcl::PointCloud<pcl::PointXYZ>::Ptr syncCloud(new pcl::PointCloud<pcl::PointXYZ>());
00017 ros::Publisher *syncCloudPubPointer = NULL;
00018 
00019 void laserDataHandler(const sensor_msgs::LaserScan::ConstPtr& laserData)
00020 {
00021   pcl::PointXYZ point;
00022   syncCloud->clear();
00023   for (int i = 0; i < increNum; i++) {
00024     double angle = minAngle + increAngle * i;
00025     point.x = laserData->ranges[i] * sin(angle);
00026     point.y = 0;
00027     point.z = laserData->ranges[i] * cos(angle);
00028 
00029     syncCloud->push_back(point);
00030   }
00031 
00032   syncCloud->header.frame_id = "camera2";
00033   syncCloud->header.stamp = laserData->header.stamp;
00034   sensor_msgs::PointCloud2 syncCloud2;
00035   pcl::toROSMsg(*syncCloud, syncCloud2);
00036   syncCloudPubPointer->publish(syncCloud2);
00037 }
00038 
00039 int main(int argc, char** argv)
00040 {
00041   ros::init(argc, argv, "scanConverter");
00042   ros::NodeHandle nh;
00043 
00044   ros::Subscriber laserDataSub = nh.subscribe<sensor_msgs::LaserScan> ("/scan", 5, laserDataHandler);
00045 
00046   ros::Publisher syncCloudPub = nh.advertise<sensor_msgs::PointCloud2> ("/sync_scan_cloud_filtered", 5);
00047   syncCloudPubPointer = &syncCloudPub;
00048 
00049   ros::spin();
00050 
00051   return 0;
00052 }


demo_lidar
Author(s): Ji Zhang
autogenerated on Fri Jan 3 2014 11:17:40