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 #include <laser_proc/LaserProc.h>
00035
00036 using namespace laser_proc;
00037
00038 sensor_msgs::LaserScanPtr LaserProc::getFirstScan(const sensor_msgs::MultiEchoLaserScan& msg){
00039 sensor_msgs::LaserScanPtr out(new sensor_msgs::LaserScan());
00040 fillLaserScan(msg, *out);
00041 out->ranges.resize(msg.ranges.size());
00042 if(msg.ranges.size() == msg.intensities.size()){
00043 out->intensities.resize(msg.intensities.size());
00044 }
00045
00046 for(size_t i = 0; i < out->ranges.size(); i++){
00047 size_t index = getFirstValue(msg.ranges[i], out->ranges[i]);
00048 if(out->intensities.size() > 0){
00049 if(msg.intensities[i].echoes.size() > 0){
00050 out->intensities[i] = msg.intensities[i].echoes[index];
00051 } else {
00052 out->intensities[i] = 0.0;
00053 }
00054 }
00055 }
00056 return out;
00057 }
00058
00059 sensor_msgs::LaserScanPtr LaserProc::getLastScan(const sensor_msgs::MultiEchoLaserScan& msg){
00060 sensor_msgs::LaserScanPtr out(new sensor_msgs::LaserScan());
00061 fillLaserScan(msg, *out);
00062 out->ranges.resize(msg.ranges.size());
00063 if(msg.ranges.size() == msg.intensities.size()){
00064 out->intensities.resize(msg.intensities.size());
00065 }
00066 for(size_t i = 0; i < out->ranges.size(); i++){
00067 size_t index = getLastValue(msg.ranges[i], out->ranges[i]);
00068 if(out->intensities.size() > 0){
00069 if(msg.intensities[i].echoes.size() > 0){
00070 out->intensities[i] = msg.intensities[i].echoes[index];
00071 } else {
00072 out->intensities[i] = 0.0;
00073 }
00074 }
00075 }
00076 return out;
00077 }
00078
00079 sensor_msgs::LaserScanPtr LaserProc::getMostIntenseScan(const sensor_msgs::MultiEchoLaserScan& msg){
00080 sensor_msgs::LaserScanPtr out(new sensor_msgs::LaserScan());
00081 fillLaserScan(msg, *out);
00082 if(msg.ranges.size() == msg.intensities.size()){
00083 out->ranges.resize(msg.ranges.size());
00084 out->intensities.resize(msg.intensities.size());
00085 } else {
00086 std::stringstream ss;
00087 ss << "getMostIntenseScan::Size of ranges does not equal size of intensities, cannot create scan.";
00088 throw std::runtime_error(ss.str());
00089 }
00090 for(size_t i = 0; i < out->intensities.size(); i++){
00091 getMostIntenseValue(msg.ranges[i], msg.intensities[i], out->ranges[i], out->intensities[i]);
00092 }
00093 return out;
00094 }
00095
00096 void LaserProc::fillLaserScan(const sensor_msgs::MultiEchoLaserScan& msg, sensor_msgs::LaserScan& out){
00097 out.header = msg.header;
00098 out.angle_min = msg.angle_min;
00099 out.angle_max = msg.angle_max;
00100 out.angle_increment = msg.angle_increment;
00101 out.time_increment = msg.time_increment;
00102 out.scan_time = msg.scan_time;
00103 out.range_min = msg.range_min;
00104 out.range_max = msg.range_max;
00105 }
00106
00108 size_t LaserProc::getFirstValue(const sensor_msgs::LaserEcho& ranges, float& range){
00109 if(ranges.echoes.size() > 0){
00110 size_t index = 0;
00111 range = ranges.echoes[index];
00112 return index;
00113 }
00114
00115 range = std::numeric_limits<float>::quiet_NaN();
00116 return 0;
00117 }
00118
00120 size_t LaserProc::getLastValue(const sensor_msgs::LaserEcho& ranges, float& range){
00121 if(ranges.echoes.size() > 0){
00122 size_t index = ranges.echoes.size()-1;
00123 range = ranges.echoes[index];
00124 return index;
00125 }
00126
00127 range = std::numeric_limits<float>::quiet_NaN();
00128 return 0;
00129 }
00130
00131 void LaserProc::getMostIntenseValue(const sensor_msgs::LaserEcho& ranges, const sensor_msgs::LaserEcho& intensities, float& range, float& intensity){
00132 if(intensities.echoes.size() == 0){
00133 range = std::numeric_limits<float>::quiet_NaN();
00134 intensity = 0.0;
00135 return;
00136 }
00137
00138 std::vector<float>::const_iterator max_iter = std::max_element(intensities.echoes.begin(), intensities.echoes.end());
00139 size_t index = std::distance(intensities.echoes.begin(), max_iter);
00140
00141 if(ranges.echoes.size() > 0){
00142 range = ranges.echoes[index];
00143 intensity = *max_iter;
00144 } else {
00145 range = std::numeric_limits<float>::quiet_NaN();
00146 intensity = 0.0;
00147 return;
00148 }
00149 }