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 <cmath>
31 
32 #include <ros/ros.h>
33 
36 
38 
39 #include <gtest/gtest.h>
40 
42  const tf2::Stamped<tf2::Transform> proj2base,
43  const tf2::Stamped<tf2::Transform> targ2proj,
44  const tf2::Stamped<tf2::Transform> truth)
45 {
46  tf2::Transform result = track_odometry::projectTranslation(proj2base, targ2proj);
47 
48  const double error_x = std::abs(result.getOrigin().x() - truth.getOrigin().x());
49  const double error_y = std::abs(result.getOrigin().y() - truth.getOrigin().y());
50  const double error_z = std::abs(result.getOrigin().z() - truth.getOrigin().z());
51  const tf2::Quaternion error_q = result.getRotation() * truth.getRotation().inverse();
52  ASSERT_LT(error_x, 0.001);
53  ASSERT_LT(error_y, 0.001);
54  ASSERT_LT(error_z, 0.001);
55  ASSERT_LT(std::abs(error_q.getAngle()), 0.001);
56 }
57 
58 TEST(TfProjection, ProjectionTransform)
59 {
62  tf2::Transform(tf2::Quaternion(tf2::Vector3(0.0, 0.0, 1.0), M_PI / 2.0),
63  tf2::Vector3(1.0, 3.0, 10.0)),
64  ros::Time(0),
65  "map"),
66  // projected: t(1.0, 3.0, 0.0), r((0.0, 0.0, 1.0), M_PI/2.0)
68  tf2::Transform(tf2::Quaternion(tf2::Vector3(0.0, 0.0, 1.0), M_PI / 2.0),
69  tf2::Vector3(1.0, 0.0, 0.5)),
70  ros::Time(0),
71  "odom"),
72  // rotate 90deg: (-3.0, 1.0, 0.0), r((0.0, 0.0, 1.0), M_PI)
73  // offset x+1.0, z+0.5: t(-2.0, 1.0, 0.5), r((0.0, 0.0, 1.0), M_PI)
75  tf2::Transform(tf2::Quaternion(tf2::Vector3(0.0, 0.0, 1.0), M_PI),
76  tf2::Vector3(-2.0, 1.0, 0.5)),
77  ros::Time(0),
78  "odom"));
79 
82  tf2::Transform(tf2::Quaternion(tf2::Vector3(0.0, 0.0, 1.0), 0.0),
83  tf2::Vector3(1.0, 1.0, 100.0)),
84  ros::Time(0),
85  "map"),
86  // projected: t(1.0, 1.0, 0.0), r((0.0, 0.0, 1.0), 0.0)
88  tf2::Transform(tf2::Quaternion(tf2::Vector3(1.0, 0.0, 0.0), M_PI / 6.0),
89  tf2::Vector3(0.0, -std::sqrt(3.0) / 2.0, 3.0 / 2.0)),
90  ros::Time(0),
91  "odom"),
92  // rotate 30deg and offset to make it on z axis
94  tf2::Transform(tf2::Quaternion(tf2::Vector3(1.0, 0.0, 0.0), M_PI / 6.0),
95  tf2::Vector3(1.0, 0.0, 2.0)),
96  ros::Time(0),
97  "odom"));
98 }
99 
100 int main(int argc, char** argv)
101 {
102  ::testing::InitGoogleTest(&argc, argv);
103 
104  return RUN_ALL_TESTS();
105 }
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 Wed May 12 2021 02:20:38