test_state_6dof.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019, the mcl_3dl 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 <cstddef>
31 #include <cmath>
32 
33 #include <gtest/gtest.h>
34 
35 #include <mcl_3dl/state_6dof.h>
36 
37 TEST(State6DOF, Constructors)
38 {
39  const mcl_3dl::State6DOF a(
40  mcl_3dl::Vec3(1.0, 2.0, 3.0), mcl_3dl::Quat(0.001, 0.002, 0.003, 0.99));
41 
42  ASSERT_FALSE(a.isDiff());
43  ASSERT_EQ(a.pos_, mcl_3dl::Vec3(1.0, 2.0, 3.0));
44  ASSERT_EQ(a.rot_, mcl_3dl::Quat(0.001, 0.002, 0.003, 0.99));
45  ASSERT_EQ(a.rot_, mcl_3dl::Quat(0.001, 0.002, 0.003, 0.99));
46  ASSERT_EQ(a.odom_err_integ_lin_, mcl_3dl::Vec3(0.0, 0.0, 0.0));
47  ASSERT_EQ(a.odom_err_integ_ang_, mcl_3dl::Vec3(0.0, 0.0, 0.0));
48 
49  const mcl_3dl::State6DOF b(
50  mcl_3dl::Vec3(4.0, 5.0, 6.0), mcl_3dl::Vec3(0.1, 0.2, 0.3));
51 
52  ASSERT_TRUE(b.isDiff());
53  ASSERT_EQ(b.pos_, mcl_3dl::Vec3(4.0, 5.0, 6.0));
54  ASSERT_EQ(b.rot_, mcl_3dl::Quat(0.0, 0.0, 0.0, 1.0));
55  ASSERT_EQ(b.rpy_.v_, mcl_3dl::Vec3(0.1, 0.2, 0.3));
56  ASSERT_EQ(b.odom_err_integ_lin_, mcl_3dl::Vec3(0.0, 0.0, 0.0));
57  ASSERT_EQ(b.odom_err_integ_ang_, mcl_3dl::Vec3(0.0, 0.0, 0.0));
58 }
59 
60 TEST(State6DOF, Accessors)
61 {
62  const mcl_3dl::State6DOF a(
63  mcl_3dl::Vec3(1.0, 2.0, 3.0), mcl_3dl::Quat(0.001, 0.002, 0.003, 0.99));
64 
65  ASSERT_EQ(a[0], 1.0f);
66  ASSERT_EQ(a[1], 2.0f);
67  ASSERT_EQ(a[2], 3.0f);
68  ASSERT_EQ(a[3], 0.001f);
69  ASSERT_EQ(a[4], 0.002f);
70  ASSERT_EQ(a[5], 0.003f);
71  ASSERT_EQ(a[6], 0.99f);
72  ASSERT_EQ(a[7], 0.0f);
73  ASSERT_EQ(a[8], 0.0f);
74  ASSERT_EQ(a[9], 0.0f);
75  ASSERT_EQ(a[10], 0.0f);
76  ASSERT_EQ(a[11], 0.0f);
77  ASSERT_EQ(a[12], 0.0f);
78 
80  for (size_t i = 0; i < b.size(); ++i)
81  b[i] = 0.1 * (i + 1);
82  for (size_t i = 0; i < b.size(); ++i)
83  ASSERT_FLOAT_EQ(b[i], 0.1 * (i + 1));
84 
85  const mcl_3dl::State6DOF c = b;
86  for (size_t i = 0; i < b.size(); ++i)
87  ASSERT_FLOAT_EQ(c[i], 0.1 * (i + 1));
88 }
89 
90 TEST(State6DOF, Adder)
91 {
92  const mcl_3dl::State6DOF a(
93  mcl_3dl::Vec3(1.0, 2.0, 3.0), mcl_3dl::Quat(mcl_3dl::Vec3(0.0, 0.0, 1.0), 0.1));
94  const mcl_3dl::State6DOF b(
95  mcl_3dl::Vec3(4.0, 5.0, 6.0), mcl_3dl::Quat(mcl_3dl::Vec3(0.0, 0.0, 1.0), 0.2));
96 
97  const mcl_3dl::State6DOF sum = a + b;
98  const mcl_3dl::State6DOF sub = a - b;
99  const mcl_3dl::Quat sum_rot(mcl_3dl::Vec3(0.0, 0.0, 1.0), 0.3);
100  const mcl_3dl::Quat sub_rot(mcl_3dl::Vec3(0.0, 0.0, 1.0), -0.1);
101 
102  ASSERT_EQ(sum.pos_, mcl_3dl::Vec3(5.0, 7.0, 9.0));
103  ASSERT_FLOAT_EQ(sum.rot_.x_, sum_rot.x_);
104  ASSERT_FLOAT_EQ(sum.rot_.y_, sum_rot.y_);
105  ASSERT_FLOAT_EQ(sum.rot_.z_, sum_rot.z_);
106  ASSERT_FLOAT_EQ(sum.rot_.w_, sum_rot.w_);
107  ASSERT_EQ(sub.pos_, mcl_3dl::Vec3(-3.0, -3.0, -3.0));
108  ASSERT_FLOAT_EQ(sub.rot_.x_, sub_rot.x_);
109  ASSERT_FLOAT_EQ(sub.rot_.y_, sub_rot.y_);
110  ASSERT_FLOAT_EQ(sub.rot_.z_, sub_rot.z_);
111  ASSERT_FLOAT_EQ(sub.rot_.w_, sub_rot.w_);
112 }
113 
114 int main(int argc, char** argv)
115 {
116  testing::InitGoogleTest(&argc, argv);
117 
118  return RUN_ALL_TESTS();
119 }
f
float y_
Definition: quat.h:44
mcl_3dl::Vec3 pos_
Definition: state_6dof.h:52
mcl_3dl::Vec3 odom_err_integ_ang_
Definition: state_6dof.h:60
mcl_3dl::Vec3 odom_err_integ_lin_
Definition: state_6dof.h:59
size_t size() const override
Definition: state_6dof.h:150
TEST(State6DOF, Constructors)
float w_
Definition: quat.h:46
bool isDiff() const
Definition: state_6dof.h:183
int main(int argc, char **argv)
mcl_3dl::Quat rot_
Definition: state_6dof.h:53
float z_
Definition: quat.h:45
float x_
Definition: quat.h:43


mcl_3dl
Author(s): Atsushi Watanabe
autogenerated on Wed May 12 2021 02:16:29