test_tf_projection.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2017, the neonavigation authors
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the copyright holder nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <ros/ros.h>
33 
35 #include <gtest/gtest.h>
36 
38  const tf2::Stamped<tf2::Transform> proj2base,
39  const tf2::Stamped<tf2::Transform> targ2proj,
40  const tf2::Stamped<tf2::Transform> truth)
41 {
42  tf2::Transform result = track_odometry::projectTranslation(proj2base, targ2proj);
43 
44  const float error_x = fabs(result.getOrigin().x() - truth.getOrigin().x());
45  const float error_y = fabs(result.getOrigin().y() - truth.getOrigin().y());
46  const float error_z = fabs(result.getOrigin().z() - truth.getOrigin().z());
47  const tf2::Quaternion error_q = result.getRotation() * truth.getRotation().inverse();
48  ASSERT_LT(error_x, 0.001);
49  ASSERT_LT(error_y, 0.001);
50  ASSERT_LT(error_z, 0.001);
51  ASSERT_LT(fabs(error_q.getAngle()), 0.001);
52 }
53 
54 TEST(TfProjection, ProjectionTransform)
55 {
58  tf2::Transform(tf2::Quaternion(tf2::Vector3(0.0, 0.0, 1.0), M_PI / 2.0),
59  tf2::Vector3(1.0, 3.0, 10.0)),
60  ros::Time(0),
61  "map"),
62  // projected: t(1.0, 3.0, 0.0), r((0.0, 0.0, 1.0), M_PI/2.0)
64  tf2::Transform(tf2::Quaternion(tf2::Vector3(0.0, 0.0, 1.0), M_PI / 2.0),
65  tf2::Vector3(1.0, 0.0, 0.5)),
66  ros::Time(0),
67  "odom"),
68  // rotate 90deg: (-3.0, 1.0, 0.0), r((0.0, 0.0, 1.0), M_PI)
69  // offset x+1.0, z+0.5: t(-2.0, 1.0, 0.5), r((0.0, 0.0, 1.0), M_PI)
71  tf2::Transform(tf2::Quaternion(tf2::Vector3(0.0, 0.0, 1.0), M_PI),
72  tf2::Vector3(-2.0, 1.0, 0.5)),
73  ros::Time(0),
74  "odom"));
75 
78  tf2::Transform(tf2::Quaternion(tf2::Vector3(0.0, 0.0, 1.0), 0.0),
79  tf2::Vector3(1.0, 1.0, 100.0)),
80  ros::Time(0),
81  "map"),
82  // projected: t(1.0, 1.0, 0.0), r((0.0, 0.0, 1.0), 0.0)
84  tf2::Transform(tf2::Quaternion(tf2::Vector3(1.0, 0.0, 0.0), M_PI / 6.0),
85  tf2::Vector3(0.0, -sqrtf(3.0) / 2.0, 3.0 / 2.0)),
86  ros::Time(0),
87  "odom"),
88  // rotate 30deg and offset to make it on z axis
90  tf2::Transform(tf2::Quaternion(tf2::Vector3(1.0, 0.0, 0.0), M_PI / 6.0),
91  tf2::Vector3(1.0, 0.0, 2.0)),
92  ros::Time(0),
93  "odom"));
94 }
95 
96 int main(int argc, char** argv)
97 {
98  ::testing::InitGoogleTest(&argc, argv);
99 
100  return RUN_ALL_TESTS();
101 }
Quaternion getRotation() const
TF2SIMD_FORCE_INLINE Vector3 & getOrigin()
void testTransform(const tf2::Stamped< tf2::Transform > proj2base, const tf2::Stamped< tf2::Transform > targ2proj, const tf2::Stamped< tf2::Transform > truth)
tf2::Transform projectTranslation(const tf2::Transform &trans, const tf2::Transform &trans_target)
TEST(TfProjection, ProjectionTransform)
int main(int argc, char **argv)


track_odometry
Author(s): Atsushi Watanabe
autogenerated on Tue Jul 9 2019 05:00:05