many_map_test_suite.cpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2017, 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 
39 #include <yaml-cpp/yaml.h>
40 #include <memory>
41 #include <string>
42 #include <vector>
43 
44 namespace global_planner_tests
45 {
47  const std::string& planner_name, const std::string& maps_list_filename,
48  bool check_exception_type, bool verbose, bool quit_early)
49 {
50  // Initialize Costmap
51  ros::NodeHandle nh("~");
52  std::shared_ptr<EasyCostmap> easy_costmap = std::make_shared<EasyCostmap>();
53  planner.initialize(nh, planner_name, tf, easy_costmap);
54 
55  // Read Configuration
56  YAML::Node config = YAML::LoadFile(resolve_filename(maps_list_filename));
57  std::string prefix = "";
58  int max_failure_cases = 10;
59  if (config["standard_prefix"])
60  {
61  prefix = config["standard_prefix"].as<std::string>();
62  }
63  if (config["max_failure_cases"])
64  {
65  max_failure_cases = config["max_failure_cases"].as<int>();
66  }
67 
68  // Start the timer
69  struct timeval start, end;
70  double start_t, end_t, t_diff;
71  gettimeofday(&start, nullptr);
72 
73  bool passes_all = true;
74 
75  // Check all the Full Coverage Maps
76  for (const std::string base_filename : config["full_coverage_maps"].as<std::vector<std::string> >())
77  {
78  std::string map_filename = prefix + base_filename;
79  ROS_INFO("Testing full coverage map \"%s\"", map_filename.c_str());
80  easy_costmap->loadMapFromFile(map_filename);
81 
82  bool ret = global_planner_tests::hasCompleteCoverage(planner, *easy_costmap, max_failure_cases,
83  check_exception_type, verbose, quit_early);
84  if (quit_early && !ret) return ret;
85  passes_all &= ret;
86  }
87 
88  // Check all the No Coverage Maps
89  for (const std::string base_filename : config["no_coverage_maps"].as<std::vector<std::string> >())
90  {
91  std::string map_filename = prefix + base_filename;
92  ROS_INFO("Testing no coverage map \"%s\"", map_filename.c_str());
93  easy_costmap->loadMapFromFile(map_filename);
94 
95  bool invalid_test = global_planner_tests::hasNoPaths(planner, *easy_costmap,
96  check_exception_type, verbose, quit_early);
97  if (quit_early && !invalid_test) return invalid_test;
98  passes_all &= invalid_test;
99  }
100 
101  gettimeofday(&end, nullptr);
102  start_t = start.tv_sec + static_cast<double>(start.tv_usec) / 1e6;
103  end_t = end.tv_sec + static_cast<double>(end.tv_usec) / 1e6;
104  t_diff = end_t - start_t;
105  ROS_INFO("%s Full Planning Time: %.9f", planner_name.c_str(), t_diff);
106 
107  return passes_all;
108 }
109 } // namespace global_planner_tests
std::string resolve_filename(const std::string &filename)
Replace a package:// prefix with the actual path to the given package.
Definition: util.cpp:43
virtual void initialize(const ros::NodeHandle &parent, const std::string &name, TFListenerPtr tf, Costmap::Ptr costmap)=0
bool many_map_test_suite(nav_core2::GlobalPlanner &planner, TFListenerPtr tf, const std::string &planner_name, const std::string &maps_list_filename="package://global_planner_tests/config/standard_tests.yaml", bool check_exception_type=true, bool verbose=false, bool quit_early=true)
Run a collection of global_planner_tests on the provided maps.
#define ROS_INFO(...)
bool hasCompleteCoverage(nav_core2::GlobalPlanner &planner, const nav_core2::Costmap &costmap, int max_failure_cases=10, bool check_exception_type=true, bool verbose=false, bool quit_early=true)
Run a bunch of tests, assuming there is a valid path from any free cell to any other free cell...
std::shared_ptr< tf::TransformListener > TFListenerPtr
bool hasNoPaths(nav_core2::GlobalPlanner &planner, const nav_core2::Costmap &costmap, bool check_exception_type=true, bool verbose=false, bool quit_early=true)
Run a bunch of tests, assuming there are no valid paths from any free cell to any other free cell...


global_planner_tests
Author(s):
autogenerated on Sun Jan 10 2021 04:08:30