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 #include <laser_joint_processor/joint_imager.h>
00037
00038 using namespace std;
00039 using namespace laser_joint_processor;
00040 using joint_states_settler::DeflatedJointStates;
00041
00042 static const float eps = 1e-6;
00043
00044 typedef settlerlib::SortedDeque<joint_states_settler::DeflatedJointStates> DeflatedDeque;
00045
00046 void populateCache(DeflatedDeque& cache, const ros::Time& start, const unsigned int N)
00047 {
00048 for (unsigned int i=0; i<N; i++)
00049 {
00050 joint_states_settler::DeflatedJointStates deflated;
00051 deflated.header.stamp = start + ros::Duration(i,0);
00052 deflated.channels_.resize(2);
00053 deflated.channels_[0] = 10*i;
00054 deflated.channels_[1] = 100*i;
00055
00056 cache.add(deflated);
00057 }
00058 }
00059
00060
00061 class JointImager_EasyTests : public ::testing::Test
00062 {
00063 protected:
00064 virtual void SetUp()
00065 {
00066 cache_.setMaxSize(1000);
00067 populateCache(cache_, ros::Time(0,0), 100);
00068
00069 snapshot_.time_increment = 1;
00070 snapshot_.readings_per_scan = 3;
00071 snapshot_.num_scans = 4;
00072 snapshot_.scan_start.resize(4);
00073 snapshot_.scan_start[0] = ros::Time(.5);
00074 snapshot_.scan_start[1] = ros::Time(10);
00075 snapshot_.scan_start[2] = ros::Time(35);
00076 snapshot_.scan_start[3] = ros::Time(50.5);
00077
00078 bool success;
00079 success =imager_.update(snapshot_, cache_, ros::Duration(2,0));
00080 ASSERT_TRUE(success);
00081
00082 image0_ = imager_.getJointImage(0);
00083 image1_ = imager_.getJointImage(1);
00084 }
00085
00086 DeflatedDeque cache_;
00087 calibration_msgs::DenseLaserSnapshot snapshot_;
00088 JointImager imager_;
00089
00090 IplImage* image0_;
00091 IplImage* image1_;
00092 };
00093
00094 float imageAt(IplImage* image, int row, int col, int channel)
00095 {
00096 return *(((float*)(image->imageData + row*image->widthStep)) + image->nChannels*col + channel);
00097 }
00098
00099 TEST_F(JointImager_EasyTests, positions)
00100 {
00101 EXPECT_NEAR(imageAt(image0_, 0, 0, 0), 5, eps);
00102 EXPECT_NEAR(imageAt(image0_, 1, 0, 0), 100, eps);
00103 EXPECT_NEAR(imageAt(image0_, 2, 0, 0), 350, eps);
00104 EXPECT_NEAR(imageAt(image0_, 0, 2, 0), 25, eps);
00105 EXPECT_NEAR(imageAt(image0_, 3, 2, 0), 525, eps);
00106
00107 EXPECT_NEAR(imageAt(image1_, 0, 0, 0), 50, eps);
00108 EXPECT_NEAR(imageAt(image1_, 3, 2, 0), 5250, eps);
00109
00110 }
00111
00112 TEST_F(JointImager_EasyTests, velocities)
00113 {
00114 EXPECT_NEAR(imageAt(image0_, 0, 0, 1), 10, eps);
00115 EXPECT_NEAR(imageAt(image0_, 0, 1, 1), 10, eps);
00116 EXPECT_NEAR(imageAt(image0_, 0, 2, 1), 10, eps);
00117 EXPECT_NEAR(imageAt(image0_, 3, 0, 1), 10, eps);
00118 EXPECT_NEAR(imageAt(image0_, 3, 1, 1), 10, eps);
00119 EXPECT_NEAR(imageAt(image0_, 3, 2, 1), 10, eps);
00120
00121 EXPECT_NEAR(imageAt(image1_, 0, 0, 1), 100, eps);
00122 EXPECT_NEAR(imageAt(image1_, 0, 1, 1), 100, eps);
00123 EXPECT_NEAR(imageAt(image1_, 0, 2, 1), 100, eps);
00124 EXPECT_NEAR(imageAt(image1_, 3, 0, 1), 100, eps);
00125 EXPECT_NEAR(imageAt(image1_, 3, 1, 1), 100, eps);
00126 EXPECT_NEAR(imageAt(image1_, 3, 2, 1), 100, eps);
00127 }
00128
00129 int main(int argc, char **argv){
00130 testing::InitGoogleTest(&argc, argv);
00131 return RUN_ALL_TESTS();
00132 }