00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
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
00045 KDL::Rotation::Quaternion(x, y, z, w).GetRPY(roll1, pitch1, yaw1);
00046 {
00047
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
00053 geometry_msgs::QuaternionStamped qst;
00054 qst.quaternion = q;
00055 yprTest(qst, yaw1, pitch1, roll1);
00056 }
00057
00058
00059 {
00060
00061 tf2::Quaternion q(x, y, z, w);
00062 yprTest(q, yaw1, pitch1, roll1);
00063
00064
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
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