$search
00001 /********************************************************************* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2008, Willow Garage, Inc. 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * * Redistributions in binary form must reproduce the above 00014 * copyright notice, this list of conditions and the following 00015 * disclaimer in the documentation and/or other materials provided 00016 * with the distribution. 00017 * * Neither the name of the Willow Garage nor the names of its 00018 * contributors may be used to endorse or promote products derived 00019 * from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 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 }