test_utils.cpp
Go to the documentation of this file.
00001 // Copyright 2014 Open Source Robotics Foundation, Inc.
00002 //
00003 // Licensed under the Apache License, Version 2.0 (the "License");
00004 // you may not use this file except in compliance with the License.
00005 // You may obtain a copy of the License at
00006 //
00007 //     http://www.apache.org/licenses/LICENSE-2.0
00008 //
00009 // Unless required by applicable law or agreed to in writing, software
00010 // distributed under the License is distributed on an "AS IS" BASIS,
00011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012 // See the License for the specific language governing permissions and
00013 // limitations under the License.
00014 
00015 #include <gtest/gtest.h>
00016 #include <tf2/utils.h>
00017 #include <tf2_kdl/tf2_kdl.h>
00018 #include <tf2_geometry_msgs/tf2_geometry_msgs.h>
00019 #include <ros/time.h>
00020 
00021 double epsilon = 1e-9;
00022 
00023 template<typename T>
00024 void yprTest(const T& t, double yaw1, double pitch1, double roll1) {
00025   double yaw2, pitch2, roll2;
00026 
00027   tf2::getEulerYPR(t, yaw2, pitch2, roll2);  
00028 
00029   EXPECT_NEAR(yaw1, yaw2, epsilon);
00030   EXPECT_NEAR(pitch1, pitch2, epsilon);
00031   EXPECT_NEAR(roll1, roll2, epsilon);
00032   EXPECT_NEAR(tf2::getYaw(t), yaw1, epsilon);
00033 }
00034 
00035 TEST(tf2Utils, yaw)
00036 {
00037   double x, y, z, w;
00038   x = 0.4;
00039   y = 0.5;
00040   z = 0.6;
00041   w = 0.7;
00042 
00043   double yaw1, pitch1, roll1;
00044   // Compute results one way with KDL
00045   KDL::Rotation::Quaternion(x, y, z, w).GetRPY(roll1, pitch1, yaw1);
00046   {
00047     // geometry_msgs::Quaternion
00048     geometry_msgs::Quaternion q;
00049     q.x = x; q.y =y; q.z = z; q.w = w;
00050     yprTest(q, yaw1, pitch1, roll1);
00051 
00052     // geometry_msgs::QuaternionStamped
00053     geometry_msgs::QuaternionStamped qst;
00054     qst.quaternion = q;
00055     yprTest(qst, yaw1, pitch1, roll1);
00056   }
00057 
00058   
00059   {
00060     // tf2::Quaternion
00061     tf2::Quaternion q(x, y, z, w);
00062     yprTest(q, yaw1, pitch1, roll1);
00063 
00064     // tf2::Stamped<tf2::Quaternion>
00065     tf2::Stamped<tf2::Quaternion> sq;
00066     sq.setData(q);
00067     yprTest(sq, yaw1, pitch1, roll1);
00068   }
00069 }
00070 
00071 TEST(tf2Utils, identity)
00072 {
00073   geometry_msgs::Transform t;
00074   t.translation.x = 0.1;
00075   t.translation.y = 0.2;
00076   t.translation.z = 0.3;
00077   t.rotation.x = 0.4;
00078   t.rotation.y = 0.5;
00079   t.rotation.z = 0.6;
00080   t.rotation.w = 0.7;
00081 
00082   // Test identity
00083   t = tf2::getTransformIdentity<geometry_msgs::Transform>();
00084 
00085   EXPECT_EQ(t.translation.x, 0);
00086   EXPECT_EQ(t.translation.y, 0);
00087   EXPECT_EQ(t.translation.z, 0);
00088   EXPECT_EQ(t.rotation.x, 0);
00089   EXPECT_EQ(t.rotation.y, 0);
00090   EXPECT_EQ(t.rotation.z, 0);
00091   EXPECT_EQ(t.rotation.w, 1);
00092 }
00093 
00094 int main(int argc, char** argv)
00095 {
00096   testing::InitGoogleTest(&argc, argv);
00097   return RUN_ALL_TESTS();
00098 }
00099 


test_tf2
Author(s): Tully Foote, Eitan Marder-Eppstein
autogenerated on Thu Jun 6 2019 20:23:15