laser_interval_calc.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2008, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
36 
38 #include <ros/console.h>
39 #include <vector>
40 #include <algorithm>
41 
42 using namespace laser_cb_detector;
43 using namespace std;
44 
45 bool LaserIntervalCalc::computeInterval(const calibration_msgs::DenseLaserSnapshot& snapshot,
46  const calibration_msgs::CalibrationPattern& features,
47  calibration_msgs::Interval& result)
48 {
49  const unsigned int N = features.image_points.size();
50 
51  vector<ros::Time> min_times, max_times;
52  min_times.resize(N);
53  max_times.resize(N);
54 
55  if (N == 0)
56  {
57  result.start = snapshot.header.stamp;
58  result.end = snapshot.header.stamp;
59  return true;
60  }
61 
62  // Find the min and max time bounds for each image point. Store this in vectors min_times and max_times
63  for (unsigned int i=0; i<N; i++)
64  {
65  // Figure out which scan happened first
66  int x_rounded = (int) features.image_points[i].x;
67  int y_rounded = (int) features.image_points[i].y;
68 
69  // Don't need an x axis range check, since we don't dereference anything based on this index
70 
71  // Error checking on Y axis
72  if (features.image_points[i].y <= 0.0 || y_rounded >= (int) snapshot.num_scans-1)
73  {
74  ROS_ERROR("Image point #%u (%.2f, %.2f) is outside of Y range (0.00, %u)", i,
75  features.image_points[i].x, features.image_points[i].y, snapshot.num_scans-1);
76  return false;
77  }
78 
79  ros::Time min_scan_start = min( snapshot.scan_start[y_rounded],
80  snapshot.scan_start[y_rounded+1] );
81  ros::Time max_scan_start = max( snapshot.scan_start[y_rounded],
82  snapshot.scan_start[y_rounded+1] );
83 
84  min_times[i] = min_scan_start + ros::Duration(snapshot.time_increment * x_rounded);
85  max_times[i] = max_scan_start + ros::Duration(snapshot.time_increment * (x_rounded+1));
86  }
87 
88  // Compute the min and max times over both vectors
89  ros::Time min_time = min_times[0];
90  ros::Time max_time = max_times[0];
91 
92  for (unsigned int i=0; i<N; i++)
93  {
94  min_time = min (min_time, min_times[i]);
95  max_time = max (max_time, max_times[i]);
96  }
97 
98  result.start = min_time;
99  result.end = max_time;
100 
101  return true;
102 }
static bool computeInterval(const calibration_msgs::DenseLaserSnapshot &snapshot, const calibration_msgs::CalibrationPattern &features, calibration_msgs::Interval &result)
int min(int a, int b)
#define ROS_ERROR(...)


laser_cb_detector
Author(s): Vijay Pradeep
autogenerated on Thu Jun 6 2019 19:17:28