GaitGenerator.h
Go to the documentation of this file.
00001 /* -*- mode:c++ -*- */
00002 #ifndef GAITGENERATOR_H
00003 #define GAITGENERATOR_H
00004 #include "PreviewController.h"
00005 #include "../ImpedanceController/RatsMatrix.h"
00006 #include "interpolator.h"
00007 #include <vector>
00008 #include <queue>
00009 #include <boost/assign.hpp>
00010 #include <boost/lambda/lambda.hpp>
00011 #include <boost/shared_ptr.hpp>
00012 
00013 #ifdef FOR_TESTGAITGENERATOR
00014 #warning "Compile for testGaitGenerator"
00015 #endif // FOR_TESTGAITGENERATOR
00016 
00017 namespace rats
00018 {
00019     void cycloid_midpoint (hrp::Vector3& ret,
00020                            const double ratio, const hrp::Vector3& start,
00021                            const hrp::Vector3& goal, const double height,
00022                            const double default_top_ratio = 0.5);
00023     void multi_mid_coords (coordinates& mid_coords, const std::vector<coordinates>& cs, const double eps = 0.001);
00024 
00025     enum orbit_type {SHUFFLING, CYCLOID, RECTANGLE, STAIR, CYCLOIDDELAY, CYCLOIDDELAYKICK, CROSS};
00026     enum leg_type {RLEG, LLEG, RARM, LARM, BOTH, ALL};
00027     enum stride_limitation_type {SQUARE, CIRCLE};
00028     std::string leg_type_to_leg_type_string (const leg_type l_r);
00029 
00030     struct step_node
00031     {
00032         leg_type l_r;
00033         coordinates worldcoords;
00034         double step_height, step_time, toe_angle, heel_angle;
00035         step_node () : l_r(RLEG), worldcoords(coordinates()),
00036                        step_height(), step_time(),
00037                        toe_angle(), heel_angle(){};
00038         step_node (const leg_type _l_r, const coordinates& _worldcoords,
00039                    const double _step_height, const double _step_time,
00040                    const double _toe_angle, const double _heel_angle)
00041             : l_r(_l_r), worldcoords(_worldcoords),
00042               step_height(_step_height), step_time(_step_time),
00043               toe_angle(_toe_angle), heel_angle(_heel_angle) {};
00044         step_node (const std::string& _l_r, const coordinates& _worldcoords,
00045                    const double _step_height, const double _step_time,
00046                    const double _toe_angle, const double _heel_angle)
00047             : l_r((_l_r == "rleg") ? RLEG :
00048                   (_l_r == "rarm") ? RARM :
00049                   (_l_r == "larm") ? LARM :
00050                   LLEG), worldcoords(_worldcoords),
00051               step_height(_step_height), step_time(_step_time),
00052               toe_angle(_toe_angle), heel_angle(_heel_angle) {};
00053         friend std::ostream &operator<<(std::ostream &os, const step_node &sn)
00054         {
00055             os << "footstep" << std::endl;
00056             os << "  name = [" << ((sn.l_r==LLEG)?std::string("lleg"):
00057                                    (sn.l_r==RARM)?std::string("rarm"):
00058                                    (sn.l_r==LARM)?std::string("larm"):
00059                                    std::string("rleg")) << "]" << std::endl;
00060             os << "  pos =";
00061             os << (sn.worldcoords.pos).format(Eigen::IOFormat(Eigen::StreamPrecision, 0, ", ", ", ", "", "", " [", "]")) << std::endl;
00062             os << "  rot =";
00063             os << (sn.worldcoords.rot).format(Eigen::IOFormat(Eigen::StreamPrecision, 0, ", ", "", " [", "]")) << std::endl;
00064             os << "  step_height = " << sn.step_height << "[m], step_time = " << sn.step_time << "[s], "
00065                << "toe_angle = " << sn.toe_angle << "[deg], heel_angle = " << sn.heel_angle << "[deg]";
00066             return os;
00067         };
00068     };
00069 
00070     /* footstep parameter */
00071     struct footstep_parameter
00072     {
00073         /* translate pos is translate position of a leg from default foot_midcoords
00074          *   vector -> (list rleg-pos[m] lleg-pos[m] )
00075          */
00076         std::vector<hrp::Vector3> leg_default_translate_pos;
00077         /* stride params indicate max stride */
00078         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]*/;
00079         footstep_parameter (const std::vector<hrp::Vector3>& _leg_pos,
00080                             const double _stride_fwd_x, const double _stride_outside_y, const double _stride_outside_theta,
00081                             const double _stride_bwd_x, const double _stride_inside_y, const double _stride_inside_theta)
00082             : leg_default_translate_pos(_leg_pos),
00083               stride_fwd_x(_stride_fwd_x), stride_outside_y(_stride_outside_y), stride_outside_theta(_stride_outside_theta),
00084               stride_bwd_x(_stride_bwd_x), stride_inside_y(_stride_inside_y), stride_inside_theta(_stride_inside_theta) {};
00085     };
00086 
00087     /* velocity parameter for velocity mode */
00088     struct velocity_mode_parameter
00089     {
00090         /* velocity is [mm/s], [mm/s], [deg/s] */
00091         double velocity_x, velocity_y, velocity_theta;
00092         void set (const double _vx, const double _vy, const double _vth)
00093         {
00094             velocity_x = _vx;
00095             velocity_y = _vy;
00096             velocity_theta = _vth;
00097         };
00098         velocity_mode_parameter ()
00099             :velocity_x(0), velocity_y(0), velocity_theta(0) {};
00100     };
00101 
00102     /* Phase name of toe heel contact.
00103      *   SOLE0 : Sole contact (start). Foot angle is 0. ZMP transition is ee -> toe.
00104      *   SOLE2TOE : Transition of foot angle (0 -> toe_angle). ZMP is on toe.
00105      *   TOE2SOLE : Transition of foot angle (toe_angle -> 0). ZMP is on toe.
00106      *   SOLE1 : Foot_angle is 0.
00107      *   SOLE2HEEL : Transition of foot angle (0 -> -1 * heel_angle). ZMP is on heel.
00108      *   HEEL2SOLE : Transition of foot angle (-1 * heel_angle -> 0). ZMP is on heel.
00109      *   SOLE2 : Sole contact (end). Foot angle is 0. ZMP transition is heel -> ee.
00110      */
00111     enum toe_heel_phase {SOLE0, SOLE2TOE, TOE2SOLE, SOLE1, SOLE2HEEL, HEEL2SOLE, SOLE2, NUM_TH_PHASES};
00112     static double no_using_toe_heel_ratio = 1.0; // Ratio not to use toe and heel contact
00113     static double using_toe_heel_ratio = 0.0; // Ratio to use toe and heel contact
00114 
00115     enum toe_heel_type {SOLE, TOE, HEEL};
00116     struct toe_heel_types
00117     {
00118         toe_heel_type src_type, dst_type;
00119         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)
00120         {
00121         };
00122     };
00123 
00124     /* Manager for toe heel phase. */
00125     class toe_heel_phase_counter
00126     {
00127         double toe_heel_phase_ratio[NUM_TH_PHASES];
00128         size_t toe_heel_phase_count[NUM_TH_PHASES], one_step_count;
00129         bool calc_toe_heel_phase_count_from_raio ()
00130         {
00131             double ratio_sum = 0.0;
00132             for (size_t i = 0; i < NUM_TH_PHASES; i++) {
00133                 ratio_sum += toe_heel_phase_ratio[i];
00134                 toe_heel_phase_count[i] = static_cast<size_t>(one_step_count * ratio_sum);
00135             }
00136             return true;
00137         };
00138     public:
00139         toe_heel_phase_counter () : one_step_count(0)
00140         {
00141             toe_heel_phase_ratio[SOLE0] = 0.05;
00142             toe_heel_phase_ratio[SOLE2TOE] = 0.25;
00143             toe_heel_phase_ratio[TOE2SOLE] = 0.2;
00144             toe_heel_phase_ratio[SOLE1] = 0.0;
00145             toe_heel_phase_ratio[SOLE2HEEL] = 0.2;
00146             toe_heel_phase_ratio[HEEL2SOLE] = 0.25;
00147             toe_heel_phase_ratio[SOLE2] = 0.05;
00148         };
00149         bool check_toe_heel_phase_ratio_validity (const std::vector<double>& ratio)
00150         {
00151             bool ret = true;
00152             // Check size
00153             if (ratio.size() != NUM_TH_PHASES) {
00154                 ret = false;
00155             }
00156             // Check sum == 1.0
00157             double sum_ratio = 0.0;
00158             for (int i = 0; i < NUM_TH_PHASES; i++) sum_ratio += ratio[i];
00159             if (std::fabs(sum_ratio-1.0) > 1e-3) {
00160                 ret = false;
00161             }
00162             if (!ret) {
00163                 std::cerr << "toe_heel_phase_ratio is not set, "
00164                           << ", required length = " << NUM_TH_PHASES << " != input length " << ratio.size()
00165                           << ", sum_ratio = " << sum_ratio << " is not 1.0."
00166                           << std::endl;
00167             } else {
00168                 std::cerr << "toe_heel_phase_ratio is successfully set." << std::endl;
00169             }
00170             return ret;
00171         };
00172         // setter
00173         void set_one_step_count (const size_t _count)
00174         {
00175             one_step_count = _count;
00176             calc_toe_heel_phase_count_from_raio();
00177         };
00178         bool set_toe_heel_phase_ratio (const std::vector<double>& ratio)
00179         {
00180             if (check_toe_heel_phase_ratio_validity(ratio)) {
00181                 for (size_t i = 0; i < NUM_TH_PHASES; i++) toe_heel_phase_ratio[i] = ratio[i];
00182                 return true;
00183             } else {
00184                 return false;
00185             }
00186         };
00187         // getter
00188         void get_toe_heel_phase_ratio (std::vector<double>& ratio) const
00189         {
00190             for (size_t i = 0; i < NUM_TH_PHASES; i++) ratio[i] = toe_heel_phase_ratio[i];
00191         };
00192         // functions for checking phase and calculating phase time and ratio
00193         bool is_phase_starting (const size_t current_count, const toe_heel_phase _phase) const
00194         {
00195             return (current_count == toe_heel_phase_count[_phase]);
00196         };
00197         bool is_between_phases (const size_t current_count, const toe_heel_phase phase0, const toe_heel_phase phase1) const
00198         {
00199             return (toe_heel_phase_count[phase0] <= current_count) && (current_count < toe_heel_phase_count[phase1]);
00200         };
00201         bool is_between_phases (const size_t current_count, const toe_heel_phase phase1) const
00202         {
00203             return (current_count < toe_heel_phase_count[phase1]);
00204         };
00205         bool is_no_SOLE1_phase () const { return toe_heel_phase_count[TOE2SOLE] == toe_heel_phase_count[SOLE1]; };
00206         // Calculate period [s] between start_phase and goal_phase
00207         double calc_phase_period (const toe_heel_phase start_phase, const toe_heel_phase goal_phase, const double _dt) const
00208         {
00209             return _dt * (toe_heel_phase_count[goal_phase]-toe_heel_phase_count[start_phase]);
00210         };
00211         // Calculate ratio between start_phase and goal_phase.
00212         //   If current_count is 0->goal_phase_count, start_phase : 0 -> goal_phase : 1
00213         double calc_phase_ratio (const size_t current_count, const toe_heel_phase start_phase, const toe_heel_phase goal_phase) const
00214         {
00215             return static_cast<double>(current_count-toe_heel_phase_count[start_phase]) / (toe_heel_phase_count[goal_phase]-toe_heel_phase_count[start_phase]);
00216         };
00217         // Calculate ratio to goal_phase.
00218         //   If current_count is 0->goal_phase_count, start : 0 -> goal_phase : 1
00219         double calc_phase_ratio (const size_t current_count, const toe_heel_phase goal_phase) const
00220         {
00221             return static_cast<double>(current_count) / (toe_heel_phase_count[goal_phase]);
00222         };
00223         // Calculate ratio for toe heel transition.
00224         //   If toe or heel are used, ratio is 0.0. Otherwise, ratio is (0.0, 1.0].
00225         //   We assume current_count is 0->goal_phase_count.
00226         double calc_phase_ratio_for_toe_heel_transition (const size_t current_count) const
00227         {
00228             if (is_between_phases(current_count, SOLE0)) {
00229                 // ratio : 1 -> 0
00230                 return 1-calc_phase_ratio(current_count, SOLE0);
00231             } else if (is_between_phases(current_count, HEEL2SOLE, SOLE2) || toe_heel_phase_count[SOLE2] == current_count) {
00232                 // ratio : 0 -> 1
00233                 return calc_phase_ratio(current_count, HEEL2SOLE, SOLE2);
00234             } else {
00235                 // If using toe or heel, 0
00236                 return using_toe_heel_ratio;
00237             }
00238         };
00239     };
00240 
00241     /* Checker for toe heel type. */
00242     class toe_heel_type_checker
00243     {
00244     private:
00245         double toe_check_thre, heel_check_thre; // [m]
00246     public:
00247         toe_heel_type_checker () : toe_check_thre(0), heel_check_thre(0)
00248         {
00249         };
00250         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)
00251         {
00252         };
00253         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
00254         {
00255             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);
00256             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);
00257             if (local_toe_pos(2) < -50*1e-3 && (local_toe_pos(0) + toe_check_thre < 0 || local_heel_pos(0) - heel_check_thre > 0) ) {
00258                 return TOE;
00259             } else if (local_toe_pos(0) + toe_check_thre < 0) {
00260                 return TOE;
00261             } else if (local_heel_pos(0) - heel_check_thre > 0) {
00262                 return HEEL;
00263             } else {
00264                 return SOLE;
00265             }
00266         };
00267         void print_param (const std::string print_str = "") const
00268         {
00269             std::cerr << "[" << print_str << "]   toe_check_thre = " << toe_check_thre << ", heel_check_thre = " << heel_check_thre << std::endl;
00270         };
00271         // Setter
00272         void set_toe_check_thre (const double _toe_check_thre) { toe_check_thre = _toe_check_thre; };
00273         void set_heel_check_thre (const double _heel_check_thre) { heel_check_thre = _heel_check_thre; };
00274         // Getter
00275         double get_toe_check_thre () const { return toe_check_thre; };
00276         double get_heel_check_thre () const { return heel_check_thre; };
00277     };
00278 
00279     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);
00280 
00281     /* refzmp_generator to generate current refzmp from footstep_node_list */
00282     class refzmp_generator
00283     {
00284 #ifdef HAVE_MAIN
00285     public:
00286 #endif
00287       std::vector<hrp::Vector3> refzmp_cur_list;
00288       std::map<leg_type, double> zmp_weight_map;
00289       std::vector< std::vector<hrp::Vector3> > foot_x_axises_list; // Swing foot x axis list according to refzmp_cur_list
00290       std::vector< std::vector<leg_type> > swing_leg_types_list; // Swing leg list according to refzmp_cur_list
00291       std::vector<size_t> step_count_list; // Swing leg list according to refzmp_cur_list
00292       std::vector<toe_heel_types> toe_heel_types_list;
00293       std::vector<hrp::Vector3> default_zmp_offsets; /* list of RLEG and LLEG */
00294       size_t refzmp_index, refzmp_count, one_step_count;
00295       double toe_zmp_offset_x, heel_zmp_offset_x; // [m]
00296       double dt;
00297       toe_heel_phase_counter thp;
00298       bool use_toe_heel_transition, use_toe_heel_auto_set;
00299       boost::shared_ptr<interpolator> zmp_weight_interpolator;
00300       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);
00301       const bool is_start_double_support_phase () const { return refzmp_index == 0; };
00302       const bool is_second_phase () const { return refzmp_index == 1; };
00303       const bool is_second_last_phase () const { return refzmp_index == refzmp_cur_list.size()-2; };
00304       const bool is_end_double_support_phase () const { return refzmp_index == refzmp_cur_list.size() - 1; };
00305 #ifndef HAVE_MAIN
00306     public:
00307 #endif
00308       refzmp_generator(const double _dt)
00309         : refzmp_cur_list(), foot_x_axises_list(), swing_leg_types_list(), step_count_list(), toe_heel_types_list(), default_zmp_offsets(),
00310           refzmp_index(0), refzmp_count(0), one_step_count(0),
00311           toe_zmp_offset_x(0), heel_zmp_offset_x(0), dt(_dt),
00312           thp(), use_toe_heel_transition(false), use_toe_heel_auto_set(false)
00313       {
00314           default_zmp_offsets.push_back(hrp::Vector3::Zero());
00315           default_zmp_offsets.push_back(hrp::Vector3::Zero());
00316           default_zmp_offsets.push_back(hrp::Vector3::Zero());
00317           default_zmp_offsets.push_back(hrp::Vector3::Zero());
00318           double zmp_weight_initial_value[4] = {1.0, 1.0, 0.1, 0.1};
00319           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> > ();
00320           zmp_weight_interpolator = boost::shared_ptr<interpolator>(new interpolator(4, dt));
00321           zmp_weight_interpolator->set(zmp_weight_initial_value); /* set initial value */
00322           zmp_weight_interpolator->setName("GaitGenerator zmp_weight_interpolator");
00323       };
00324       ~refzmp_generator()
00325       {
00326       };
00327       void remove_refzmp_cur_list_over_length (const size_t len)
00328       {
00329         while ( refzmp_cur_list.size() > len) refzmp_cur_list.pop_back();
00330         while ( foot_x_axises_list.size() > len) foot_x_axises_list.pop_back();
00331         while ( swing_leg_types_list.size() > len) swing_leg_types_list.pop_back();
00332         while ( step_count_list.size() > len) step_count_list.pop_back();
00333         while ( toe_heel_types_list.size() > len) toe_heel_types_list.pop_back();
00334       };
00335       void reset (const size_t _refzmp_count)
00336       {
00337         set_indices(0);
00338         one_step_count = _refzmp_count;
00339         set_refzmp_count(_refzmp_count);
00340         refzmp_cur_list.clear();
00341         foot_x_axises_list.clear();
00342         swing_leg_types_list.clear();
00343         step_count_list.clear();
00344         toe_heel_types_list.clear();
00345         thp.set_one_step_count(one_step_count);
00346       };
00347       void push_refzmp_from_footstep_nodes_for_dual (const std::vector<step_node>& fns,
00348                                                      const std::vector<step_node>& _support_leg_steps,
00349                                                      const std::vector<step_node>& _swing_leg_steps);
00350         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);
00351       void update_refzmp ();
00352       // setter
00353       void set_indices (const size_t idx) { refzmp_index = idx; };
00354       void set_refzmp_count(const size_t _refzmp_count) { refzmp_count = _refzmp_count; };
00355       void set_default_zmp_offsets(const std::vector<hrp::Vector3>& tmp) { default_zmp_offsets = tmp; };
00356       void set_toe_zmp_offset_x (const double _off) { toe_zmp_offset_x = _off; };
00357       void set_heel_zmp_offset_x (const double _off) { heel_zmp_offset_x = _off; };
00358       void set_use_toe_heel_transition (const bool _u) { use_toe_heel_transition = _u; };
00359       void set_use_toe_heel_auto_set (const bool _u) { use_toe_heel_auto_set = _u; };
00360       void set_zmp_weight_map (const std::map<leg_type, double> _map) {
00361           double zmp_weight_array[4] = {_map.find(RLEG)->second, _map.find(LLEG)->second, _map.find(RARM)->second, _map.find(LARM)->second};
00362           if (zmp_weight_interpolator->isEmpty()) {
00363               zmp_weight_interpolator->clear();
00364               double zmp_weight_initial_value[4] = {zmp_weight_map[RLEG], zmp_weight_map[LLEG], zmp_weight_map[RARM], zmp_weight_map[LARM]};
00365               zmp_weight_interpolator->set(zmp_weight_initial_value);
00366               zmp_weight_interpolator->setGoal(zmp_weight_array, 2.0, true);
00367           } else {
00368               std::cerr << "zmp_weight_map cannot be set because interpolating." << std::endl;
00369           }
00370       };
00371       bool set_toe_heel_phase_ratio (const std::vector<double>& ratio) { return thp.set_toe_heel_phase_ratio(ratio); };
00372       // getter
00373       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)
00374       {
00375         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);
00376         return refzmp_cur_list.size() > refzmp_index;
00377       };
00378       const hrp::Vector3& get_refzmp_cur () const { return refzmp_cur_list.front(); };
00379       const hrp::Vector3& get_default_zmp_offset (const leg_type lt) const { return default_zmp_offsets[lt]; };
00380       double get_toe_zmp_offset_x () const { return toe_zmp_offset_x; };
00381       double get_heel_zmp_offset_x () const { return heel_zmp_offset_x; };
00382       bool get_use_toe_heel_transition () const { return use_toe_heel_transition; };
00383       bool get_use_toe_heel_auto_set () const { return use_toe_heel_auto_set; };
00384       const std::map<leg_type, double> get_zmp_weight_map () const { return zmp_weight_map; };
00385       void proc_zmp_weight_map_interpolation () {
00386           if (!zmp_weight_interpolator->isEmpty()) {
00387               double zmp_weight_output[4];
00388               zmp_weight_interpolator->get(zmp_weight_output, true);
00389               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> > ();
00390           }
00391       };
00392 #ifdef FOR_TESTGAITGENERATOR
00393     std::vector<hrp::Vector3> get_default_zmp_offsets() const { return default_zmp_offsets; };
00394 #endif // FOR_TESTGAITGENERATOR
00395     };
00396 
00397     class delay_hoffarbib_trajectory_generator
00398     {
00399     private:
00400       hrp::Vector3 pos, vel, acc; // [m], [m/s], [m/s^2]
00401       double dt; // [s]
00402       // Parameters for antecedent path generation
00403       std::vector<hrp::Vector3> point_vec;
00404       std::vector<double> distance_vec;
00405       std::vector<double> sum_distance_vec;
00406       double total_path_length;
00407       // Implement hoffarbib to configure remain_time;
00408       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)
00409       {
00410         double jerk = (-9.0/ tmp_remain_time) * (_acc - tmp_goal_acc / 3.0) +
00411             (-36.0 / (tmp_remain_time * tmp_remain_time)) * (tmp_goal_vel * 2.0 / 3.0 + _vel) +
00412             (60.0 / (tmp_remain_time * tmp_remain_time * tmp_remain_time)) * (tmp_goal - _pos);
00413         _acc = _acc + dt * jerk;
00414         _vel = _vel + dt * _acc;
00415         _pos = _pos + dt * _vel;
00416       };
00417     protected:
00418       double time_offset; // [s]
00419       double final_distance_weight;
00420       double time_offset_xy2z; // [s]
00421       size_t one_step_count, current_count, double_support_count_before, double_support_count_after; // time/dt
00422       virtual double calc_antecedent_path (const hrp::Vector3& start, const hrp::Vector3& goal, const double height) = 0;
00423     public:
00424       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) {};
00425       ~delay_hoffarbib_trajectory_generator() { };
00426       void set_dt (const double _dt) { dt = _dt; };
00427       void set_swing_trajectory_delay_time_offset (const double _time_offset) { time_offset = _time_offset; };
00428       void set_swing_trajectory_final_distance_weight (const double _final_distance_weight) { final_distance_weight = _final_distance_weight; };
00429       void set_swing_trajectory_time_offset_xy2z (const double _tmp) { time_offset_xy2z = _tmp; };
00430       void reset (const size_t _one_step_len, const double default_double_support_ratio_before, const double default_double_support_ratio_after)
00431       {
00432         one_step_count = _one_step_len;
00433         current_count = 0;
00434         double_support_count_before = (default_double_support_ratio_before*one_step_count);
00435         double_support_count_after = (default_double_support_ratio_after*one_step_count);
00436       };
00437       void reset_all (const double _dt, const size_t _one_step_len,
00438                       const double default_double_support_ratio_before, const double default_double_support_ratio_after,
00439                       const double _time_offset, const double _final_distance_weight, const double _time_offset_xy2z)
00440       {
00441           set_dt(_dt);
00442           reset (_one_step_len, default_double_support_ratio_before, default_double_support_ratio_after);
00443           set_swing_trajectory_delay_time_offset(_time_offset);
00444           set_swing_trajectory_final_distance_weight(_final_distance_weight);
00445           set_swing_trajectory_time_offset_xy2z(_time_offset_xy2z);
00446       };
00447       void get_trajectory_point (hrp::Vector3& ret, const hrp::Vector3& start, const hrp::Vector3& goal, const double height)
00448       {
00449         if ( current_count <= double_support_count_before ) { // first double support phase
00450           pos = start;
00451           vel = hrp::Vector3::Zero();
00452           acc = hrp::Vector3::Zero();
00453         } else if ( current_count >= one_step_count - double_support_count_after ) { // last double support phase
00454           pos = goal;
00455           vel = hrp::Vector3::Zero();
00456           acc = hrp::Vector3::Zero();
00457         }
00458         if ( double_support_count_before <= current_count && current_count < one_step_count - double_support_count_after ) { // swing phase
00459           size_t swing_remain_count = one_step_count - current_count - double_support_count_after;
00460           size_t swing_one_step_count = one_step_count - double_support_count_before - double_support_count_after;
00461           double final_path_distance_ratio = calc_antecedent_path(start, goal, height);
00462           size_t tmp_time_offset_count = time_offset/dt;
00463           //size_t final_path_count = 0; // Revert to previous version
00464           size_t final_path_count = final_path_distance_ratio * swing_one_step_count;
00465           if (final_path_count>static_cast<size_t>(time_offset_xy2z/dt)) final_path_count = static_cast<size_t>(time_offset_xy2z/dt);
00466           // XY interpolation
00467           if (swing_remain_count > final_path_count+tmp_time_offset_count) { // antecedent path is still interpolating
00468             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)));
00469             for (size_t i = 0; i < 2; i++) hoffarbib_interpolation (pos(i), vel(i), acc(i), time_offset, tmpgoal(i));
00470           } else if (swing_remain_count > final_path_count) { // antecedent path already reached to goal
00471             double tmprt = (swing_remain_count-final_path_count)*dt;
00472             for (size_t i = 0; i < 2; i++) hoffarbib_interpolation (pos(i), vel(i), acc(i), tmprt, goal(i));
00473           } else {
00474             for (size_t i = 0; i < 2; i++) pos(i) = goal(i);
00475           }
00476           // Z interpolation
00477           if (swing_remain_count > tmp_time_offset_count) { // antecedent path is still interpolating
00478             hrp::Vector3 tmpgoal = interpolate_antecedent_path((swing_one_step_count - swing_remain_count) / static_cast<double>(swing_one_step_count - tmp_time_offset_count));
00479             hoffarbib_interpolation (pos(2), vel(2), acc(2), time_offset, tmpgoal(2));
00480           } else if (swing_remain_count > 0) { // antecedent path already reached to goal
00481             hoffarbib_interpolation (pos(2), vel(2), acc(2), swing_remain_count*dt, goal(2));
00482           } else {
00483             pos(2) = goal(2);
00484           }
00485         }
00486         ret = pos;
00487         current_count++;
00488       };
00489       double get_swing_trajectory_delay_time_offset () const { return time_offset; };
00490       double get_swing_trajectory_final_distance_weight () const { return final_distance_weight; };
00491       double get_swing_trajectory_time_offset_xy2z () const { return time_offset_xy2z; };
00492       // interpolate path vector
00493       //   tmp_ratio : ratio value [0, 1]
00494       //   org_point_vec : vector of via points
00495       //   e.g., move tmp_ratio from 0 to 1 => move point from org_point_vec.front() to org_point_vec.back()
00496       double calc_antecedent_path_base (const std::vector<hrp::Vector3> org_point_vec)
00497       {
00498         total_path_length = 0;
00499         point_vec.clear();
00500         distance_vec.clear();
00501         point_vec.push_back(org_point_vec.front());
00502         // remove distance-zero points
00503         for (size_t i = 0; i < org_point_vec.size()-1; i++) {
00504           double tmp_distance = (org_point_vec[i+1]-org_point_vec[i]).norm();
00505           if (i==org_point_vec.size()-2) tmp_distance*=final_distance_weight;
00506           if ( tmp_distance > 1e-5 ) {
00507             point_vec.push_back(org_point_vec[i+1]);
00508             distance_vec.push_back(tmp_distance);
00509             total_path_length += tmp_distance;
00510           }
00511         }
00512         if ( total_path_length < 1e-5 ) { // if total path is zero, return goal point.
00513           return 0;
00514         }
00515         // point_vec        : [p0, p1, ..., pN-1, pN]
00516         // distance_vec     : [  d0, ...,     dN-1  ]
00517         // sum_distance_vec : [l0, l1, ..., lN-1, lN] <= lj = \Sum_{i=0}^{j-1} di
00518         sum_distance_vec.clear();
00519         sum_distance_vec.push_back(0);
00520         double tmp_dist = 0;
00521         for (size_t i = 0; i < distance_vec.size(); i++) {
00522           sum_distance_vec.push_back(tmp_dist + distance_vec[i]);
00523           tmp_dist += distance_vec[i];
00524         }
00525         return distance_vec.back()/total_path_length;
00526       };
00527       hrp::Vector3 interpolate_antecedent_path (const double tmp_ratio) const
00528       {
00529         if ( total_path_length < 1e-5 ) { // if total path is zero, return goal point.
00530           return point_vec.back();
00531         }
00532         // select current segment in which 'tmp_ratio' is included
00533         double current_length = tmp_ratio * total_path_length;
00534         for (size_t i = 0; i < sum_distance_vec.size(); i++) {
00535           if ( (sum_distance_vec[i] <= current_length) && (current_length <= sum_distance_vec[i+1]) ) {
00536             double tmpr = ((current_length - sum_distance_vec[i]) / distance_vec[i]);
00537             return ((1-tmpr) * point_vec[i] + tmpr * point_vec[1+i]);
00538           }
00539         }
00540         // if illegal tmp-ratio
00541         if (current_length < 0) return point_vec.front();
00542         else return point_vec.back();
00543       };
00544     };
00545 
00546     class rectangle_delay_hoffarbib_trajectory_generator : public delay_hoffarbib_trajectory_generator
00547     {
00548       double calc_antecedent_path (const hrp::Vector3& start, const hrp::Vector3& goal, const double height)
00549       {
00550         std::vector<hrp::Vector3> rectangle_path;
00551         double max_height = std::max(start(2), goal(2))+height;
00552         rectangle_path.push_back(start);
00553         rectangle_path.push_back(hrp::Vector3(start(0), start(1), max_height));
00554         rectangle_path.push_back(hrp::Vector3(goal(0), goal(1), max_height));
00555         rectangle_path.push_back(goal);
00556         return calc_antecedent_path_base(rectangle_path);
00557       };
00558     };
00559 
00560     class stair_delay_hoffarbib_trajectory_generator : public delay_hoffarbib_trajectory_generator
00561     {
00562       hrp::Vector3 way_point_offset;
00563       double calc_antecedent_path (const hrp::Vector3& start, const hrp::Vector3& goal, const double height)
00564       {
00565         std::vector<hrp::Vector3> path;
00566         double max_height = std::max(start(2), goal(2))+height;
00567         hrp::Vector3 diff_vec = goal - start;
00568         diff_vec(2) = 0.0; // projection on horizontal plane
00569         path.push_back(start);
00570         // currently way_point_offset(1) is not used.
00571         //if ( diff_vec.norm() > 1e-4 && (goal(2) - start(2)) > way_point_offset(2) ) {
00572         if ( diff_vec.norm() > 1e-4 && (goal(2) - start(2)) > 0.02) {
00573           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))));
00574         }
00575         path.push_back(hrp::Vector3(start(0), start(1), max_height));
00576         path.push_back(hrp::Vector3(goal(0), goal(1), max_height));
00577         //if ( diff_vec.norm() > 1e-4 && (start(2) - goal(2)) > way_point_offset(2) ) {
00578         if ( diff_vec.norm() > 1e-4 && (start(2) - goal(2)) > 0.02) {
00579           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))));
00580         }
00581         // if (height > 20 * 1e-3) {
00582         //   path.push_back(hrp::Vector3(goal(0), goal(1), 20*1e-3+goal(2)));
00583         // }
00584         path.push_back(goal);
00585         return calc_antecedent_path_base(path);
00586       };
00587     public:
00588       stair_delay_hoffarbib_trajectory_generator () : delay_hoffarbib_trajectory_generator(), way_point_offset(hrp::Vector3(0.03, 0.0, 0.0)) {};
00589       ~stair_delay_hoffarbib_trajectory_generator () {};
00590       void set_stair_trajectory_way_point_offset (const hrp::Vector3 _offset) { way_point_offset = _offset; };
00591       hrp::Vector3 get_stair_trajectory_way_point_offset() const { return way_point_offset; };
00592     };
00593 
00594     class cycloid_delay_hoffarbib_trajectory_generator : public delay_hoffarbib_trajectory_generator
00595     {
00596       double calc_antecedent_path (const hrp::Vector3& start, const hrp::Vector3& goal, const double height)
00597       {
00598         std::vector<hrp::Vector3> cycloid_path;
00599         hrp::Vector3 tmpv, via_goal(goal);
00600         double ratio = 0.4;
00601         via_goal(2) += ratio*height;
00602         double tmpheight = ((start(2)+goal(2))/2.0+height-(start(2)+via_goal(2))/2.0);
00603         cycloid_path.push_back(start);
00604         cycloid_midpoint(tmpv, 0.2, start, via_goal, tmpheight);
00605         cycloid_path.push_back(tmpv);
00606         cycloid_midpoint(tmpv, 0.4, start, via_goal, tmpheight);
00607         cycloid_path.push_back(tmpv);
00608         cycloid_midpoint(tmpv, 0.6, start, via_goal, tmpheight);
00609         cycloid_path.push_back(tmpv);
00610         cycloid_midpoint(tmpv, 0.8, start, via_goal, tmpheight);
00611         cycloid_path.push_back(tmpv);
00612         cycloid_path.push_back(via_goal);
00613         cycloid_path.push_back(goal);
00614         return calc_antecedent_path_base(cycloid_path);
00615       };
00616     };
00617 
00618     class cycloid_delay_kick_hoffarbib_trajectory_generator : public delay_hoffarbib_trajectory_generator
00619     {
00620     private:
00621       hrp::Matrix33 start_rot;
00622       hrp::Vector3 kick_point_offset;
00623     public:
00624         cycloid_delay_kick_hoffarbib_trajectory_generator() : delay_hoffarbib_trajectory_generator(), kick_point_offset(hrp::Vector3(-0.1, 0.0, 0.0)) {};
00625       void set_cycloid_delay_kick_point_offset (const hrp::Vector3 _offset) { kick_point_offset = _offset; };
00626       void set_start_rot (const hrp::Matrix33 _offset) { start_rot = _offset; };
00627       hrp::Vector3 get_cycloid_delay_kick_point_offset () const { return kick_point_offset; };
00628       double calc_antecedent_path (const hrp::Vector3& start, const hrp::Vector3& goal, const double height)
00629       {
00630         std::vector<hrp::Vector3> cycloid_path;
00631         hrp::Vector3 tmpv, via_goal(goal);
00632         double ratio = 0.4;
00633         via_goal(2) += ratio*height;
00634         double tmpheight = ((start(2)+goal(2))/2.0+height-(start(2)+via_goal(2))/2.0);
00635         // kick_point_offset = start_rot * kick_point_offset;
00636         cycloid_path.push_back(start);
00637         if(height > 1e-4){
00638             cycloid_path.push_back(start + start_rot * kick_point_offset);
00639             cycloid_midpoint(tmpv, 0.2, start + start_rot * kick_point_offset, via_goal, tmpheight);
00640             cycloid_path.push_back(tmpv);
00641             cycloid_midpoint(tmpv, 0.4, start + start_rot * kick_point_offset, via_goal, tmpheight);
00642             cycloid_path.push_back(tmpv);
00643             cycloid_midpoint(tmpv, 0.6, start + start_rot * kick_point_offset, via_goal, tmpheight);
00644             cycloid_path.push_back(tmpv);
00645             cycloid_midpoint(tmpv, 0.8, start + start_rot * kick_point_offset, via_goal, tmpheight);
00646             cycloid_path.push_back(tmpv);
00647         }
00648         cycloid_path.push_back(via_goal);
00649         cycloid_path.push_back(goal);
00650         return calc_antecedent_path_base(cycloid_path);
00651       };
00652     };
00653     
00654     class cross_delay_hoffarbib_trajectory_generator : public delay_hoffarbib_trajectory_generator
00655     {
00656     private:
00657       leg_type swing_leg;
00658     public:
00659       cross_delay_hoffarbib_trajectory_generator () : delay_hoffarbib_trajectory_generator(), way_point_offset(hrp::Vector3(0.04, 0.15, 0.0)) {};
00660       ~cross_delay_hoffarbib_trajectory_generator () {};
00661       void set_swing_leg (leg_type _lr) { swing_leg = _lr; };
00662       hrp::Vector3 way_point_offset;
00663       double calc_antecedent_path (const hrp::Vector3& start, const hrp::Vector3& goal, const double height)
00664       {
00665         std::vector<hrp::Vector3> path;
00666         double max_height = std::max(start(2), goal(2))+height;
00667         hrp::Vector3 diff_vec = goal - start;
00668         diff_vec(2) = 0.0; // projection on horizontal plane
00669         path.push_back(start);
00670         if ( swing_leg == LLEG ) { // swing_leg is left
00671             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))));
00672             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))));
00673         } else { // swing_leg is right
00674             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))));
00675             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))));
00676         }
00677         if (height > 30 * 1e-3) {
00678           path.push_back(hrp::Vector3(goal(0), goal(1), 30*1e-3+goal(2)));
00679         }
00680         path.push_back(goal);
00681         return calc_antecedent_path_base(path);
00682       };
00683     };
00684 
00685     /* leg_coords_generator to generate current swing_leg_coords and support_leg_coords from footstep_node_list */
00686     class leg_coords_generator
00687     {
00688 #ifdef HAVE_MAIN
00689     public:
00690 #endif
00691       std::vector< std::vector<step_node> > swing_leg_dst_steps_list, support_leg_steps_list;
00692       // Support leg coordinates.
00693       std::vector<step_node> support_leg_steps;
00694       // Swing leg coordinates is interpolated from swing_leg_src_coords to swing_leg_dst_coords during swing phase.
00695       std::vector<step_node> swing_leg_steps, swing_leg_src_steps, swing_leg_dst_steps;
00696       double default_step_height, default_top_ratio, current_step_height, swing_ratio, dt, current_toe_angle, current_heel_angle;
00697       double time_offset, final_distance_weight, time_offset_xy2z;
00698       std::vector<double> current_swing_time;
00699       // Index for current footstep. footstep_index should be [0,footstep_node_list.size()]. Current footstep is footstep_node_list[footstep_index].
00700       size_t footstep_index;
00701       // 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.
00702       size_t lcg_count, one_step_count, next_one_step_count;
00703       // Current support leg
00704       std::vector<leg_type> support_leg_types, swing_leg_types;
00705       orbit_type default_orbit_type;
00706       bool is_swing_phase;
00707       // Foot trajectory generators
00708       std::vector<rectangle_delay_hoffarbib_trajectory_generator> rdtg;
00709       stair_delay_hoffarbib_trajectory_generator sdtg;
00710       std::vector<cycloid_delay_hoffarbib_trajectory_generator> cdtg;
00711       cycloid_delay_kick_hoffarbib_trajectory_generator cdktg;
00712       cross_delay_hoffarbib_trajectory_generator crdtg;
00713       toe_heel_phase_counter thp;
00714       interpolator* foot_midcoords_interpolator;
00715       coordinates swing_support_midcoords;
00716       // Map for interpolator of each swing foot rot interpolation. In constructor, prepared for all limbs. In control loop, swing foot element is used.
00717       std::map<leg_type, interpolator*> swing_foot_rot_interpolator;
00718       // Parameters for toe-heel contact
00719       interpolator* toe_heel_interpolator;
00720       double toe_pos_offset_x, heel_pos_offset_x, toe_angle, heel_angle, foot_dif_rot_angle, toe_heel_dif_angle;
00721       bool use_toe_joint, use_toe_heel_auto_set;
00722       toe_heel_type current_src_toe_heel_type, current_dst_toe_heel_type;
00723       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);
00724       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);
00725       double calc_interpolated_toe_heel_angle (const toe_heel_phase start_phase, const toe_heel_phase goal_phase, const double start, const double goal);
00726       void modif_foot_coords_for_toe_heel_phase (coordinates& org_coords, const double _current_toe_angle, const double _current_heel_angle);
00727       void cycloid_midcoords (coordinates& ret, const coordinates& start,
00728                               const coordinates& goal, const double height) const;
00729       void rectangle_midcoords (coordinates& ret, const coordinates& start,
00730                                 const coordinates& goal, const double height, const size_t swing_trajectory_generator_idx);
00731       void stair_midcoords (coordinates& ret, const coordinates& start,
00732                             const coordinates& goal, const double height);
00733       void cycloid_delay_midcoords (coordinates& ret, const coordinates& start,
00734                                     const coordinates& goal, const double height, const size_t swing_trajectory_generator_idx);
00735       void cycloid_delay_kick_midcoords (coordinates& ret, const coordinates& start,
00736                                     const coordinates& goal, const double height);
00737       void cross_delay_midcoords (coordinates& ret, const coordinates& start,
00738                                   const coordinates& goal, const double height, leg_type lr);
00739       void calc_ratio_from_double_support_ratio (const double default_double_support_ratio_before, const double default_double_support_ratio_after);
00740       void calc_swing_support_mid_coords ();
00741 #ifndef HAVE_MAIN
00742     public:
00743 #endif
00744       leg_coords_generator(const double _dt)
00745         : support_leg_steps(), swing_leg_steps(), swing_leg_src_steps(), swing_leg_dst_steps(),
00746           default_step_height(0.05), default_top_ratio(0.5), current_step_height(0.0), swing_ratio(0), dt(_dt),
00747           current_toe_angle(0), current_heel_angle(0),
00748           time_offset(0.35), final_distance_weight(1.0), time_offset_xy2z(0),
00749           footstep_index(0), lcg_count(0), default_orbit_type(CYCLOID),
00750           rdtg(), cdtg(),
00751           thp(),
00752           foot_midcoords_interpolator(NULL), swing_foot_rot_interpolator(), toe_heel_interpolator(NULL),
00753           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),
00754           current_src_toe_heel_type(SOLE), current_dst_toe_heel_type(SOLE)
00755       {
00756         support_leg_types.assign (1, RLEG);
00757         swing_leg_types.assign (1, LLEG);
00758         current_swing_time.assign (4, 0.0);
00759         sdtg.set_dt(dt);
00760         cdktg.set_dt(dt);
00761         crdtg.set_dt(dt);
00762         if (foot_midcoords_interpolator == NULL) foot_midcoords_interpolator = new interpolator(6, dt); // POS + RPY
00763         std::vector<leg_type> tmp_leg_types = boost::assign::list_of<leg_type>(RLEG)(LLEG)(RARM)(LARM);
00764          for (size_t i = 0; i < tmp_leg_types.size(); i++) {
00765              if ( swing_foot_rot_interpolator.find(tmp_leg_types[i]) == swing_foot_rot_interpolator.end() ) {
00766                  swing_foot_rot_interpolator.insert(std::pair<leg_type, interpolator*>(tmp_leg_types[i], new interpolator(3, dt))); // RPY
00767                  swing_foot_rot_interpolator[tmp_leg_types[i]]->setName("GaitGenerator swing_foot_rot_interpolator " + leg_type_to_leg_type_string(tmp_leg_types[i]));
00768                  std::cerr << "GaitGenerator swing_foot_rot_interpolator " + leg_type_to_leg_type_string(tmp_leg_types[i]) << std::endl;;
00769              }
00770          }
00771         //if (foot_ratio_interpolator == NULL) foot_ratio_interpolator = new interpolator(1, dt, interpolator::LINEAR);
00772         if (toe_heel_interpolator == NULL) toe_heel_interpolator = new interpolator(1, dt);
00773         foot_midcoords_interpolator->setName("GaitGenerator foot_midcoords_interpolator");
00774         toe_heel_interpolator->setName("GaitGenerator toe_heel_interpolator");
00775       };
00776       ~leg_coords_generator()
00777       {
00778         if (foot_midcoords_interpolator != NULL) {
00779             delete foot_midcoords_interpolator;
00780             foot_midcoords_interpolator = NULL;
00781         }
00782         for (std::map<leg_type, interpolator*>::iterator it = swing_foot_rot_interpolator.begin(); it != swing_foot_rot_interpolator.end(); it++) {
00783             if (it->second != NULL) {
00784                 delete it->second;
00785                 it->second = NULL;
00786             }
00787         }
00788         if (toe_heel_interpolator != NULL) {
00789             delete toe_heel_interpolator;
00790             toe_heel_interpolator = NULL;
00791         }
00792       };
00793       void set_default_step_height (const double _tmp) { default_step_height = _tmp; };
00794       void set_default_top_ratio (const double _tmp) { default_top_ratio = _tmp; };
00795       void set_default_orbit_type (const orbit_type _tmp) { default_orbit_type = _tmp; };
00796       void set_swing_trajectory_delay_time_offset (const double _time_offset)
00797       {
00798         sdtg.set_swing_trajectory_delay_time_offset(_time_offset);
00799         cdktg.set_swing_trajectory_delay_time_offset(_time_offset);
00800         crdtg.set_swing_trajectory_delay_time_offset(_time_offset);
00801         time_offset = _time_offset;
00802       };
00803       void set_swing_trajectory_final_distance_weight (const double _final_distance_weight)
00804       {
00805         sdtg.set_swing_trajectory_final_distance_weight(_final_distance_weight);
00806         cdktg.set_swing_trajectory_final_distance_weight(_final_distance_weight);
00807         crdtg.set_swing_trajectory_final_distance_weight(_final_distance_weight);
00808         final_distance_weight = _final_distance_weight;
00809       };
00810       void set_swing_trajectory_time_offset_xy2z (const double _tmp)
00811       {
00812         sdtg.set_swing_trajectory_time_offset_xy2z(_tmp);
00813         cdktg.set_swing_trajectory_time_offset_xy2z(_tmp);
00814         crdtg.set_swing_trajectory_time_offset_xy2z(_tmp);
00815         time_offset_xy2z = _tmp;
00816       };
00817       void set_stair_trajectory_way_point_offset (const hrp::Vector3 _offset) { sdtg.set_stair_trajectory_way_point_offset(_offset); };
00818       void set_cycloid_delay_kick_point_offset (const hrp::Vector3 _offset) { cdktg.set_cycloid_delay_kick_point_offset(_offset); };
00819       void set_toe_pos_offset_x (const double _offx) { toe_pos_offset_x = _offx; };
00820       void set_heel_pos_offset_x (const double _offx) { heel_pos_offset_x = _offx; };
00821       void set_toe_angle (const double _angle) { toe_angle = _angle; };
00822       void set_heel_angle (const double _angle) { heel_angle = _angle; };
00823       void set_use_toe_joint (const bool ut) { use_toe_joint = ut; };
00824       void set_use_toe_heel_auto_set (const bool ut) { use_toe_heel_auto_set = ut; };
00825       void set_swing_support_steps_list (const std::vector< std::vector<step_node> >& fnsl)
00826       {
00827           std::vector<step_node> prev_support_leg_steps = support_leg_steps_list.front();
00828           support_leg_steps_list.clear();
00829           swing_leg_dst_steps_list.clear();
00830           support_leg_steps_list.push_back(prev_support_leg_steps);
00831           swing_leg_dst_steps_list = fnsl;
00832           for (size_t i = 0; i < fnsl.size(); i++) {
00833               if (i > 0) {
00834                   if (is_same_footstep_nodes(fnsl.at(i), fnsl.at(i-1))) {
00835                       support_leg_steps_list.push_back(support_leg_steps_list.back());
00836                   } else {
00837                       /* current support leg steps = prev swing leg dst steps + (prev support leg steps without current swing leg names) */
00838                       std::vector<step_node> tmp_support_leg_steps = swing_leg_dst_steps_list.at(i-1);
00839                       std::copy(support_leg_steps_list.back().begin(),
00840                                 support_leg_steps_list.back().end(),
00841                                 std::back_inserter(tmp_support_leg_steps));
00842                       for (size_t j = 0; j < swing_leg_dst_steps_list.at(i).size(); j++) {
00843                           std::vector<step_node>::iterator it = std::remove_if(tmp_support_leg_steps.begin(),
00844                                                                                tmp_support_leg_steps.end(),
00845                                                                                (&boost::lambda::_1->* &step_node::l_r == swing_leg_dst_steps_list.at(i).at(j).l_r));
00846                           tmp_support_leg_steps.erase(it, tmp_support_leg_steps.end());
00847                       }
00848                       support_leg_steps_list.push_back(tmp_support_leg_steps);
00849               }
00850             }
00851           }
00852       };
00853       bool set_toe_heel_phase_ratio (const std::vector<double>& ratio) { return thp.set_toe_heel_phase_ratio(ratio); };
00854       void reset(const size_t _one_step_count, const size_t _next_one_step_count,
00855                  const std::vector<step_node>& _swing_leg_dst_steps,
00856                  const std::vector<step_node>& _swing_leg_src_steps,
00857                  const std::vector<step_node>& _support_leg_steps,
00858                  const double default_double_support_ratio_before,
00859                  const double default_double_support_ratio_after)
00860       {
00861         support_leg_steps_list.clear();
00862         swing_leg_dst_steps_list.clear();
00863         /* swing_leg_steps.clear(); */
00864         swing_leg_dst_steps = _swing_leg_dst_steps;
00865         swing_leg_src_steps = _swing_leg_src_steps;
00866         support_leg_steps = _support_leg_steps;
00867         support_leg_steps_list.push_back(support_leg_steps);
00868         one_step_count = lcg_count = _one_step_count;
00869         next_one_step_count = _next_one_step_count;
00870         thp.set_one_step_count(one_step_count);
00871         footstep_index = 0;
00872         current_step_height = 0.0;
00873         switch (default_orbit_type) {
00874         case RECTANGLE:
00875             rdtg.clear();
00876             for (size_t i = 0; i < swing_leg_dst_steps.size(); i++) {
00877                 rdtg.push_back(rectangle_delay_hoffarbib_trajectory_generator());
00878                 rdtg.back().reset_all(dt, one_step_count,
00879                                       default_double_support_ratio_before, default_double_support_ratio_after,
00880                                       time_offset, final_distance_weight, time_offset_xy2z);
00881             }
00882             break;
00883         case STAIR:
00884             sdtg.reset(one_step_count, default_double_support_ratio_before, default_double_support_ratio_after);
00885             break;
00886         case CYCLOIDDELAY:
00887             cdtg.clear();
00888             for (size_t i = 0; i < swing_leg_dst_steps.size(); i++) {
00889                 cdtg.push_back(cycloid_delay_hoffarbib_trajectory_generator());
00890                 cdtg.back().reset_all(dt, one_step_count,
00891                                       default_double_support_ratio_before, default_double_support_ratio_after,
00892                                       time_offset, final_distance_weight, time_offset_xy2z);
00893             }
00894             break;
00895         case CYCLOIDDELAYKICK:
00896             cdktg.reset(one_step_count, default_double_support_ratio_before, default_double_support_ratio_after);
00897             break;
00898         case CROSS:
00899             crdtg.reset(one_step_count, default_double_support_ratio_before, default_double_support_ratio_after);
00900             break;
00901         default:
00902             break;
00903         }
00904         current_src_toe_heel_type = current_dst_toe_heel_type = SOLE;
00905       };
00906       void clear_interpolators ( ) {
00907         double tmpsw[3];
00908         for (std::map<leg_type, interpolator*>::iterator it = swing_foot_rot_interpolator.begin(); it != swing_foot_rot_interpolator.end(); it++) {
00909             while (!it->second->isEmpty()) it->second->get(tmpsw, true);
00910         }
00911         double tmpfm[foot_midcoords_interpolator->dimension()];
00912         while (!foot_midcoords_interpolator->isEmpty()) {
00913             foot_midcoords_interpolator->get(tmpfm, true);
00914         }
00915         double tmp;
00916         while (!toe_heel_interpolator->isEmpty()) {
00917             toe_heel_interpolator->get(&tmp, true);
00918         }
00919       };
00920       bool is_same_footstep_nodes(const std::vector<step_node>& fns_1, const std::vector<step_node>& fns_2) const;
00921       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);
00922       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)
00923       {
00924           if (_footstep_index > 0) {
00925               if (is_same_footstep_nodes(fnsl[_footstep_index], fnsl[_footstep_index-1])) {
00926                   ret_swing_leg_src_steps = swing_leg_dst_steps_list[_footstep_index-1];
00927               } else {
00928                   /* current swing leg src coords = (previout support leg coords + previous swing leg dst coords) - current support leg coords */
00929                   std::vector<step_node> tmp_swing_leg_src_steps = support_leg_steps_list[_footstep_index-1];
00930                   std::copy(swing_leg_dst_steps_list[_footstep_index-1].begin(),
00931                             swing_leg_dst_steps_list[_footstep_index-1].end(),
00932                             std::back_inserter(tmp_swing_leg_src_steps));
00933                   std::vector<step_node> tmp_support_leg_steps = support_leg_steps_list[_footstep_index];
00934                   for (size_t i = 0; i < tmp_support_leg_steps.size(); i++) {
00935                       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));
00936                       tmp_swing_leg_src_steps.erase(it, tmp_swing_leg_src_steps.end());
00937                   }
00938                   ret_swing_leg_src_steps = tmp_swing_leg_src_steps;
00939               }
00940           }
00941       };
00942       void calc_swing_support_params_from_footstep_nodes_list (const std::vector< std::vector<step_node> >& fnsl)
00943       {
00944           // Get current swing coords, support coords, and support leg parameters
00945           size_t current_footstep_index = (footstep_index < fnsl.size() - 1 ? footstep_index : fnsl.size()-1);
00946           swing_leg_dst_steps = fnsl[current_footstep_index];
00947           if (footstep_index != 0) { // If not initial step, support_leg_coords is previous swing_leg_dst_coords // why we need this?
00948               support_leg_steps = support_leg_steps_list[current_footstep_index];
00949           }
00950           support_leg_types.clear();
00951           for (std::vector<step_node>::iterator it = support_leg_steps.begin(); it != support_leg_steps.end(); it++) {
00952               support_leg_types.push_back(it->l_r);
00953           }
00954           swing_leg_types.clear();
00955           for (std::vector<step_node>::iterator it = swing_leg_dst_steps.begin(); it != swing_leg_dst_steps.end(); it++) {
00956               swing_leg_types.push_back(it->l_r);
00957           }
00958           calc_swing_leg_src_steps(swing_leg_src_steps, fnsl, current_footstep_index);
00959       };
00960       size_t get_footstep_index() const { return footstep_index; };
00961       size_t get_lcg_count() const { return lcg_count; };
00962       double get_current_swing_time(const size_t idx) const { return current_swing_time.at(idx); };
00963       const std::vector<step_node>& get_swing_leg_steps() const { return swing_leg_steps; };
00964       const std::vector<step_node>& get_support_leg_steps() const { return support_leg_steps; };
00965       const std::vector<step_node>& get_swing_leg_src_steps() const { return swing_leg_src_steps; };
00966       const std::vector<step_node>& get_swing_leg_dst_steps() const { return swing_leg_dst_steps; };
00967       const std::vector<step_node>& get_swing_leg_dst_steps_idx(const size_t idx) const { return swing_leg_dst_steps_list[idx]; };
00968       const std::vector<step_node>& get_support_leg_steps_idx(const size_t idx) const { return support_leg_steps_list[idx]; };
00969       const std::vector<leg_type>& get_support_leg_types() const { return support_leg_types;};
00970       const std::vector<leg_type>& get_swing_leg_types() const { return swing_leg_types;};
00971       double get_default_step_height () const { return default_step_height;};
00972       void get_swing_support_mid_coords(coordinates& ret) const
00973       {
00974         ret = swing_support_midcoords;
00975       };
00976       std::vector<leg_type> get_current_support_states () const
00977       {
00978           if ( is_swing_phase ) {
00979               return get_support_leg_types();
00980           } else {
00981               std::vector<leg_type> tmp_sup_types = get_support_leg_types();
00982               std::vector<leg_type> tmp_swg_types = get_swing_leg_types();
00983               std::copy(tmp_swg_types.begin(), tmp_swg_types.end(), std::back_inserter(tmp_sup_types));
00984               return tmp_sup_types;
00985           }
00986       };
00987       orbit_type get_default_orbit_type () const { return default_orbit_type; };
00988       double get_swing_trajectory_delay_time_offset () const { return time_offset; };
00989       double get_swing_trajectory_final_distance_weight () const { return final_distance_weight; };
00990       double get_swing_trajectory_time_offset_xy2z () const { return time_offset_xy2z; };
00991       hrp::Vector3 get_stair_trajectory_way_point_offset () const { return sdtg.get_stair_trajectory_way_point_offset(); };
00992       hrp::Vector3 get_cycloid_delay_kick_point_offset () const { return cdktg.get_cycloid_delay_kick_point_offset() ; };
00993       double get_toe_pos_offset_x () const { return toe_pos_offset_x; };
00994       double get_heel_pos_offset_x () const { return heel_pos_offset_x; };
00995       double get_toe_angle () const { return toe_angle; };
00996       double get_heel_angle () const { return heel_angle; };
00997       double get_foot_dif_rot_angle () const { return foot_dif_rot_angle; };
00998       bool get_use_toe_joint () const { return use_toe_joint; };
00999       bool get_use_toe_heel_auto_set () const { return use_toe_heel_auto_set; };
01000       void get_toe_heel_phase_ratio (std::vector<double>& ratio) const { thp.get_toe_heel_phase_ratio(ratio); };
01001       double get_current_toe_heel_ratio (const bool _use_toe_heel_transition) const
01002       {
01003           if (_use_toe_heel_transition && current_step_height > 0.0) { // If swing phase
01004               return thp.calc_phase_ratio_for_toe_heel_transition(one_step_count - lcg_count);
01005           } else { // If support phase such as double support phase of starting and ending.
01006               return no_using_toe_heel_ratio;
01007           }
01008       };
01009 #ifdef FOR_TESTGAITGENERATOR
01010       size_t get_one_step_count() const { return one_step_count; };
01011       double get_toe_heel_dif_angle() const { return toe_heel_dif_angle; };
01012 #endif // FOR_TESTGAITGENERATOR
01013     };
01014 
01015   class gait_generator
01016   {
01017 
01018   public:
01019 #ifndef HAVE_MAIN
01020   private:
01021 #endif
01022 
01023     enum velocity_mode_flag { VEL_IDLING, VEL_DOING, VEL_ENDING };
01024     enum emergency_flag { IDLING, EMERGENCY_STOP, STOPPING };
01025 
01026     /* member variables for gait_generator */
01027     // Footstep list to be executed
01028     //   First and last footstep are used for double support phase.
01029     std::vector< std::vector<step_node> > footstep_nodes_list;
01030     // Footstep list for overwriting future footstep queue
01031     std::vector< std::vector<step_node> > overwrite_footstep_nodes_list;
01032     refzmp_generator rg;
01033     leg_coords_generator lcg;
01034     footstep_parameter footstep_param;
01035     velocity_mode_parameter vel_param, offset_vel_param;
01036     toe_heel_type_checker thtc;
01037     hrp::Vector3 cog, refzmp, prev_que_rzmp; /* cog by calculating proc_one_tick */
01038     std::vector<hrp::Vector3> swing_foot_zmp_offsets, prev_que_sfzos;
01039     double dt; /* control loop [s] */
01040     std::vector<std::string> all_limbs;
01041     double default_step_time;
01042     double default_double_support_ratio_before, default_double_support_ratio_after, default_double_support_static_ratio_before, default_double_support_static_ratio_after;
01043     double default_double_support_ratio_swing_before; /*first double support time for leg coords generator */
01044     double default_double_support_ratio_swing_after; /*last double support time for leg coords generator */
01045     double gravitational_acceleration;
01046     size_t finalize_count, optional_go_pos_finalize_footstep_num;
01047     // overwrite_footstep_index is used for footstep overwriting.
01048     //   When overwrite_footstep_index == get_overwritable_index(), overwrite footsteps after overwrite_footstep_index.
01049     size_t overwrite_footstep_index;
01050     // overwritable_footstep_index_offset is used for emergency stop and velocity mode.
01051     //   overwritable footstep index is "footstep_index + overwritable_footstep_index_offset", which is obtained by get_overwritable_index().
01052     size_t overwritable_footstep_index_offset;
01053     velocity_mode_flag velocity_mode_flg;
01054     emergency_flag emergency_flg;
01055     bool use_inside_step_limitation;
01056     std::map<leg_type, std::string> leg_type_map;
01057     coordinates initial_foot_mid_coords;
01058     bool solved;
01059     double leg_margin[4], stride_limitation_for_circle_type[5], overwritable_stride_limitation[5], footstep_modification_gain, cp_check_margin[2], margin_time_ratio;
01060     bool use_stride_limitation, is_emergency_walking[2], modify_footsteps;
01061     hrp::Vector3 diff_cp, modified_d_footstep;
01062     std::vector<bool> act_contact_states;
01063     stride_limitation_type default_stride_limitation_type;
01064 
01065     /* preview controller parameters */
01066     //preview_dynamics_filter<preview_control>* preview_controller_ptr;
01067     preview_dynamics_filter<extended_preview_control>* preview_controller_ptr;
01068 
01069     void append_go_pos_step_nodes (const coordinates& _ref_coords,
01070                                    const std::vector<leg_type>& lts)
01071     {
01072         append_go_pos_step_nodes(_ref_coords, lts, footstep_nodes_list);
01073     };
01074 
01075     void append_go_pos_step_nodes (const coordinates& _ref_coords,
01076                                    const std::vector<leg_type>& lts,
01077                                    std::vector< std::vector<step_node> >& _footstep_nodes_list) const
01078     {
01079       std::vector<step_node> sns;
01080       for (size_t i = 0; i < lts.size(); i++) {
01081           sns.push_back(step_node(lts.at(i), _ref_coords,
01082                                   lcg.get_default_step_height(), default_step_time,
01083                                   lcg.get_toe_angle(), lcg.get_heel_angle()));
01084           sns.at(i).worldcoords.pos += sns.at(i).worldcoords.rot * footstep_param.leg_default_translate_pos[lts.at(i)];
01085       }
01086       _footstep_nodes_list.push_back(sns);
01087     };
01088     void overwrite_refzmp_queue(const std::vector< std::vector<step_node> >& fnsl);
01089     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;
01090     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);
01091     void append_footstep_list_velocity_mode ();
01092     void append_footstep_list_velocity_mode (std::vector< std::vector<step_node> >& _footstep_nodes_list, const velocity_mode_parameter& cur_vel_param) const;
01093     inline leg_type get_leg_type_from_ee_name (const std::string& ee_name) const
01094     {
01095         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;
01096     };
01097 
01098 #ifndef HAVE_MAIN
01099     /* inhibit copy constructor and copy insertion not by implementing */
01100     gait_generator (const gait_generator& _p);
01101     gait_generator &operator=(const gait_generator &_p);
01102   public:
01103 #endif
01104     gait_generator (double _dt,
01105                     /* arguments for footstep_parameter */
01106                     const std::vector<hrp::Vector3>& _leg_pos, std::vector<std::string> _all_limbs,
01107                     const double _stride_fwd_x, const double _stride_outside_y, const double _stride_outside_theta,
01108                     const double _stride_bwd_x, const double _stride_inside_y, const double _stride_inside_theta)
01109         : footstep_nodes_list(), overwrite_footstep_nodes_list(), rg(_dt), lcg(_dt),
01110         footstep_param(_leg_pos, _stride_fwd_x, _stride_outside_y, _stride_outside_theta, _stride_bwd_x, _stride_inside_y, _stride_inside_theta),
01111         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()),
01112         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),
01113         finalize_count(0), optional_go_pos_finalize_footstep_num(0), overwrite_footstep_index(0), overwritable_footstep_index_offset(1),
01114         velocity_mode_flg(VEL_IDLING), emergency_flg(IDLING), margin_time_ratio(0.01), footstep_modification_gain(5e-6),
01115         use_inside_step_limitation(true), use_stride_limitation(false), modify_footsteps(false), default_stride_limitation_type(SQUARE),
01116         preview_controller_ptr(NULL) {
01117         swing_foot_zmp_offsets.assign (1, hrp::Vector3::Zero());
01118         prev_que_sfzos.assign (1, hrp::Vector3::Zero());
01119         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> > ();
01120         for (size_t i = 0; i < 4; i++) leg_margin[i] = 0.1;
01121         for (size_t i = 0; i < 5; i++) stride_limitation_for_circle_type[i] = 0.2;
01122         for (size_t i = 0; i < 5; i++) overwritable_stride_limitation[i] = 0.2;
01123         for (size_t i = 0; i < 2; i++) is_emergency_walking[i] = false;
01124         for (size_t i = 0; i < 2; i++) cp_check_margin[i] = 0.025;
01125     };
01126     ~gait_generator () {
01127       if ( preview_controller_ptr != NULL ) {
01128         delete preview_controller_ptr;
01129         preview_controller_ptr = NULL;
01130       }
01131     };
01132     void initialize_gait_parameter (const hrp::Vector3& cog,
01133                                     const std::vector<step_node>& initial_support_leg_steps,
01134                                     const std::vector<step_node>& initial_swing_leg_dst_steps,
01135                                     const double delay = 1.6);
01136     bool proc_one_tick ();
01137     void limit_stride (step_node& cur_fs, const step_node& prev_fs, const double (&limit)[5]) const;
01138     void modify_footsteps_for_recovery ();
01139     void append_footstep_nodes (const std::vector<std::string>& _legs, const std::vector<coordinates>& _fss)
01140     {
01141         std::vector<step_node> tmp_sns;
01142         for (size_t i = 0; i < _legs.size(); i++) {
01143             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()));
01144         }
01145         footstep_nodes_list.push_back(tmp_sns);
01146     };
01147     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)
01148     {
01149         std::vector<step_node> tmp_sns;
01150         for (size_t i = 0; i < _legs.size(); i++) {
01151             tmp_sns.push_back(step_node(_legs[i], _fss[i], _step_height, _step_time, _toe_angle, _heel_angle));
01152         }
01153         footstep_nodes_list.push_back(tmp_sns);
01154     };
01155     void clear_footstep_nodes_list () {
01156         footstep_nodes_list.clear();
01157         overwrite_footstep_nodes_list.clear();
01158         overwrite_footstep_index = 0;
01159     };
01160     bool go_pos_param_2_footstep_nodes_list (const double goal_x, const double goal_y, const double goal_theta, /* [mm] [mm] [deg] */
01161                                              const std::vector<coordinates>& initial_support_legs_coords, coordinates start_ref_coords,
01162                                              const std::vector<leg_type>& initial_support_legs,
01163                                              const bool is_initialize = true) {
01164         std::vector< std::vector<step_node> > new_footstep_nodes_list;
01165         return go_pos_param_2_footstep_nodes_list (goal_x, goal_y, goal_theta,
01166                                                    initial_support_legs_coords, start_ref_coords,
01167                                                    initial_support_legs,
01168                                                    new_footstep_nodes_list,
01169                                                    is_initialize);
01170     };
01171     bool go_pos_param_2_footstep_nodes_list (const double goal_x, const double goal_y, const double goal_theta, /* [mm] [mm] [deg] */
01172                                              const std::vector<coordinates>& initial_support_legs_coords, coordinates start_ref_coords,
01173                                              const std::vector<leg_type>& initial_support_legs,
01174                                              std::vector< std::vector<step_node> >& new_footstep_nodes_list,
01175                                              const bool is_initialize = true);
01176     void go_pos_param_2_footstep_nodes_list_core (const double goal_x, const double goal_y, const double goal_theta, /* [mm] [mm] [deg] */
01177                                                   const std::vector<coordinates>& initial_support_legs_coords, coordinates start_ref_coords,
01178                                                   const std::vector<leg_type>& initial_support_legs,
01179                                                   std::vector< std::vector<step_node> >& new_footstep_nodes_list,
01180                                                   const bool is_initialize, const size_t overwritable_fs_index) const;
01181     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] */
01182                                                const std::string& tmp_swing_leg,
01183                                                const coordinates& _support_leg_coords);
01184     void initialize_velocity_mode (const coordinates& _ref_coords,
01185                                    const double vel_x, const double vel_y, const double vel_theta, /* [mm/s] [mm/s] [deg/s] */
01186                                    const std::vector<leg_type>& current_legs);
01187     void finalize_velocity_mode ();
01188     void append_finalize_footstep ()
01189     {
01190       append_finalize_footstep(footstep_nodes_list);
01191     };
01192     void append_finalize_footstep (std::vector< std::vector<step_node> >& _footstep_nodes_list) const
01193     {
01194       std::vector<step_node> sns = _footstep_nodes_list[_footstep_nodes_list.size()-2];
01195       for (size_t i = 0; i < sns.size(); i++) {
01196           sns.at(i).step_height = sns.at(i).toe_angle = sns.at(i).heel_angle = 0.0;
01197       }
01198       _footstep_nodes_list.push_back(sns);
01199     };
01200     void emergency_stop ()
01201     {
01202       if (!footstep_nodes_list.empty()) {
01203         velocity_mode_flg = VEL_IDLING;
01204         emergency_flg = EMERGENCY_STOP;
01205       }
01206     };
01207     /* parameter setting */
01208     void set_default_step_time (const double _default_step_time) { default_step_time = _default_step_time; };
01209     void set_default_double_support_ratio_before (const double _default_double_support_ratio_before) { default_double_support_ratio_before = _default_double_support_ratio_before; };
01210     void set_default_double_support_ratio_after (const double _default_double_support_ratio_after) { default_double_support_ratio_after = _default_double_support_ratio_after; };
01211     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; };
01212     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; };
01213     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; };
01214     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; };
01215     void set_default_zmp_offsets(const std::vector<hrp::Vector3>& tmp) { rg.set_default_zmp_offsets(tmp); };
01216     void set_toe_zmp_offset_x (const double _off) { rg.set_toe_zmp_offset_x(_off); };
01217     void set_heel_zmp_offset_x (const double _off) { rg.set_heel_zmp_offset_x(_off); };
01218     void set_use_toe_heel_transition (const bool _u) { rg.set_use_toe_heel_transition(_u); };
01219     void set_use_toe_heel_auto_set (const bool _u) { rg.set_use_toe_heel_auto_set(_u); lcg.set_use_toe_heel_auto_set(_u); };
01220     void set_zmp_weight_map (const std::map<leg_type, double> _map) { rg.set_zmp_weight_map(_map); };
01221     void set_default_step_height(const double _tmp) { lcg.set_default_step_height(_tmp); };
01222     void set_default_top_ratio(const double _tmp) { lcg.set_default_top_ratio(_tmp); };
01223     void set_velocity_param (const double vel_x, const double vel_y, const double vel_theta) /* [mm/s] [mm/s] [deg/s] */
01224     {
01225       vel_param.set(vel_x, vel_y, vel_theta);
01226     };
01227     void set_offset_velocity_param (const double vel_x, const double vel_y, const double vel_theta) /* [mm/s] [mm/s] [deg/s] */
01228     {
01229       offset_vel_param.set(vel_x, vel_y, vel_theta);
01230     };
01231     void set_stride_parameters (const double _stride_fwd_x, const double _stride_outside_y, const double _stride_outside_theta,
01232                                 const double _stride_bwd_x, const double _stride_inside_y, const double _stride_inside_theta)
01233     {
01234       footstep_param.stride_fwd_x = _stride_fwd_x;
01235       footstep_param.stride_outside_y = _stride_outside_y;
01236       footstep_param.stride_outside_theta = _stride_outside_theta;
01237       footstep_param.stride_bwd_x = _stride_bwd_x;
01238       footstep_param.stride_inside_y = _stride_inside_y;
01239       footstep_param.stride_inside_theta = _stride_inside_theta;
01240     };
01241     void set_use_inside_step_limitation(const bool uu) { use_inside_step_limitation = uu; };
01242     void set_default_orbit_type (const orbit_type type) { lcg.set_default_orbit_type(type); };
01243     void set_swing_trajectory_delay_time_offset (const double _time_offset) { lcg.set_swing_trajectory_delay_time_offset(_time_offset); };
01244     void set_swing_trajectory_final_distance_weight (const double _final_distance_weight) { lcg.set_swing_trajectory_final_distance_weight(_final_distance_weight); };
01245     void set_swing_trajectory_time_offset_xy2z (const double _tmp) { lcg.set_swing_trajectory_time_offset_xy2z(_tmp); };
01246     void set_stair_trajectory_way_point_offset (const hrp::Vector3 _offset) { lcg.set_stair_trajectory_way_point_offset(_offset); };
01247     void set_cycloid_delay_kick_point_offset (const hrp::Vector3 _offset) { lcg.set_cycloid_delay_kick_point_offset(_offset); };
01248     void set_gravitational_acceleration (const double ga) { gravitational_acceleration = ga; };
01249     void set_toe_pos_offset_x (const double _offx) { lcg.set_toe_pos_offset_x(_offx); };
01250     void set_heel_pos_offset_x (const double _offx) { lcg.set_heel_pos_offset_x(_offx); };
01251     void set_toe_angle (const double _angle) { lcg.set_toe_angle(_angle); };
01252     void set_heel_angle (const double _angle) { lcg.set_heel_angle(_angle); };
01253     bool set_toe_heel_phase_ratio (const std::vector<double>& ratio)
01254     {
01255         bool lcgret = lcg.set_toe_heel_phase_ratio(ratio);
01256         bool rgret = rg.set_toe_heel_phase_ratio(ratio);
01257         return lcgret && rgret;
01258     };
01259     void set_use_toe_joint (const bool ut) { lcg.set_use_toe_joint(ut); };
01260     void set_leg_default_translate_pos (const std::vector<hrp::Vector3>& off) { footstep_param.leg_default_translate_pos = off;};
01261     void set_optional_go_pos_finalize_footstep_num (const size_t num) { optional_go_pos_finalize_footstep_num = num; };
01262     void set_all_limbs (const std::vector<std::string>& _all_limbs) { all_limbs = _all_limbs; };
01263     void set_overwritable_footstep_index_offset (const size_t _of) { overwritable_footstep_index_offset = _of;};
01264     void set_foot_steps_list (const std::vector< std::vector<step_node> >& fnsl)
01265     {
01266         clear_footstep_nodes_list();
01267         footstep_nodes_list = fnsl;
01268         append_finalize_footstep();
01269         print_footstep_nodes_list();
01270     };
01271     void set_overwrite_foot_steps_list (const std::vector< std::vector<step_node> >& fnsl)
01272     {
01273         overwrite_footstep_nodes_list.clear();
01274         overwrite_footstep_nodes_list = fnsl;
01275         append_finalize_footstep(overwrite_footstep_nodes_list);
01276         print_footstep_nodes_list(overwrite_footstep_nodes_list);
01277     };
01278     void set_leg_margin (const double _leg_margin[4]) {
01279       for (size_t i = 0; i < 4; i++) {
01280         leg_margin[i] = _leg_margin[i];
01281       }
01282     };
01283     void set_stride_limitation_for_circle_type (const double (&_stride_limitation_for_circle_type)[5]) {
01284       for (size_t i = 0; i < 5; i++) {
01285         stride_limitation_for_circle_type[i] = _stride_limitation_for_circle_type[i];
01286       }
01287     };
01288     void set_overwritable_stride_limitation (const double (&_overwritable_stride_limitation)[5]) {
01289       for (size_t i = 0; i < 5; i++) {
01290         overwritable_stride_limitation[i] = _overwritable_stride_limitation[i];
01291       }
01292     };
01293     void set_footstep_modification_gain (const double _footstep_modification_gain) { footstep_modification_gain = _footstep_modification_gain; };
01294     void set_cp_check_margin (const double (&_cp_check_margin)[2]) {
01295       for (size_t i=0; i < 2; i++) {
01296         cp_check_margin[i] = _cp_check_margin[i];
01297       }
01298     };
01299     void set_act_contact_states (const std::vector<bool>& _act_contact_states) {
01300       if (act_contact_states.empty()) act_contact_states.resize(_act_contact_states.size());
01301       for (size_t i = 0; i < act_contact_states.size(); i++) {
01302         act_contact_states[i] = _act_contact_states[i];
01303       }
01304     };
01305     void set_use_stride_limitation (const bool _use_stride_limitation) { use_stride_limitation = _use_stride_limitation; };
01306     void set_modify_footsteps (const bool _modify_footsteps) { modify_footsteps = _modify_footsteps; };
01307     void set_margin_time_ratio (const double _margin_time_ratio) { margin_time_ratio = _margin_time_ratio; };
01308     void set_diff_cp (const hrp::Vector3 _cp) { diff_cp = _cp; };
01309     void set_stride_limitation_type (const stride_limitation_type _tmp) { default_stride_limitation_type = _tmp; };
01310     void set_toe_check_thre (const double _a) { thtc.set_toe_check_thre(_a); };
01311     void set_heel_check_thre (const double _a) { thtc.set_heel_check_thre(_a); };
01312     /* 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. */
01313     size_t get_overwritable_index () const
01314     {
01315         return lcg.get_footstep_index()+overwritable_footstep_index_offset;
01316     };
01317     bool set_overwrite_foot_step_index (const size_t idx)
01318     {
01319         if (idx >= get_overwritable_index()) {
01320             overwrite_footstep_index = idx;
01321             return true;
01322         } else {
01323             return false;
01324         }
01325     };
01326     bool get_footstep_nodes_by_index (std::vector<step_node>& csl, const size_t idx) const
01327     {
01328         if (footstep_nodes_list.size()-1 >= idx) {
01329             csl = footstep_nodes_list.at(idx);
01330             return true;
01331         } else {
01332             return false;
01333         }
01334     };
01335     void print_footstep_nodes_list (const std::vector< std::vector<step_node> > _footstep_nodes_list) const
01336     {
01337         for (size_t i = 0; i < _footstep_nodes_list.size(); i++) {
01338             for (size_t j = 0; j < _footstep_nodes_list.at(i).size(); j++) {
01339                 std::cerr << "[" << i << "] " << _footstep_nodes_list.at(i).at(j) << std::endl;
01340             }
01341         }
01342     };
01343     void print_footstep_nodes_list () const
01344     {
01345       print_footstep_nodes_list(footstep_nodes_list);
01346     };
01347     /* parameter getting */
01348     const hrp::Vector3& get_cog () const { return cog; };
01349     hrp::Vector3 get_cog_vel () const {
01350       double refcog_vel[3];
01351       preview_controller_ptr->get_refcog_vel(refcog_vel);
01352       return hrp::Vector3(refcog_vel[0], refcog_vel[1], refcog_vel[2]);
01353     };
01354     hrp::Vector3 get_cog_acc () const {
01355       double refcog_acc[3];
01356       preview_controller_ptr->get_refcog_acc(refcog_acc);
01357       return hrp::Vector3(refcog_acc[0], refcog_acc[1], refcog_acc[2]);
01358     };
01359     const hrp::Vector3& get_refzmp () const { return refzmp;};
01360     hrp::Vector3 get_cart_zmp () const
01361     {
01362         double czmp[3];
01363         preview_controller_ptr->get_cart_zmp(czmp);
01364         return hrp::Vector3(czmp[0], czmp[1], czmp[2]);
01365     };
01366     std::vector<std::string> convert_leg_types_to_names (const std::vector<leg_type>& lts) const {
01367       std::vector<std::string> ret;
01368       for (std::vector<leg_type>::const_iterator it = lts.begin(); it != lts.end(); it++) {
01369           ret.push_back(leg_type_map.find(*it)->second);
01370       }
01371       return ret;
01372     };
01373     const std::vector<hrp::Vector3>& get_swing_foot_zmp_offsets () const { return swing_foot_zmp_offsets;};
01374     std::vector<hrp::Vector3> get_support_foot_zmp_offsets () const {
01375       std::vector<hrp::Vector3> ret;
01376       for (size_t i = 0; i < lcg.get_support_leg_types().size(); i++) {
01377           ret.push_back(rg.get_default_zmp_offset(lcg.get_support_leg_types().at(i)));
01378       }
01379       return ret;
01380     };
01381     // Get foot zmp offsets by checking whether given EE name is swing or support
01382     bool get_swing_support_foot_zmp_offsets_from_ee_name (hrp::Vector3& ret, const std::string& ee_name) const
01383     {
01384         leg_type lt = get_leg_type_from_ee_name(ee_name);
01385         std::vector<leg_type>::const_iterator it = std::find(lcg.get_support_leg_types().begin(), lcg.get_support_leg_types().end(), lt);
01386         if (it != lcg.get_support_leg_types().end()) { // If support leg
01387             ret = get_support_foot_zmp_offsets()[std::distance(lcg.get_support_leg_types().begin(), it)];
01388         } else {
01389             it = std::find(lcg.get_swing_leg_types().begin(), lcg.get_swing_leg_types().end(), lt);
01390             if (it != lcg.get_swing_leg_types().end()) { // If swing leg
01391                 ret = get_swing_foot_zmp_offsets()[std::distance(lcg.get_swing_leg_types().begin(), it)];
01392             } else { // Otherwise
01393                 return false;
01394             }
01395         }
01396         return true;
01397     };
01398     double get_toe_zmp_offset_x () const { return rg.get_toe_zmp_offset_x(); };
01399     double get_heel_zmp_offset_x () const { return rg.get_heel_zmp_offset_x(); };
01400     bool get_use_toe_heel_transition () const { return rg.get_use_toe_heel_transition(); };
01401     bool get_use_toe_heel_auto_set () const { return rg.get_use_toe_heel_auto_set(); };
01402     const std::map<leg_type, double> get_zmp_weight_map () const { return rg.get_zmp_weight_map(); };
01403     void proc_zmp_weight_map_interpolation () { return rg.proc_zmp_weight_map_interpolation(); };
01404     std::vector<std::string> get_footstep_front_leg_names () const {
01405       std::vector<leg_type> lts;
01406       for (size_t i = 0; i < footstep_nodes_list[0].size(); i++) {
01407           lts.push_back(footstep_nodes_list[0].at(i).l_r);
01408       }
01409       return convert_leg_types_to_names(lts);
01410     };
01411     std::vector<std::string> get_footstep_back_leg_names () const {
01412       std::vector<leg_type> lts;
01413       for (size_t i = 0; i < footstep_nodes_list.back().size(); i++) {
01414           lts.push_back(footstep_nodes_list.back().at(i).l_r);
01415       }
01416       return convert_leg_types_to_names(lts);
01417     };
01418     const std::vector<std::string> get_support_leg_names() const { return convert_leg_types_to_names(lcg.get_support_leg_types());};
01419     const std::vector<std::string> get_swing_leg_names() const { return convert_leg_types_to_names(lcg.get_swing_leg_types());};
01420     const std::vector<step_node>& get_swing_leg_steps() const { return lcg.get_swing_leg_steps(); };
01421     const std::vector<step_node>& get_support_leg_steps() const { return lcg.get_support_leg_steps(); };
01422     const std::vector<step_node>& get_swing_leg_src_steps() const { return lcg.get_swing_leg_src_steps(); };
01423     const std::vector<step_node>& get_swing_leg_dst_steps() const { return lcg.get_swing_leg_dst_steps(); };
01424     const coordinates get_dst_foot_midcoords() const /* get foot_midcoords calculated from swing_leg_dst_coords */
01425     {
01426       coordinates tmp(lcg.get_swing_leg_dst_steps().front().worldcoords);
01427       tmp.pos += tmp.rot * hrp::Vector3(-1*footstep_param.leg_default_translate_pos[lcg.get_swing_leg_dst_steps().front().l_r]);
01428       return tmp;
01429     };
01430     void get_swing_support_mid_coords(coordinates& ret) const { lcg.get_swing_support_mid_coords(ret); };
01431     void get_stride_parameters (double& _stride_fwd_x, double& _stride_outside_y, double& _stride_outside_theta,
01432                                 double& _stride_bwd_x, double& _stride_inside_y, double& _stride_inside_theta) const
01433     {
01434       _stride_fwd_x = footstep_param.stride_fwd_x;
01435       _stride_outside_y = footstep_param.stride_outside_y;
01436       _stride_outside_theta = footstep_param.stride_outside_theta;
01437       _stride_bwd_x = footstep_param.stride_bwd_x;
01438       _stride_inside_y = footstep_param.stride_inside_y;
01439       _stride_inside_theta = footstep_param.stride_inside_theta;
01440     };
01441     size_t get_footstep_index() const { return lcg.get_footstep_index(); };
01442     size_t get_lcg_count() const { return lcg.get_lcg_count(); };
01443     double get_current_swing_time(const size_t idx) const { return lcg.get_current_swing_time(idx); };
01444     // Get current swing time by checking whether given EE name is swing or support
01445     double get_current_swing_time_from_ee_name (const std::string ee_name) const
01446     {
01447         return get_current_swing_time( get_leg_type_from_ee_name(ee_name) );
01448     };
01449     std::vector<leg_type> get_current_support_states() const { return lcg.get_current_support_states();};
01450     double get_default_step_time () const { return default_step_time; };
01451     double get_default_step_height () const { return lcg.get_default_step_height(); };
01452     double get_default_double_support_ratio_before () const { return default_double_support_ratio_before; };
01453     double get_default_double_support_ratio_after () const { return default_double_support_ratio_after; };
01454     double get_default_double_support_static_ratio_before () const { return default_double_support_static_ratio_before; };
01455     double get_default_double_support_static_ratio_after () const { return default_double_support_static_ratio_after; };
01456     double get_default_double_support_ratio_swing_before () const {return default_double_support_ratio_swing_before; };
01457     double get_default_double_support_ratio_swing_after () const {return default_double_support_ratio_swing_after; };
01458     std::vector< std::vector<step_node> > get_remaining_footstep_nodes_list () const
01459     {
01460         std::vector< std::vector<step_node> > fsnl;
01461         size_t fsl_size = (footstep_nodes_list.size()>lcg.get_footstep_index() ? footstep_nodes_list.size()-lcg.get_footstep_index() : 0);
01462         // The rest of fsl are swing dst coords from now.
01463         for (size_t i = 0; i < fsl_size; i++) {
01464             fsnl.push_back(footstep_nodes_list[i+lcg.get_footstep_index()]);
01465         }
01466         return fsnl;
01467     };
01468     orbit_type get_default_orbit_type () const { return lcg.get_default_orbit_type(); };
01469     double get_swing_trajectory_delay_time_offset () const { return lcg.get_swing_trajectory_delay_time_offset(); };
01470     double get_swing_trajectory_final_distance_weight () const { return lcg.get_swing_trajectory_final_distance_weight(); };
01471     double get_swing_trajectory_time_offset_xy2z () const { return lcg.get_swing_trajectory_time_offset_xy2z(); };
01472     hrp::Vector3 get_stair_trajectory_way_point_offset () const { return lcg.get_stair_trajectory_way_point_offset(); };
01473     hrp::Vector3 get_cycloid_delay_kick_point_offset () const { return lcg.get_cycloid_delay_kick_point_offset(); };
01474     double get_gravitational_acceleration () const { return gravitational_acceleration; } ;
01475     double get_toe_pos_offset_x () const { return lcg.get_toe_pos_offset_x(); };
01476     double get_heel_pos_offset_x () const { return lcg.get_heel_pos_offset_x(); };
01477     double get_toe_angle () const { return lcg.get_toe_angle(); };
01478     double get_heel_angle () const { return lcg.get_heel_angle(); };
01479     double get_foot_dif_rot_angle () const { return lcg.get_foot_dif_rot_angle(); };
01480     void get_toe_heel_phase_ratio (std::vector<double>& ratio) const { lcg.get_toe_heel_phase_ratio(ratio); };
01481     int get_NUM_TH_PHASES () const { return NUM_TH_PHASES; };
01482     bool get_use_toe_joint () const { return lcg.get_use_toe_joint(); };
01483     double get_current_toe_heel_ratio () const { return lcg.get_current_toe_heel_ratio(get_use_toe_heel_transition()); };
01484     // Get current toe heel ratio by checking whether given EE name is swing or support
01485     bool get_current_toe_heel_ratio_from_ee_name (double& ret, const std::string& ee_name) const
01486     {
01487         leg_type lt = get_leg_type_from_ee_name(ee_name);
01488         if (std::find(lcg.get_support_leg_types().begin(), lcg.get_support_leg_types().end(), lt)!=lcg.get_support_leg_types().end()) { // If support
01489             ret = rats::no_using_toe_heel_ratio;
01490         } 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
01491             ret = get_current_toe_heel_ratio();
01492         } else { // Otherwise
01493             return false;
01494         }
01495         return true;
01496     };
01497     void get_leg_default_translate_pos (std::vector<hrp::Vector3>& off) const { off = footstep_param.leg_default_translate_pos; };
01498     size_t get_overwritable_footstep_index_offset () const { return overwritable_footstep_index_offset; };
01499     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;
01500     const std::map<leg_type, std::string> get_leg_type_map () const { return leg_type_map; };
01501     size_t get_optional_go_pos_finalize_footstep_num () const { return optional_go_pos_finalize_footstep_num; };
01502     bool is_finalizing (const double tm) const { return ((preview_controller_ptr->get_delay()*2 - default_step_time/dt)-finalize_count) <= (tm/dt)-1; };
01503     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
01504     double get_leg_margin (const size_t idx) const { return leg_margin[idx]; };
01505     double get_stride_limitation_for_circle_type (const size_t idx) const { return stride_limitation_for_circle_type[idx]; };
01506     double get_overwritable_stride_limitation (const size_t idx) const { return overwritable_stride_limitation[idx]; };
01507     double get_footstep_modification_gain () const { return footstep_modification_gain; };
01508     double get_cp_check_margin (const size_t idx) const { return cp_check_margin[idx]; };
01509     bool get_modify_footsteps () const { return modify_footsteps; };
01510     double get_margin_time_ratio () const { return margin_time_ratio; };
01511     bool get_use_stride_limitation () const { return use_stride_limitation; };
01512     stride_limitation_type get_stride_limitation_type () const { return default_stride_limitation_type; };
01513     double get_toe_check_thre () const { return thtc.get_toe_check_thre(); };
01514     double get_heel_check_thre () const { return thtc.get_heel_check_thre(); };
01515     // Get ee coords by checking whether given EE name is swing or support
01516     bool get_swing_support_ee_coords_from_ee_name (hrp::Vector3& cpos, hrp::Matrix33& crot, const std::string& ee_name) const
01517     {
01518         leg_type lt = get_leg_type_from_ee_name(ee_name);
01519         if (std::find(lcg.get_support_leg_types().begin(), lcg.get_support_leg_types().end(), lt) != lcg.get_support_leg_types().end()) { // If support
01520             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;
01521             cpos = tmpc.pos;
01522             crot = tmpc.rot;
01523         } 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
01524             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;
01525             cpos = tmpc.pos;
01526             crot = tmpc.rot;
01527         } else { // Otherwise
01528             return false;
01529         }
01530         return true;
01531     };
01532     // Get current support state (true=support, false=swing) by checking whether given EE name is swing or support
01533     bool get_current_support_state_from_ee_name (const std::string& ee_name) const
01534     {
01535         leg_type lt = get_leg_type_from_ee_name(ee_name);
01536         std::vector<leg_type> tmp = lcg.get_current_support_states();
01537         return std::find(tmp.begin(), tmp.end(), lt) != tmp.end();
01538     };
01539 #ifdef FOR_TESTGAITGENERATOR
01540     size_t get_one_step_count() const { return lcg.get_one_step_count(); };
01541     void get_footstep_nodes_list (std::vector< std::vector<step_node> > & fsl) const
01542     {
01543         fsl = footstep_nodes_list;
01544     };
01545     double get_toe_heel_dif_angle () const { return lcg.get_toe_heel_dif_angle(); };
01546     std::vector<hrp::Vector3> get_default_zmp_offsets() const { return rg.get_default_zmp_offsets(); };
01547 #endif // FOR_TESTGAITGENERATOR
01548     void print_param (const std::string& print_str = "") const
01549     {
01550         double stride_fwd_x, stride_outside_y, stride_outside_th, stride_bwd_x, stride_inside_y, stride_inside_th;
01551         get_stride_parameters(stride_fwd_x, stride_outside_y, stride_outside_th, stride_bwd_x, stride_inside_y, stride_inside_th);
01552         std::cerr << "[" << print_str << "]   stride_parameter = " << stride_fwd_x << "[m], " << stride_outside_y << "[m], " << stride_outside_th << "[deg], "
01553                   << stride_bwd_x << "[m], " << stride_inside_y << "[m], " << stride_inside_th << "[deg]" << std::endl;
01554         std::cerr << "[" << print_str << "]   leg_default_translate_pos = ";
01555         for (size_t i = 0; i < footstep_param.leg_default_translate_pos.size(); i++) {
01556             std::cerr << footstep_param.leg_default_translate_pos[i].format(Eigen::IOFormat(Eigen::StreamPrecision, 0, ", ", ", ", "", "", "    [", "]"));
01557         }
01558         std::cerr << std::endl;
01559         std::cerr << "[" << print_str << "]   default_step_time = " << get_default_step_time() << "[s]" << std::endl;
01560         std::cerr << "[" << print_str << "]   default_step_height = " << get_default_step_height() << "[m]" << std::endl;
01561         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;
01562         std::cerr << "[" << print_str << "]   default_orbit_type = ";
01563         if (get_default_orbit_type() == SHUFFLING) {
01564             std::cerr << "SHUFFLING" << std::endl;
01565         } else if (get_default_orbit_type() == CYCLOID) {
01566             std::cerr << "CYCLOID" << std::endl;
01567         } else if (get_default_orbit_type() == RECTANGLE) {
01568             std::cerr << "RECTANGLE" << std::endl;
01569         } else if (get_default_orbit_type() == STAIR) {
01570             std::cerr << "STAIR" << std::endl;
01571         } else if (get_default_orbit_type() == CYCLOIDDELAY) {
01572             std::cerr << "CYCLOIDDELAY" << std::endl;
01573         } else if (get_default_orbit_type() == CYCLOIDDELAYKICK) {
01574             std::cerr << "CYCLOIDDELAYKICK" << std::endl;
01575         } else if (get_default_orbit_type() == CROSS) {
01576             std::cerr << "CROSS" << std::endl;
01577         }
01578         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()
01579                   << ", swing_trajectory_time_offset_xy2z = " << get_swing_trajectory_time_offset_xy2z() << std::endl;
01580         hrp::Vector3 tmpv;
01581         tmpv = get_stair_trajectory_way_point_offset();
01582         std::cerr << "[" << print_str << "]   stair_trajectory_way_point_offset = " << tmpv.format(Eigen::IOFormat(Eigen::StreamPrecision, 0, ", ", ", ", "", "", "    [", "]")) << "[m]" << std::endl;
01583         tmpv = get_cycloid_delay_kick_point_offset();
01584         std::cerr << "[" << print_str << "]   cycloid_delay_kick_point_offset = " << tmpv.format(Eigen::IOFormat(Eigen::StreamPrecision, 0, ", ", ", ", "", "", "    [", "]")) << "[m]" << std::endl;
01585         std::cerr << "[" << print_str << "]   gravitational_acceleration = " << get_gravitational_acceleration() << "[m/s^2]" << std::endl;
01586         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;
01587         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;
01588         std::cerr << "[" << print_str << "]   toe_angle = " << get_toe_angle() << "[deg]" << std::endl;
01589         std::cerr << "[" << print_str << "]   heel_angle = " << get_heel_angle() << "[deg]" << std::endl;
01590         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;
01591         std::vector<double> tmp_ratio(get_NUM_TH_PHASES(), 0.0);
01592         get_toe_heel_phase_ratio(tmp_ratio);
01593         std::cerr << "[" << print_str << "]   toe_heel_phase_ratio = [";
01594         for (int i = 0; i < get_NUM_TH_PHASES(); i++) std::cerr << tmp_ratio[i] << " ";
01595         std::cerr << "]" << std::endl;
01596         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;
01597         std::cerr << "[" << print_str << "]   default_stride_limitation_type = ";
01598         if (default_stride_limitation_type == SQUARE) {
01599           std::cerr << "SQUARE" << std::endl;
01600         } else if (default_stride_limitation_type == CIRCLE) {
01601           std::cerr << "CIRCLE" << std::endl;
01602         }
01603         thtc.print_param(print_str);
01604     };
01605   };
01606 }
01607 #endif /* GAITGENERATOR_H */


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Wed May 15 2019 05:02:17