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
00036
00037 #include <laser_cb_detector/laser_interval_calc.h>
00038 #include <ros/console.h>
00039 #include <vector>
00040 #include <algorithm>
00041
00042 using namespace laser_cb_detector;
00043 using namespace std;
00044
00045 bool LaserIntervalCalc::computeInterval(const calibration_msgs::DenseLaserSnapshot& snapshot,
00046 const calibration_msgs::CalibrationPattern& features,
00047 calibration_msgs::Interval& result)
00048 {
00049 const unsigned int N = features.image_points.size();
00050
00051 vector<ros::Time> min_times, max_times;
00052 min_times.resize(N);
00053 max_times.resize(N);
00054
00055 if (N == 0)
00056 {
00057 result.start = snapshot.header.stamp;
00058 result.end = snapshot.header.stamp;
00059 return true;
00060 }
00061
00062
00063 for (unsigned int i=0; i<N; i++)
00064 {
00065
00066 int x_rounded = (int) features.image_points[i].x;
00067 int y_rounded = (int) features.image_points[i].y;
00068
00069
00070
00071
00072 if (features.image_points[i].y <= 0.0 || y_rounded >= (int) snapshot.num_scans-1)
00073 {
00074 ROS_ERROR("Image point #%u (%.2f, %.2f) is outside of Y range (0.00, %u)", i,
00075 features.image_points[i].x, features.image_points[i].y, snapshot.num_scans-1);
00076 return false;
00077 }
00078
00079 ros::Time min_scan_start = min( snapshot.scan_start[y_rounded],
00080 snapshot.scan_start[y_rounded+1] );
00081 ros::Time max_scan_start = max( snapshot.scan_start[y_rounded],
00082 snapshot.scan_start[y_rounded+1] );
00083
00084 min_times[i] = min_scan_start + ros::Duration(snapshot.time_increment * x_rounded);
00085 max_times[i] = max_scan_start + ros::Duration(snapshot.time_increment * (x_rounded+1));
00086 }
00087
00088
00089 ros::Time min_time = min_times[0];
00090 ros::Time max_time = max_times[0];
00091
00092 for (unsigned int i=0; i<N; i++)
00093 {
00094 min_time = min (min_time, min_times[i]);
00095 max_time = max (max_time, max_times[i]);
00096 }
00097
00098 result.start = min_time;
00099 result.end = max_time;
00100
00101 return true;
00102 }