heatmap_node.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  */
37 #include <pluginlib/class_loader.h>
38 #include <algorithm>
39 #include <memory>
40 #include <string>
41 #include <vector>
42 
46 
56 int main(int argc, char** argv)
57 {
58  // *************** Initialize the Planner ****************************************************************************
59  ros::init(argc, argv, "plan");
60  ros::NodeHandle private_nh("~");
61  TFListenerPtr tf = std::make_shared<tf::TransformListener>(ros::Duration(10));
62 
63  std::string map_filename;
64  private_nh.param("map_filename", map_filename, std::string("package://global_planner_tests/maps/smile.png"));
65  std::shared_ptr<global_planner_tests::EasyCostmap> global_costmap =
66  std::make_shared<global_planner_tests::EasyCostmap>(map_filename);
67 
68  pluginlib::ClassLoader<nav_core2::GlobalPlanner> global_planner_loader("nav_core2", "nav_core2::GlobalPlanner");
69 
70  std::string planner_name;
71  private_nh.param("global_planner", planner_name, std::string("dlux_global_planner::DluxGlobalPlanner"));
72  boost::shared_ptr<nav_core2::GlobalPlanner> global_planner = global_planner_loader.createInstance(planner_name);
73  global_planner->initialize(private_nh, global_planner_loader.getName(planner_name), tf, global_costmap);
74 
75  // *************** Get a list of every free cell**********************************************************************
76  PoseList free_cells, occupied_cells;
77  groupCells(*global_costmap, free_cells, occupied_cells);
78 
79  int saved_pct = -1;
80  unsigned int n = free_cells.size();
81  if (n == 0)
82  {
83  return 0;
84  }
85 
86  // *************** Attempt planning between every pair of free cells**************************************************
87  int passing_plans = 0, total_plans = 0;
88  std::vector<unsigned int> failures(n, 0);
89 
90  for (unsigned int j = 0; j < n; j++)
91  {
92  for (unsigned int i = 0; i < n; i++)
93  {
94  // Print progress updates
95  {
96  int pct = (total_plans / static_cast<float>(n * n)) * 20;
97  if (pct != saved_pct)
98  {
99  float passing = 0.0;
100  if (total_plans > 0)
101  {
102  passing = 100.0 * passing_plans / total_plans;
103  }
104  ROS_INFO("%d%% complete. %d tests, %.0f%% passing", pct * 100 / 20, total_plans, passing);
105  saved_pct = pct;
106  }
107  }
108  total_plans = total_plans + 1;
109 
110  if (planExists(*global_planner, free_cells[i], free_cells[j]))
111  {
112  passing_plans = passing_plans + 1;
113  }
114  else
115  {
116  // Mark the start and end cells of the planning failure
117  failures[i] += 1;
118  failures[j] += 1;
119  }
120  if (!ros::ok()) return false;
121  }
122  }
123 
124  // *************** Construct/Print an ASCII map of the failures*******************************************************
125  const nav_grid::NavGridInfo& info = global_costmap->getInfo();
126  std::vector<char> mmap(info.width * info.height, '.');
127  unsigned int highest = *std::max_element(failures.begin(), failures.end());
128 
129  for (unsigned int i = 0; i < n; i++)
130  {
131  unsigned int x, y;
132  worldToGridBounded(info, free_cells[i].pose.x, free_cells[i].pose.y, x, y);
133  int ct = failures[i];
134  if (ct == 0)
135  {
136  mmap[ global_costmap->getIndex(x, y) ] = ' ';
137  }
138  else
139  {
140  double f = static_cast<double>(ct) / highest;
141  int m = static_cast<int>(f * 9);
142  mmap[ global_costmap->getIndex(x, y) ] = '0' + m;
143  }
144  }
145  for (int j = info.height - 1; j >= 0; j--)
146  {
147  for (unsigned int i = 0; i < info.width; i++)
148  {
149  printf("%c", mmap[ global_costmap->getIndex(i, j) ]);
150  }
151  printf("\n");
152  }
153 
154  ROS_INFO("%d/%d valid plans found.", passing_plans, total_plans);
155  return 0;
156 }
std::vector< nav_2d_msgs::Pose2DStamped > PoseList
f
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
TFSIMD_FORCE_INLINE const tfScalar & y() const
#define ROS_INFO(...)
bool param(const std::string &param_name, T &param_val, const T &default_val) const
ROSCPP_DECL bool ok()
TFSIMD_FORCE_INLINE const tfScalar & x() const
bool planExists(nav_core2::GlobalPlanner &planner, nav_2d_msgs::Pose2DStamped start, nav_2d_msgs::Pose2DStamped goal)
Simple check to see if a plan exists. Returns a boolean instead of returning path or throwing an exce...
int main(int argc, char **argv)
std::shared_ptr< tf::TransformListener > TFListenerPtr
void groupCells(const nav_core2::Costmap &costmap, PoseList &free_cells, PoseList &occupied_cells, bool include_edges=true)
Populate two lists of poses from a costmap. one with all the free cells, the other with all the occup...
bool worldToGridBounded(const NavGridInfo &info, double wx, double wy, unsigned int &mx, unsigned int &my)


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