test_door_functions.cpp
Go to the documentation of this file.
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 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  * $Id: test_executive_functions.cpp 14649 2009-04-30 01:13:48Z meeussen $
00035  *
00036  *********************************************************************/
00037 
00038 /* Author: Wim Meeussen */
00039 
00040 #include <door_msgs/Door.h>
00041 #include <ros/ros.h>
00042 #include <gtest/gtest.h>
00043 #include <kdl/frames.hpp>
00044 #include "pr2_doors_common/door_functions.h"
00045 
00046 
00047 using namespace ros;
00048 using namespace std;
00049 using namespace KDL;
00050 using namespace pr2_doors_common;
00051 
00052 
00053 
00054 
00055 int g_argc;
00056 char** g_argv;
00057 
00058 class TestEKF : public testing::Test
00059 {
00060 public:
00061   door_msgs::Door my_door_1, my_door_2, my_door_3, my_door_4, my_door_5, my_door_6;
00062 
00063 protected:
00065   TestEKF()
00066   {
00067     my_door_1.frame_p1.x = 1.0;
00068     my_door_1.frame_p1.y = -0.5;
00069     my_door_1.frame_p2.x = 1.0;
00070     my_door_1.frame_p2.y = 0.5;
00071     my_door_1.door_p1.x = 1.0;
00072     my_door_1.door_p1.y = -0.5;
00073     my_door_1.door_p2.x = 1.0;
00074     my_door_1.door_p2.y = 0.5;
00075     my_door_1.travel_dir.x = 1.0;
00076     my_door_1.travel_dir.y = 0.0;
00077     my_door_1.travel_dir.z = 0.0;
00078     my_door_1.rot_dir = door_msgs::Door::ROT_DIR_COUNTERCLOCKWISE;
00079     my_door_1.hinge = door_msgs::Door::HINGE_P2;
00080     my_door_1.header.frame_id = "base_footprint";
00081     
00082     my_door_2.frame_p2.x = 1.0;
00083     my_door_2.frame_p2.y = -0.5;
00084     my_door_2.frame_p1.x = 1.0;
00085     my_door_2.frame_p1.y = 0.5;
00086     my_door_2.door_p2.x = 1.0;
00087     my_door_2.door_p2.y = -0.5;
00088     my_door_2.door_p1.x = 1.0;
00089     my_door_2.door_p1.y = 0.5;
00090     my_door_2.travel_dir.x = 1.0;
00091     my_door_2.travel_dir.y = 0.0;
00092     my_door_2.travel_dir.z = 0.0;
00093     my_door_2.rot_dir = door_msgs::Door::ROT_DIR_COUNTERCLOCKWISE;
00094     my_door_2.hinge = door_msgs::Door::HINGE_P1;
00095     my_door_2.header.frame_id = "base_footprint";
00096 
00097     my_door_3.frame_p1.x = 1.0;
00098     my_door_3.frame_p1.y = -0.5;
00099     my_door_3.frame_p2.x = 1.0;
00100     my_door_3.frame_p2.y = 0.5;
00101     my_door_3.door_p1.x = 1.75;
00102     my_door_3.door_p1.y = -0.25;
00103     my_door_3.door_p2.x = 1.0;
00104     my_door_3.door_p2.y = 0.5;
00105     my_door_3.travel_dir.x = 1.0;
00106     my_door_3.travel_dir.y = 0.0;
00107     my_door_3.travel_dir.z = 0.0;
00108     my_door_3.rot_dir = door_msgs::Door::ROT_DIR_COUNTERCLOCKWISE;
00109     my_door_3.hinge = door_msgs::Door::HINGE_P2;
00110     my_door_3.header.frame_id = "base_footprint";
00111 
00112     my_door_4.frame_p2.x = 1.0;
00113     my_door_4.frame_p2.y = -0.5;
00114     my_door_4.frame_p1.x = 1.0;
00115     my_door_4.frame_p1.y = 0.5;
00116     my_door_4.door_p2.x = 1.75;
00117     my_door_4.door_p2.y = -0.25;
00118     my_door_4.door_p1.x = 1.0;
00119     my_door_4.door_p1.y = 0.5;
00120     my_door_4.travel_dir.x = 1.0;
00121     my_door_4.travel_dir.y = 0.0;
00122     my_door_4.travel_dir.z = 0.0;
00123     my_door_4.rot_dir = door_msgs::Door::ROT_DIR_COUNTERCLOCKWISE;
00124     my_door_4.hinge = door_msgs::Door::HINGE_P2;
00125     my_door_4.header.frame_id = "base_footprint";
00126 
00127     my_door_5.frame_p1.x = 1.0;
00128     my_door_5.frame_p1.y = -0.5;
00129     my_door_5.frame_p2.x = 1.0;
00130     my_door_5.frame_p2.y = 0.5;
00131     my_door_5.door_p1.x = 0.25;
00132     my_door_5.door_p1.y = -0.25;
00133     my_door_5.door_p2.x = 1.0;
00134     my_door_5.door_p2.y = 0.5;
00135     my_door_5.travel_dir.x = 1.0;
00136     my_door_5.travel_dir.y = 0.0;
00137     my_door_5.travel_dir.z = 0.0;
00138     my_door_5.rot_dir = door_msgs::Door::ROT_DIR_CLOCKWISE;
00139     my_door_5.hinge = door_msgs::Door::HINGE_P2;
00140     my_door_5.header.frame_id = "base_footprint";
00141 
00142     my_door_6.frame_p2.x = 1.0;
00143     my_door_6.frame_p2.y = -0.5;
00144     my_door_6.frame_p1.x = 1.0;
00145     my_door_6.frame_p1.y = 0.5;
00146     my_door_6.door_p2.x = 0.25;
00147     my_door_6.door_p2.y = -0.25;
00148     my_door_6.door_p1.x = 1.0;
00149     my_door_6.door_p1.y = 0.5;
00150     my_door_6.travel_dir.x = 1.0;
00151     my_door_6.travel_dir.y = 0.0;
00152     my_door_6.travel_dir.z = 0.0;
00153     my_door_6.rot_dir = door_msgs::Door::ROT_DIR_CLOCKWISE;
00154     my_door_6.hinge = door_msgs::Door::HINGE_P2;
00155     my_door_6.header.frame_id = "base_footprint";
00156   }
00157   
00158 
00160   ~TestEKF()
00161   {}
00162 };
00163 
00164 
00165 
00166 bool approx(double v1, double v2, double eps=0.01)
00167 {
00168   return fabs(v1-v2) < eps;
00169 }
00170 
00171 bool approx(Vector v1, Vector v2, double eps=0.01)
00172 {
00173   return approx(v1(0), v2(0), eps) && approx(v1(1), v2(1), eps) &&approx(v1(2), v2(2), eps);
00174 }
00175 
00176 
00177 TEST_F(TestEKF, test)
00178 {
00179   cout << "door 1 " << my_door_1 << endl;
00180   ASSERT_TRUE(approx(getDoorAngle(my_door_1), 0));
00181   ASSERT_TRUE(approx(getFrameNormal(my_door_1), Vector(1,0,0)));
00182   ASSERT_TRUE(approx(getDoorNormal(my_door_1), Vector(1,0,0)));
00183 
00184   cout << "door 2 " << my_door_2 << endl;
00185   ASSERT_TRUE(approx(getDoorAngle(my_door_2), 0));
00186   ASSERT_TRUE(approx(getFrameNormal(my_door_2), Vector(1,0,0)));
00187   ASSERT_TRUE(approx(getDoorNormal(my_door_2), Vector(1,0,0)));
00188 
00189   cout << "door 3 " << my_door_3 << endl;
00190   Vector v3(1,1,0); v3.Normalize();
00191   ASSERT_TRUE(approx(getDoorAngle(my_door_3), M_PI/4.0));
00192   ASSERT_TRUE(approx(getFrameNormal(my_door_3), Vector(1,0,0)));
00193   ASSERT_TRUE(approx(getDoorNormal(my_door_3), v3));
00194 
00195   cout << "door 4 " << my_door_4 << endl;
00196   ASSERT_TRUE(approx(getDoorAngle(my_door_4), M_PI/4.0));
00197   ASSERT_TRUE(approx(getFrameNormal(my_door_4), Vector(1,0,0)));
00198   ASSERT_TRUE(approx(getDoorNormal(my_door_4), v3));
00199 
00200   cout << "door 5 " << my_door_5 << endl;
00201   Vector v5(1,-1,0); v5.Normalize();
00202   ASSERT_TRUE(approx(getDoorAngle(my_door_5), -M_PI/4.0));
00203   ASSERT_TRUE(approx(getFrameNormal(my_door_5), Vector(1,0,0)));
00204   ASSERT_TRUE(approx(getDoorNormal(my_door_5), v5));
00205 
00206   cout << "door 6 " << my_door_6 << endl;
00207   ASSERT_TRUE(approx(getDoorAngle(my_door_6), -M_PI/4.0));
00208   ASSERT_TRUE(approx(getFrameNormal(my_door_6), Vector(1,0,0)));
00209   ASSERT_TRUE(approx(getDoorNormal(my_door_6), v5));
00210 
00211   SUCCEED();
00212 }
00213 
00214 
00215 
00216 
00217 
00218 int main(int argc, char** argv)
00219 {
00220   testing::InitGoogleTest(&argc, argv);
00221   g_argc = argc;
00222   g_argv = argv;
00223   return RUN_ALL_TESTS();
00224 }


pr2_doors_common
Author(s): Wim Meeussen
autogenerated on Wed Dec 11 2013 14:16:50