resolution_test.cpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2018, Locus Robotics
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  */
34 #include <gtest/gtest.h>
35 #include <nav_2d_utils/path_ops.h>
36 
39 
40 TEST(ResolutionTest, simple_example)
41 {
42  nav_2d_msgs::Path2D path;
43  // Space between points is one meter
44  addPose(path, 0.0, 0.0);
45  addPose(path, 0.0, 1.0);
46 
47  // resolution>=1, path won't change
48  EXPECT_EQ(2U, adjustPlanResolution(path, 2.0).poses.size());
49  EXPECT_EQ(2U, adjustPlanResolution(path, 1.0).poses.size());
50 
51  // 0.5 <= resolution < 1.0, one point should be added in the middle
52  EXPECT_EQ(3U, adjustPlanResolution(path, 0.8).poses.size());
53  EXPECT_EQ(3U, adjustPlanResolution(path, 0.5).poses.size());
54 
55  // 0.333 <= resolution < 0.5, two points need to be added
56  EXPECT_EQ(4U, adjustPlanResolution(path, 0.34).poses.size());
57 
58  // 0.25 <= resolution < 0.333, three points need to be added
59  EXPECT_EQ(5U, adjustPlanResolution(path, 0.32).poses.size());
60 }
61 
62 TEST(ResolutionTest, real_example)
63 {
64  // This test is based on a real-world example
65  nav_2d_msgs::Path2D path;
66  addPose(path, 17.779193, -0.972024);
67  addPose(path, 17.799171, -0.950775);
68  addPose(path, 17.851942, -0.903709);
69  EXPECT_EQ(3U, adjustPlanResolution(path, 0.2).poses.size());
70  EXPECT_EQ(4U, adjustPlanResolution(path, 0.05).poses.size());
71 }
72 
73 
74 int main(int argc, char** argv)
75 {
76  testing::InitGoogleTest(&argc, argv);
77  return RUN_ALL_TESTS();
78 }
void addPose(nav_2d_msgs::Path2D &path, double x, double y, double theta=0.0)
Convenience function to add a pose to a path in one line.
Definition: path_ops.cpp:184
int main(int argc, char **argv)
nav_2d_msgs::Path2D adjustPlanResolution(const nav_2d_msgs::Path2D &global_plan_in, double resolution)
Increase plan resolution to match that of the costmap by adding points linearly between points...
Definition: path_ops.cpp:76
TEST(ResolutionTest, simple_example)


nav_2d_utils
Author(s):
autogenerated on Wed Jun 26 2019 20:06:11