test_motion_cache.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018, 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 <cstddef>
31 
32 #include <gtest/gtest.h>
33 
37 
38 TEST(MotionCache, Generate)
39 {
40  const int range = 4;
41  const int angle = 4;
42  const float angular_resolution = M_PI * 2 / angle;
43  const float linear_resolution = 0.5;
44 
46  MotionCache cache;
47  cache.reset(
48  linear_resolution, angular_resolution, range,
49  gm.getAddressor());
50 
51  // Straight motions
52  const int xy_yaw_straight[][3] =
53  {
54  { 1, 0, 0 },
55  { 0, 1, 1 },
56  { -1, 0, 2 },
57  { 0, -1, 3 },
58  };
59  for (auto& xy_yaw : xy_yaw_straight)
60  {
61  for (int i = 1; i <= range + 1; ++i)
62  {
63  const CyclicVecInt<3, 2> goal(
64  i * xy_yaw[0], i * xy_yaw[1], xy_yaw[2]);
65  const auto c = cache.find(xy_yaw[2], goal);
66  if (i > range)
67  {
68  ASSERT_EQ(c, cache.end(xy_yaw[2]));
69  continue;
70  }
71  ASSERT_NE(c, cache.end(xy_yaw[2]));
72  for (const auto& p : c->second.getMotion())
73  {
74  // Must be in the same quadrant
75  if (xy_yaw[0] == 0)
76  ASSERT_EQ(xy_yaw[0], 0);
77  else
78  ASSERT_GE(p[0] * xy_yaw[0], 0);
79  if (xy_yaw[1] == 0)
80  ASSERT_EQ(xy_yaw[1], 0);
81  else
82  ASSERT_GE(p[1] * xy_yaw[1], 0);
83  }
84  ASSERT_EQ(c->second.getDistance(), i);
85  ASSERT_EQ(static_cast<int>(c->second.getMotion().size()), i);
86  }
87  }
88 
89  // 90 deg rotation
90  const int xy_syaw_gyaw_90[][4] =
91  {
92  { 1, 1, 0, 1 },
93  { -1, 1, 1, 2 },
94  { -1, -1, 2, 3 },
95  { 1, -1, 3, 0 },
96  { 1, -1, 0, 3 },
97  { 1, 1, 1, 0 },
98  { -1, 1, 2, 1 },
99  { -1, -1, 3, 2 },
100  };
101  for (auto& xy_syaw_gyaw : xy_syaw_gyaw_90)
102  {
103  for (int i = 1; i <= range + 1; ++i)
104  {
105  const CyclicVecInt<3, 2> goal(
106  i * xy_syaw_gyaw[0], i * xy_syaw_gyaw[1], xy_syaw_gyaw[3]);
107  const auto c = cache.find(xy_syaw_gyaw[2], goal);
108  if (i * sqrt(2) >= range)
109  {
110  ASSERT_EQ(c, cache.end(xy_syaw_gyaw[2]));
111  continue;
112  }
113  ASSERT_NE(c, cache.end(xy_syaw_gyaw[2]));
114 
115  for (const auto& p : c->second.getMotion())
116  {
117  // Must be in the same quadrant
118  ASSERT_GE(p[0] * xy_syaw_gyaw[0], 0);
119  ASSERT_GE(p[1] * xy_syaw_gyaw[1], 0);
120  }
121 
122  const float arc_length = i * 2 * M_PI / 4;
123  EXPECT_NEAR(c->second.getDistance(), arc_length, 0.1);
124  }
125  }
126 }
127 
128 int main(int argc, char** argv)
129 {
130  testing::InitGoogleTest(&argc, argv);
131 
132  return RUN_ALL_TESTS();
133 }
const Cache::const_iterator end(const int start_yaw) const
Definition: motion_cache.h:74
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
const Cache::const_iterator find(const int start_yaw, const CyclicVecInt< 3, 2 > &goal) const
Definition: motion_cache.h:65
TEST(MotionCache, Generate)
INLINE Rall1d< T, V, S > sqrt(const Rall1d< T, V, S > &arg)
std::function< void(CyclicVecInt< 3, 2 >, size_t &, size_t &)> getAddressor() const
void reset(const float linear_resolution, const float angular_resolution, const int range, const std::function< void(CyclicVecInt< 3, 2 >, size_t &, size_t &)> gm_addr)
int main(int argc, char **argv)


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