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


planner_cspace
Author(s): Atsushi Watanabe
autogenerated on Wed May 12 2021 02:20:42