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 <ros/time.h>
43 
44 TEST(tf2Convert, kdlToBullet)
45 {
46  double epsilon = 1e-9;
47 
48  tf2::Stamped<btVector3> b(btVector3(1,2,3), ros::Time(), "my_frame");
49 
52  tf2::convert(b1, k1);
53 
55  tf2::convert(k1, b2);
56 
57  EXPECT_EQ(b.frame_id_, b2.frame_id_);
58  EXPECT_NEAR(b.stamp_.toSec(), b2.stamp_.toSec(), epsilon);
59  EXPECT_NEAR(b.x(), b2.x(), epsilon);
60  EXPECT_NEAR(b.y(), b2.y(), epsilon);
61  EXPECT_NEAR(b.z(), b2.z(), epsilon);
62 
63 
64  EXPECT_EQ(b1.frame_id_, b2.frame_id_);
65  EXPECT_NEAR(b1.stamp_.toSec(), b2.stamp_.toSec(), epsilon);
66  EXPECT_NEAR(b1.x(), b2.x(), epsilon);
67  EXPECT_NEAR(b1.y(), b2.y(), epsilon);
68  EXPECT_NEAR(b1.z(), b2.z(), epsilon);
69 }
70 
71 TEST(tf2Convert, kdlBulletROSConversions)
72 {
73  double epsilon = 1e-9;
74 
75  tf2::Stamped<btVector3> b1(btVector3(1,2,3), ros::Time(), "my_frame"), b2, b3, b4;
76  geometry_msgs::PointStamped r1, r2, r3;
77  tf2::Stamped<KDL::Vector> k1, k2, k3;
78 
79  // Do bullet -> self -> bullet -> KDL -> self -> KDL -> ROS -> self -> ROS -> KDL -> bullet -> ROS -> bullet
80  tf2::convert(b1, b1);
81  tf2::convert(b1, b2);
82  tf2::convert(b2, k1);
83  tf2::convert(k1, k1);
84  tf2::convert(k1, k2);
85  tf2::convert(k2, r1);
86  tf2::convert(r1, r1);
87  tf2::convert(r1, r2);
88  tf2::convert(r2, k3);
89  tf2::convert(k3, b3);
90  tf2::convert(b3, r3);
91  tf2::convert(r3, b4);
92 
93  EXPECT_EQ(b1.frame_id_, b4.frame_id_);
94  EXPECT_NEAR(b1.stamp_.toSec(), b4.stamp_.toSec(), epsilon);
95  EXPECT_NEAR(b1.x(), b4.x(), epsilon);
96  EXPECT_NEAR(b1.y(), b4.y(), epsilon);
97  EXPECT_NEAR(b1.z(), b4.z(), epsilon);
98 }
99 
100 int main(int argc, char** argv)
101 {
102  testing::InitGoogleTest(&argc, argv);
103  return RUN_ALL_TESTS();
104 }
105 
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 Fri Jun 7 2019 21:45:56