grid_map_model.cpp
Go to the documentation of this file.
2 
3 
4 
6 {
7 GridMapModel::GridMapModel(const std::string& name)
8  : CollisionCheckGridMapPlugin(name)
9 {
10 }
11 
12 bool GridMapModel::loadParams(const vigir_generic_params::ParameterSet& params)
13 {
14  if (!CollisionCheckGridMapPlugin::loadParams(params))
15  return false;
16 
17  params.getParam("collision_check/collision_check_accuracy", (int&)collision_check_accuracy);
18  return true;
19 }
20 
21 void GridMapModel::mapCallback(const nav_msgs::OccupancyGridConstPtr& occupancy_grid_map)
22 {
23  CollisionCheckGridMapPlugin::mapCallback(occupancy_grid_map);
24 
25  boost::unique_lock<boost::shared_mutex> lock(grid_map_shared_mutex_);
26  distance_map.setMap(occupancy_grid_map);
27 }
28 
29 bool GridMapModel::collision_check(double x, double y, double cos_theta, double sin_theta, double height, double width) const
30 {
31  double d = distance_map.distanceMapAt(x, y);
32 
33  bool out_of_bounds = d < 0.0; // if out of bounds => assume no collision
34 
35  if (out_of_bounds && collision_check_accuracy != 2)
36  return false;
37 
38  d = std::max(d-distance_map.getResolution(), 0.0);
39 
40  double r_o = width*width + height*height;
41 
42  if (!out_of_bounds)
43  {
44  if (d*d >= 0.25 * r_o)
45  return false;
46  else if (collision_check_accuracy == 0)
47  return false;
48  }
49 
50  double h_half = 0.5 * height;
51  double w_half = 0.5 * width;
52  double r_i = std::min(w_half, h_half);
53 
54  if (!out_of_bounds)
55  {
56  if (d <= r_i)
57  return true;
58  else if (collision_check_accuracy == 1)
59  return true;
60  }
61  else if (r_i < distance_map.getResolution())
62  {
63  return false;
64  }
65 
66  double h_new;
67  double w_new;
68  double delta_x;
69  double delta_y;
70  if (width < height)
71  {
72  double h_clear = out_of_bounds ? 0.0 : sqrt(d*d - w_half*w_half);
73  h_new = h_half - h_clear;
74  w_new = width;
75  delta_x = h_clear + 0.5 * h_new;
76  delta_y = 0.0;
77  }
78  else // footWidth >= footHeight
79  {
80  double w_clear = out_of_bounds ? 0.0 : sqrt(d*d - h_half*h_half);
81  h_new = height;
82  w_new = w_half - w_clear;
83  delta_x = 0.0;
84  delta_y = w_clear + 0.5 * w_new;
85  }
86  double x_shift = cos_theta*delta_x - sin_theta*delta_y;
87  double y_shift = sin_theta*delta_x + cos_theta*delta_y;
88 
89  return (collision_check(x+x_shift, y+y_shift, cos_theta, sin_theta, h_new, w_new) ||
90  collision_check(x-x_shift, y-y_shift, cos_theta, sin_theta, h_new, w_new));
91 }
92 }
d
void setMap(const nav_msgs::OccupancyGridConstPtr &gridMap)
Initialize map from a ROS OccupancyGrid message.
Definition: grid_map_2d.cpp:56
GridMapModel(const std::string &name)
void mapCallback(const nav_msgs::OccupancyGridConstPtr &occupancy_grid_map_)
bool collision_check(double x, double y, double cos_theta, double sin_theta, double height, double width) const
Checks if a footstep (represented by its center and orientation) collides with an obstacle...
vigir_gridmap_2d::GridMap2D distance_map
float distanceMapAt(double wx, double wy) const
Returns distance (in m) at world coordinates <wx,wy> in m; -1 if out of bounds!
float getResolution() const
Definition: grid_map_2d.h:119
bool loadParams(const vigir_generic_params::ParameterSet &params=vigir_generic_params::ParameterSet()) override


vigir_footstep_planning_default_plugins
Author(s): Alexander Stumpf
autogenerated on Sun Nov 17 2019 03:30:01