test_utils.cpp
Go to the documentation of this file.
1 // Copyright 2014 Open Source Robotics Foundation, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <gtest/gtest.h>
16 #include <tf2/utils.h>
17 #include <tf2_kdl/tf2_kdl.h>
19 #include <ros/time.h>
20 
21 double epsilon = 1e-9;
22 
23 template<typename T>
24 void yprTest(const T& t, double yaw1, double pitch1, double roll1) {
25  double yaw2, pitch2, roll2;
26 
27  tf2::getEulerYPR(t, yaw2, pitch2, roll2);
28 
29  EXPECT_NEAR(yaw1, yaw2, epsilon);
30  EXPECT_NEAR(pitch1, pitch2, epsilon);
31  EXPECT_NEAR(roll1, roll2, epsilon);
32  EXPECT_NEAR(tf2::getYaw(t), yaw1, epsilon);
33 }
34 
35 TEST(tf2Utils, yaw)
36 {
37  double x, y, z, w;
38  x = 0.4;
39  y = 0.5;
40  z = 0.6;
41  w = 0.7;
42 
43  double yaw1, pitch1, roll1;
44  // Compute results one way with KDL
45  KDL::Rotation::Quaternion(x, y, z, w).GetRPY(roll1, pitch1, yaw1);
46  {
47  // geometry_msgs::Quaternion
48  geometry_msgs::Quaternion q;
49  q.x = x; q.y =y; q.z = z; q.w = w;
50  yprTest(q, yaw1, pitch1, roll1);
51 
52  // geometry_msgs::QuaternionStamped
53  geometry_msgs::QuaternionStamped qst;
54  qst.quaternion = q;
55  yprTest(qst, yaw1, pitch1, roll1);
56  }
57 
58 
59  {
60  // tf2::Quaternion
61  tf2::Quaternion q(x, y, z, w);
62  yprTest(q, yaw1, pitch1, roll1);
63 
64  // tf2::Stamped<tf2::Quaternion>
66  sq.setData(q);
67  yprTest(sq, yaw1, pitch1, roll1);
68  }
69 }
70 
71 TEST(tf2Utils, identity)
72 {
73  geometry_msgs::Transform t;
74  t.translation.x = 0.1;
75  t.translation.y = 0.2;
76  t.translation.z = 0.3;
77  t.rotation.x = 0.4;
78  t.rotation.y = 0.5;
79  t.rotation.z = 0.6;
80  t.rotation.w = 0.7;
81 
82  // Test identity
83  t = tf2::getTransformIdentity<geometry_msgs::Transform>();
84 
85  EXPECT_EQ(t.translation.x, 0);
86  EXPECT_EQ(t.translation.y, 0);
87  EXPECT_EQ(t.translation.z, 0);
88  EXPECT_EQ(t.rotation.x, 0);
89  EXPECT_EQ(t.rotation.y, 0);
90  EXPECT_EQ(t.rotation.z, 0);
91  EXPECT_EQ(t.rotation.w, 1);
92 }
93 
94 int main(int argc, char** argv)
95 {
96  testing::InitGoogleTest(&argc, argv);
97  return RUN_ALL_TESTS();
98 }
99 
double epsilon
Definition: test_utils.cpp:21
void getEulerYPR(const A &a, double &yaw, double &pitch, double &roll)
int main(int argc, char **argv)
Definition: test_utils.cpp:94
static Rotation Quaternion(double x, double y, double z, double w)
TFSIMD_FORCE_INLINE const tfScalar & y() const
geometry_msgs::TransformStamped t
TEST(tf2Utils, yaw)
Definition: test_utils.cpp:35
TFSIMD_FORCE_INLINE const tfScalar & x() const
void yprTest(const T &t, double yaw1, double pitch1, double roll1)
Definition: test_utils.cpp:24
void GetRPY(double &roll, double &pitch, double &yaw) const
TFSIMD_FORCE_INLINE const tfScalar & z() const
double getYaw(const A &a)
TFSIMD_FORCE_INLINE const tfScalar & w() const
void setData(const T &input)


test_tf2
Author(s): Tully Foote, Eitan Marder-Eppstein
autogenerated on Fri Jun 7 2019 21:45:56