Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00051 #include <string>
00052 #include <limits>
00053 #include <sensor_msgs/PointCloud2.h>
00054 #include <sensor_msgs/Range.h>
00055 #include <pcl_ros/point_cloud.h>
00056 #include "ranges_to_cloud.h"
00057
00058 namespace segbot_sensors
00059 {
00061 RangesToCloud::RangesToCloud(ros::NodeHandle node,
00062 ros::NodeHandle private_nh)
00063 {
00064
00065 points_ =
00066 node.advertise<sensor_msgs::PointCloud2>("range_points", 1);
00067
00068
00069 ranges_ =
00070 node.subscribe("sensor_ranges", 10,
00071 &RangesToCloud::processRanges, (RangesToCloud *) this,
00072 ros::TransportHints().tcpNoDelay(true));
00073 }
00074
00075 void RangesToCloud::processRanges(const segbot_sensors::RangeArray::ConstPtr
00076 &ranges_msg)
00077 {
00078 unsigned int nsensors = ranges_msg->ranges.size();
00079 ROS_DEBUG_STREAM("Received " << nsensors << " ranges");
00080 if (nsensors == 0)
00081 return;
00082
00083
00084 pcl::PointCloud<pcl::PointXYZ>::Ptr
00085 cloud(new pcl::PointCloud<pcl::PointXYZ>());
00086
00087 cloud->header.stamp =
00088 pcl_conversions::toPCL(ranges_msg->ranges[0].header).stamp;
00089 cloud->header.frame_id = "sensor_base";
00090 cloud->height = 1;
00091
00092
00093 for (int sensor = 0; sensor < nsensors; ++sensor)
00094 {
00095
00096 const sensor_msgs::Range *r = &ranges_msg->ranges[sensor];
00097 if (r->range < std::numeric_limits<float>::infinity())
00098 {
00099
00100 tf::StampedTransform transform;
00101 try
00102 {
00103 listener_.lookupTransform(cloud->header.frame_id,
00104 r->header.frame_id,
00105 ros::Time(0), transform);
00106 }
00107 catch (tf::TransformException ex)
00108 {
00109 ROS_WARN_STREAM(ex.what());
00110 continue;
00111 }
00112
00113 tf::Point pt(r->range, 0.0, 0.0);
00114 pt = transform * pt;
00115
00116 pcl::PointXYZ pcl_point;
00117 pcl_point.x = pt.m_floats[0];
00118 pcl_point.y = pt.m_floats[1];
00119 pcl_point.z = pt.m_floats[2];
00120 cloud->points.push_back(pcl_point);
00121 ++cloud->width;
00122 }
00123 }
00124
00125
00126 points_.publish(cloud);
00127 }
00128
00129
00130 };