helper.h
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 
21 #ifndef FOOTSTEP_PLANNER_HELPER_H_
22 #define FOOTSTEP_PLANNER_HELPER_H_
23 
24 #define DEBUG_HASH 0
25 #define DEBUG_TIME 0
26 
27 
28 #include <gridmap_2d/GridMap2D.h>
29 #include <angles/angles.h>
30 #include <tf/tf.h>
31 
32 #include <math.h>
33 
34 
35 namespace footstep_planner
36 {
37 static const double TWO_PI = 2 * M_PI;
38 
39 static const double FLOAT_CMP_THR = 0.0001;
40 
41 enum Leg { RIGHT=0, LEFT=1, NOLEG=2 };
42 
43 
48 inline double euclidean_distance_sq(int x1, int y1, int x2, int y2)
49 {
50  // note: do *not* use pow() to square!
51  return (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2);
52 }
53 
54 
56 inline double euclidean_distance(int x1, int y1, int x2, int y2)
57 {
58  return sqrt(double(euclidean_distance_sq(x1, y1, x2, y2)));
59 }
60 
61 
63 inline double euclidean_distance(double x1, double y1, double x2, double y2)
64 {
65  return sqrt(euclidean_distance_sq(x1, y1, x2, y2));
66 }
67 
68 
70 inline double euclidean_distance_sq(double x1, double y1, double x2,
71  double y2)
72 {
73  // note: do *not* use pow() to square!
74  return (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2);
75 }
76 
77 
79 inline double grid_cost(int x1, int y1, int x2, int y2, float cell_size)
80 {
81  int x = abs(x1 - x2);
82  int y = abs(y1 - y2);
83 
84  if (x + y > 1)
85  return M_SQRT2 * cell_size;
86  else
87  return cell_size;
88 }
89 
90 
92 inline int angle_state_2_cell(double angle, int angle_bin_num)
93 {
94  double bin_size_half = M_PI / angle_bin_num;
95  return int(angles::normalize_angle_positive(angle + bin_size_half) /
96  TWO_PI * angle_bin_num);
97 }
98 
99 
101 inline double angle_cell_2_state(int angle, int angle_bin_num)
102 {
103  double bin_size = TWO_PI / angle_bin_num;
104  return angle * bin_size;
105 }
106 
107 
112 inline int state_2_cell(float value, float cell_size)
113 {
114  return value >= 0 ? int(value / cell_size) : int(value / cell_size) - 1;
115 }
116 
117 
122 inline double cell_2_state(int value, double cell_size)
123 {
124  return (double(value) + 0.5) * cell_size;
125 }
126 
127 
129 // TODO: check consistency for negative values
130 inline int disc_val(double length, double cell_size)
131 {
132  return int(floor((length / cell_size) + 0.5));
133 }
134 
135 
140 // TODO: check consistency for negative values
141 inline double cont_val(int length, double cell_size)
142 {
143  return double(length * cell_size);
144 }
145 
146 
148 inline unsigned int int_hash(int key)
149 {
150  key += (key << 12);
151  key ^= (key >> 22);
152  key += (key << 4);
153  key ^= (key >> 9);
154  key += (key << 10);
155  key ^= (key >> 2);
156  key += (key << 7);
157  key ^= (key >> 12);
158  return key;
159 }
160 
161 
166 inline unsigned int calc_hash_tag(int x, int y, int theta, int leg,
167  int max_hash_size)
168 {
169  return int_hash((int_hash(x) << 3) + (int_hash(y) << 2) +
170  (int_hash(theta) << 1) + (int_hash(leg)))
171  % max_hash_size;
172 }
173 
174 
176 inline int round(double r)
177 {
178  return (r > 0.0) ? floor(r + 0.5) : ceil(r - 0.5);
179 }
180 
181 
200 bool collision_check(double x, double y, double theta,
201  double height, double width, int accuracy,
202  const gridmap_2d::GridMap2D& distance_map);
203 
204 
212 bool pointWithinPolygon(int x, int y,
213  const std::vector<std::pair<int, int> >& edges);
214 }
215 #endif /* FOOTSTEP_PLANNER_HELPER_H_ */
double cell_2_state(int value, double cell_size)
Calculate the respective (continuous) state value for a cell. (Should be used to get a State from a d...
Definition: helper.h:122
double grid_cost(int x1, int y1, int x2, int y2, float cell_size)
Definition: helper.h:79
static const double TWO_PI
Definition: helper.h:37
unsigned int int_hash(int key)
Definition: helper.h:148
double euclidean_distance_sq(int x1, int y1, int x2, int y2)
Definition: helper.h:48
static const double FLOAT_CMP_THR
Definition: helper.h:39
def normalize_angle_positive(angle)
double euclidean_distance(int x1, int y1, int x2, int y2)
Definition: helper.h:56
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
int disc_val(double length, double cell_size)
Discretize a (continuous) value into cell size.
Definition: helper.h:130
double angle_cell_2_state(int angle, int angle_bin_num)
Calculate the respective (continuous) angle for a bin.
Definition: helper.h:101
int state_2_cell(float value, float cell_size)
Discretize a (continuous) state value into a cell. (Should be used to discretize a State to a Plannin...
Definition: helper.h:112
int angle_state_2_cell(double angle, int angle_bin_num)
Discretize a (continuous) angle into a bin.
Definition: helper.h:92
int round(double r)
Rounding half towards zero.
Definition: helper.h:176
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
unsigned int calc_hash_tag(int x, int y, int theta, int leg, int max_hash_size)
Definition: helper.h:166
double cont_val(int length, double cell_size)
Calculates the continuous value for a length discretized in cell size.
Definition: helper.h:141


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