step_cost_key.cpp
Go to the documentation of this file.
2 
3 #include <boost/unordered_set.hpp>
4 #include <boost/functional/hash.hpp>
5 
6 #include <tf/tf.h>
7 
8 
9 
11 {
12 StepCostKey::StepCostKey(const std::vector<double> &state, double cell_size, double angle_bin_size)
13  : cell_size(cell_size)
14  , angle_bin_size(angle_bin_size)
15 {
16  setState(state);
17 }
18 
19 StepCostKey::StepCostKey(const State &left_foot, const State &right_foot, const State &swing_foot, double cell_size, double angle_bin_size)
20  : cell_size(cell_size)
21  , angle_bin_size(angle_bin_size)
22 {
23  std::vector<double> state;
24  transformStates(left_foot, right_foot, swing_foot, state);
25  setState(state);
26 }
27 
29  : std::vector<int>(other)
30  , cell_size(other.cell_size)
32 {
33 }
34 
35 bool StepCostKey::operator== (const StepCostKey &other) const
36 {
37  unsigned long int size = std::min(this->size(), other.size());
38 
39  for (unsigned long int i = 0; i < size; i++)
40  {
41  if ((*this)[i] == other[i])
42  continue;
43 
44  return false;
45  }
46 
47  return true;
48 }
49 
50 bool StepCostKey::operator< (const StepCostKey &other) const
51 {
52  unsigned long int size = std::min(this->size(), other.size());
53 
54  for (unsigned long int i = 0; i < size; i++)
55  {
56  if ((*this)[i] == other[i])
57  continue;
58 
59  if ((*this)[i] < other[i])
60  return true;
61 
62  if ((*this)[i] > other[i])
63  return false;
64  }
65 
66  return false;
67 }
68 
69 void StepCostKey::setState(const std::vector<double> &state)
70 {
71  this->clear();
72  this->reserve(state.size());
73 
74  unsigned int i = 0;
75 
76  this->push_back(cont_2_disc(state[i++], cell_size));
77  this->push_back(cont_2_disc(state[i++], cell_size));
78  //this->push_back(cont_2_disc(state[i++], cell_size));
79  //this->push_back(cont_2_disc(state[i++], angle_bin_size));
80  //this->push_back(cont_2_disc(state[i++], angle_bin_size));
81  this->push_back(cont_2_disc(state[i++], angle_bin_size));
82 
83  this->push_back(cont_2_disc(state[i++], cell_size));
84  this->push_back(cont_2_disc(state[i++], cell_size));
85  //this->push_back(cont_2_disc(state[i++], cell_size));
86  //this->push_back(cont_2_disc(state[i++], angle_bin_size));
87  //this->push_back(cont_2_disc(state[i++], angle_bin_size));
88  this->push_back(cont_2_disc(state[i++], angle_bin_size));
89 
90  //this->push_back(state[i++]);
91 
92  //ROS_INFO("%f %f %f | %f %f %f", state[0], state[1], state[2], state[3], state[4], state[5]);
93  //ROS_INFO("%i %i %i | %i %i %i", (*this)[0], (*this)[1], (*this)[2], (*this)[3], (*this)[4], (*this)[5]);
94  //ROS_INFO("--------");
95 }
96 
97 void StepCostKey::getState(std::vector<double> &state) const
98 {
99  state.clear();
100  state.reserve(this->size());
101 
102  unsigned int i = 0;
103 
104  state.push_back(disc_2_cont((*this)[i++], cell_size));
105  state.push_back(disc_2_cont((*this)[i++], cell_size));
106  //state.push_back(disc_2_cont((*this)[i++], cell_size));
107  //state.push_back(disc_2_cont((*this)[i++], angle_bin_size));
108  //state.push_back(disc_2_cont((*this)[i++], angle_bin_size));
109  state.push_back(disc_2_cont((*this)[i++], angle_bin_size));
110 
111  state.push_back(disc_2_cont((*this)[i++], cell_size));
112  state.push_back(disc_2_cont((*this)[i++], cell_size));
113  //state.push_back(disc_2_cont((*this)[i++], cell_size));
114  //state.push_back(disc_2_cont((*this)[i++], angle_bin_size));
115  //state.push_back(disc_2_cont((*this)[i++], angle_bin_size));
116  state.push_back(disc_2_cont((*this)[i++], angle_bin_size));
117 
118  //state.push_back((*this)[i++]);
119 }
120 
121 void StepCostKey::transformStates(const State &left_foot, const State &right_foot, const State &swing_foot, std::vector<double> &state) const
122 {
123  /*
124  * State definition:
125  * A state is given by the left foot poses (before and after swinging).
126  * Both poses must be given in the frame of the right standing foot.
127  */
128 
129  tf::Pose left_foot_pose = left_foot.getPose();
130  tf::Pose right_foot_pose = right_foot.getPose();
131  tf::Pose swing_foot_pose = swing_foot.getPose();
132 
133  // transform left foot pose after executing the step relative to right foot
134  tf::Pose left_foot_before;
135  tf::Pose left_foot_after;
136 
137  // swing foot is left foot -> trivial
138  if (swing_foot.getLeg() == LEFT)
139  {
140  // determine transformation, so right standing foot is origin
141  tf::Transform world_to_right_foot = tf::Transform(right_foot_pose.getRotation(), right_foot_pose.getOrigin());
142  world_to_right_foot = world_to_right_foot.inverse();
143 
144  // transform left standing foot pose into right foot frame
145  left_foot_before = world_to_right_foot * left_foot_pose;
146 
147  // transform left swing pose into right foot frame
148  left_foot_after = world_to_right_foot * swing_foot_pose;
149  }
150  // mirror all states to swinging left foot
151  else // data_point.swing_foot.foot_index == RIGHT
152  {
153  // determine transformation, so left standing foot is origin
154  tf::Transform world_to_left_foot = tf::Transform(left_foot_pose.getRotation(), left_foot_pose.getOrigin());
155  world_to_left_foot = world_to_left_foot.inverse();
156 
157  // transform right standing foot pose into left foot frame
158  tf::Pose right_foot_before;
159  right_foot_before = world_to_left_foot * right_foot_pose;
160 
161  // transform right swing pose into left foot frame
162  tf::Pose right_foot_after;
163  right_foot_after = world_to_left_foot * swing_foot_pose;
164 
165  // now we are mirroring all data to right foot frame
166  mirrorPoseOnXPlane(left_foot_before, right_foot_before);
167  mirrorPoseOnXPlane(left_foot_after, right_foot_after);
168  }
169 
170  state.clear();
171  state.reserve(STATE_DIM);
172  double r, p, y;
173 
174  // left foot before swing
175  left_foot_before.getBasis().getRPY(r, p, y);
176  state.push_back(left_foot_before.getOrigin().getX());
177  state.push_back(left_foot_before.getOrigin().getY());
178  //state.push_back(left_foot_before.getOrigin().getZ());
179  //state.push_back(r);
180  //state.push_back(p);
181  state.push_back(y);
182 
183  // left foot after swing
184  left_foot_after.getBasis().getRPY(r, p, y);
185  state.push_back(left_foot_after.getOrigin().getX());
186  state.push_back(left_foot_after.getOrigin().getY());
187  //state.push_back(left_foot_after.getOrigin().getZ());
188  //state.push_back(r);
189  //state.push_back(p);
190  state.push_back(y);
191 
192  // terrain type
193  //state.push_back(data_point.terrain_type;
194 
195  //ROS_INFO("------- foot --------------------------");
196  //ROS_INFO("%f %f %f / %f %f %f", state[0], state[1], state[2], state[3], state[4], state[5]);
197  //ROS_INFO("%f %f %f / %f %f %f", state[6], state[7], state[8], state[9], state[10], state[11]);
198 }
199 
200 void StepCostKey::mirrorPoseOnXPlane(tf::Pose &mirror, const tf::Pose &orig) const
201 {
202  mirror.setBasis(orig.getBasis());
203  tf::Matrix3x3& basis = mirror.getBasis();
204  basis[0][1] = -basis[0][1];
205  basis[1][0] = -basis[1][0];
206  basis[2][1] = -basis[2][1];
207 
208  mirror.setOrigin(orig.getOrigin());
209  tf::Vector3& origin = mirror.getOrigin();
210  origin[1] = -origin[1];
211 
212 
213 // double r, p, y;
214 // tf::Matrix3x3(orig.getRotation()).getRPY(r, p, y);
215 // mirror.setRotation(tf::createQuaternionFromRPY(-r, p, -y));
216 
217 // tf::Vector3 v = orig.getOrigin();
218 // v.setY(-v.getY());
219 // mirror.setOrigin(v);
220 
221 
222 // tfScalar m[16];
223 // ROS_INFO("------------------");
224 // mirror.getOpenGLMatrix(m);
225 // ROS_INFO("%f %f %f %f", m[0], m[4], m[8], m[12]);
226 // ROS_INFO("%f %f %f %f", m[1], m[5], m[9], m[13]);
227 // ROS_INFO("%f %f %f %f", m[2], m[6], m[10], m[14]);
228 // ROS_INFO("%f %f %f %f", m[3], m[7], m[11], m[15]);
229 
230 // ROS_INFO("-");
231 // orig.getOpenGLMatrix(m);
232 
233 // ROS_INFO("%f %f %f %f", m[0], m[4], m[8], m[12]);
234 // ROS_INFO("%f %f %f %f", m[1], m[5], m[9], m[13]);
235 // ROS_INFO("%f %f %f %f", m[2], m[6], m[10], m[14]);
236 // ROS_INFO("%f %f %f %f", m[3], m[7], m[11], m[15]);
237 
238 // ROS_INFO("-");
239 
240 // ROS_INFO("%f %f %f %f", m[0], -m[4], m[8], m[12]);
241 // ROS_INFO("%f %f %f %f", -m[1], m[5], m[9], -m[13]);
242 // ROS_INFO("%f %f %f %f", m[2], -m[6], m[10], m[14]);
243 // ROS_INFO("%f %f %f %f", m[3], m[7], m[11], m[15]);
244 }
245 }
246 
248 {
249  std::size_t seed = 0;
250  for (unsigned int i = 0; i < STATE_DIM; i++)
251  {
252  boost::hash_combine(seed, key[i]);
253  }
254  return seed;
255 }
StepCostKey(const std::vector< double > &state, double cell_size, double angle_bin_size)
bool operator<(const StepCostKey &other) const
void transformStates(const State &left_foot, const State &right_foot, const State &swing_foot, std::vector< double > &state) const
void mirrorPoseOnXPlane(tf::Pose &mirror, const tf::Pose &orig) const
double disc_2_cont(int value, double cell_size) const
discrete to continuous
Definition: step_cost_key.h:65
bool operator==(const StepCostKey &other) const
std::size_t hash_value(const vigir_footstep_planning::StepCostKey &key)
#define STATE_DIM
Definition: step_cost_key.h:34
void setState(const std::vector< double > &state)
void getState(std::vector< double > &state) const
int cont_2_disc(double value, double cell_size) const
continuous to discrete
Definition: step_cost_key.h:59


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