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 #include <gtest/gtest.h>
00036
00037 #include <sensor_msgs/LaserScan.h>
00038 #include <dense_laser_assembler/dense_laser_assembler.h>
00039
00040 using namespace std;
00041 using namespace dense_laser_assembler;
00042
00043 sensor_msgs::LaserScanConstPtr buildScan(const ros::Time& stamp, double start_angle, double start_range, double start_intensity, const unsigned int N)
00044 {
00045 sensor_msgs::LaserScanPtr scan(new sensor_msgs::LaserScan);
00046
00047 scan->header.stamp = stamp;
00048
00049 scan->angle_increment = 1.0;
00050 scan->angle_min = start_angle;
00051 scan->angle_max = start_angle + (N-1)*scan->angle_increment;
00052 scan->time_increment = 1.0;
00053 scan->scan_time = 0.0;
00054 scan->range_min = 0.0;
00055 scan->range_max = 1000.0;
00056 scan->ranges.resize(N);
00057 scan->intensities.resize(N);
00058 for (unsigned int i=0; i<N; i++)
00059 {
00060 scan->ranges[i] = start_range + 1.0*i;
00061 scan->intensities[i] = start_intensity + 1.0*i;
00062
00063 }
00064
00065 return scan;
00066 }
00067
00068 static const unsigned int NUM_SCANS = 20;
00069 static const unsigned int RAYS_PER_SCAN = 50;
00070 static const double eps = 1e-8;
00071
00072 void addScans1(const ros::Time& start_stamp, double start_angle, DenseLaserAssembler& assembler)
00073 {
00074
00075 for (unsigned int i=0; i<NUM_SCANS; i++)
00076 {
00077 sensor_msgs::LaserScanConstPtr scan = buildScan(start_stamp + ros::Duration(i,0), start_angle, 100*i, 1000*i, RAYS_PER_SCAN);
00078 assembler.add(scan);
00079 }
00080 }
00081
00082 TEST(DenseLaserAssembler, easy)
00083 {
00084 DenseLaserAssembler assembler;
00085 addScans1(ros::Time(10,0), 0.0, assembler);
00086
00087 calibration_msgs::DenseLaserSnapshot snapshot;
00088 bool result;
00089 result = assembler.assembleSnapshot(ros::Time(9,0), ros::Time(31,0), snapshot);
00090 ASSERT_TRUE(result);
00091 ASSERT_EQ(snapshot.ranges.size(), NUM_SCANS * RAYS_PER_SCAN);
00092 ASSERT_EQ(snapshot.intensities.size(), NUM_SCANS * RAYS_PER_SCAN);
00093 ASSERT_EQ(snapshot.readings_per_scan, RAYS_PER_SCAN);
00094 ASSERT_EQ(snapshot.num_scans, NUM_SCANS);
00095 ASSERT_EQ(snapshot.scan_start.size(), NUM_SCANS);
00096
00097
00098 EXPECT_EQ(snapshot.scan_start[0], ros::Time(10,0));
00099 EXPECT_EQ(snapshot.scan_start[5], ros::Time(15,0));
00100 EXPECT_EQ(snapshot.scan_start[19], ros::Time(29,0));
00101
00102
00103 EXPECT_NEAR(snapshot.ranges[0], 0, eps);
00104 EXPECT_NEAR(snapshot.ranges[70], 120, eps);
00105 EXPECT_NEAR(snapshot.ranges[999], 1949, eps);
00106
00107
00108 EXPECT_NEAR(snapshot.intensities[0], 0, eps);
00109 EXPECT_NEAR(snapshot.intensities[70], 1020, eps);
00110 EXPECT_NEAR(snapshot.intensities[999], 19049, eps);
00111 }
00112
00113 TEST(DenseLaserAssembler, mismatchedMetadata)
00114 {
00115 DenseLaserAssembler assembler;
00116 addScans1(ros::Time( 10,0), 0.0, assembler);
00117 addScans1(ros::Time(110,0), 1.0, assembler);
00118
00119 calibration_msgs::DenseLaserSnapshot snapshot;
00120 bool result;
00121 result = assembler.assembleSnapshot(ros::Time(9,0), ros::Time(31,0), snapshot);
00122 EXPECT_TRUE(result);
00123 EXPECT_EQ(snapshot.ranges.size(), NUM_SCANS * RAYS_PER_SCAN);
00124
00125 result = assembler.assembleSnapshot(ros::Time(109,0), ros::Time(131,0), snapshot);
00126 EXPECT_TRUE(result);
00127 EXPECT_EQ(snapshot.ranges.size(), NUM_SCANS * RAYS_PER_SCAN);
00128
00129 result = assembler.assembleSnapshot(ros::Time(9,0), ros::Time(131,0), snapshot);
00130 EXPECT_FALSE(result);
00131 }
00132
00133
00134 int main(int argc, char **argv){
00135 testing::InitGoogleTest(&argc, argv);
00136 return RUN_ALL_TESTS();
00137 }