GaitGenerator.h
Go to the documentation of this file.
1 /* -*- mode:c++ -*- */
2 #ifndef GAITGENERATOR_H
3 #define GAITGENERATOR_H
4 #include "PreviewController.h"
5 #include "../ImpedanceController/RatsMatrix.h"
6 #include "interpolator.h"
7 #include <vector>
8 #include <queue>
9 #include <boost/assign.hpp>
10 #include <boost/lambda/lambda.hpp>
11 #include <boost/shared_ptr.hpp>
12 
13 #ifdef FOR_TESTGAITGENERATOR
14 #warning "Compile for testGaitGenerator"
15 #endif // FOR_TESTGAITGENERATOR
16 
17 namespace rats
18 {
19  void cycloid_midpoint (hrp::Vector3& ret,
20  const double ratio, const hrp::Vector3& start,
21  const hrp::Vector3& goal, const double height,
22  const double default_top_ratio = 0.5);
23  void multi_mid_coords (coordinates& mid_coords, const std::vector<coordinates>& cs, const double eps = 0.001);
24 
28  std::string leg_type_to_leg_type_string (const leg_type l_r);
29 
30  struct step_node
31  {
35  step_node () : l_r(RLEG), worldcoords(coordinates()),
36  step_height(), step_time(),
37  toe_angle(), heel_angle(){};
38  step_node (const leg_type _l_r, const coordinates& _worldcoords,
39  const double _step_height, const double _step_time,
40  const double _toe_angle, const double _heel_angle)
41  : l_r(_l_r), worldcoords(_worldcoords),
42  step_height(_step_height), step_time(_step_time),
43  toe_angle(_toe_angle), heel_angle(_heel_angle) {};
44  step_node (const std::string& _l_r, const coordinates& _worldcoords,
45  const double _step_height, const double _step_time,
46  const double _toe_angle, const double _heel_angle)
47  : l_r((_l_r == "rleg") ? RLEG :
48  (_l_r == "rarm") ? RARM :
49  (_l_r == "larm") ? LARM :
50  LLEG), worldcoords(_worldcoords),
51  step_height(_step_height), step_time(_step_time),
52  toe_angle(_toe_angle), heel_angle(_heel_angle) {};
53  friend std::ostream &operator<<(std::ostream &os, const step_node &sn)
54  {
55  os << "footstep" << std::endl;
56  os << " name = [" << ((sn.l_r==LLEG)?std::string("lleg"):
57  (sn.l_r==RARM)?std::string("rarm"):
58  (sn.l_r==LARM)?std::string("larm"):
59  std::string("rleg")) << "]" << std::endl;
60  os << " pos =";
61  os << (sn.worldcoords.pos).format(Eigen::IOFormat(Eigen::StreamPrecision, 0, ", ", ", ", "", "", " [", "]")) << std::endl;
62  os << " rot =";
63  os << (sn.worldcoords.rot).format(Eigen::IOFormat(Eigen::StreamPrecision, 0, ", ", "", " [", "]")) << std::endl;
64  os << " step_height = " << sn.step_height << "[m], step_time = " << sn.step_time << "[s], "
65  << "toe_angle = " << sn.toe_angle << "[deg], heel_angle = " << sn.heel_angle << "[deg]";
66  return os;
67  };
68  };
69 
70  /* footstep parameter */
72  {
73  /* translate pos is translate position of a leg from default foot_midcoords
74  * vector -> (list rleg-pos[m] lleg-pos[m] )
75  */
76  std::vector<hrp::Vector3> leg_default_translate_pos;
77  /* stride params indicate max stride */
78  double stride_fwd_x/*[m]*/, stride_outside_y/*[m]*/, stride_outside_theta/*[deg]*/, stride_bwd_x/*[m]*/, stride_inside_y/*[m]*/, stride_inside_theta/*[deg]*/;
79  footstep_parameter (const std::vector<hrp::Vector3>& _leg_pos,
80  const double _stride_fwd_x, const double _stride_outside_y, const double _stride_outside_theta,
81  const double _stride_bwd_x, const double _stride_inside_y, const double _stride_inside_theta)
82  : leg_default_translate_pos(_leg_pos),
83  stride_fwd_x(_stride_fwd_x), stride_outside_y(_stride_outside_y), stride_outside_theta(_stride_outside_theta),
84  stride_bwd_x(_stride_bwd_x), stride_inside_y(_stride_inside_y), stride_inside_theta(_stride_inside_theta) {};
85  };
86 
87  /* velocity parameter for velocity mode */
89  {
90  /* velocity is [mm/s], [mm/s], [deg/s] */
91  double velocity_x, velocity_y, velocity_theta;
92  void set (const double _vx, const double _vy, const double _vth)
93  {
94  velocity_x = _vx;
95  velocity_y = _vy;
96  velocity_theta = _vth;
97  };
99  :velocity_x(0), velocity_y(0), velocity_theta(0) {};
100  };
101 
102  /* Phase name of toe heel contact.
103  * SOLE0 : Sole contact (start). Foot angle is 0. ZMP transition is ee -> toe.
104  * SOLE2TOE : Transition of foot angle (0 -> toe_angle). ZMP is on toe.
105  * TOE2SOLE : Transition of foot angle (toe_angle -> 0). ZMP is on toe.
106  * SOLE1 : Foot_angle is 0.
107  * SOLE2HEEL : Transition of foot angle (0 -> -1 * heel_angle). ZMP is on heel.
108  * HEEL2SOLE : Transition of foot angle (-1 * heel_angle -> 0). ZMP is on heel.
109  * SOLE2 : Sole contact (end). Foot angle is 0. ZMP transition is heel -> ee.
110  */
112  static double no_using_toe_heel_ratio = 1.0; // Ratio not to use toe and heel contact
113  static double using_toe_heel_ratio = 0.0; // Ratio to use toe and heel contact
114 
117  {
119  toe_heel_types (const toe_heel_type _src_type = SOLE, const toe_heel_type _dst_type = SOLE) : src_type(_src_type), dst_type(_dst_type)
120  {
121  };
122  };
123 
124  /* Manager for toe heel phase. */
126  {
127  double toe_heel_phase_ratio[NUM_TH_PHASES];
128  size_t toe_heel_phase_count[NUM_TH_PHASES], one_step_count;
130  {
131  double ratio_sum = 0.0;
132  for (size_t i = 0; i < NUM_TH_PHASES; i++) {
133  ratio_sum += toe_heel_phase_ratio[i];
134  toe_heel_phase_count[i] = static_cast<size_t>(one_step_count * ratio_sum);
135  }
136  return true;
137  };
138  public:
139  toe_heel_phase_counter () : one_step_count(0)
140  {
141  toe_heel_phase_ratio[SOLE0] = 0.05;
142  toe_heel_phase_ratio[SOLE2TOE] = 0.25;
143  toe_heel_phase_ratio[TOE2SOLE] = 0.2;
144  toe_heel_phase_ratio[SOLE1] = 0.0;
145  toe_heel_phase_ratio[SOLE2HEEL] = 0.2;
146  toe_heel_phase_ratio[HEEL2SOLE] = 0.25;
147  toe_heel_phase_ratio[SOLE2] = 0.05;
148  };
149  bool check_toe_heel_phase_ratio_validity (const std::vector<double>& ratio)
150  {
151  bool ret = true;
152  // Check size
153  if (ratio.size() != NUM_TH_PHASES) {
154  ret = false;
155  }
156  // Check sum == 1.0
157  double sum_ratio = 0.0;
158  for (int i = 0; i < NUM_TH_PHASES; i++) sum_ratio += ratio[i];
159  if (std::fabs(sum_ratio-1.0) > 1e-3) {
160  ret = false;
161  }
162  if (!ret) {
163  std::cerr << "toe_heel_phase_ratio is not set, "
164  << ", required length = " << NUM_TH_PHASES << " != input length " << ratio.size()
165  << ", sum_ratio = " << sum_ratio << " is not 1.0."
166  << std::endl;
167  } else {
168  std::cerr << "toe_heel_phase_ratio is successfully set." << std::endl;
169  }
170  return ret;
171  };
172  // setter
173  void set_one_step_count (const size_t _count)
174  {
175  one_step_count = _count;
176  calc_toe_heel_phase_count_from_raio();
177  };
178  bool set_toe_heel_phase_ratio (const std::vector<double>& ratio)
179  {
180  if (check_toe_heel_phase_ratio_validity(ratio)) {
181  for (size_t i = 0; i < NUM_TH_PHASES; i++) toe_heel_phase_ratio[i] = ratio[i];
182  return true;
183  } else {
184  return false;
185  }
186  };
187  // getter
188  void get_toe_heel_phase_ratio (std::vector<double>& ratio) const
189  {
190  for (size_t i = 0; i < NUM_TH_PHASES; i++) ratio[i] = toe_heel_phase_ratio[i];
191  };
192  // functions for checking phase and calculating phase time and ratio
193  bool is_phase_starting (const size_t current_count, const toe_heel_phase _phase) const
194  {
195  return (current_count == toe_heel_phase_count[_phase]);
196  };
197  bool is_between_phases (const size_t current_count, const toe_heel_phase phase0, const toe_heel_phase phase1) const
198  {
199  return (toe_heel_phase_count[phase0] <= current_count) && (current_count < toe_heel_phase_count[phase1]);
200  };
201  bool is_between_phases (const size_t current_count, const toe_heel_phase phase1) const
202  {
203  return (current_count < toe_heel_phase_count[phase1]);
204  };
205  bool is_no_SOLE1_phase () const { return toe_heel_phase_count[TOE2SOLE] == toe_heel_phase_count[SOLE1]; };
206  // Calculate period [s] between start_phase and goal_phase
207  double calc_phase_period (const toe_heel_phase start_phase, const toe_heel_phase goal_phase, const double _dt) const
208  {
209  return _dt * (toe_heel_phase_count[goal_phase]-toe_heel_phase_count[start_phase]);
210  };
211  // Calculate ratio between start_phase and goal_phase.
212  // If current_count is 0->goal_phase_count, start_phase : 0 -> goal_phase : 1
213  double calc_phase_ratio (const size_t current_count, const toe_heel_phase start_phase, const toe_heel_phase goal_phase) const
214  {
215  return static_cast<double>(current_count-toe_heel_phase_count[start_phase]) / (toe_heel_phase_count[goal_phase]-toe_heel_phase_count[start_phase]);
216  };
217  // Calculate ratio to goal_phase.
218  // If current_count is 0->goal_phase_count, start : 0 -> goal_phase : 1
219  double calc_phase_ratio (const size_t current_count, const toe_heel_phase goal_phase) const
220  {
221  return static_cast<double>(current_count) / (toe_heel_phase_count[goal_phase]);
222  };
223  // Calculate ratio for toe heel transition.
224  // If toe or heel are used, ratio is 0.0. Otherwise, ratio is (0.0, 1.0].
225  // We assume current_count is 0->goal_phase_count.
226  double calc_phase_ratio_for_toe_heel_transition (const size_t current_count) const
227  {
228  if (is_between_phases(current_count, SOLE0)) {
229  // ratio : 1 -> 0
230  return 1-calc_phase_ratio(current_count, SOLE0);
231  } else if (is_between_phases(current_count, HEEL2SOLE, SOLE2) || toe_heel_phase_count[SOLE2] == current_count) {
232  // ratio : 0 -> 1
233  return calc_phase_ratio(current_count, HEEL2SOLE, SOLE2);
234  } else {
235  // If using toe or heel, 0
236  return using_toe_heel_ratio;
237  }
238  };
239  };
240 
241  /* Checker for toe heel type. */
243  {
244  private:
245  double toe_check_thre, heel_check_thre; // [m]
246  public:
247  toe_heel_type_checker () : toe_check_thre(0), heel_check_thre(0)
248  {
249  };
250  toe_heel_type_checker (const double _toe_check_thre, const double _heel_check_thre) : toe_check_thre(_toe_check_thre), heel_check_thre(_heel_check_thre)
251  {
252  };
253  toe_heel_type check_toe_heel_type_from_swing_support_coords (const coordinates& swing_coords, const coordinates& support_coords, const double toe_pos_offset_x, const double heel_pos_offset_x) const
254  {
255  hrp::Vector3 local_toe_pos = support_coords.rot.transpose() * (swing_coords.rot * hrp::Vector3(toe_pos_offset_x,0,0) + swing_coords.pos - support_coords.pos);
256  hrp::Vector3 local_heel_pos = support_coords.rot.transpose() * (swing_coords.rot * hrp::Vector3(heel_pos_offset_x,0,0) + swing_coords.pos - support_coords.pos);
257  if (local_toe_pos(2) < -50*1e-3 && (local_toe_pos(0) + toe_check_thre < 0 || local_heel_pos(0) - heel_check_thre > 0) ) {
258  return TOE;
259  } else if (local_toe_pos(0) + toe_check_thre < 0) {
260  return TOE;
261  } else if (local_heel_pos(0) - heel_check_thre > 0) {
262  return HEEL;
263  } else {
264  return SOLE;
265  }
266  };
267  void print_param (const std::string print_str = "") const
268  {
269  std::cerr << "[" << print_str << "] toe_check_thre = " << toe_check_thre << ", heel_check_thre = " << heel_check_thre << std::endl;
270  };
271  // Setter
272  void set_toe_check_thre (const double _toe_check_thre) { toe_check_thre = _toe_check_thre; };
273  void set_heel_check_thre (const double _heel_check_thre) { heel_check_thre = _heel_check_thre; };
274  // Getter
275  double get_toe_check_thre () const { return toe_check_thre; };
276  double get_heel_check_thre () const { return heel_check_thre; };
277  };
278 
279  double set_value_according_to_toe_heel_type (const toe_heel_type tht, const double toe_value, const double heel_value, const double default_value);
280 
281  /* refzmp_generator to generate current refzmp from footstep_node_list */
283  {
284 #ifdef HAVE_MAIN
285  public:
286 #endif
287  std::vector<hrp::Vector3> refzmp_cur_list;
288  std::map<leg_type, double> zmp_weight_map;
289  std::vector< std::vector<hrp::Vector3> > foot_x_axises_list; // Swing foot x axis list according to refzmp_cur_list
290  std::vector< std::vector<leg_type> > swing_leg_types_list; // Swing leg list according to refzmp_cur_list
291  std::vector<size_t> step_count_list; // Swing leg list according to refzmp_cur_list
292  std::vector<toe_heel_types> toe_heel_types_list;
293  std::vector<hrp::Vector3> default_zmp_offsets; /* list of RLEG and LLEG */
294  size_t refzmp_index, refzmp_count, one_step_count;
295  double toe_zmp_offset_x, heel_zmp_offset_x; // [m]
296  double dt;
298  bool use_toe_heel_transition, use_toe_heel_auto_set;
300  void calc_current_refzmp (hrp::Vector3& ret, std::vector<hrp::Vector3>& swing_foot_zmp_offsets, const double default_double_support_ratio_before, const double default_double_support_ratio_after, const double default_double_support_static_ratio_before, const double default_double_support_static_ratio_after);
301  const bool is_start_double_support_phase () const { return refzmp_index == 0; };
302  const bool is_second_phase () const { return refzmp_index == 1; };
303  const bool is_second_last_phase () const { return refzmp_index == refzmp_cur_list.size()-2; };
304  const bool is_end_double_support_phase () const { return refzmp_index == refzmp_cur_list.size() - 1; };
305 #ifndef HAVE_MAIN
306  public:
307 #endif
308  refzmp_generator(const double _dt)
309  : refzmp_cur_list(), foot_x_axises_list(), swing_leg_types_list(), step_count_list(), toe_heel_types_list(), default_zmp_offsets(),
310  refzmp_index(0), refzmp_count(0), one_step_count(0),
311  toe_zmp_offset_x(0), heel_zmp_offset_x(0), dt(_dt),
312  thp(), use_toe_heel_transition(false), use_toe_heel_auto_set(false)
313  {
314  default_zmp_offsets.push_back(hrp::Vector3::Zero());
315  default_zmp_offsets.push_back(hrp::Vector3::Zero());
316  default_zmp_offsets.push_back(hrp::Vector3::Zero());
317  default_zmp_offsets.push_back(hrp::Vector3::Zero());
318  double zmp_weight_initial_value[4] = {1.0, 1.0, 0.1, 0.1};
319  zmp_weight_map = boost::assign::map_list_of<leg_type, double>(RLEG, zmp_weight_initial_value[0])(LLEG, zmp_weight_initial_value[1])(RARM, zmp_weight_initial_value[2])(LARM, zmp_weight_initial_value[3]).convert_to_container< std::map<leg_type, double> > ();
320  zmp_weight_interpolator = boost::shared_ptr<interpolator>(new interpolator(4, dt));
321  zmp_weight_interpolator->set(zmp_weight_initial_value); /* set initial value */
322  zmp_weight_interpolator->setName("GaitGenerator zmp_weight_interpolator");
323  };
325  {
326  };
327  void remove_refzmp_cur_list_over_length (const size_t len)
328  {
329  while ( refzmp_cur_list.size() > len) refzmp_cur_list.pop_back();
330  while ( foot_x_axises_list.size() > len) foot_x_axises_list.pop_back();
331  while ( swing_leg_types_list.size() > len) swing_leg_types_list.pop_back();
332  while ( step_count_list.size() > len) step_count_list.pop_back();
333  while ( toe_heel_types_list.size() > len) toe_heel_types_list.pop_back();
334  };
335  void reset (const size_t _refzmp_count)
336  {
337  set_indices(0);
338  one_step_count = _refzmp_count;
339  set_refzmp_count(_refzmp_count);
340  refzmp_cur_list.clear();
341  foot_x_axises_list.clear();
342  swing_leg_types_list.clear();
343  step_count_list.clear();
344  toe_heel_types_list.clear();
345  thp.set_one_step_count(one_step_count);
346  };
347  void push_refzmp_from_footstep_nodes_for_dual (const std::vector<step_node>& fns,
348  const std::vector<step_node>& _support_leg_steps,
349  const std::vector<step_node>& _swing_leg_steps);
350  void push_refzmp_from_footstep_nodes_for_single (const std::vector<step_node>& fns, const std::vector<step_node>& _support_leg_steps, const toe_heel_types& tht);
351  void update_refzmp ();
352  // setter
353  void set_indices (const size_t idx) { refzmp_index = idx; };
354  void set_refzmp_count(const size_t _refzmp_count) { refzmp_count = _refzmp_count; };
355  void set_default_zmp_offsets(const std::vector<hrp::Vector3>& tmp) { default_zmp_offsets = tmp; };
356  void set_toe_zmp_offset_x (const double _off) { toe_zmp_offset_x = _off; };
357  void set_heel_zmp_offset_x (const double _off) { heel_zmp_offset_x = _off; };
358  void set_use_toe_heel_transition (const bool _u) { use_toe_heel_transition = _u; };
359  void set_use_toe_heel_auto_set (const bool _u) { use_toe_heel_auto_set = _u; };
360  void set_zmp_weight_map (const std::map<leg_type, double> _map) {
361  double zmp_weight_array[4] = {_map.find(RLEG)->second, _map.find(LLEG)->second, _map.find(RARM)->second, _map.find(LARM)->second};
362  if (zmp_weight_interpolator->isEmpty()) {
363  zmp_weight_interpolator->clear();
364  double zmp_weight_initial_value[4] = {zmp_weight_map[RLEG], zmp_weight_map[LLEG], zmp_weight_map[RARM], zmp_weight_map[LARM]};
365  zmp_weight_interpolator->set(zmp_weight_initial_value);
366  zmp_weight_interpolator->setGoal(zmp_weight_array, 2.0, true);
367  } else {
368  std::cerr << "zmp_weight_map cannot be set because interpolating." << std::endl;
369  }
370  };
371  bool set_toe_heel_phase_ratio (const std::vector<double>& ratio) { return thp.set_toe_heel_phase_ratio(ratio); };
372  // getter
373  bool get_current_refzmp (hrp::Vector3& rzmp, std::vector<hrp::Vector3>& swing_foot_zmp_offsets, const double default_double_support_ratio_before, const double default_double_support_ratio_after, const double default_double_support_static_ratio_before, const double default_double_support_static_ratio_after)
374  {
375  if (refzmp_cur_list.size() > refzmp_index ) calc_current_refzmp(rzmp, swing_foot_zmp_offsets, default_double_support_ratio_before, default_double_support_ratio_after, default_double_support_static_ratio_before, default_double_support_static_ratio_after);
376  return refzmp_cur_list.size() > refzmp_index;
377  };
378  const hrp::Vector3& get_refzmp_cur () const { return refzmp_cur_list.front(); };
379  const hrp::Vector3& get_default_zmp_offset (const leg_type lt) const { return default_zmp_offsets[lt]; };
380  double get_toe_zmp_offset_x () const { return toe_zmp_offset_x; };
381  double get_heel_zmp_offset_x () const { return heel_zmp_offset_x; };
382  bool get_use_toe_heel_transition () const { return use_toe_heel_transition; };
383  bool get_use_toe_heel_auto_set () const { return use_toe_heel_auto_set; };
384  const std::map<leg_type, double> get_zmp_weight_map () const { return zmp_weight_map; };
386  if (!zmp_weight_interpolator->isEmpty()) {
387  double zmp_weight_output[4];
388  zmp_weight_interpolator->get(zmp_weight_output, true);
389  zmp_weight_map = boost::assign::map_list_of<leg_type, double>(RLEG, zmp_weight_output[0])(LLEG, zmp_weight_output[1])(RARM, zmp_weight_output[2])(LARM, zmp_weight_output[3]).convert_to_container < std::map<leg_type, double> > ();
390  }
391  };
392 #ifdef FOR_TESTGAITGENERATOR
393  std::vector<hrp::Vector3> get_default_zmp_offsets() const { return default_zmp_offsets; };
394 #endif // FOR_TESTGAITGENERATOR
395  };
396 
398  {
399  private:
400  hrp::Vector3 pos, vel, acc; // [m], [m/s], [m/s^2]
401  double dt; // [s]
402  // Parameters for antecedent path generation
403  std::vector<hrp::Vector3> point_vec;
404  std::vector<double> distance_vec;
405  std::vector<double> sum_distance_vec;
407  // Implement hoffarbib to configure remain_time;
408  void hoffarbib_interpolation (double& _pos, double& _vel, double& _acc, const double tmp_remain_time, const double tmp_goal, const double tmp_goal_vel = 0, const double tmp_goal_acc = 0)
409  {
410  double jerk = (-9.0/ tmp_remain_time) * (_acc - tmp_goal_acc / 3.0) +
411  (-36.0 / (tmp_remain_time * tmp_remain_time)) * (tmp_goal_vel * 2.0 / 3.0 + _vel) +
412  (60.0 / (tmp_remain_time * tmp_remain_time * tmp_remain_time)) * (tmp_goal - _pos);
413  _acc = _acc + dt * jerk;
414  _vel = _vel + dt * _acc;
415  _pos = _pos + dt * _vel;
416  };
417  protected:
418  double time_offset; // [s]
420  double time_offset_xy2z; // [s]
421  size_t one_step_count, current_count, double_support_count_before, double_support_count_after; // time/dt
422  virtual double calc_antecedent_path (const hrp::Vector3& start, const hrp::Vector3& goal, const double height) = 0;
423  public:
424  delay_hoffarbib_trajectory_generator () : time_offset(0.35), final_distance_weight(1.0), time_offset_xy2z(0), one_step_count(0), current_count(0), double_support_count_before(0), double_support_count_after(0) {};
426  void set_dt (const double _dt) { dt = _dt; };
427  void set_swing_trajectory_delay_time_offset (const double _time_offset) { time_offset = _time_offset; };
428  void set_swing_trajectory_final_distance_weight (const double _final_distance_weight) { final_distance_weight = _final_distance_weight; };
429  void set_swing_trajectory_time_offset_xy2z (const double _tmp) { time_offset_xy2z = _tmp; };
430  void reset (const size_t _one_step_len, const double default_double_support_ratio_before, const double default_double_support_ratio_after)
431  {
432  one_step_count = _one_step_len;
433  current_count = 0;
434  double_support_count_before = (default_double_support_ratio_before*one_step_count);
435  double_support_count_after = (default_double_support_ratio_after*one_step_count);
436  };
437  void reset_all (const double _dt, const size_t _one_step_len,
438  const double default_double_support_ratio_before, const double default_double_support_ratio_after,
439  const double _time_offset, const double _final_distance_weight, const double _time_offset_xy2z)
440  {
441  set_dt(_dt);
442  reset (_one_step_len, default_double_support_ratio_before, default_double_support_ratio_after);
443  set_swing_trajectory_delay_time_offset(_time_offset);
444  set_swing_trajectory_final_distance_weight(_final_distance_weight);
445  set_swing_trajectory_time_offset_xy2z(_time_offset_xy2z);
446  };
447  void get_trajectory_point (hrp::Vector3& ret, const hrp::Vector3& start, const hrp::Vector3& goal, const double height)
448  {
449  if ( current_count <= double_support_count_before ) { // first double support phase
450  pos = start;
451  vel = hrp::Vector3::Zero();
452  acc = hrp::Vector3::Zero();
453  } else if ( current_count >= one_step_count - double_support_count_after ) { // last double support phase
454  pos = goal;
455  vel = hrp::Vector3::Zero();
456  acc = hrp::Vector3::Zero();
457  }
458  if ( double_support_count_before <= current_count && current_count < one_step_count - double_support_count_after ) { // swing phase
459  size_t swing_remain_count = one_step_count - current_count - double_support_count_after;
460  size_t swing_one_step_count = one_step_count - double_support_count_before - double_support_count_after;
461  double final_path_distance_ratio = calc_antecedent_path(start, goal, height);
462  size_t tmp_time_offset_count = time_offset/dt;
463  //size_t final_path_count = 0; // Revert to previous version
464  size_t final_path_count = final_path_distance_ratio * swing_one_step_count;
465  if (final_path_count>static_cast<size_t>(time_offset_xy2z/dt)) final_path_count = static_cast<size_t>(time_offset_xy2z/dt);
466  // XY interpolation
467  if (swing_remain_count > final_path_count+tmp_time_offset_count) { // antecedent path is still interpolating
468  hrp::Vector3 tmpgoal = interpolate_antecedent_path((swing_one_step_count - swing_remain_count) / static_cast<double>(swing_one_step_count - (final_path_count+tmp_time_offset_count)));
469  for (size_t i = 0; i < 2; i++) hoffarbib_interpolation (pos(i), vel(i), acc(i), time_offset, tmpgoal(i));
470  } else if (swing_remain_count > final_path_count) { // antecedent path already reached to goal
471  double tmprt = (swing_remain_count-final_path_count)*dt;
472  for (size_t i = 0; i < 2; i++) hoffarbib_interpolation (pos(i), vel(i), acc(i), tmprt, goal(i));
473  } else {
474  for (size_t i = 0; i < 2; i++) pos(i) = goal(i);
475  }
476  // Z interpolation
477  if (swing_remain_count > tmp_time_offset_count) { // antecedent path is still interpolating
478  hrp::Vector3 tmpgoal = interpolate_antecedent_path((swing_one_step_count - swing_remain_count) / static_cast<double>(swing_one_step_count - tmp_time_offset_count));
479  hoffarbib_interpolation (pos(2), vel(2), acc(2), time_offset, tmpgoal(2));
480  } else if (swing_remain_count > 0) { // antecedent path already reached to goal
481  hoffarbib_interpolation (pos(2), vel(2), acc(2), swing_remain_count*dt, goal(2));
482  } else {
483  pos(2) = goal(2);
484  }
485  }
486  ret = pos;
487  current_count++;
488  };
489  double get_swing_trajectory_delay_time_offset () const { return time_offset; };
490  double get_swing_trajectory_final_distance_weight () const { return final_distance_weight; };
491  double get_swing_trajectory_time_offset_xy2z () const { return time_offset_xy2z; };
492  // interpolate path vector
493  // tmp_ratio : ratio value [0, 1]
494  // org_point_vec : vector of via points
495  // e.g., move tmp_ratio from 0 to 1 => move point from org_point_vec.front() to org_point_vec.back()
496  double calc_antecedent_path_base (const std::vector<hrp::Vector3> org_point_vec)
497  {
498  total_path_length = 0;
499  point_vec.clear();
500  distance_vec.clear();
501  point_vec.push_back(org_point_vec.front());
502  // remove distance-zero points
503  for (size_t i = 0; i < org_point_vec.size()-1; i++) {
504  double tmp_distance = (org_point_vec[i+1]-org_point_vec[i]).norm();
505  if (i==org_point_vec.size()-2) tmp_distance*=final_distance_weight;
506  if ( tmp_distance > 1e-5 ) {
507  point_vec.push_back(org_point_vec[i+1]);
508  distance_vec.push_back(tmp_distance);
509  total_path_length += tmp_distance;
510  }
511  }
512  if ( total_path_length < 1e-5 ) { // if total path is zero, return goal point.
513  return 0;
514  }
515  // point_vec : [p0, p1, ..., pN-1, pN]
516  // distance_vec : [ d0, ..., dN-1 ]
517  // sum_distance_vec : [l0, l1, ..., lN-1, lN] <= lj = \Sum_{i=0}^{j-1} di
518  sum_distance_vec.clear();
519  sum_distance_vec.push_back(0);
520  double tmp_dist = 0;
521  for (size_t i = 0; i < distance_vec.size(); i++) {
522  sum_distance_vec.push_back(tmp_dist + distance_vec[i]);
523  tmp_dist += distance_vec[i];
524  }
525  return distance_vec.back()/total_path_length;
526  };
527  hrp::Vector3 interpolate_antecedent_path (const double tmp_ratio) const
528  {
529  if ( total_path_length < 1e-5 ) { // if total path is zero, return goal point.
530  return point_vec.back();
531  }
532  // select current segment in which 'tmp_ratio' is included
533  double current_length = tmp_ratio * total_path_length;
534  for (size_t i = 0; i < sum_distance_vec.size(); i++) {
535  if ( (sum_distance_vec[i] <= current_length) && (current_length <= sum_distance_vec[i+1]) ) {
536  double tmpr = ((current_length - sum_distance_vec[i]) / distance_vec[i]);
537  return ((1-tmpr) * point_vec[i] + tmpr * point_vec[1+i]);
538  }
539  }
540  // if illegal tmp-ratio
541  if (current_length < 0) return point_vec.front();
542  else return point_vec.back();
543  };
544  };
545 
547  {
548  double calc_antecedent_path (const hrp::Vector3& start, const hrp::Vector3& goal, const double height)
549  {
550  std::vector<hrp::Vector3> rectangle_path;
551  double max_height = std::max(start(2), goal(2))+height;
552  rectangle_path.push_back(start);
553  rectangle_path.push_back(hrp::Vector3(start(0), start(1), max_height));
554  rectangle_path.push_back(hrp::Vector3(goal(0), goal(1), max_height));
555  rectangle_path.push_back(goal);
556  return calc_antecedent_path_base(rectangle_path);
557  };
558  };
559 
561  {
563  double calc_antecedent_path (const hrp::Vector3& start, const hrp::Vector3& goal, const double height)
564  {
565  std::vector<hrp::Vector3> path;
566  double max_height = std::max(start(2), goal(2))+height;
567  hrp::Vector3 diff_vec = goal - start;
568  diff_vec(2) = 0.0; // projection on horizontal plane
569  path.push_back(start);
570  // currently way_point_offset(1) is not used.
571  //if ( diff_vec.norm() > 1e-4 && (goal(2) - start(2)) > way_point_offset(2) ) {
572  if ( diff_vec.norm() > 1e-4 && (goal(2) - start(2)) > 0.02) {
573  path.push_back(hrp::Vector3(start+-1*way_point_offset(0)*diff_vec.normalized()+hrp::Vector3(0,0,way_point_offset(2)+max_height-start(2))));
574  }
575  path.push_back(hrp::Vector3(start(0), start(1), max_height));
576  path.push_back(hrp::Vector3(goal(0), goal(1), max_height));
577  //if ( diff_vec.norm() > 1e-4 && (start(2) - goal(2)) > way_point_offset(2) ) {
578  if ( diff_vec.norm() > 1e-4 && (start(2) - goal(2)) > 0.02) {
579  path.push_back(hrp::Vector3(goal+way_point_offset(0)*diff_vec.normalized()+hrp::Vector3(0,0,way_point_offset(2)+max_height-goal(2))));
580  }
581  // if (height > 20 * 1e-3) {
582  // path.push_back(hrp::Vector3(goal(0), goal(1), 20*1e-3+goal(2)));
583  // }
584  path.push_back(goal);
585  return calc_antecedent_path_base(path);
586  };
587  public:
590  void set_stair_trajectory_way_point_offset (const hrp::Vector3 _offset) { way_point_offset = _offset; };
591  hrp::Vector3 get_stair_trajectory_way_point_offset() const { return way_point_offset; };
592  };
593 
595  {
596  double calc_antecedent_path (const hrp::Vector3& start, const hrp::Vector3& goal, const double height)
597  {
598  std::vector<hrp::Vector3> cycloid_path;
599  hrp::Vector3 tmpv, via_goal(goal);
600  double ratio = 0.4;
601  via_goal(2) += ratio*height;
602  double tmpheight = ((start(2)+goal(2))/2.0+height-(start(2)+via_goal(2))/2.0);
603  cycloid_path.push_back(start);
604  cycloid_midpoint(tmpv, 0.2, start, via_goal, tmpheight);
605  cycloid_path.push_back(tmpv);
606  cycloid_midpoint(tmpv, 0.4, start, via_goal, tmpheight);
607  cycloid_path.push_back(tmpv);
608  cycloid_midpoint(tmpv, 0.6, start, via_goal, tmpheight);
609  cycloid_path.push_back(tmpv);
610  cycloid_midpoint(tmpv, 0.8, start, via_goal, tmpheight);
611  cycloid_path.push_back(tmpv);
612  cycloid_path.push_back(via_goal);
613  cycloid_path.push_back(goal);
614  return calc_antecedent_path_base(cycloid_path);
615  };
616  };
617 
619  {
620  private:
623  public:
625  void set_cycloid_delay_kick_point_offset (const hrp::Vector3 _offset) { kick_point_offset = _offset; };
626  void set_start_rot (const hrp::Matrix33 _offset) { start_rot = _offset; };
627  hrp::Vector3 get_cycloid_delay_kick_point_offset () const { return kick_point_offset; };
628  double calc_antecedent_path (const hrp::Vector3& start, const hrp::Vector3& goal, const double height)
629  {
630  std::vector<hrp::Vector3> cycloid_path;
631  hrp::Vector3 tmpv, via_goal(goal);
632  double ratio = 0.4;
633  via_goal(2) += ratio*height;
634  double tmpheight = ((start(2)+goal(2))/2.0+height-(start(2)+via_goal(2))/2.0);
635  // kick_point_offset = start_rot * kick_point_offset;
636  cycloid_path.push_back(start);
637  if(height > 1e-4){
638  cycloid_path.push_back(start + start_rot * kick_point_offset);
639  cycloid_midpoint(tmpv, 0.2, start + start_rot * kick_point_offset, via_goal, tmpheight);
640  cycloid_path.push_back(tmpv);
641  cycloid_midpoint(tmpv, 0.4, start + start_rot * kick_point_offset, via_goal, tmpheight);
642  cycloid_path.push_back(tmpv);
643  cycloid_midpoint(tmpv, 0.6, start + start_rot * kick_point_offset, via_goal, tmpheight);
644  cycloid_path.push_back(tmpv);
645  cycloid_midpoint(tmpv, 0.8, start + start_rot * kick_point_offset, via_goal, tmpheight);
646  cycloid_path.push_back(tmpv);
647  }
648  cycloid_path.push_back(via_goal);
649  cycloid_path.push_back(goal);
650  return calc_antecedent_path_base(cycloid_path);
651  };
652  };
653 
655  {
656  private:
658  public:
661  void set_swing_leg (leg_type _lr) { swing_leg = _lr; };
663  double calc_antecedent_path (const hrp::Vector3& start, const hrp::Vector3& goal, const double height)
664  {
665  std::vector<hrp::Vector3> path;
666  double max_height = std::max(start(2), goal(2))+height;
667  hrp::Vector3 diff_vec = goal - start;
668  diff_vec(2) = 0.0; // projection on horizontal plane
669  path.push_back(start);
670  if ( swing_leg == LLEG ) { // swing_leg is left
671  path.push_back(hrp::Vector3(start+-1*way_point_offset(0)*diff_vec.normalized()+hrp::Vector3(0,way_point_offset(1),way_point_offset(2)+max_height-start(2))));
672  path.push_back(hrp::Vector3(goal+way_point_offset(0)*diff_vec.normalized()+hrp::Vector3(0,way_point_offset(1),way_point_offset(2)+max_height-goal(2))));
673  } else { // swing_leg is right
674  path.push_back(hrp::Vector3(start+-1*way_point_offset(0)*diff_vec.normalized()+hrp::Vector3(0,-way_point_offset(1),way_point_offset(2)+max_height-start(2))));
675  path.push_back(hrp::Vector3(goal+way_point_offset(0)*diff_vec.normalized()+hrp::Vector3(0,-way_point_offset(1),way_point_offset(2)+max_height-goal(2))));
676  }
677  if (height > 30 * 1e-3) {
678  path.push_back(hrp::Vector3(goal(0), goal(1), 30*1e-3+goal(2)));
679  }
680  path.push_back(goal);
681  return calc_antecedent_path_base(path);
682  };
683  };
684 
685  /* leg_coords_generator to generate current swing_leg_coords and support_leg_coords from footstep_node_list */
687  {
688 #ifdef HAVE_MAIN
689  public:
690 #endif
691  std::vector< std::vector<step_node> > swing_leg_dst_steps_list, support_leg_steps_list;
692  // Support leg coordinates.
693  std::vector<step_node> support_leg_steps;
694  // Swing leg coordinates is interpolated from swing_leg_src_coords to swing_leg_dst_coords during swing phase.
695  std::vector<step_node> swing_leg_steps, swing_leg_src_steps, swing_leg_dst_steps;
696  double default_step_height, default_top_ratio, current_step_height, swing_ratio, dt, current_toe_angle, current_heel_angle;
697  double time_offset, final_distance_weight, time_offset_xy2z;
698  std::vector<double> current_swing_time;
699  // Index for current footstep. footstep_index should be [0,footstep_node_list.size()]. Current footstep is footstep_node_list[footstep_index].
701  // one_step_count is total counter num of current steps (= step_time/dt). lcg_count is counter for lcg. During one step, lcg_count decreases from one_step_count to 0.
702  size_t lcg_count, one_step_count, next_one_step_count;
703  // Current support leg
704  std::vector<leg_type> support_leg_types, swing_leg_types;
707  // Foot trajectory generators
708  std::vector<rectangle_delay_hoffarbib_trajectory_generator> rdtg;
710  std::vector<cycloid_delay_hoffarbib_trajectory_generator> cdtg;
716  // Map for interpolator of each swing foot rot interpolation. In constructor, prepared for all limbs. In control loop, swing foot element is used.
717  std::map<leg_type, interpolator*> swing_foot_rot_interpolator;
718  // Parameters for toe-heel contact
720  double toe_pos_offset_x, heel_pos_offset_x, toe_angle, heel_angle, foot_dif_rot_angle, toe_heel_dif_angle;
721  bool use_toe_joint, use_toe_heel_auto_set;
722  toe_heel_type current_src_toe_heel_type, current_dst_toe_heel_type;
723  void calc_current_swing_foot_rot (std::map<leg_type, hrp::Vector3>& tmp_swing_foot_rot, const double _default_double_support_ratio_before, const double _default_double_support_ratio_after);
724  void calc_current_swing_leg_steps (std::vector<step_node>& rets, const double step_height, const double _current_toe_angle, const double _current_heel_angle, const double _default_double_support_ratio_before, const double _default_double_support_ratio_after);
725  double calc_interpolated_toe_heel_angle (const toe_heel_phase start_phase, const toe_heel_phase goal_phase, const double start, const double goal);
726  void modif_foot_coords_for_toe_heel_phase (coordinates& org_coords, const double _current_toe_angle, const double _current_heel_angle);
727  void cycloid_midcoords (coordinates& ret, const coordinates& start,
728  const coordinates& goal, const double height) const;
729  void rectangle_midcoords (coordinates& ret, const coordinates& start,
730  const coordinates& goal, const double height, const size_t swing_trajectory_generator_idx);
731  void stair_midcoords (coordinates& ret, const coordinates& start,
732  const coordinates& goal, const double height);
733  void cycloid_delay_midcoords (coordinates& ret, const coordinates& start,
734  const coordinates& goal, const double height, const size_t swing_trajectory_generator_idx);
735  void cycloid_delay_kick_midcoords (coordinates& ret, const coordinates& start,
736  const coordinates& goal, const double height);
737  void cross_delay_midcoords (coordinates& ret, const coordinates& start,
738  const coordinates& goal, const double height, leg_type lr);
739  void calc_ratio_from_double_support_ratio (const double default_double_support_ratio_before, const double default_double_support_ratio_after);
740  void calc_swing_support_mid_coords ();
741 #ifndef HAVE_MAIN
742  public:
743 #endif
744  leg_coords_generator(const double _dt)
745  : support_leg_steps(), swing_leg_steps(), swing_leg_src_steps(), swing_leg_dst_steps(),
746  default_step_height(0.05), default_top_ratio(0.5), current_step_height(0.0), swing_ratio(0), dt(_dt),
747  current_toe_angle(0), current_heel_angle(0),
748  time_offset(0.35), final_distance_weight(1.0), time_offset_xy2z(0),
749  footstep_index(0), lcg_count(0), default_orbit_type(CYCLOID),
750  rdtg(), cdtg(),
751  thp(),
752  foot_midcoords_interpolator(NULL), swing_foot_rot_interpolator(), toe_heel_interpolator(NULL),
753  toe_pos_offset_x(0.0), heel_pos_offset_x(0.0), toe_angle(0.0), heel_angle(0.0), foot_dif_rot_angle(0.0), toe_heel_dif_angle(0.0), use_toe_joint(false), use_toe_heel_auto_set(false),
754  current_src_toe_heel_type(SOLE), current_dst_toe_heel_type(SOLE)
755  {
756  support_leg_types.assign (1, RLEG);
757  swing_leg_types.assign (1, LLEG);
758  current_swing_time.assign (4, 0.0);
759  sdtg.set_dt(dt);
760  cdktg.set_dt(dt);
761  crdtg.set_dt(dt);
762  if (foot_midcoords_interpolator == NULL) foot_midcoords_interpolator = new interpolator(6, dt); // POS + RPY
763  std::vector<leg_type> tmp_leg_types = boost::assign::list_of<leg_type>(RLEG)(LLEG)(RARM)(LARM);
764  for (size_t i = 0; i < tmp_leg_types.size(); i++) {
765  if ( swing_foot_rot_interpolator.find(tmp_leg_types[i]) == swing_foot_rot_interpolator.end() ) {
766  swing_foot_rot_interpolator.insert(std::pair<leg_type, interpolator*>(tmp_leg_types[i], new interpolator(3, dt))); // RPY
767  swing_foot_rot_interpolator[tmp_leg_types[i]]->setName("GaitGenerator swing_foot_rot_interpolator " + leg_type_to_leg_type_string(tmp_leg_types[i]));
768  std::cerr << "GaitGenerator swing_foot_rot_interpolator " + leg_type_to_leg_type_string(tmp_leg_types[i]) << std::endl;;
769  }
770  }
771  //if (foot_ratio_interpolator == NULL) foot_ratio_interpolator = new interpolator(1, dt, interpolator::LINEAR);
772  if (toe_heel_interpolator == NULL) toe_heel_interpolator = new interpolator(1, dt);
773  foot_midcoords_interpolator->setName("GaitGenerator foot_midcoords_interpolator");
774  toe_heel_interpolator->setName("GaitGenerator toe_heel_interpolator");
775  };
777  {
778  if (foot_midcoords_interpolator != NULL) {
779  delete foot_midcoords_interpolator;
780  foot_midcoords_interpolator = NULL;
781  }
782  for (std::map<leg_type, interpolator*>::iterator it = swing_foot_rot_interpolator.begin(); it != swing_foot_rot_interpolator.end(); it++) {
783  if (it->second != NULL) {
784  delete it->second;
785  it->second = NULL;
786  }
787  }
788  if (toe_heel_interpolator != NULL) {
789  delete toe_heel_interpolator;
790  toe_heel_interpolator = NULL;
791  }
792  };
793  void set_default_step_height (const double _tmp) { default_step_height = _tmp; };
794  void set_default_top_ratio (const double _tmp) { default_top_ratio = _tmp; };
795  void set_default_orbit_type (const orbit_type _tmp) { default_orbit_type = _tmp; };
796  void set_swing_trajectory_delay_time_offset (const double _time_offset)
797  {
798  sdtg.set_swing_trajectory_delay_time_offset(_time_offset);
799  cdktg.set_swing_trajectory_delay_time_offset(_time_offset);
800  crdtg.set_swing_trajectory_delay_time_offset(_time_offset);
801  time_offset = _time_offset;
802  };
803  void set_swing_trajectory_final_distance_weight (const double _final_distance_weight)
804  {
805  sdtg.set_swing_trajectory_final_distance_weight(_final_distance_weight);
806  cdktg.set_swing_trajectory_final_distance_weight(_final_distance_weight);
807  crdtg.set_swing_trajectory_final_distance_weight(_final_distance_weight);
808  final_distance_weight = _final_distance_weight;
809  };
810  void set_swing_trajectory_time_offset_xy2z (const double _tmp)
811  {
815  time_offset_xy2z = _tmp;
816  };
819  void set_toe_pos_offset_x (const double _offx) { toe_pos_offset_x = _offx; };
820  void set_heel_pos_offset_x (const double _offx) { heel_pos_offset_x = _offx; };
821  void set_toe_angle (const double _angle) { toe_angle = _angle; };
822  void set_heel_angle (const double _angle) { heel_angle = _angle; };
823  void set_use_toe_joint (const bool ut) { use_toe_joint = ut; };
824  void set_use_toe_heel_auto_set (const bool ut) { use_toe_heel_auto_set = ut; };
825  void set_swing_support_steps_list (const std::vector< std::vector<step_node> >& fnsl)
826  {
827  std::vector<step_node> prev_support_leg_steps = support_leg_steps_list.front();
828  support_leg_steps_list.clear();
829  swing_leg_dst_steps_list.clear();
830  support_leg_steps_list.push_back(prev_support_leg_steps);
831  swing_leg_dst_steps_list = fnsl;
832  for (size_t i = 0; i < fnsl.size(); i++) {
833  if (i > 0) {
834  if (is_same_footstep_nodes(fnsl.at(i), fnsl.at(i-1))) {
835  support_leg_steps_list.push_back(support_leg_steps_list.back());
836  } else {
837  /* current support leg steps = prev swing leg dst steps + (prev support leg steps without current swing leg names) */
838  std::vector<step_node> tmp_support_leg_steps = swing_leg_dst_steps_list.at(i-1);
839  std::copy(support_leg_steps_list.back().begin(),
840  support_leg_steps_list.back().end(),
841  std::back_inserter(tmp_support_leg_steps));
842  for (size_t j = 0; j < swing_leg_dst_steps_list.at(i).size(); j++) {
843  std::vector<step_node>::iterator it = std::remove_if(tmp_support_leg_steps.begin(),
844  tmp_support_leg_steps.end(),
845  (&boost::lambda::_1->* &step_node::l_r == swing_leg_dst_steps_list.at(i).at(j).l_r));
846  tmp_support_leg_steps.erase(it, tmp_support_leg_steps.end());
847  }
848  support_leg_steps_list.push_back(tmp_support_leg_steps);
849  }
850  }
851  }
852  };
853  bool set_toe_heel_phase_ratio (const std::vector<double>& ratio) { return thp.set_toe_heel_phase_ratio(ratio); };
854  void reset(const size_t _one_step_count, const size_t _next_one_step_count,
855  const std::vector<step_node>& _swing_leg_dst_steps,
856  const std::vector<step_node>& _swing_leg_src_steps,
857  const std::vector<step_node>& _support_leg_steps,
858  const double default_double_support_ratio_before,
859  const double default_double_support_ratio_after)
860  {
861  support_leg_steps_list.clear();
862  swing_leg_dst_steps_list.clear();
863  /* swing_leg_steps.clear(); */
864  swing_leg_dst_steps = _swing_leg_dst_steps;
865  swing_leg_src_steps = _swing_leg_src_steps;
866  support_leg_steps = _support_leg_steps;
867  support_leg_steps_list.push_back(support_leg_steps);
868  one_step_count = lcg_count = _one_step_count;
869  next_one_step_count = _next_one_step_count;
870  thp.set_one_step_count(one_step_count);
871  footstep_index = 0;
872  current_step_height = 0.0;
873  switch (default_orbit_type) {
874  case RECTANGLE:
875  rdtg.clear();
876  for (size_t i = 0; i < swing_leg_dst_steps.size(); i++) {
878  rdtg.back().reset_all(dt, one_step_count,
879  default_double_support_ratio_before, default_double_support_ratio_after,
880  time_offset, final_distance_weight, time_offset_xy2z);
881  }
882  break;
883  case STAIR:
884  sdtg.reset(one_step_count, default_double_support_ratio_before, default_double_support_ratio_after);
885  break;
886  case CYCLOIDDELAY:
887  cdtg.clear();
888  for (size_t i = 0; i < swing_leg_dst_steps.size(); i++) {
890  cdtg.back().reset_all(dt, one_step_count,
891  default_double_support_ratio_before, default_double_support_ratio_after,
892  time_offset, final_distance_weight, time_offset_xy2z);
893  }
894  break;
895  case CYCLOIDDELAYKICK:
896  cdktg.reset(one_step_count, default_double_support_ratio_before, default_double_support_ratio_after);
897  break;
898  case CROSS:
899  crdtg.reset(one_step_count, default_double_support_ratio_before, default_double_support_ratio_after);
900  break;
901  default:
902  break;
903  }
904  current_src_toe_heel_type = current_dst_toe_heel_type = SOLE;
905  };
907  double tmpsw[3];
908  for (std::map<leg_type, interpolator*>::iterator it = swing_foot_rot_interpolator.begin(); it != swing_foot_rot_interpolator.end(); it++) {
909  while (!it->second->isEmpty()) it->second->get(tmpsw, true);
910  }
911  double tmpfm[foot_midcoords_interpolator->dimension()];
912  while (!foot_midcoords_interpolator->isEmpty()) {
913  foot_midcoords_interpolator->get(tmpfm, true);
914  }
915  double tmp;
916  while (!toe_heel_interpolator->isEmpty()) {
917  toe_heel_interpolator->get(&tmp, true);
918  }
919  };
920  bool is_same_footstep_nodes(const std::vector<step_node>& fns_1, const std::vector<step_node>& fns_2) const;
921  void update_leg_steps (const std::vector< std::vector<step_node> >& fnsl, const double default_double_support_ratio_before, const double default_double_support_ratio_after, const toe_heel_type_checker& thtc);
922  void calc_swing_leg_src_steps (std::vector<step_node>& ret_swing_leg_src_steps, const std::vector< std::vector<step_node> >& fnsl, const size_t _footstep_index)
923  {
924  if (_footstep_index > 0) {
925  if (is_same_footstep_nodes(fnsl[_footstep_index], fnsl[_footstep_index-1])) {
926  ret_swing_leg_src_steps = swing_leg_dst_steps_list[_footstep_index-1];
927  } else {
928  /* current swing leg src coords = (previout support leg coords + previous swing leg dst coords) - current support leg coords */
929  std::vector<step_node> tmp_swing_leg_src_steps = support_leg_steps_list[_footstep_index-1];
930  std::copy(swing_leg_dst_steps_list[_footstep_index-1].begin(),
931  swing_leg_dst_steps_list[_footstep_index-1].end(),
932  std::back_inserter(tmp_swing_leg_src_steps));
933  std::vector<step_node> tmp_support_leg_steps = support_leg_steps_list[_footstep_index];
934  for (size_t i = 0; i < tmp_support_leg_steps.size(); i++) {
935  std::vector<step_node>::iterator it = std::remove_if(tmp_swing_leg_src_steps.begin(), tmp_swing_leg_src_steps.end(), (&boost::lambda::_1->* &step_node::l_r == tmp_support_leg_steps.at(i).l_r));
936  tmp_swing_leg_src_steps.erase(it, tmp_swing_leg_src_steps.end());
937  }
938  ret_swing_leg_src_steps = tmp_swing_leg_src_steps;
939  }
940  }
941  };
942  void calc_swing_support_params_from_footstep_nodes_list (const std::vector< std::vector<step_node> >& fnsl)
943  {
944  // Get current swing coords, support coords, and support leg parameters
945  size_t current_footstep_index = (footstep_index < fnsl.size() - 1 ? footstep_index : fnsl.size()-1);
946  swing_leg_dst_steps = fnsl[current_footstep_index];
947  if (footstep_index != 0) { // If not initial step, support_leg_coords is previous swing_leg_dst_coords // why we need this?
948  support_leg_steps = support_leg_steps_list[current_footstep_index];
949  }
950  support_leg_types.clear();
951  for (std::vector<step_node>::iterator it = support_leg_steps.begin(); it != support_leg_steps.end(); it++) {
952  support_leg_types.push_back(it->l_r);
953  }
954  swing_leg_types.clear();
955  for (std::vector<step_node>::iterator it = swing_leg_dst_steps.begin(); it != swing_leg_dst_steps.end(); it++) {
956  swing_leg_types.push_back(it->l_r);
957  }
958  calc_swing_leg_src_steps(swing_leg_src_steps, fnsl, current_footstep_index);
959  };
960  size_t get_footstep_index() const { return footstep_index; };
961  size_t get_lcg_count() const { return lcg_count; };
962  double get_current_swing_time(const size_t idx) const { return current_swing_time.at(idx); };
963  const std::vector<step_node>& get_swing_leg_steps() const { return swing_leg_steps; };
964  const std::vector<step_node>& get_support_leg_steps() const { return support_leg_steps; };
965  const std::vector<step_node>& get_swing_leg_src_steps() const { return swing_leg_src_steps; };
966  const std::vector<step_node>& get_swing_leg_dst_steps() const { return swing_leg_dst_steps; };
967  const std::vector<step_node>& get_swing_leg_dst_steps_idx(const size_t idx) const { return swing_leg_dst_steps_list[idx]; };
968  const std::vector<step_node>& get_support_leg_steps_idx(const size_t idx) const { return support_leg_steps_list[idx]; };
969  const std::vector<leg_type>& get_support_leg_types() const { return support_leg_types;};
970  const std::vector<leg_type>& get_swing_leg_types() const { return swing_leg_types;};
971  double get_default_step_height () const { return default_step_height;};
973  {
974  ret = swing_support_midcoords;
975  };
976  std::vector<leg_type> get_current_support_states () const
977  {
978  if ( is_swing_phase ) {
979  return get_support_leg_types();
980  } else {
981  std::vector<leg_type> tmp_sup_types = get_support_leg_types();
982  std::vector<leg_type> tmp_swg_types = get_swing_leg_types();
983  std::copy(tmp_swg_types.begin(), tmp_swg_types.end(), std::back_inserter(tmp_sup_types));
984  return tmp_sup_types;
985  }
986  };
987  orbit_type get_default_orbit_type () const { return default_orbit_type; };
988  double get_swing_trajectory_delay_time_offset () const { return time_offset; };
989  double get_swing_trajectory_final_distance_weight () const { return final_distance_weight; };
990  double get_swing_trajectory_time_offset_xy2z () const { return time_offset_xy2z; };
993  double get_toe_pos_offset_x () const { return toe_pos_offset_x; };
994  double get_heel_pos_offset_x () const { return heel_pos_offset_x; };
995  double get_toe_angle () const { return toe_angle; };
996  double get_heel_angle () const { return heel_angle; };
997  double get_foot_dif_rot_angle () const { return foot_dif_rot_angle; };
998  bool get_use_toe_joint () const { return use_toe_joint; };
999  bool get_use_toe_heel_auto_set () const { return use_toe_heel_auto_set; };
1000  void get_toe_heel_phase_ratio (std::vector<double>& ratio) const { thp.get_toe_heel_phase_ratio(ratio); };
1001  double get_current_toe_heel_ratio (const bool _use_toe_heel_transition) const
1002  {
1003  if (_use_toe_heel_transition && current_step_height > 0.0) { // If swing phase
1004  return thp.calc_phase_ratio_for_toe_heel_transition(one_step_count - lcg_count);
1005  } else { // If support phase such as double support phase of starting and ending.
1006  return no_using_toe_heel_ratio;
1007  }
1008  };
1009 #ifdef FOR_TESTGAITGENERATOR
1010  size_t get_one_step_count() const { return one_step_count; };
1011  double get_toe_heel_dif_angle() const { return toe_heel_dif_angle; };
1012 #endif // FOR_TESTGAITGENERATOR
1013  };
1014 
1016  {
1017 
1018  public:
1019 #ifndef HAVE_MAIN
1020  private:
1021 #endif
1022 
1023  enum velocity_mode_flag { VEL_IDLING, VEL_DOING, VEL_ENDING };
1024  enum emergency_flag { IDLING, EMERGENCY_STOP, STOPPING };
1025 
1026  /* member variables for gait_generator */
1027  // Footstep list to be executed
1028  // First and last footstep are used for double support phase.
1029  std::vector< std::vector<step_node> > footstep_nodes_list;
1030  // Footstep list for overwriting future footstep queue
1031  std::vector< std::vector<step_node> > overwrite_footstep_nodes_list;
1037  hrp::Vector3 cog, refzmp, prev_que_rzmp; /* cog by calculating proc_one_tick */
1038  std::vector<hrp::Vector3> swing_foot_zmp_offsets, prev_que_sfzos;
1039  double dt; /* control loop [s] */
1040  std::vector<std::string> all_limbs;
1042  double default_double_support_ratio_before, default_double_support_ratio_after, default_double_support_static_ratio_before, default_double_support_static_ratio_after;
1043  double default_double_support_ratio_swing_before; /*first double support time for leg coords generator */
1044  double default_double_support_ratio_swing_after; /*last double support time for leg coords generator */
1047  // overwrite_footstep_index is used for footstep overwriting.
1048  // When overwrite_footstep_index == get_overwritable_index(), overwrite footsteps after overwrite_footstep_index.
1050  // overwritable_footstep_index_offset is used for emergency stop and velocity mode.
1051  // overwritable footstep index is "footstep_index + overwritable_footstep_index_offset", which is obtained by get_overwritable_index().
1056  std::map<leg_type, std::string> leg_type_map;
1058  bool solved;
1059  double leg_margin[4], stride_limitation_for_circle_type[5], overwritable_stride_limitation[5], footstep_modification_gain, cp_check_margin[2], margin_time_ratio;
1060  bool use_stride_limitation, is_emergency_walking[2], modify_footsteps;
1062  std::vector<bool> act_contact_states;
1064 
1065  /* preview controller parameters */
1066  //preview_dynamics_filter<preview_control>* preview_controller_ptr;
1068 
1069  void append_go_pos_step_nodes (const coordinates& _ref_coords,
1070  const std::vector<leg_type>& lts)
1071  {
1072  append_go_pos_step_nodes(_ref_coords, lts, footstep_nodes_list);
1073  };
1074 
1075  void append_go_pos_step_nodes (const coordinates& _ref_coords,
1076  const std::vector<leg_type>& lts,
1077  std::vector< std::vector<step_node> >& _footstep_nodes_list) const
1078  {
1079  std::vector<step_node> sns;
1080  for (size_t i = 0; i < lts.size(); i++) {
1081  sns.push_back(step_node(lts.at(i), _ref_coords,
1082  lcg.get_default_step_height(), default_step_time,
1083  lcg.get_toe_angle(), lcg.get_heel_angle()));
1084  sns.at(i).worldcoords.pos += sns.at(i).worldcoords.rot * footstep_param.leg_default_translate_pos[lts.at(i)];
1085  }
1086  _footstep_nodes_list.push_back(sns);
1087  };
1088  void overwrite_refzmp_queue(const std::vector< std::vector<step_node> >& fnsl);
1089  void calc_ref_coords_trans_vector_velocity_mode (coordinates& ref_coords, hrp::Vector3& trans, double& dth, const std::vector<step_node>& sup_fns, const velocity_mode_parameter& cur_vel_param) const;
1090  void calc_next_coords_velocity_mode (std::vector< std::vector<step_node> >& ret_list, const size_t idx, const size_t future_step_num = 3);
1091  void append_footstep_list_velocity_mode ();
1092  void append_footstep_list_velocity_mode (std::vector< std::vector<step_node> >& _footstep_nodes_list, const velocity_mode_parameter& cur_vel_param) const;
1093  inline leg_type get_leg_type_from_ee_name (const std::string& ee_name) const
1094  {
1095  return std::find_if(leg_type_map.begin(), leg_type_map.end(), (&boost::lambda::_1->* &std::map<leg_type, std::string>::value_type::second == ee_name))->first;
1096  };
1097 
1098 #ifndef HAVE_MAIN
1099  /* inhibit copy constructor and copy insertion not by implementing */
1100  gait_generator (const gait_generator& _p);
1101  gait_generator &operator=(const gait_generator &_p);
1102  public:
1103 #endif
1104  gait_generator (double _dt,
1105  /* arguments for footstep_parameter */
1106  const std::vector<hrp::Vector3>& _leg_pos, std::vector<std::string> _all_limbs,
1107  const double _stride_fwd_x, const double _stride_outside_y, const double _stride_outside_theta,
1108  const double _stride_bwd_x, const double _stride_inside_y, const double _stride_inside_theta)
1109  : footstep_nodes_list(), overwrite_footstep_nodes_list(), rg(_dt), lcg(_dt),
1110  footstep_param(_leg_pos, _stride_fwd_x, _stride_outside_y, _stride_outside_theta, _stride_bwd_x, _stride_inside_y, _stride_inside_theta),
1111  vel_param(), offset_vel_param(), thtc(), cog(hrp::Vector3::Zero()), refzmp(hrp::Vector3::Zero()), prev_que_rzmp(hrp::Vector3::Zero()), diff_cp(hrp::Vector3::Zero()), modified_d_footstep(hrp::Vector3::Zero()),
1112  dt(_dt), all_limbs(_all_limbs), default_step_time(1.0), default_double_support_ratio_before(0.1), default_double_support_ratio_after(0.1), default_double_support_static_ratio_before(0.0), default_double_support_static_ratio_after(0.0), default_double_support_ratio_swing_before(0.1), default_double_support_ratio_swing_after(0.1), gravitational_acceleration(DEFAULT_GRAVITATIONAL_ACCELERATION),
1113  finalize_count(0), optional_go_pos_finalize_footstep_num(0), overwrite_footstep_index(0), overwritable_footstep_index_offset(1),
1114  velocity_mode_flg(VEL_IDLING), emergency_flg(IDLING), margin_time_ratio(0.01), footstep_modification_gain(5e-6),
1115  use_inside_step_limitation(true), use_stride_limitation(false), modify_footsteps(false), default_stride_limitation_type(SQUARE),
1116  preview_controller_ptr(NULL) {
1117  swing_foot_zmp_offsets.assign (1, hrp::Vector3::Zero());
1118  prev_que_sfzos.assign (1, hrp::Vector3::Zero());
1119  leg_type_map = boost::assign::map_list_of<leg_type, std::string>(RLEG, "rleg")(LLEG, "lleg")(RARM, "rarm")(LARM, "larm").convert_to_container < std::map<leg_type, std::string> > ();
1120  for (size_t i = 0; i < 4; i++) leg_margin[i] = 0.1;
1121  for (size_t i = 0; i < 5; i++) stride_limitation_for_circle_type[i] = 0.2;
1122  for (size_t i = 0; i < 5; i++) overwritable_stride_limitation[i] = 0.2;
1123  for (size_t i = 0; i < 2; i++) is_emergency_walking[i] = false;
1124  for (size_t i = 0; i < 2; i++) cp_check_margin[i] = 0.025;
1125  };
1127  if ( preview_controller_ptr != NULL ) {
1128  delete preview_controller_ptr;
1129  preview_controller_ptr = NULL;
1130  }
1131  };
1132  void initialize_gait_parameter (const hrp::Vector3& cog,
1133  const std::vector<step_node>& initial_support_leg_steps,
1134  const std::vector<step_node>& initial_swing_leg_dst_steps,
1135  const double delay = 1.6);
1136  bool proc_one_tick ();
1137  void limit_stride (step_node& cur_fs, const step_node& prev_fs, const double (&limit)[5]) const;
1138  void modify_footsteps_for_recovery ();
1139  void append_footstep_nodes (const std::vector<std::string>& _legs, const std::vector<coordinates>& _fss)
1140  {
1141  std::vector<step_node> tmp_sns;
1142  for (size_t i = 0; i < _legs.size(); i++) {
1143  tmp_sns.push_back(step_node(_legs[i], _fss[i], lcg.get_default_step_height(), default_step_time, lcg.get_toe_angle(), lcg.get_heel_angle()));
1144  }
1145  footstep_nodes_list.push_back(tmp_sns);
1146  };
1147  void append_footstep_nodes (const std::vector<std::string>& _legs, const std::vector<coordinates>& _fss, const double _step_height, const double _step_time, const double _toe_angle, const double _heel_angle)
1148  {
1149  std::vector<step_node> tmp_sns;
1150  for (size_t i = 0; i < _legs.size(); i++) {
1151  tmp_sns.push_back(step_node(_legs[i], _fss[i], _step_height, _step_time, _toe_angle, _heel_angle));
1152  }
1153  footstep_nodes_list.push_back(tmp_sns);
1154  };
1156  footstep_nodes_list.clear();
1157  overwrite_footstep_nodes_list.clear();
1158  overwrite_footstep_index = 0;
1159  };
1160  bool go_pos_param_2_footstep_nodes_list (const double goal_x, const double goal_y, const double goal_theta, /* [mm] [mm] [deg] */
1161  const std::vector<coordinates>& initial_support_legs_coords, coordinates start_ref_coords,
1162  const std::vector<leg_type>& initial_support_legs,
1163  const bool is_initialize = true) {
1164  std::vector< std::vector<step_node> > new_footstep_nodes_list;
1165  return go_pos_param_2_footstep_nodes_list (goal_x, goal_y, goal_theta,
1166  initial_support_legs_coords, start_ref_coords,
1167  initial_support_legs,
1168  new_footstep_nodes_list,
1169  is_initialize);
1170  };
1171  bool go_pos_param_2_footstep_nodes_list (const double goal_x, const double goal_y, const double goal_theta, /* [mm] [mm] [deg] */
1172  const std::vector<coordinates>& initial_support_legs_coords, coordinates start_ref_coords,
1173  const std::vector<leg_type>& initial_support_legs,
1174  std::vector< std::vector<step_node> >& new_footstep_nodes_list,
1175  const bool is_initialize = true);
1176  void go_pos_param_2_footstep_nodes_list_core (const double goal_x, const double goal_y, const double goal_theta, /* [mm] [mm] [deg] */
1177  const std::vector<coordinates>& initial_support_legs_coords, coordinates start_ref_coords,
1178  const std::vector<leg_type>& initial_support_legs,
1179  std::vector< std::vector<step_node> >& new_footstep_nodes_list,
1180  const bool is_initialize, const size_t overwritable_fs_index) const;
1181  void go_single_step_param_2_footstep_nodes_list (const double goal_x, const double goal_y, const double goal_z, const double goal_theta, /* [mm] [mm] [mm] [deg] */
1182  const std::string& tmp_swing_leg,
1183  const coordinates& _support_leg_coords);
1184  void initialize_velocity_mode (const coordinates& _ref_coords,
1185  const double vel_x, const double vel_y, const double vel_theta, /* [mm/s] [mm/s] [deg/s] */
1186  const std::vector<leg_type>& current_legs);
1187  void finalize_velocity_mode ();
1189  {
1190  append_finalize_footstep(footstep_nodes_list);
1191  };
1192  void append_finalize_footstep (std::vector< std::vector<step_node> >& _footstep_nodes_list) const
1193  {
1194  std::vector<step_node> sns = _footstep_nodes_list[_footstep_nodes_list.size()-2];
1195  for (size_t i = 0; i < sns.size(); i++) {
1196  sns.at(i).step_height = sns.at(i).toe_angle = sns.at(i).heel_angle = 0.0;
1197  }
1198  _footstep_nodes_list.push_back(sns);
1199  };
1201  {
1202  if (!footstep_nodes_list.empty()) {
1203  velocity_mode_flg = VEL_IDLING;
1204  emergency_flg = EMERGENCY_STOP;
1205  }
1206  };
1207  /* parameter setting */
1208  void set_default_step_time (const double _default_step_time) { default_step_time = _default_step_time; };
1209  void set_default_double_support_ratio_before (const double _default_double_support_ratio_before) { default_double_support_ratio_before = _default_double_support_ratio_before; };
1210  void set_default_double_support_ratio_after (const double _default_double_support_ratio_after) { default_double_support_ratio_after = _default_double_support_ratio_after; };
1211  void set_default_double_support_static_ratio_before (const double _default_double_support_static_ratio_before) { default_double_support_static_ratio_before = _default_double_support_static_ratio_before; };
1212  void set_default_double_support_static_ratio_after (const double _default_double_support_static_ratio_after) { default_double_support_static_ratio_after = _default_double_support_static_ratio_after; };
1213  void set_default_double_support_ratio_swing_before (const double _default_double_support_ratio_swing_before) { default_double_support_ratio_swing_before = _default_double_support_ratio_swing_before; };
1214  void set_default_double_support_ratio_swing_after (const double _default_double_support_ratio_swing_after) { default_double_support_ratio_swing_after = _default_double_support_ratio_swing_after; };
1215  void set_default_zmp_offsets(const std::vector<hrp::Vector3>& tmp) { rg.set_default_zmp_offsets(tmp); };
1216  void set_toe_zmp_offset_x (const double _off) { rg.set_toe_zmp_offset_x(_off); };
1217  void set_heel_zmp_offset_x (const double _off) { rg.set_heel_zmp_offset_x(_off); };
1220  void set_zmp_weight_map (const std::map<leg_type, double> _map) { rg.set_zmp_weight_map(_map); };
1221  void set_default_step_height(const double _tmp) { lcg.set_default_step_height(_tmp); };
1222  void set_default_top_ratio(const double _tmp) { lcg.set_default_top_ratio(_tmp); };
1223  void set_velocity_param (const double vel_x, const double vel_y, const double vel_theta) /* [mm/s] [mm/s] [deg/s] */
1224  {
1225  vel_param.set(vel_x, vel_y, vel_theta);
1226  };
1227  void set_offset_velocity_param (const double vel_x, const double vel_y, const double vel_theta) /* [mm/s] [mm/s] [deg/s] */
1228  {
1229  offset_vel_param.set(vel_x, vel_y, vel_theta);
1230  };
1231  void set_stride_parameters (const double _stride_fwd_x, const double _stride_outside_y, const double _stride_outside_theta,
1232  const double _stride_bwd_x, const double _stride_inside_y, const double _stride_inside_theta)
1233  {
1234  footstep_param.stride_fwd_x = _stride_fwd_x;
1235  footstep_param.stride_outside_y = _stride_outside_y;
1236  footstep_param.stride_outside_theta = _stride_outside_theta;
1237  footstep_param.stride_bwd_x = _stride_bwd_x;
1238  footstep_param.stride_inside_y = _stride_inside_y;
1239  footstep_param.stride_inside_theta = _stride_inside_theta;
1240  };
1241  void set_use_inside_step_limitation(const bool uu) { use_inside_step_limitation = uu; };
1243  void set_swing_trajectory_delay_time_offset (const double _time_offset) { lcg.set_swing_trajectory_delay_time_offset(_time_offset); };
1244  void set_swing_trajectory_final_distance_weight (const double _final_distance_weight) { lcg.set_swing_trajectory_final_distance_weight(_final_distance_weight); };
1248  void set_gravitational_acceleration (const double ga) { gravitational_acceleration = ga; };
1249  void set_toe_pos_offset_x (const double _offx) { lcg.set_toe_pos_offset_x(_offx); };
1250  void set_heel_pos_offset_x (const double _offx) { lcg.set_heel_pos_offset_x(_offx); };
1251  void set_toe_angle (const double _angle) { lcg.set_toe_angle(_angle); };
1252  void set_heel_angle (const double _angle) { lcg.set_heel_angle(_angle); };
1253  bool set_toe_heel_phase_ratio (const std::vector<double>& ratio)
1254  {
1255  bool lcgret = lcg.set_toe_heel_phase_ratio(ratio);
1256  bool rgret = rg.set_toe_heel_phase_ratio(ratio);
1257  return lcgret && rgret;
1258  };
1259  void set_use_toe_joint (const bool ut) { lcg.set_use_toe_joint(ut); };
1260  void set_leg_default_translate_pos (const std::vector<hrp::Vector3>& off) { footstep_param.leg_default_translate_pos = off;};
1261  void set_optional_go_pos_finalize_footstep_num (const size_t num) { optional_go_pos_finalize_footstep_num = num; };
1262  void set_all_limbs (const std::vector<std::string>& _all_limbs) { all_limbs = _all_limbs; };
1263  void set_overwritable_footstep_index_offset (const size_t _of) { overwritable_footstep_index_offset = _of;};
1264  void set_foot_steps_list (const std::vector< std::vector<step_node> >& fnsl)
1265  {
1266  clear_footstep_nodes_list();
1267  footstep_nodes_list = fnsl;
1268  append_finalize_footstep();
1269  print_footstep_nodes_list();
1270  };
1271  void set_overwrite_foot_steps_list (const std::vector< std::vector<step_node> >& fnsl)
1272  {
1273  overwrite_footstep_nodes_list.clear();
1274  overwrite_footstep_nodes_list = fnsl;
1275  append_finalize_footstep(overwrite_footstep_nodes_list);
1276  print_footstep_nodes_list(overwrite_footstep_nodes_list);
1277  };
1278  void set_leg_margin (const double _leg_margin[4]) {
1279  for (size_t i = 0; i < 4; i++) {
1280  leg_margin[i] = _leg_margin[i];
1281  }
1282  };
1283  void set_stride_limitation_for_circle_type (const double (&_stride_limitation_for_circle_type)[5]) {
1284  for (size_t i = 0; i < 5; i++) {
1285  stride_limitation_for_circle_type[i] = _stride_limitation_for_circle_type[i];
1286  }
1287  };
1288  void set_overwritable_stride_limitation (const double (&_overwritable_stride_limitation)[5]) {
1289  for (size_t i = 0; i < 5; i++) {
1290  overwritable_stride_limitation[i] = _overwritable_stride_limitation[i];
1291  }
1292  };
1293  void set_footstep_modification_gain (const double _footstep_modification_gain) { footstep_modification_gain = _footstep_modification_gain; };
1294  void set_cp_check_margin (const double (&_cp_check_margin)[2]) {
1295  for (size_t i=0; i < 2; i++) {
1296  cp_check_margin[i] = _cp_check_margin[i];
1297  }
1298  };
1299  void set_act_contact_states (const std::vector<bool>& _act_contact_states) {
1300  if (act_contact_states.empty()) act_contact_states.resize(_act_contact_states.size());
1301  for (size_t i = 0; i < act_contact_states.size(); i++) {
1302  act_contact_states[i] = _act_contact_states[i];
1303  }
1304  };
1305  void set_use_stride_limitation (const bool _use_stride_limitation) { use_stride_limitation = _use_stride_limitation; };
1306  void set_modify_footsteps (const bool _modify_footsteps) { modify_footsteps = _modify_footsteps; };
1307  void set_margin_time_ratio (const double _margin_time_ratio) { margin_time_ratio = _margin_time_ratio; };
1308  void set_diff_cp (const hrp::Vector3 _cp) { diff_cp = _cp; };
1309  void set_stride_limitation_type (const stride_limitation_type _tmp) { default_stride_limitation_type = _tmp; };
1310  void set_toe_check_thre (const double _a) { thtc.set_toe_check_thre(_a); };
1311  void set_heel_check_thre (const double _a) { thtc.set_heel_check_thre(_a); };
1312  /* Get overwritable footstep index. For example, if overwritable_footstep_index_offset = 1, overwrite next footstep. If overwritable_footstep_index_offset = 0, overwrite current swinging footstep. */
1313  size_t get_overwritable_index () const
1314  {
1315  return lcg.get_footstep_index()+overwritable_footstep_index_offset;
1316  };
1317  bool set_overwrite_foot_step_index (const size_t idx)
1318  {
1319  if (idx >= get_overwritable_index()) {
1320  overwrite_footstep_index = idx;
1321  return true;
1322  } else {
1323  return false;
1324  }
1325  };
1326  bool get_footstep_nodes_by_index (std::vector<step_node>& csl, const size_t idx) const
1327  {
1328  if (footstep_nodes_list.size()-1 >= idx) {
1329  csl = footstep_nodes_list.at(idx);
1330  return true;
1331  } else {
1332  return false;
1333  }
1334  };
1335  void print_footstep_nodes_list (const std::vector< std::vector<step_node> > _footstep_nodes_list) const
1336  {
1337  for (size_t i = 0; i < _footstep_nodes_list.size(); i++) {
1338  for (size_t j = 0; j < _footstep_nodes_list.at(i).size(); j++) {
1339  std::cerr << "[" << i << "] " << _footstep_nodes_list.at(i).at(j) << std::endl;
1340  }
1341  }
1342  };
1344  {
1345  print_footstep_nodes_list(footstep_nodes_list);
1346  };
1347  /* parameter getting */
1348  const hrp::Vector3& get_cog () const { return cog; };
1350  double refcog_vel[3];
1351  preview_controller_ptr->get_refcog_vel(refcog_vel);
1352  return hrp::Vector3(refcog_vel[0], refcog_vel[1], refcog_vel[2]);
1353  };
1355  double refcog_acc[3];
1356  preview_controller_ptr->get_refcog_acc(refcog_acc);
1357  return hrp::Vector3(refcog_acc[0], refcog_acc[1], refcog_acc[2]);
1358  };
1359  const hrp::Vector3& get_refzmp () const { return refzmp;};
1361  {
1362  double czmp[3];
1363  preview_controller_ptr->get_cart_zmp(czmp);
1364  return hrp::Vector3(czmp[0], czmp[1], czmp[2]);
1365  };
1366  std::vector<std::string> convert_leg_types_to_names (const std::vector<leg_type>& lts) const {
1367  std::vector<std::string> ret;
1368  for (std::vector<leg_type>::const_iterator it = lts.begin(); it != lts.end(); it++) {
1369  ret.push_back(leg_type_map.find(*it)->second);
1370  }
1371  return ret;
1372  };
1373  const std::vector<hrp::Vector3>& get_swing_foot_zmp_offsets () const { return swing_foot_zmp_offsets;};
1374  std::vector<hrp::Vector3> get_support_foot_zmp_offsets () const {
1375  std::vector<hrp::Vector3> ret;
1376  for (size_t i = 0; i < lcg.get_support_leg_types().size(); i++) {
1377  ret.push_back(rg.get_default_zmp_offset(lcg.get_support_leg_types().at(i)));
1378  }
1379  return ret;
1380  };
1381  // Get foot zmp offsets by checking whether given EE name is swing or support
1382  bool get_swing_support_foot_zmp_offsets_from_ee_name (hrp::Vector3& ret, const std::string& ee_name) const
1383  {
1384  leg_type lt = get_leg_type_from_ee_name(ee_name);
1385  std::vector<leg_type>::const_iterator it = std::find(lcg.get_support_leg_types().begin(), lcg.get_support_leg_types().end(), lt);
1386  if (it != lcg.get_support_leg_types().end()) { // If support leg
1387  ret = get_support_foot_zmp_offsets()[std::distance(lcg.get_support_leg_types().begin(), it)];
1388  } else {
1389  it = std::find(lcg.get_swing_leg_types().begin(), lcg.get_swing_leg_types().end(), lt);
1390  if (it != lcg.get_swing_leg_types().end()) { // If swing leg
1391  ret = get_swing_foot_zmp_offsets()[std::distance(lcg.get_swing_leg_types().begin(), it)];
1392  } else { // Otherwise
1393  return false;
1394  }
1395  }
1396  return true;
1397  };
1398  double get_toe_zmp_offset_x () const { return rg.get_toe_zmp_offset_x(); };
1399  double get_heel_zmp_offset_x () const { return rg.get_heel_zmp_offset_x(); };
1402  const std::map<leg_type, double> get_zmp_weight_map () const { return rg.get_zmp_weight_map(); };
1404  std::vector<std::string> get_footstep_front_leg_names () const {
1405  std::vector<leg_type> lts;
1406  for (size_t i = 0; i < footstep_nodes_list[0].size(); i++) {
1407  lts.push_back(footstep_nodes_list[0].at(i).l_r);
1408  }
1409  return convert_leg_types_to_names(lts);
1410  };
1411  std::vector<std::string> get_footstep_back_leg_names () const {
1412  std::vector<leg_type> lts;
1413  for (size_t i = 0; i < footstep_nodes_list.back().size(); i++) {
1414  lts.push_back(footstep_nodes_list.back().at(i).l_r);
1415  }
1416  return convert_leg_types_to_names(lts);
1417  };
1418  const std::vector<std::string> get_support_leg_names() const { return convert_leg_types_to_names(lcg.get_support_leg_types());};
1419  const std::vector<std::string> get_swing_leg_names() const { return convert_leg_types_to_names(lcg.get_swing_leg_types());};
1420  const std::vector<step_node>& get_swing_leg_steps() const { return lcg.get_swing_leg_steps(); };
1421  const std::vector<step_node>& get_support_leg_steps() const { return lcg.get_support_leg_steps(); };
1422  const std::vector<step_node>& get_swing_leg_src_steps() const { return lcg.get_swing_leg_src_steps(); };
1423  const std::vector<step_node>& get_swing_leg_dst_steps() const { return lcg.get_swing_leg_dst_steps(); };
1424  const coordinates get_dst_foot_midcoords() const /* get foot_midcoords calculated from swing_leg_dst_coords */
1425  {
1426  coordinates tmp(lcg.get_swing_leg_dst_steps().front().worldcoords);
1427  tmp.pos += tmp.rot * hrp::Vector3(-1*footstep_param.leg_default_translate_pos[lcg.get_swing_leg_dst_steps().front().l_r]);
1428  return tmp;
1429  };
1431  void get_stride_parameters (double& _stride_fwd_x, double& _stride_outside_y, double& _stride_outside_theta,
1432  double& _stride_bwd_x, double& _stride_inside_y, double& _stride_inside_theta) const
1433  {
1434  _stride_fwd_x = footstep_param.stride_fwd_x;
1435  _stride_outside_y = footstep_param.stride_outside_y;
1436  _stride_outside_theta = footstep_param.stride_outside_theta;
1437  _stride_bwd_x = footstep_param.stride_bwd_x;
1438  _stride_inside_y = footstep_param.stride_inside_y;
1439  _stride_inside_theta = footstep_param.stride_inside_theta;
1440  };
1441  size_t get_footstep_index() const { return lcg.get_footstep_index(); };
1442  size_t get_lcg_count() const { return lcg.get_lcg_count(); };
1443  double get_current_swing_time(const size_t idx) const { return lcg.get_current_swing_time(idx); };
1444  // Get current swing time by checking whether given EE name is swing or support
1445  double get_current_swing_time_from_ee_name (const std::string ee_name) const
1446  {
1447  return get_current_swing_time( get_leg_type_from_ee_name(ee_name) );
1448  };
1449  std::vector<leg_type> get_current_support_states() const { return lcg.get_current_support_states();};
1450  double get_default_step_time () const { return default_step_time; };
1451  double get_default_step_height () const { return lcg.get_default_step_height(); };
1452  double get_default_double_support_ratio_before () const { return default_double_support_ratio_before; };
1453  double get_default_double_support_ratio_after () const { return default_double_support_ratio_after; };
1454  double get_default_double_support_static_ratio_before () const { return default_double_support_static_ratio_before; };
1455  double get_default_double_support_static_ratio_after () const { return default_double_support_static_ratio_after; };
1456  double get_default_double_support_ratio_swing_before () const {return default_double_support_ratio_swing_before; };
1457  double get_default_double_support_ratio_swing_after () const {return default_double_support_ratio_swing_after; };
1458  std::vector< std::vector<step_node> > get_remaining_footstep_nodes_list () const
1459  {
1460  std::vector< std::vector<step_node> > fsnl;
1461  size_t fsl_size = (footstep_nodes_list.size()>lcg.get_footstep_index() ? footstep_nodes_list.size()-lcg.get_footstep_index() : 0);
1462  // The rest of fsl are swing dst coords from now.
1463  for (size_t i = 0; i < fsl_size; i++) {
1464  fsnl.push_back(footstep_nodes_list[i+lcg.get_footstep_index()]);
1465  }
1466  return fsnl;
1467  };
1474  double get_gravitational_acceleration () const { return gravitational_acceleration; } ;
1475  double get_toe_pos_offset_x () const { return lcg.get_toe_pos_offset_x(); };
1476  double get_heel_pos_offset_x () const { return lcg.get_heel_pos_offset_x(); };
1477  double get_toe_angle () const { return lcg.get_toe_angle(); };
1478  double get_heel_angle () const { return lcg.get_heel_angle(); };
1479  double get_foot_dif_rot_angle () const { return lcg.get_foot_dif_rot_angle(); };
1480  void get_toe_heel_phase_ratio (std::vector<double>& ratio) const { lcg.get_toe_heel_phase_ratio(ratio); };
1481  int get_NUM_TH_PHASES () const { return NUM_TH_PHASES; };
1482  bool get_use_toe_joint () const { return lcg.get_use_toe_joint(); };
1483  double get_current_toe_heel_ratio () const { return lcg.get_current_toe_heel_ratio(get_use_toe_heel_transition()); };
1484  // Get current toe heel ratio by checking whether given EE name is swing or support
1485  bool get_current_toe_heel_ratio_from_ee_name (double& ret, const std::string& ee_name) const
1486  {
1487  leg_type lt = get_leg_type_from_ee_name(ee_name);
1488  if (std::find(lcg.get_support_leg_types().begin(), lcg.get_support_leg_types().end(), lt)!=lcg.get_support_leg_types().end()) { // If support
1490  } else if (std::find(lcg.get_swing_leg_types().begin(), lcg.get_support_leg_types().end(), lt)!=lcg.get_swing_leg_types().end()) { // If swing
1491  ret = get_current_toe_heel_ratio();
1492  } else { // Otherwise
1493  return false;
1494  }
1495  return true;
1496  };
1497  void get_leg_default_translate_pos (std::vector<hrp::Vector3>& off) const { off = footstep_param.leg_default_translate_pos; };
1498  size_t get_overwritable_footstep_index_offset () const { return overwritable_footstep_index_offset; };
1499  const std::vector<leg_type> calc_counter_leg_types_from_footstep_nodes (const std::vector<step_node>& fns, std::vector<std::string> _all_limbs) const;
1500  const std::map<leg_type, std::string> get_leg_type_map () const { return leg_type_map; };
1501  size_t get_optional_go_pos_finalize_footstep_num () const { return optional_go_pos_finalize_footstep_num; };
1502  bool is_finalizing (const double tm) const { return ((preview_controller_ptr->get_delay()*2 - default_step_time/dt)-finalize_count) <= (tm/dt)-1; };
1503  size_t get_overwrite_check_timing () const { return static_cast<size_t>(footstep_nodes_list[lcg.get_footstep_index()][0].step_time/dt * 0.5) - 1;}; // Almost middle of step time
1504  double get_leg_margin (const size_t idx) const { return leg_margin[idx]; };
1505  double get_stride_limitation_for_circle_type (const size_t idx) const { return stride_limitation_for_circle_type[idx]; };
1506  double get_overwritable_stride_limitation (const size_t idx) const { return overwritable_stride_limitation[idx]; };
1507  double get_footstep_modification_gain () const { return footstep_modification_gain; };
1508  double get_cp_check_margin (const size_t idx) const { return cp_check_margin[idx]; };
1509  bool get_modify_footsteps () const { return modify_footsteps; };
1510  double get_margin_time_ratio () const { return margin_time_ratio; };
1511  bool get_use_stride_limitation () const { return use_stride_limitation; };
1512  stride_limitation_type get_stride_limitation_type () const { return default_stride_limitation_type; };
1513  double get_toe_check_thre () const { return thtc.get_toe_check_thre(); };
1514  double get_heel_check_thre () const { return thtc.get_heel_check_thre(); };
1515  // Get ee coords by checking whether given EE name is swing or support
1516  bool get_swing_support_ee_coords_from_ee_name (hrp::Vector3& cpos, hrp::Matrix33& crot, const std::string& ee_name) const
1517  {
1518  leg_type lt = get_leg_type_from_ee_name(ee_name);
1519  if (std::find(lcg.get_support_leg_types().begin(), lcg.get_support_leg_types().end(), lt) != lcg.get_support_leg_types().end()) { // If support
1520  coordinates tmpc = std::find_if(lcg.get_support_leg_steps().begin(), lcg.get_support_leg_steps().end(), (&boost::lambda::_1->* &step_node::l_r == lt))->worldcoords;
1521  cpos = tmpc.pos;
1522  crot = tmpc.rot;
1523  } else if (std::find(lcg.get_swing_leg_types().begin(), lcg.get_swing_leg_types().end(), lt) != lcg.get_swing_leg_types().end()) { // If swing
1524  coordinates tmpc = std::find_if(lcg.get_swing_leg_steps().begin(), lcg.get_swing_leg_steps().end(), (&boost::lambda::_1->* &step_node::l_r == lt))->worldcoords;
1525  cpos = tmpc.pos;
1526  crot = tmpc.rot;
1527  } else { // Otherwise
1528  return false;
1529  }
1530  return true;
1531  };
1532  // Get current support state (true=support, false=swing) by checking whether given EE name is swing or support
1533  bool get_current_support_state_from_ee_name (const std::string& ee_name) const
1534  {
1535  leg_type lt = get_leg_type_from_ee_name(ee_name);
1536  std::vector<leg_type> tmp = lcg.get_current_support_states();
1537  return std::find(tmp.begin(), tmp.end(), lt) != tmp.end();
1538  };
1539 #ifdef FOR_TESTGAITGENERATOR
1540  size_t get_one_step_count() const { return lcg.get_one_step_count(); };
1541  void get_footstep_nodes_list (std::vector< std::vector<step_node> > & fsl) const
1542  {
1543  fsl = footstep_nodes_list;
1544  };
1545  double get_toe_heel_dif_angle () const { return lcg.get_toe_heel_dif_angle(); };
1546  std::vector<hrp::Vector3> get_default_zmp_offsets() const { return rg.get_default_zmp_offsets(); };
1547 #endif // FOR_TESTGAITGENERATOR
1548  void print_param (const std::string& print_str = "") const
1549  {
1550  double stride_fwd_x, stride_outside_y, stride_outside_th, stride_bwd_x, stride_inside_y, stride_inside_th;
1551  get_stride_parameters(stride_fwd_x, stride_outside_y, stride_outside_th, stride_bwd_x, stride_inside_y, stride_inside_th);
1552  std::cerr << "[" << print_str << "] stride_parameter = " << stride_fwd_x << "[m], " << stride_outside_y << "[m], " << stride_outside_th << "[deg], "
1553  << stride_bwd_x << "[m], " << stride_inside_y << "[m], " << stride_inside_th << "[deg]" << std::endl;
1554  std::cerr << "[" << print_str << "] leg_default_translate_pos = ";
1555  for (size_t i = 0; i < footstep_param.leg_default_translate_pos.size(); i++) {
1556  std::cerr << footstep_param.leg_default_translate_pos[i].format(Eigen::IOFormat(Eigen::StreamPrecision, 0, ", ", ", ", "", "", " [", "]"));
1557  }
1558  std::cerr << std::endl;
1559  std::cerr << "[" << print_str << "] default_step_time = " << get_default_step_time() << "[s]" << std::endl;
1560  std::cerr << "[" << print_str << "] default_step_height = " << get_default_step_height() << "[m]" << std::endl;
1561  std::cerr << "[" << print_str << "] default_double_support_ratio_before = " << get_default_double_support_ratio_before() << ", default_double_support_ratio_before = " << get_default_double_support_ratio_after() << ", default_double_support_static_ratio_before = " << get_default_double_support_static_ratio_before() << ", default_double_support_static_ratio_after = " << get_default_double_support_static_ratio_after() << ", default_double_support_static_ratio_swing_before = " << get_default_double_support_ratio_swing_before() << ", default_double_support_static_ratio_swing_after = " << get_default_double_support_ratio_swing_after() << std::endl;
1562  std::cerr << "[" << print_str << "] default_orbit_type = ";
1563  if (get_default_orbit_type() == SHUFFLING) {
1564  std::cerr << "SHUFFLING" << std::endl;
1565  } else if (get_default_orbit_type() == CYCLOID) {
1566  std::cerr << "CYCLOID" << std::endl;
1567  } else if (get_default_orbit_type() == RECTANGLE) {
1568  std::cerr << "RECTANGLE" << std::endl;
1569  } else if (get_default_orbit_type() == STAIR) {
1570  std::cerr << "STAIR" << std::endl;
1571  } else if (get_default_orbit_type() == CYCLOIDDELAY) {
1572  std::cerr << "CYCLOIDDELAY" << std::endl;
1573  } else if (get_default_orbit_type() == CYCLOIDDELAYKICK) {
1574  std::cerr << "CYCLOIDDELAYKICK" << std::endl;
1575  } else if (get_default_orbit_type() == CROSS) {
1576  std::cerr << "CROSS" << std::endl;
1577  }
1578  std::cerr << "[" << print_str << "] swing_trajectory_delay_time_offset = " << get_swing_trajectory_delay_time_offset() << "[s], swing_trajectory_final_distance_weight = " << get_swing_trajectory_final_distance_weight()
1579  << ", swing_trajectory_time_offset_xy2z = " << get_swing_trajectory_time_offset_xy2z() << std::endl;
1580  hrp::Vector3 tmpv;
1581  tmpv = get_stair_trajectory_way_point_offset();
1582  std::cerr << "[" << print_str << "] stair_trajectory_way_point_offset = " << tmpv.format(Eigen::IOFormat(Eigen::StreamPrecision, 0, ", ", ", ", "", "", " [", "]")) << "[m]" << std::endl;
1583  tmpv = get_cycloid_delay_kick_point_offset();
1584  std::cerr << "[" << print_str << "] cycloid_delay_kick_point_offset = " << tmpv.format(Eigen::IOFormat(Eigen::StreamPrecision, 0, ", ", ", ", "", "", " [", "]")) << "[m]" << std::endl;
1585  std::cerr << "[" << print_str << "] gravitational_acceleration = " << get_gravitational_acceleration() << "[m/s^2]" << std::endl;
1586  std::cerr << "[" << print_str << "] toe_pos_offset_x = " << get_toe_pos_offset_x() << "[mm], heel_pos_offset_x = " << get_heel_pos_offset_x() << "[mm]" << std::endl;
1587  std::cerr << "[" << print_str << "] toe_zmp_offset_x = " << get_toe_zmp_offset_x() << "[mm], heel_zmp_offset_x = " << get_heel_zmp_offset_x() << "[mm]" << std::endl;
1588  std::cerr << "[" << print_str << "] toe_angle = " << get_toe_angle() << "[deg]" << std::endl;
1589  std::cerr << "[" << print_str << "] heel_angle = " << get_heel_angle() << "[deg]" << std::endl;
1590  std::cerr << "[" << print_str << "] use_toe_joint = " << (get_use_toe_joint()?"true":"false") << ", use_toe_heel_transition = " << (get_use_toe_heel_transition()?"true":"false") << ", use_toe_heel_auto_set = " << (get_use_toe_heel_auto_set()?"true":"false") << std::endl;
1591  std::vector<double> tmp_ratio(get_NUM_TH_PHASES(), 0.0);
1592  get_toe_heel_phase_ratio(tmp_ratio);
1593  std::cerr << "[" << print_str << "] toe_heel_phase_ratio = [";
1594  for (int i = 0; i < get_NUM_TH_PHASES(); i++) std::cerr << tmp_ratio[i] << " ";
1595  std::cerr << "]" << std::endl;
1596  std::cerr << "[" << print_str << "] optional_go_pos_finalize_footstep_num = " << optional_go_pos_finalize_footstep_num << ", overwritable_footstep_index_offset = " << overwritable_footstep_index_offset << std::endl;
1597  std::cerr << "[" << print_str << "] default_stride_limitation_type = ";
1598  if (default_stride_limitation_type == SQUARE) {
1599  std::cerr << "SQUARE" << std::endl;
1600  } else if (default_stride_limitation_type == CIRCLE) {
1601  std::cerr << "CIRCLE" << std::endl;
1602  }
1603  thtc.print_param(print_str);
1604  };
1605  };
1606 }
1607 #endif /* GAITGENERATOR_H */
orbit_type get_default_orbit_type() const
void set_overwrite_foot_steps_list(const std::vector< std::vector< step_node > > &fnsl)
const hrp::Vector3 & get_refzmp() const
friend std::ostream & operator<<(std::ostream &os, const step_node &sn)
Definition: GaitGenerator.h:53
double get_gravitational_acceleration() const
bool go_pos_param_2_footstep_nodes_list(const double goal_x, const double goal_y, const double goal_theta, const std::vector< coordinates > &initial_support_legs_coords, coordinates start_ref_coords, const std::vector< leg_type > &initial_support_legs, const bool is_initialize=true)
footstep_parameter footstep_param
const std::vector< hrp::Vector3 > & get_swing_foot_zmp_offsets() const
#define max(a, b)
void set_swing_trajectory_final_distance_weight(const double _final_distance_weight)
void set_gravitational_acceleration(const double ga)
double get_default_step_time() const
void set_swing_trajectory_delay_time_offset(const double _time_offset)
bool get_current_support_state_from_ee_name(const std::string &ee_name) const
bool get_swing_support_foot_zmp_offsets_from_ee_name(hrp::Vector3 &ret, const std::string &ee_name) const
void set_toe_angle(const double _angle)
void set_default_double_support_ratio_swing_before(const double _default_double_support_ratio_swing_before)
std::map< leg_type, std::string > leg_type_map
size_t get_optional_go_pos_finalize_footstep_num() const
void set_default_double_support_static_ratio_after(const double _default_double_support_static_ratio_after)
void hoffarbib_interpolation(double &_pos, double &_vel, double &_acc, const double tmp_remain_time, const double tmp_goal, const double tmp_goal_vel=0, const double tmp_goal_acc=0)
void append_finalize_footstep(std::vector< std::vector< step_node > > &_footstep_nodes_list) const
const std::map< leg_type, double > get_zmp_weight_map() const
void set_stride_limitation_for_circle_type(const double(&_stride_limitation_for_circle_type)[5])
void set_toe_check_thre(const double _a)
void set_all_limbs(const std::vector< std::string > &_all_limbs)
toe_heel_type_checker(const double _toe_check_thre, const double _heel_check_thre)
void set_use_stride_limitation(const bool _use_stride_limitation)
void set_swing_trajectory_delay_time_offset(const double _time_offset)
double calc_phase_ratio(const size_t current_count, const toe_heel_phase start_phase, const toe_heel_phase goal_phase) const
void calc_swing_support_params_from_footstep_nodes_list(const std::vector< std::vector< step_node > > &fnsl)
void set_heel_angle(const double _angle)
const bool is_second_phase() const
double get_swing_trajectory_time_offset_xy2z() const
static const double DEFAULT_GRAVITATIONAL_ACCELERATION
void multi_mid_coords(coordinates &ret, const std::vector< coordinates > &cs, const double eps)
hrp::Vector3 get_stair_trajectory_way_point_offset() const
std::vector< hrp::Vector3 > swing_foot_zmp_offsets
bool check_toe_heel_phase_ratio_validity(const std::vector< double > &ratio)
double calc_antecedent_path(const hrp::Vector3 &start, const hrp::Vector3 &goal, const double height)
const hrp::Vector3 & get_refzmp_cur() const
stride_limitation_type default_stride_limitation_type
void set_refzmp_count(const size_t _refzmp_count)
void set_default_step_height(const double _tmp)
bool get_use_toe_heel_transition() const
void set_use_toe_heel_auto_set(const bool ut)
hrp::Matrix33 rot
Definition: RatsMatrix.h:20
void set_overwritable_stride_limitation(const double(&_overwritable_stride_limitation)[5])
preview_dynamics_filter< extended_preview_control > * preview_controller_ptr
void print_param(const std::string print_str="") const
double get_current_toe_heel_ratio() const
void reset_all(const double _dt, const size_t _one_step_len, const double default_double_support_ratio_before, const double default_double_support_ratio_after, const double _time_offset, const double _final_distance_weight, const double _time_offset_xy2z)
double get_heel_pos_offset_x() const
bool is_between_phases(const size_t current_count, const toe_heel_phase phase0, const toe_heel_phase phase1) const
toe_heel_phase
void set_swing_trajectory_final_distance_weight(const double _final_distance_weight)
void set_one_step_count(const size_t _count)
const hrp::Vector3 & get_default_zmp_offset(const leg_type lt) const
bool get_modify_footsteps() const
double calc_phase_ratio(const size_t current_count, const toe_heel_phase goal_phase) const
void set_zmp_weight_map(const std::map< leg_type, double > _map)
coordinates initial_foot_mid_coords
void set_toe_pos_offset_x(const double _offx)
std::vector< std::vector< step_node > > footstep_nodes_list
const bool is_second_last_phase() const
void append_go_pos_step_nodes(const coordinates &_ref_coords, const std::vector< leg_type > &lts, std::vector< std::vector< step_node > > &_footstep_nodes_list) const
const std::vector< step_node > & get_support_leg_steps() const
void setName(const std::string &_name)
Definition: interpolator.h:63
void reset(const size_t _one_step_len, const double default_double_support_ratio_before, const double default_double_support_ratio_after)
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
void set_default_double_support_ratio_swing_after(const double _default_double_support_ratio_swing_after)
std::string leg_type_to_leg_type_string(const leg_type l_r)
void get_leg_default_translate_pos(std::vector< hrp::Vector3 > &off) const
cycloid_delay_kick_hoffarbib_trajectory_generator cdktg
void reset(const size_t _refzmp_count)
void set_swing_trajectory_time_offset_xy2z(const double _tmp)
hrp::Vector3 interpolate_antecedent_path(const double tmp_ratio) const
void set_optional_go_pos_finalize_footstep_num(const size_t num)
std::vector< size_t > step_count_list
interpolator * foot_midcoords_interpolator
void set_heel_zmp_offset_x(const double _off)
void set_offset_velocity_param(const double vel_x, const double vel_y, const double vel_theta)
void get_swing_support_mid_coords(coordinates &ret) const
const std::vector< std::string > get_support_leg_names() const
double get_default_double_support_static_ratio_after() const
const coordinates get_dst_foot_midcoords() const
bool get_use_stride_limitation() const
int dimension() const
Definition: interpolator.h:62
void set_diff_cp(const hrp::Vector3 _cp)
cross_delay_hoffarbib_trajectory_generator crdtg
hrp::Vector3 get_cycloid_delay_kick_point_offset() const
std::vector< std::string > convert_leg_types_to_names(const std::vector< leg_type > &lts) const
std::vector< hrp::Vector3 > leg_default_translate_pos
Definition: GaitGenerator.h:76
void set_use_toe_heel_transition(const bool _u)
const std::vector< step_node > & get_swing_leg_steps() const
size_t get_lcg_count() const
png_uint_32 i
void set_overwritable_footstep_index_offset(const size_t _of)
size_t overwritable_footstep_index_offset
gait_generator(double _dt, const std::vector< hrp::Vector3 > &_leg_pos, std::vector< std::string > _all_limbs, const double _stride_fwd_x, const double _stride_outside_y, const double _stride_outside_theta, const double _stride_bwd_x, const double _stride_inside_y, const double _stride_inside_theta)
toe_heel_type current_src_toe_heel_type
toe_heel_type_checker thtc
def default_value(type_)
double calc_antecedent_path(const hrp::Vector3 &start, const hrp::Vector3 &goal, const double height)
std::vector< double > current_swing_time
png_infop png_bytep * trans
double get_heel_check_thre() const
static double no_using_toe_heel_ratio
size_t get_overwrite_check_timing() const
bool set_toe_heel_phase_ratio(const std::vector< double > &ratio)
double get_toe_pos_offset_x() const
coordinates worldcoords
Definition: GaitGenerator.h:33
void set_stair_trajectory_way_point_offset(const hrp::Vector3 _offset)
void append_footstep_nodes(const std::vector< std::string > &_legs, const std::vector< coordinates > &_fss, const double _step_height, const double _step_time, const double _toe_angle, const double _heel_angle)
double get_overwritable_stride_limitation(const size_t idx) const
void set_modify_footsteps(const bool _modify_footsteps)
hrp::Vector3 get_cog_vel() const
hrp::Vector3 get_stair_trajectory_way_point_offset() const
Eigen::Vector3d Vector3
double calc_antecedent_path_base(const std::vector< hrp::Vector3 > org_point_vec)
void set_default_zmp_offsets(const std::vector< hrp::Vector3 > &tmp)
void set_use_toe_joint(const bool ut)
void set_cycloid_delay_kick_point_offset(const hrp::Vector3 _offset)
double get_stride_limitation_for_circle_type(const size_t idx) const
bool set_toe_heel_phase_ratio(const std::vector< double > &ratio)
void set_default_double_support_ratio_before(const double _default_double_support_ratio_before)
Eigen::Matrix3d Matrix33
void set_leg_margin(const double _leg_margin[4])
double get_heel_angle() const
std::vector< toe_heel_types > toe_heel_types_list
OpenHRP::vector3 Vector3
void append_footstep_nodes(const std::vector< std::string > &_legs, const std::vector< coordinates > &_fss)
double get_default_double_support_static_ratio_before() const
std::vector< hrp::Vector3 > get_support_foot_zmp_offsets() const
void set_use_toe_heel_auto_set(const bool _u)
const bool is_start_double_support_phase() const
bool set_toe_heel_phase_ratio(const std::vector< double > &ratio)
const std::vector< step_node > & get_support_leg_steps() const
bool is_phase_starting(const size_t current_count, const toe_heel_phase _phase) const
velocity_mode_parameter vel_param
leg_type get_leg_type_from_ee_name(const std::string &ee_name) const
toe_heel_phase_counter thp
double get_default_step_height() const
std::vector< leg_type > get_current_support_states() const
bool is_finalizing(const double tm) const
void append_go_pos_step_nodes(const coordinates &_ref_coords, const std::vector< leg_type > &lts)
void set_swing_trajectory_final_distance_weight(const double _final_distance_weight)
bool get_footstep_nodes_by_index(std::vector< step_node > &csl, const size_t idx) const
double get_heel_pos_offset_x() const
double calc_phase_period(const toe_heel_phase start_phase, const toe_heel_phase goal_phase, const double _dt) const
double get_current_swing_time(const size_t idx) const
void print_footstep_nodes_list() const
std::vector< leg_type > swing_leg_types
void set_default_zmp_offsets(const std::vector< hrp::Vector3 > &tmp)
void get_toe_heel_phase_ratio(std::vector< double > &ratio) const
const std::map< leg_type, double > get_zmp_weight_map() const
void set_stair_trajectory_way_point_offset(const hrp::Vector3 _offset)
bool set_overwrite_foot_step_index(const size_t idx)
def j(str, encoding="cp932")
void set_act_contact_states(const std::vector< bool > &_act_contact_states)
void set_default_step_height(const double _tmp)
coordinates swing_support_midcoords
double get_toe_zmp_offset_x() const
void set_indices(const size_t idx)
const std::vector< std::string > get_swing_leg_names() const
double get_current_swing_time(const size_t idx) const
std::vector< hrp::Vector3 > refzmp_cur_list
double get_foot_dif_rot_angle() const
bool get_current_toe_heel_ratio_from_ee_name(double &ret, const std::string &ee_name) const
refzmp_generator(const double _dt)
void set_heel_pos_offset_x(const double _offx)
void set_cycloid_delay_kick_point_offset(const hrp::Vector3 _offset)
void set_toe_pos_offset_x(const double _offx)
std::map< leg_type, interpolator * > swing_foot_rot_interpolator
void set_use_inside_step_limitation(const bool uu)
void set_stride_parameters(const double _stride_fwd_x, const double _stride_outside_y, const double _stride_outside_theta, const double _stride_bwd_x, const double _stride_inside_y, const double _stride_inside_theta)
const std::map< leg_type, std::string > get_leg_type_map() const
void set_default_top_ratio(const double _tmp)
void set_toe_zmp_offset_x(const double _off)
void set_default_orbit_type(const orbit_type _tmp)
std::vector< leg_type > get_current_support_states() const
double get_heel_zmp_offset_x() const
stair_delay_hoffarbib_trajectory_generator sdtg
double get_margin_time_ratio() const
void proc_zmp_weight_map_interpolation()
void set_default_double_support_ratio_after(const double _default_double_support_ratio_after)
void set_velocity_param(const double vel_x, const double vel_y, const double vel_theta)
std::vector< step_node > support_leg_steps
void proc_zmp_weight_map_interpolation()
void set_footstep_modification_gain(const double _footstep_modification_gain)
void set_cp_check_margin(const double(&_cp_check_margin)[2])
double get_toe_check_thre() const
std::vector< std::vector< step_node > > overwrite_footstep_nodes_list
void remove_refzmp_cur_list_over_length(const size_t len)
void set_heel_check_thre(const double _heel_check_thre)
std::vector< std::string > all_limbs
void get_toe_heel_phase_ratio(std::vector< double > &ratio) const
double default_double_support_ratio_swing_before
double get_default_double_support_ratio_swing_before() const
const bool is_end_double_support_phase() const
std::vector< std::vector< hrp::Vector3 > > foot_x_axises_list
const hrp::Vector3 & get_cog() const
void set_stride_limitation_type(const stride_limitation_type _tmp)
std::vector< bool > act_contact_states
toe_heel_types(const toe_heel_type _src_type=SOLE, const toe_heel_type _dst_type=SOLE)
void set_default_orbit_type(const orbit_type type)
path
void set_default_step_time(const double _default_step_time)
footstep_parameter(const std::vector< hrp::Vector3 > &_leg_pos, const double _stride_fwd_x, const double _stride_outside_y, const double _stride_outside_theta, const double _stride_bwd_x, const double _stride_inside_y, const double _stride_inside_theta)
Definition: GaitGenerator.h:79
static double using_toe_heel_ratio
bool get_use_toe_joint() const
void set_use_toe_heel_auto_set(const bool _u)
void set_toe_check_thre(const double _toe_check_thre)
orbit_type get_default_orbit_type() const
def norm(a)
std::vector< std::string > get_footstep_front_leg_names() const
void set_swing_trajectory_time_offset_xy2z(const double _tmp)
void set_swing_support_steps_list(const std::vector< std::vector< step_node > > &fnsl)
std::vector< hrp::Vector3 > default_zmp_offsets
double calc_phase_ratio_for_toe_heel_transition(const size_t current_count) const
leg_coords_generator lcg
velocity_mode_flag velocity_mode_flg
double get_toe_angle() const
double get_default_double_support_ratio_swing_after() const
void set_leg_default_translate_pos(const std::vector< hrp::Vector3 > &off)
std::vector< rectangle_delay_hoffarbib_trajectory_generator > rdtg
double get_current_toe_heel_ratio(const bool _use_toe_heel_transition) const
std::vector< std::string > get_footstep_back_leg_names() const
bool get_use_toe_heel_transition() const
bool get_use_toe_heel_auto_set() const
const std::vector< step_node > & get_swing_leg_dst_steps() const
bool get_use_toe_joint() const
double get_swing_trajectory_final_distance_weight() const
void calc_swing_leg_src_steps(std::vector< step_node > &ret_swing_leg_src_steps, const std::vector< std::vector< step_node > > &fnsl, const size_t _footstep_index)
double calc_antecedent_path(const hrp::Vector3 &start, const hrp::Vector3 &goal, const double height)
const std::vector< step_node > & get_swing_leg_steps() const
void cycloid_midpoint(hrp::Vector3 &ret, const double ratio, const hrp::Vector3 &start, const hrp::Vector3 &goal, const double height, const double default_top_ratio)
void set_swing_trajectory_time_offset_xy2z(const double _tmp)
std::vector< hrp::Vector3 > point_vec
size_t get_overwritable_index() const
void print_footstep_nodes_list(const std::vector< std::vector< step_node > > _footstep_nodes_list) const
double get_swing_trajectory_delay_time_offset() const
double get_footstep_modification_gain() const
bool get_use_toe_heel_auto_set() const
double get_current_swing_time_from_ee_name(const std::string ee_name) const
void set_zmp_weight_map(const std::map< leg_type, double > _map)
double calc_antecedent_path(const hrp::Vector3 &start, const hrp::Vector3 &goal, const double height)
void get(double *x_, bool popp=true)
interpolator * toe_heel_interpolator
void set_heel_check_thre(const double _a)
const std::vector< step_node > & get_swing_leg_dst_steps_idx(const size_t idx) const
void set_heel_angle(const double _angle)
void get_trajectory_point(hrp::Vector3 &ret, const hrp::Vector3 &start, const hrp::Vector3 &goal, const double height)
const std::vector< step_node > & get_support_leg_steps_idx(const size_t idx) const
bool get_swing_support_ee_coords_from_ee_name(hrp::Vector3 &cpos, hrp::Matrix33 &crot, const std::string &ee_name) const
bool is_between_phases(const size_t current_count, const toe_heel_phase phase1) const
void set_stair_trajectory_way_point_offset(const hrp::Vector3 _offset)
boost::shared_ptr< interpolator > zmp_weight_interpolator
double get_leg_margin(const size_t idx) const
void set_toe_zmp_offset_x(const double _off)
stride_limitation_type
Definition: GaitGenerator.h:27
double set_value_according_to_toe_heel_type(const toe_heel_type tht, const double toe_value, const double heel_value, const double default_value)
double get_swing_trajectory_time_offset_xy2z() const
double get_heel_check_thre() const
void get_stride_parameters(double &_stride_fwd_x, double &_stride_outside_y, double &_stride_outside_theta, double &_stride_bwd_x, double &_stride_inside_y, double &_stride_inside_theta) const
double get_swing_trajectory_final_distance_weight() const
void set_margin_time_ratio(const double _margin_time_ratio)
hrp::Vector3 modified_d_footstep
hrp::Vector3 pos
Definition: RatsMatrix.h:19
void get_swing_support_mid_coords(coordinates &ret) const
double get_default_double_support_ratio_after() const
stride_limitation_type get_stride_limitation_type() const
const std::vector< step_node > & get_swing_leg_src_steps() const
leg_coords_generator(const double _dt)
double get_heel_angle() const
bool get_current_refzmp(hrp::Vector3 &rzmp, std::vector< hrp::Vector3 > &swing_foot_zmp_offsets, const double default_double_support_ratio_before, const double default_double_support_ratio_after, const double default_double_support_static_ratio_before, const double default_double_support_static_ratio_after)
double default_double_support_static_ratio_before
double get_foot_dif_rot_angle() const
hrp::Vector3 get_cycloid_delay_kick_point_offset() const
size_t get_footstep_index() const
void print_param(const std::string &print_str="") const
toe_heel_phase_counter thp
const std::vector< step_node > & get_swing_leg_dst_steps() const
double get_toe_angle() const
double get_default_step_height() const
const std::vector< leg_type > & get_swing_leg_types() const
void set_swing_trajectory_delay_time_offset(const double _time_offset)
void set_toe_angle(const double _angle)
size_t optional_go_pos_finalize_footstep_num
void set_foot_steps_list(const std::vector< std::vector< step_node > > &fnsl)
void set_use_toe_joint(const bool ut)
void set_heel_zmp_offset_x(const double _off)
double get_swing_trajectory_final_distance_weight() const
double get_toe_pos_offset_x() const
const std::vector< leg_type > & get_support_leg_types() const
double get_default_double_support_ratio_before() const
double get_cp_check_margin(const size_t idx) const
hrp::Vector3 get_cart_zmp() const
hrp::Vector3 get_cog_acc() const
toe_heel_type src_type
double calc_antecedent_path(const hrp::Vector3 &start, const hrp::Vector3 &goal, const double height)
bool get_use_toe_heel_auto_set() const
refzmp_generator rg
std::vector< std::vector< step_node > > swing_leg_dst_steps_list
toe_heel_type check_toe_heel_type_from_swing_support_coords(const coordinates &swing_coords, const coordinates &support_coords, const double toe_pos_offset_x, const double heel_pos_offset_x) const
emergency_flag emergency_flg
size_t get_footstep_index() const
void set_use_toe_heel_transition(const bool _u)
double get_swing_trajectory_delay_time_offset() const
double default_double_support_ratio_swing_after
step_node(const std::string &_l_r, const coordinates &_worldcoords, const double _step_height, const double _step_time, const double _toe_angle, const double _heel_angle)
Definition: GaitGenerator.h:44
hrp::Vector3 get_stair_trajectory_way_point_offset() const
std::vector< cycloid_delay_hoffarbib_trajectory_generator > cdtg
std::map< leg_type, double > zmp_weight_map
void set_cycloid_delay_kick_point_offset(const hrp::Vector3 _offset)
double get_toe_check_thre() const
void set_default_double_support_static_ratio_before(const double _default_double_support_static_ratio_before)
std::vector< std::vector< leg_type > > swing_leg_types_list
double get_heel_zmp_offset_x() const
size_t get_overwritable_footstep_index_offset() const
std::vector< step_node > swing_leg_steps
step_node(const leg_type _l_r, const coordinates &_worldcoords, const double _step_height, const double _step_time, const double _toe_angle, const double _heel_angle)
Definition: GaitGenerator.h:38
void mid_coords(coordinates &mid_coords, const double p, const coordinates &c1, const coordinates &c2, const double eps)
Definition: RatsMatrix.cpp:58
void reset(const size_t _one_step_count, const size_t _next_one_step_count, const std::vector< step_node > &_swing_leg_dst_steps, const std::vector< step_node > &_swing_leg_src_steps, const std::vector< step_node > &_support_leg_steps, const double default_double_support_ratio_before, const double default_double_support_ratio_after)
size_t get_lcg_count() const
std::vector< std::vector< step_node > > get_remaining_footstep_nodes_list() const
int get_NUM_TH_PHASES() const
void set_default_top_ratio(const double _tmp)
double get_toe_zmp_offset_x() const
const std::vector< step_node > & get_swing_leg_src_steps() const
bool set_toe_heel_phase_ratio(const std::vector< double > &ratio)
void set_heel_pos_offset_x(const double _offx)
void get_toe_heel_phase_ratio(std::vector< double > &ratio) const
void set(const double _vx, const double _vy, const double _vth)
Definition: GaitGenerator.h:92


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Thu May 6 2021 02:41:50