test_convert.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 *
3 * Software License Agreement (BSD License)
4 *
5 * Copyright (c) 2009, Willow Garage, Inc.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 * * Neither the name of Willow Garage, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 *
35 * Author: Eitan Marder-Eppstein
36 *********************************************************************/
37 #include <gtest/gtest.h>
38 #include <tf2/convert.h>
39 #include <tf2_kdl/tf2_kdl.h>
40 #include <tf2_bullet/tf2_bullet.h>
42 #include <tf2_eigen/tf2_eigen.h>
43 #include <ros/time.h>
44 
45 TEST(tf2Convert, kdlToBullet)
46 {
47  double epsilon = 1e-9;
48 
49  tf2::Stamped<btVector3> b(btVector3(1,2,3), ros::Time(), "my_frame");
50 
53  tf2::convert(b1, k1);
54 
56  tf2::convert(k1, b2);
57 
58  EXPECT_EQ(b.frame_id_, b2.frame_id_);
59  EXPECT_NEAR(b.stamp_.toSec(), b2.stamp_.toSec(), epsilon);
60  EXPECT_NEAR(b.x(), b2.x(), epsilon);
61  EXPECT_NEAR(b.y(), b2.y(), epsilon);
62  EXPECT_NEAR(b.z(), b2.z(), epsilon);
63 
64 
65  EXPECT_EQ(b1.frame_id_, b2.frame_id_);
66  EXPECT_NEAR(b1.stamp_.toSec(), b2.stamp_.toSec(), epsilon);
67  EXPECT_NEAR(b1.x(), b2.x(), epsilon);
68  EXPECT_NEAR(b1.y(), b2.y(), epsilon);
69  EXPECT_NEAR(b1.z(), b2.z(), epsilon);
70 }
71 
72 TEST(tf2Convert, kdlBulletROSConversions)
73 {
74  double epsilon = 1e-9;
75 
76  tf2::Stamped<btVector3> b1(btVector3(1,2,3), ros::Time(), "my_frame"), b2, b3, b4;
77  geometry_msgs::PointStamped r1, r2, r3;
78  tf2::Stamped<KDL::Vector> k1, k2, k3;
79 
80  // Do bullet -> self -> bullet -> KDL -> self -> KDL -> ROS -> self -> ROS -> KDL -> bullet -> ROS -> bullet
81  tf2::convert(b1, b1);
82  tf2::convert(b1, b2);
83  tf2::convert(b2, k1);
84  tf2::convert(k1, k1);
85  tf2::convert(k1, k2);
86  tf2::convert(k2, r1);
87  tf2::convert(r1, r1);
88  tf2::convert(r1, r2);
89  tf2::convert(r2, k3);
90  tf2::convert(k3, b3);
91  tf2::convert(b3, r3);
92  tf2::convert(r3, b4);
93 
94  EXPECT_EQ(b1.frame_id_, b4.frame_id_);
95  EXPECT_NEAR(b1.stamp_.toSec(), b4.stamp_.toSec(), epsilon);
96  EXPECT_NEAR(b1.x(), b4.x(), epsilon);
97  EXPECT_NEAR(b1.y(), b4.y(), epsilon);
98  EXPECT_NEAR(b1.z(), b4.z(), epsilon);
99 }
100 
101 TEST(tf2Convert, ConvertTf2Quaternion)
102 {
103  tf2::Quaternion tq(1,2,3,4);
104  Eigen::Quaterniond eq;
105  tf2::convert(tq, eq);
106 
107  EXPECT_EQ(tq.w(), eq.w());
108  EXPECT_EQ(tq.x(), eq.x());
109  EXPECT_EQ(tq.y(), eq.y());
110  EXPECT_EQ(tq.z(), eq.z());
111 }
112 
113 int main(int argc, char** argv)
114 {
115  testing::InitGoogleTest(&argc, argv);
116  return RUN_ALL_TESTS();
117 }
118 
double epsilon
Definition: test_utils.cpp:21
int main(int argc, char **argv)
TEST(tf2Convert, kdlToBullet)
ros::Time stamp_
std::string frame_id_
void convert(const A &a, B &b)


test_tf2
Author(s): Tully Foote, Eitan Marder-Eppstein
autogenerated on Mon Jun 27 2022 02:43:28