24 #include <visualization_msgs/Marker.h> 25 #include <visualization_msgs/MarkerArray.h> 108 ROS_INFO(
"Laserscan thread stopping...");
110 ROS_INFO(
"Lascerscan thread stopped..");
119 x = (double)(i - (
int)((2*GAUSSIANFIELDSIZE+1) / 2));
137 connect(
scanner, SIGNAL(newData(
const sensor_msgs::LaserScan::ConstPtr&)),
this, SLOT(
laserScanCallback(
const sensor_msgs::LaserScan::ConstPtr&)));
144 if (msg->ranges.size() > 0)
146 double oldValue, newValue;
148 for(
unsigned int i=0;i<msg->ranges.size();i++) {
150 data_raw[i] = (double)msg->ranges[msg->ranges.size() - i - 1];
174 for(
unsigned int i=0;i<msg->ranges.size();i++)
188 sensor_msgs::LaserScan avgScan = *msg;
190 for(
unsigned int i=0;i<msg->ranges.size();i++) {
192 avgScan.ranges[i] =
data_avg[msg->ranges.size() - i - 1];
202 for (
int j = -(
int)GAUSSIANFIELDSIZE; j<=(int)GAUSSIANFIELDSIZE; j++)
211 for(
unsigned int i=0;i<msg->ranges.size();i++) {
227 visualization_msgs::MarkerArray myArray;
231 unsigned int currentPointCloudIndex = 0;
232 for (
unsigned int i=0;i<data_field_size-1;i++)
234 visualization_msgs::Marker marker;
235 marker.header.frame_id =
"base_laser";
237 marker.ns =
"segmentation";
238 marker.id = myArray.markers.size();
239 marker.type = visualization_msgs::Marker::SPHERE;
240 marker.action = visualization_msgs::Marker::ADD;
243 marker.pose.position.z = 0;
247 marker.color.a = 1.0;
248 marker.color.r = (double)(currentPointCloudIndex % 3 == 0);
249 marker.color.g = (double)(currentPointCloudIndex % 3 == 1);
250 marker.color.b = (double)(currentPointCloudIndex % 3 == 2);
251 myArray.markers.push_back(marker);
255 segments.push_back(i);
256 segments.push_back(i+1);
259 currentPointCloudIndex ++;
265 double varianceLeft, varianceRight, varianceTotal, currentBestVariance;
267 Eigen::Vector2d p1, p2, p3;
269 visualization_msgs::MarkerArray borderArray;
271 if (segments.size()> 1)
273 for (
unsigned int j=0; j<segments.size()-1; j++)
277 currentBestVariance = std::numeric_limits<double>::max();
278 segmentFound =
false;
282 visualization_msgs::Marker leftPoint, rightPoint;
283 leftPoint.header.frame_id = rightPoint.header.frame_id =
"base_laser";
284 leftPoint.header.stamp = rightPoint.header.stamp =
ros::Time();
285 leftPoint.ns = rightPoint.ns =
"segmentation";
286 leftPoint.id = borderArray.markers.size();
287 rightPoint.id = borderArray.markers.size() + 1;
288 leftPoint.type = rightPoint.type = visualization_msgs::Marker::SPHERE;
289 leftPoint.action = rightPoint.action = visualization_msgs::Marker::ADD;
290 leftPoint.pose.position.x =
coordinates[i+segments[j]][0];
291 leftPoint.pose.position.y =
coordinates[i+segments[j]][1];
292 rightPoint.pose.position.x =
coordinates[-i+segments[j+1]][0];
293 rightPoint.pose.position.y =
coordinates[-i+segments[j+1]][1];
294 rightPoint.pose.position.z = leftPoint.pose.position.z = 0;
295 leftPoint.scale.x = rightPoint.scale.x =
markersize;
296 leftPoint.scale.y = rightPoint.scale.y =
markersize;
297 leftPoint.scale.z = rightPoint.scale.z =
markersize;
298 leftPoint.color.r = rightPoint.color.r = 0.0;
299 leftPoint.color.g = rightPoint.color.g = 0.0;
300 leftPoint.color.b = rightPoint.color.b = 0.0;
301 leftPoint.color.a = rightPoint.color.a = 1.0;
302 borderArray.markers.push_back(leftPoint);
303 borderArray.markers.push_back(rightPoint);
306 for (
unsigned int i=DETECTIONWINDOW+segments[j];i<segments[j+1]-
DETECTIONWINDOW;i++)
308 visualization_msgs::Marker midPoint;
309 midPoint.header.frame_id =
"base_laser";
311 midPoint.ns =
"segmentation";
312 midPoint.id = borderArray.markers.size();
313 midPoint.type = visualization_msgs::Marker::SPHERE;
314 midPoint.action = visualization_msgs::Marker::ADD;
317 midPoint.pose.position.z = 0;
321 midPoint.color.r = 1.0;
322 midPoint.color.g = 1.0;
323 midPoint.color.b = 1.0;
324 midPoint.color.a = 1.0;
325 borderArray.markers.push_back(midPoint);
327 Eigen::Vector2d center;
333 Eigen::Vector2d left, right;
336 varianceLeft = approximationLeft.
variance;
342 varianceRight = approximationRight.
variance;
344 varianceTotal = varianceLeft* (i - segments[j]) + varianceRight * (segments[j+1] - i);
345 varianceTotal /= (double)(segments[j+1] - segments[j] - 1);
346 if (varianceRight < maxVarianceFilter && currentBestVariance > varianceTotal)
353 currentBestVariance = varianceTotal;
359 for (
unsigned int k = segments[j]; k <= segments[j+1]; k++)
Eigen::Vector2d approximatedVector
int calibration_scan_values
void publish(const boost::shared_ptr< M > &message) const
LaserScanThread(Abstract_LaserScanner *scanner, double segmentation_lambda, double maxVarianceFilter, double maxAngleDeviation, double variationStep, int variationStepCount)
ros::Publisher scanDataPublisher
void calculateGaussianMatrix()
static constexpr unsigned int GAUSSIANFIELDSIZE
LinearApproximator * linearApproximator
std::vector< int > segmentdistance
void trianglesFound(std::vector< Eigen::Vector2d, Eigen::aligned_allocator< Eigen::Vector2d > > *triangles)
static constexpr unsigned int DETECTIONWINDOW
double segmentation_lambda
void laserScanCallback(const sensor_msgs::LaserScan::ConstPtr &msg)
double * rotatingAccumulationWindow[AVERAGINGWINDOW]
double feld[2 *GAUSSIANFIELDSIZE+1]
std::vector< float > segments
static constexpr unsigned int AVERAGINGWINDOW
Eigen::Vector2d * coordinates
float calibration_starting_angle
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
#define ROS_DEBUG_STREAM(args)
static constexpr double sigma
std::vector< int > segmentsizes
Abstract_LaserScanner * scanner
unsigned int data_field_size
#define ROS_INFO_STREAM(args)
std::vector< Eigen::Vector2d, Eigen::aligned_allocator< Eigen::Vector2d > > edgesfound
ApproximationResult calculateApproximation(Eigen::Vector2d *functionPoints, int startIndex, int endIndex, Eigen::Vector2d centerOffset)
ros::Publisher segmentBorderPublisher
ros::Publisher segmentDataPublisher
float calibration_angle_spread