footstep.cpp
Go to the documentation of this file.
1 // SVN $HeadURL: https://alufr-ros-pkg.googlecode.com/svn/trunk/humanoid_navigation/footstep_planner/src/Dstar.cpp $
2 // SVN $Id: Dstar.cpp 1168 2011-03-30 03:18:02Z hornunga@informatik.uni-freiburg.de $
3 
4 /*
5  * A footstep planner for humanoid robots
6  *
7  * Copyright 2010-2011 Johannes Garimort, Armin Hornung, University of Freiburg
8  * http://www.ros.org/wiki/footstep_planner
9  *
10  * D* Lite (Koenig et al. 2002) partly based on the implementation
11  * by J. Neufeld (http://code.google.com/p/dstarlite/)
12  *
13  *
14  * This program is free software: you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation, version 3.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program. If not, see <http://www.gnu.org/licenses/>.
25  */
26 
28 
29 
31 {
32 Footstep::Footstep(double x, double y, double theta, double step_cost, double cell_size, int num_angle_bins, int max_hash_size)
33  : ivCellSize(cell_size)
34  , ivNumAngleBins(num_angle_bins)
35  , ivAngleBinSize(2.0*M_PI / ivNumAngleBins)
36  , ivTheta(angle_state_2_cell(theta, ivAngleBinSize))
37  , ivStepCost(step_cost)
38  , ivMaxHashSize(max_hash_size)
39  , ivDiscSuccessorLeft(num_angle_bins)
40  , ivDiscSuccessorRight(num_angle_bins)
41  , ivDiscPredecessorLeft(num_angle_bins)
42  , ivDiscPredecessorRight(num_angle_bins)
43 {
44  init(x, y);
45 }
46 
48 {}
49 
50 void Footstep::init(double x, double y)
51 {
52  int backward_angle;
53  int footstep_x;
54  int footstep_y;
55 
56  for (int a = 0; a < ivNumAngleBins; ++a)
57  {
58  backward_angle = calculateForwardStep(RIGHT, a, x, y, &footstep_x, &footstep_y);
59  ivDiscSuccessorRight[a] = footstep_xy(footstep_x, footstep_y);
60  ivDiscPredecessorLeft[backward_angle] = footstep_xy(-footstep_x, -footstep_y);
61 
62  backward_angle = calculateForwardStep(LEFT, a, x, y, &footstep_x, &footstep_y);
63  ivDiscSuccessorLeft[a] = footstep_xy(footstep_x, footstep_y);
64  ivDiscPredecessorRight[backward_angle] = footstep_xy(-footstep_x, -footstep_y);
65  }
66 }
67 
69 {
70  assert(current.getPredState() != nullptr);
71 
72  const State& left = (current.getLeg() == LEFT) ? current.getState() : current.getPredState()->getState();
73  const State& right = (current.getLeg() == RIGHT) ? current.getState() : current.getPredState()->getState();
74 
75  State swing = current.getState();
76  int x = current.getX();
77  int y = current.getY();
78  int yaw = current.getYaw();
79 
80  // theta has to be in [0..ivNumAngleBins)
81  if (yaw < 0)
82  yaw += ivNumAngleBins;
83  else if (yaw >= ivNumAngleBins)
84  yaw -= ivNumAngleBins;
85 
86  if (current.getLeg() == RIGHT)
87  {
89  x += xy.first;
90  y += xy.second;
91  yaw += ivTheta;
92  swing.setLeg(LEFT);
93  }
94  else // leg == LEFT
95  {
97  x += xy.first;
98  y += xy.second;
99  yaw -= ivTheta;
100  swing.setLeg(RIGHT);
101  }
102 
103  swing.setX(cell_2_state(x, ivCellSize));
104  swing.setY(cell_2_state(y, ivCellSize));
105  swing.setZ(current.getState().getZ());
106 
108  swing.setYaw(yaw_d);
109 
110  return PlanningState(swing, ivCellSize, ivAngleBinSize, ivMaxHashSize, &current, nullptr);
111 }
112 
114 {
115  assert(current.getSuccState() != nullptr);
116 
117  const State& left = (current.getLeg() == LEFT) ? current.getState() : current.getSuccState()->getState();
118  const State& right = (current.getLeg() == RIGHT) ? current.getState() : current.getSuccState()->getState();
119 
120  State swing = current.getState();
121  int x = current.getX();
122  int y = current.getY();
123  int yaw = current.getYaw();
124 
125  // theta has to be in [0..ivNumAngleBins)
126  if (yaw < 0)
127  yaw += ivNumAngleBins;
128  else if (yaw >= ivNumAngleBins)
129  yaw -= ivNumAngleBins;
130 
131  if (current.getLeg() == RIGHT)
132  {
134  x += xy.first;
135  y += xy.second;
136  yaw += ivTheta;
137  swing.setLeg(LEFT);
138  }
139  else // leg == LEFT
140  {
142  x += xy.first;
143  y += xy.second;
144  yaw -= ivTheta;
145  swing.setLeg(RIGHT);
146  }
147 
148  swing.setX(cell_2_state(x, ivCellSize));
149  swing.setY(cell_2_state(y, ivCellSize));
150  swing.setZ(current.getState().getZ());
151 
153  swing.setYaw(yaw_d);
154 
155  return PlanningState(swing, ivCellSize, ivAngleBinSize, ivMaxHashSize, nullptr, &current);
156 }
157 
158 int Footstep::calculateForwardStep(Leg leg, int global_theta, double x, double y, int* footstep_x, int* footstep_y) const
159 {
160  double cont_footstep_x, cont_footstep_y;
161  double cont_global_theta = angle_cell_2_state(global_theta, ivAngleBinSize);
162  double theta_cos = cos(cont_global_theta);
163  double theta_sin = sin(cont_global_theta);
164  if (leg == RIGHT)
165  {
166  cont_footstep_x = theta_cos * x - theta_sin * y;
167  cont_footstep_y = theta_sin * x + theta_cos * y;
168 
169  global_theta += ivTheta;
170  }
171  else // leg == LEFT
172  {
173  cont_footstep_x = theta_cos * x + theta_sin * y;
174  cont_footstep_y = theta_sin * x - theta_cos * y;
175 
176  global_theta -= ivTheta;
177  }
178  *footstep_x = disc_val(cont_footstep_x, ivCellSize);
179  *footstep_y = disc_val(cont_footstep_y, ivCellSize);
180 
181  // theta has to be in [0..ivNumAngleBins)
182  if (global_theta < 0)
183  global_theta += ivNumAngleBins;
184  else if (global_theta >= ivNumAngleBins)
185  global_theta -= ivNumAngleBins;
186  return global_theta;
187 }
188 } // end of namespace
Footstep(double x, double y, double theta, double step_cost, double cell_size, int num_angle_bins, int max_hash_size)
The constructor takes the continuous translation and rotation of the footstep and calculates the resp...
Definition: footstep.cpp:32
int angle_state_2_cell(double angle, double angle_bin_size)
Discretize a (continuous) angle into a bin.
Definition: math.h:167
void init(double x, double y)
Initialization method called within the constructor.
Definition: footstep.cpp:50
std::vector< footstep_xy > ivDiscSuccessorRight
The (discretized) translation(s) for a right supporting foot.
Definition: footstep.h:129
PlanningState reverseMeOnThisState(const PlanningState &current) const
Reverse this footstep on a given planning state.
Definition: footstep.cpp:113
std::pair< int, int > footstep_xy
Typedef representing the (discretized) translation of the footstep.
Definition: footstep.h:88
int ivNumAngleBins
The parameter for the discretization of the rotation.
Definition: footstep.h:115
double ivCellSize
The parameter for the discretization of the translation.
Definition: footstep.h:113
std::vector< footstep_xy > ivDiscSuccessorLeft
The (discretized) translation(s) for a left supporting foot.
Definition: footstep.h:127
A class representing the robot&#39;s pose (i.e. position and orientation) in the underlying SBPL...
TFSIMD_FORCE_INLINE const tfScalar & y() const
int ivTheta
The (discretized) rotation of the footstep.
Definition: footstep.h:119
void setY(double y)
Definition: state.h:76
std::vector< footstep_xy > ivDiscPredecessorLeft
The reversed (discretized) translation(s) for a left supporting foot.
Definition: footstep.h:131
const PlanningState * getPredState() const
void setZ(double z)
Definition: state.h:77
A class representing the robot&#39;s pose (i.e. position and orientation) in the (continuous) world view...
Definition: state.h:49
const PlanningState * getSuccState() const
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: math.h:202
PlanningState performMeOnThisState(const PlanningState &current) const
Performs this footstep (translation and rotation) on a given planning state.
Definition: footstep.cpp:68
int ivMaxHashSize
The maximal hash size.
Definition: footstep.h:124
TFSIMD_FORCE_INLINE const tfScalar & x() const
def normalize_angle(angle)
int disc_val(double length, double cell_size)
Discretize a (continuous) value into cell size.
Definition: math.h:147
double getZ() const
Definition: state.h:99
int calculateForwardStep(Leg leg, int global_theta, double x, double y, int *footstep_x, int *footstep_y) const
Discretizes the translation of the footstep for a certain (discretized) orientation of a possible sta...
Definition: footstep.cpp:158
const State & getState() const
gets the continuous State the PlanningState represents.
void setYaw(double yaw)
Definition: state.h:81
double angle_cell_2_state(int angle, double angle_bin_size)
Calculate the respective (continuous) angle for a bin.
Definition: math.h:178
std::vector< footstep_xy > ivDiscPredecessorRight
The reversed (discretized) translation(s) for a right supporting foot.
Definition: footstep.h:133
void setX(double x)
Definition: state.h:75
void setLeg(Leg leg)
Definition: state.h:91


vigir_footstep_planning_lib
Author(s): Alexander Stumpf
autogenerated on Mon Jun 10 2019 15:47:33