helper.cpp
Go to the documentation of this file.
1 /*
2  * A footstep planner for humanoid robots
3  *
4  * Copyright 2010-2011 Johannes Garimort, Armin Hornung, University of Freiburg
5  * http://www.ros.org/wiki/footstep_planner
6  *
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, version 3.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
22 
23 namespace footstep_planner
24 {
25 bool
26 collision_check(double x, double y, double theta, double height,
27  double width, int accuracy,
28  const gridmap_2d::GridMap2D& distance_map)
29 {
30  double d = distance_map.distanceMapAt(x, y);
31  if (d < 0.0) // if out of bounds => collision
32  return true;
33  d -= distance_map.getResolution();
34 
35  const double r_o = sqrt(width*width + height*height) / 2.0;
36 
37  if (d >= r_o)
38  return false;
39  else if (accuracy == 0)
40  return false;
41 
42  const double h_half = height / 2.0;
43  const double w_half = width / 2.0;
44  const double r_i = std::min(w_half, h_half);
45 
46  if (d <= r_i)
47  return true;
48  else if (accuracy == 1)
49  return true;
50 
51  double h_new;
52  double w_new;
53  double delta_x;
54  double delta_y;
55  if (width < height)
56  {
57  const double h_clear = sqrt(d*d - w_half*w_half);
58  h_new = h_half - h_clear;
59  w_new = width;
60  delta_x = h_clear + h_new / 2.0;
61  delta_y = 0.0;
62  }
63  else // footWidth >= footHeight
64  {
65  const double w_clear = sqrt(d*d - h_half*h_half);
66  h_new = height;
67  w_new = w_half - w_clear;
68  delta_x = 0.0;
69  delta_y = w_clear + w_new / 2.0;
70  }
71  const double theta_cos = cos(theta);
72  const double theta_sin = sin(theta);
73  const double x_shift = theta_cos*delta_x - theta_sin*delta_y;
74  const double y_shift = theta_sin*delta_x + theta_cos*delta_y;
75 
76  return (collision_check(x+x_shift, y+y_shift, theta, h_new, w_new,
77  accuracy, distance_map) ||
78  collision_check(x-x_shift, y-y_shift, theta, h_new, w_new,
79  accuracy, distance_map));
80 }
81 
82 
83 bool
84 pointWithinPolygon(int x, int y, const std::vector<std::pair<int, int> >& edges)
85 {
86  int cn = 0;
87 
88  // loop through all edges of the polygon
89  for(unsigned int i = 0; i < edges.size() - 1; ++i)
90  {
91  if ((edges[i].second <= y && edges[i + 1].second > y) ||
92  (edges[i].second > y && edges[i + 1].second <= y))
93  {
94  float vt = (float)(y - edges[i].second) /
95  (edges[i + 1].second - edges[i].second);
96  if (x < edges[i].first + vt * (edges[i + 1].first - edges[i].first))
97  {
98  ++cn;
99  }
100  }
101  }
102  return cn & 1;
103 }
104 }
d
float getResolution() const
bool collision_check(double x, double y, double theta, double height, double width, int accuracy, const gridmap_2d::GridMap2D &distance_map)
Checks if a footstep (represented by its center and orientation) collides with an obstacle...
Definition: helper.cpp:26
float distanceMapAt(double wx, double wy) const
bool pointWithinPolygon(int x, int y, const std::vector< std::pair< int, int > > &edges)
Crossing number method to determine whether a point lies within a polygon or not. ...
Definition: helper.cpp:84


footstep_planner
Author(s): Johannes Garimort, Armin Hornung
autogenerated on Mon Jun 10 2019 13:38:24