10 #ifndef ZMP_DISTRIBUTOR_H 11 #define ZMP_DISTRIBUTOR_H 16 #include "../ImpedanceController/JointPathEx.h" 17 #include "../TorqueFilter/IIRFilter.h" 21 #include <qpOASES.hpp> 22 using namespace qpOASES;
36 return foot_vertices[foot_idx][vtx_idx];
38 void set_vertices (
const std::vector<std::vector<Eigen::Vector2d> >& vs) { foot_vertices = vs; };
39 void get_vertices (std::vector<std::vector<Eigen::Vector2d> >& vs) { vs = foot_vertices; };
42 std::cerr <<
"[" << str <<
"] ";
43 for (
size_t i = 0;
i < foot_vertices.size();
i++) {
45 for (
size_t j = 0;
j < foot_vertices[
i].size();
j++) {
46 std::cerr <<
"[" << foot_vertices[
i][
j](0) <<
" " << foot_vertices[
i][
j](1) <<
"] ";
48 std::cerr << ((
i==foot_vertices.size()-1)?
"[m]":
"[m], ");
50 std::cerr << std::endl;;
72 if (is_lleg)
return (leg_pos(1) >= (-1 * leg_inside_margin + margin)) && (leg_pos(1) <= (leg_outside_margin - margin));
73 else return (leg_pos(1) <= (leg_inside_margin - margin)) && (leg_pos(1) >= (-1 * leg_outside_margin + margin));
77 return leg_pos(0) >= (leg_front_margin - margin);
81 return leg_pos(0) <= (-1 * leg_rear_margin + margin);
87 size_t n_ch = convex_hull.size();
88 Eigen::Vector2d ip = (convex_hull[0] + convex_hull[n_ch/3] + convex_hull[2*n_ch/3]) / 3.0;
89 size_t v_a = 0, v_b = n_ch;
90 while (v_a + 1 < v_b) {
91 size_t v_c = (v_a + v_b) / 2;
92 if (calcCrossProduct(convex_hull[v_a], convex_hull[v_c], ip) > 0) {
93 if (calcCrossProduct(convex_hull[v_a], p, ip) > 0 && calcCrossProduct(convex_hull[v_c], p, ip) < 0) v_b = v_c;
96 if (calcCrossProduct(convex_hull[v_a], p, ip) < 0 && calcCrossProduct(convex_hull[v_c], p, ip) > 0) v_a = v_c;
101 if (calcCrossProduct(convex_hull[v_a], convex_hull[v_b], p) >= 0) {
106 if (!calc_closest_boundary_point(p, v_a, v_b)) std::cerr <<
"[" << str <<
"] Cannot calculate closest boundary point on the convex hull" << std::endl;
114 std::cerr <<
"[" << str <<
"] leg_inside_margin = " << leg_inside_margin <<
"[m], leg_outside_margin = " << leg_outside_margin <<
"[m], leg_front_margin = " << leg_front_margin <<
"[m], leg_rear_margin = " << leg_rear_margin <<
"[m]" << std::endl;
115 std::cerr <<
"[" << str <<
"] wrench_alpha_blending = " << wrench_alpha_blending <<
", alpha_cutoff_freq = " << alpha_filter->getCutOffFreq() <<
"[Hz]" << std::endl;
124 return lv(0) < rv(0) || (lv(0) == rv(0) && lv(1) < rv(1));
128 void calc_convex_hull (
const std::vector<std::vector<Eigen::Vector2d> >& vs,
const std::vector<bool>& cs,
const std::vector<hrp::Vector3>& ee_pos,
const std::vector <hrp::Matrix33>& ee_rot)
131 std::vector<Eigen::Vector2d> tvs;
133 tvs.reserve(cs.size()*vs[0].size());
134 for (
size_t i = 0;
i < cs.size();
i++) {
136 for (
size_t j = 0;
j < vs[i].size();
j++) {
137 tpos = ee_pos[i] + ee_rot[i] *
hrp::Vector3(vs[i][
j](0), vs[i][
j](1), 0.0);
138 tvs.push_back(tpos.head(2));
143 int n_tvs = tvs.size(), n_ch = 0;
144 convex_hull.resize(2*n_tvs);
145 std::sort(tvs.begin(), tvs.end(), compare_eigen2d);
146 for (
int i = 0;
i < n_tvs; convex_hull[n_ch++] = tvs[
i++])
147 while (n_ch >= 2 && calcCrossProduct(convex_hull[n_ch-1], tvs[
i], convex_hull[n_ch-2]) <= 0) n_ch--;
148 for (
int i = n_tvs-2,
j = n_ch+1; i >= 0; convex_hull[n_ch++] = tvs[i--])
149 while (n_ch >=
j && calcCrossProduct(convex_hull[n_ch-1], tvs[i], convex_hull[n_ch-2]) <= 0) n_ch--;
150 convex_hull.resize(n_ch-1);
154 size_t n_ch = convex_hull.size();
155 Eigen::Vector2d cur_closest_point;
156 for (
size_t i = 0;
i < n_ch;
i++) {
157 switch(calcProjectedPoint(cur_closest_point, p, convex_hull[left_idx], convex_hull[right_idx])) {
159 p = cur_closest_point;
162 right_idx = left_idx;
163 left_idx = (left_idx + 1) % n_ch;
164 if ((p - convex_hull[right_idx]).dot(convex_hull[left_idx] - convex_hull[right_idx]) <= 0) {
165 p = cur_closest_point;
169 left_idx = right_idx;
170 right_idx = (right_idx - 1) % n_ch;
171 if ((p - convex_hull[left_idx]).dot(convex_hull[right_idx] - convex_hull[left_idx]) <= 0) {
172 p = cur_closest_point;
186 void set_vertices (
const std::vector<std::vector<Eigen::Vector2d> >& vs)
195 std::vector<std::vector<Eigen::Vector2d> > vec;
198 std::vector<Eigen::Vector2d> tvec;
199 tvec.push_back(Eigen::Vector2d(leg_front_margin, leg_inside_margin));
200 tvec.push_back(Eigen::Vector2d(leg_front_margin, -1*leg_outside_margin));
201 tvec.push_back(Eigen::Vector2d(-1*leg_rear_margin, -1*leg_outside_margin));
202 tvec.push_back(Eigen::Vector2d(-1*leg_rear_margin, leg_inside_margin));
207 std::vector<Eigen::Vector2d> tvec;
208 tvec.push_back(Eigen::Vector2d(leg_front_margin, leg_outside_margin));
209 tvec.push_back(Eigen::Vector2d(leg_front_margin, -1*leg_inside_margin));
210 tvec.push_back(Eigen::Vector2d(-1*leg_rear_margin, -1*leg_inside_margin));
211 tvec.push_back(Eigen::Vector2d(-1*leg_rear_margin, leg_outside_margin));
235 std::vector<std::vector<Eigen::Vector2d> > vec;
238 std::vector<Eigen::Vector2d> tvec;
239 tvec.push_back(Eigen::Vector2d(leg_front_margin - margin[0], leg_inside_margin - margin[2]));
240 tvec.push_back(Eigen::Vector2d(leg_front_margin - margin[0], -1*(leg_outside_margin - margin[3])));
241 tvec.push_back(Eigen::Vector2d(-1*(leg_rear_margin - margin[1]), -1*(leg_outside_margin - margin[3])));
242 tvec.push_back(Eigen::Vector2d(-1*(leg_rear_margin - margin[1]), leg_inside_margin - margin[2]));
247 std::vector<Eigen::Vector2d> tvec;
248 tvec.push_back(Eigen::Vector2d(leg_front_margin - margin[0], leg_inside_margin - margin[3]));
249 tvec.push_back(Eigen::Vector2d(leg_front_margin - margin[0], -1*(leg_outside_margin - margin[2])));
250 tvec.push_back(Eigen::Vector2d(-1*(leg_rear_margin - margin[1]), -1*(leg_outside_margin - margin[2])));
251 tvec.push_back(Eigen::Vector2d(-1*(leg_rear_margin - margin[1]), leg_inside_margin - margin[3]));
267 const std::vector<hrp::Vector3>& ee_pos,
268 const std::vector<hrp::Matrix33>& ee_rot,
269 const std::vector<std::string>& ee_name)
273 for (
size_t i = 0;
i < ee_name.size();
i++) {
274 if (ee_name[
i]==
"rleg") r_idx =
i;
277 hrp::Vector3 l_local_zmp = ee_rot[l_idx].transpose() * (tmprefzmp-ee_pos[l_idx]);
278 hrp::Vector3 r_local_zmp = ee_rot[r_idx].transpose() * (tmprefzmp-ee_pos[r_idx]);
282 if ( is_inside_foot(l_local_zmp,
true) && !is_front_of_foot(l_local_zmp) && !is_rear_of_foot(l_local_zmp)) {
284 }
else if ( is_inside_foot(r_local_zmp,
false) && !is_front_of_foot(r_local_zmp) && !is_rear_of_foot(r_local_zmp)) {
290 if (is_inside_foot(l_local_zmp,
true) && is_front_of_foot(l_local_zmp)) {
291 ledge_foot =
hrp::Vector3(leg_front_margin, l_local_zmp(1), 0.0);
292 }
else if (!is_inside_foot(l_local_zmp,
true) && is_front_of_foot(l_local_zmp)) {
293 ledge_foot =
hrp::Vector3(leg_front_margin, -1 * leg_inside_margin, 0.0);
294 }
else if (!is_inside_foot(l_local_zmp,
true) && !is_front_of_foot(l_local_zmp) && !is_rear_of_foot(l_local_zmp)) {
295 ledge_foot =
hrp::Vector3(l_local_zmp(0), -1 * leg_inside_margin, 0.0);
296 }
else if (!is_inside_foot(l_local_zmp,
true) && is_rear_of_foot(l_local_zmp)) {
297 ledge_foot =
hrp::Vector3(-1 * leg_rear_margin, -1 * leg_inside_margin, 0.0);
299 ledge_foot =
hrp::Vector3(-1 * leg_rear_margin, l_local_zmp(1), 0.0);
301 ledge_foot = ee_rot[l_idx] * ledge_foot + ee_pos[l_idx];
303 if (is_inside_foot(r_local_zmp,
false) && is_front_of_foot(r_local_zmp)) {
304 redge_foot =
hrp::Vector3(leg_front_margin, r_local_zmp(1), 0.0);
305 }
else if (!is_inside_foot(r_local_zmp,
false) && is_front_of_foot(r_local_zmp)) {
306 redge_foot =
hrp::Vector3(leg_front_margin, leg_inside_margin, 0.0);
307 }
else if (!is_inside_foot(r_local_zmp,
false) && !is_front_of_foot(r_local_zmp) && !is_rear_of_foot(r_local_zmp)) {
308 redge_foot =
hrp::Vector3(r_local_zmp(0), leg_inside_margin, 0.0);
309 }
else if (!is_inside_foot(r_local_zmp,
false) && is_rear_of_foot(r_local_zmp)) {
310 redge_foot =
hrp::Vector3(-1 * leg_rear_margin, leg_inside_margin, 0.0);
312 redge_foot =
hrp::Vector3(-1 * leg_rear_margin, r_local_zmp(1), 0.0);
314 redge_foot = ee_rot[r_idx] * redge_foot + ee_pos[r_idx];
317 alpha = difp.dot(tmprefzmp-ledge_foot)/difp.squaredNorm();
320 if (alpha>1.0) alpha = 1.0;
321 if (alpha<0.0) alpha = 0.0;
326 const std::vector<hrp::Vector3>& cop_pos,
327 const std::vector<std::string>& ee_name)
330 for (
size_t i = 0;
i < ee_name.size();
i++) {
331 if (ee_name[
i]==
"rleg") r_idx =
i;
335 double alpha = difp.dot(tmprefzmp - cop_pos[l_idx])/difp.dot(difp);
338 if (alpha>1.0) alpha = 1.0;
339 if (alpha<0.0) alpha = 0.0;
344 std::vector<double>& fz_alpha_vector,
345 const std::vector<hrp::Vector3>& ee_pos,
346 const std::vector<hrp::Matrix33>& ee_rot,
347 const std::vector<std::string>& ee_name,
350 double fz_alpha = calcAlpha(ref_zmp, ee_pos, ee_rot, ee_name);
351 double tmpalpha = calcAlpha(new_refzmp, ee_pos, ee_rot, ee_name), alpha;
353 alpha = alpha_filter->passFilter(tmpalpha);
355 fz_alpha = wrench_alpha_blending * fz_alpha + (1-wrench_alpha_blending) * alpha;
356 for (
size_t i = 0;
i < ee_name.size();
i++) {
357 alpha_vector[
i]= (ee_name[
i]==
"rleg") ? alpha : 1-alpha;
358 fz_alpha_vector[
i]=(ee_name[
i]==
"rleg") ? fz_alpha : 1-fz_alpha;
363 std::vector<double>& fz_alpha_vector,
364 const std::vector<hrp::Vector3>& cop_pos,
365 const std::vector<std::string>& ee_name,
368 double fz_alpha = calcAlphaFromCOP(ref_zmp, cop_pos, ee_name);
369 double tmpalpha = calcAlphaFromCOP(new_refzmp, cop_pos, ee_name), alpha;
371 alpha = alpha_filter->passFilter(tmpalpha);
373 fz_alpha = wrench_alpha_blending * fz_alpha + (1-wrench_alpha_blending) * alpha;
374 for (
size_t i = 0;
i < ee_name.size();
i++) {
375 alpha_vector[
i]= (ee_name[
i]==
"rleg") ? alpha : 1-alpha;
376 fz_alpha_vector[
i]=(ee_name[
i]==
"rleg") ? fz_alpha : 1-fz_alpha;
381 const std::vector<hrp::Vector3>& cop_pos,
382 const std::vector<std::string>& ee_name,
385 std::vector<double> distances;
386 double tmpdistance = 0;
387 for (
size_t i = 0;
i < ee_name.size();
i++) {
388 distances.push_back((cop_pos[
i]-ref_zmp).
norm());
389 tmpdistance += (cop_pos[
i]-ref_zmp).
norm();
391 for (
size_t i = 0;
i < ee_name.size();
i++) {
392 alpha_vector[
i] = tmpdistance/distances[
i];
397 std::vector<double>& fz_alpha_vector,
398 const std::vector<hrp::Vector3>& cop_pos,
399 const std::vector<std::string>& ee_name,
402 calcAlphaVectorFromCOPDistanceCommon(alpha_vector, cop_pos, ee_name, new_refzmp);
403 calcAlphaVectorFromCOPDistanceCommon(fz_alpha_vector, cop_pos, ee_name, ref_zmp);
404 for (
size_t i = 0;
i < ee_name.size();
i++) {
405 fz_alpha_vector[
i] = wrench_alpha_blending * fz_alpha_vector[
i] + (1-wrench_alpha_blending) * alpha_vector[
i];
410 const std::vector<hrp::Vector3>& ee_pos,
411 const std::vector<hrp::Vector3>& cop_pos,
412 const std::vector<hrp::Matrix33>& ee_rot,
413 const std::vector<std::string>& ee_name,
414 const std::vector<double>& limb_gains,
415 const std::vector<double>& toeheel_ratio,
417 const double total_fz,
const double dt,
const bool printp =
true,
const std::string& print_str =
"")
419 std::vector<double> alpha_vector(2), fz_alpha_vector(2);
420 calcAlphaVector(alpha_vector, fz_alpha_vector, ee_pos, ee_rot, ee_name, new_refzmp, ref_zmp);
421 ref_foot_force[0] =
hrp::Vector3(0,0, fz_alpha_vector[0] * total_fz);
422 ref_foot_force[1] =
hrp::Vector3(0,0, fz_alpha_vector[1] * total_fz);
426 double gamma = fz_alpha;
427 double beta = m_wrenches[1].data[2] / ( m_wrenches[0].data[2] + m_wrenches[1].data[2] );
428 beta = isnan(beta) ? 0 : beta;
429 double steepness = 8;
430 double r = - 1/(1+exp(-6*steepness*(gamma-1+1/steepness))) + 1/(1+exp(-6*steepness*(gamma-1/steepness)));
431 fz_alpha = r * beta + ( 1 - r ) * gamma;
434 ref_foot_force[0] =
hrp::Vector3(0,0, fz_alpha * total_fz);
435 ref_foot_force[1] =
hrp::Vector3(0,0, (1-fz_alpha) * total_fz);
437 std::cerr <<
"[" << m_profile.instance_name <<
"] slip st parameters" << std::endl;
438 std::cerr <<
"[" << m_profile.instance_name <<
"] " << ref_foot_force[1](2) <<
" " << ref_foot_force[0](2) <<
" a:"<< steepness <<
" beta:" << beta <<
" gamma:" << gamma <<
" r:" << r <<
" fz_alpha:" << fz_alpha <<
" alpha:" << alpha << std::endl;
442 for (
size_t i = 0;
i < 2;
i++) {
443 tau_0 -= (cop_pos[
i] - new_refzmp).
cross(ref_foot_force[
i]);
480 ref_foot_moment[0](0) = tau_0(0) * alpha_vector[0];
481 ref_foot_moment[1](0) = tau_0(0) * alpha_vector[1];
482 ref_foot_moment[0](1) = tau_0(1) * alpha_vector[0];
483 ref_foot_moment[1](1) = tau_0(1) * alpha_vector[1];
484 ref_foot_moment[0](2) = ref_foot_moment[1](2)= 0.0;
489 hrp::Vector3 foot_dist_coords_y = (cop_pos[1] - cop_pos[0]);
490 foot_dist_coords_y(2) = 0.0;
491 foot_dist_coords_y.normalize();
494 foot_dist_coords_rot(0,0) = foot_dist_coords_x(0);
495 foot_dist_coords_rot(1,0) = foot_dist_coords_x(1);
496 foot_dist_coords_rot(2,0) = foot_dist_coords_x(2);
497 foot_dist_coords_rot(0,1) = foot_dist_coords_y(0);
498 foot_dist_coords_rot(1,1) = foot_dist_coords_y(1);
499 foot_dist_coords_rot(2,1) = foot_dist_coords_y(2);
500 foot_dist_coords_rot(0,2) = 0;
501 foot_dist_coords_rot(1,2) = 0;
502 foot_dist_coords_rot(2,2) = 1;
503 tau_0 = hrp::Vector3::Zero();
510 Gmat(0,0) = 1.0; Gmat(0,1) = 0.0; Gmat(0,2) = 0.0;
511 Gmat(0,3) = 1.0; Gmat(0,4) = 0.0; Gmat(0,5) = 0.0;
512 Gmat(1,0) = (cop_pos[0](1)-new_refzmp(1));
515 Gmat(1,3) = (cop_pos[1](1)-new_refzmp(1));
518 Gmat(2,0) = -(cop_pos[0](0)-new_refzmp(0));
521 Gmat(2,3) = -(cop_pos[1](0)-new_refzmp(0));
525 for (
size_t i = 0;
i < 6;
i++) {
526 for (
size_t j = 0;
j < 6;
j++) {
530 double beta_r =0 , beta_l =0;
532 double alpha_r = 0.9;
533 double alpha_l = 0.1;
534 if (alpha > alpha_r) beta_r = std::pow((alpha/alpha_r-1.0), kk)/std::pow((1.0/alpha_r-1.0), kk);
536 if (alpha < alpha_l) beta_l = std::pow((alpha/alpha_l-1.0), kk);
541 Wmat(3,3) = (1-alpha);
542 Wmat(5,5) = (1-alpha);
550 fmvec = Gmat_ret* fvec;
557 ref_foot_moment[0] = foot_dist_coords_rot * ref_foot_moment[0];
558 ref_foot_moment[1] = foot_dist_coords_rot * ref_foot_moment[1];
564 std::cerr <<
"[" << print_str <<
"] " 565 <<
"total_tau = " <<
hrp::Vector3(tau_0).format(Eigen::IOFormat(Eigen::StreamPrecision, 0,
", ",
", ",
"",
"",
"[",
"]")) <<
"[Nm]" << std::endl;
566 std::cerr <<
"[" << print_str <<
"] " 567 <<
"ref_force_R = " <<
hrp::Vector3(ref_foot_force[0]).format(Eigen::IOFormat(Eigen::StreamPrecision, 0,
", ",
", ",
"",
"",
"[",
"]")) <<
"[N]" << std::endl;
568 std::cerr <<
"[" << print_str <<
"] " 569 <<
"ref_force_L = " <<
hrp::Vector3(ref_foot_force[1]).format(Eigen::IOFormat(Eigen::StreamPrecision, 0,
", ",
", ",
"",
"",
"[",
"]")) <<
"[N]" << std::endl;
570 std::cerr <<
"[" << print_str <<
"] " 571 <<
"ref_moment_R = " <<
hrp::Vector3(ref_foot_moment[0]).format(Eigen::IOFormat(Eigen::StreamPrecision, 0,
", ",
", ",
"",
"",
"[",
"]")) <<
"[Nm]" << std::endl;
572 std::cerr <<
"[" << print_str <<
"] " 573 <<
"ref_moment_L = " <<
hrp::Vector3(ref_foot_moment[1]).format(Eigen::IOFormat(Eigen::StreamPrecision, 0,
", ",
", ",
"",
"",
"[",
"]")) <<
"[Nm]" << std::endl;
578 void solveForceMomentQPOASES (std::vector<hrp::dvector>& fret,
579 const size_t state_dim,
584 real_t* H =
new real_t[state_dim*state_dim];
585 real_t* g =
new real_t[state_dim];
586 real_t* lb =
new real_t[state_dim];
587 real_t* ub =
new real_t[state_dim];
588 for (
size_t i = 0;
i < state_dim;
i++) {
589 for (
size_t j = 0;
j < state_dim;
j++) {
590 H[
i*state_dim+
j] = Hmat(
i,
j);
596 QProblemB example( state_dim );
599 options.initialStatusBounds = ST_INACTIVE;
600 options.numRefinementSteps = 1;
601 options.enableCholeskyRefactorisation = 1;
603 options.printLevel = PL_NONE;
604 example.setOptions( options );
607 example.init( H,g,lb,ub, nWSR,0 );
608 real_t* xOpt =
new real_t[state_dim];
609 example.getPrimalSolution( xOpt );
610 size_t state_dim_one = state_dim / ee_num;
611 for (
size_t fidx = 0; fidx < ee_num; fidx++) {
612 for (
size_t i = 0;
i < state_dim_one;
i++) {
613 fret[fidx](
i) = xOpt[
i+state_dim_one*fidx];
623 void distributeZMPToForceMomentsQP (std::vector<hrp::Vector3>& ref_foot_force, std::vector<hrp::Vector3>& ref_foot_moment,
624 const std::vector<hrp::Vector3>& ee_pos,
625 const std::vector<hrp::Vector3>& cop_pos,
626 const std::vector<hrp::Matrix33>& ee_rot,
627 const std::vector<std::string>& ee_name,
628 const std::vector<double>& limb_gains,
629 const std::vector<double>& toeheel_ratio,
631 const double total_fz,
const double dt,
const bool printp =
true,
const std::string& print_str =
"",
632 const bool use_cop_distribution =
false)
634 size_t ee_num = ee_name.size();
635 std::vector<double> alpha_vector(ee_num), fz_alpha_vector(ee_num);
636 if ( use_cop_distribution ) {
638 calcAlphaVectorFromCOPDistance(alpha_vector, fz_alpha_vector, cop_pos, ee_name, new_refzmp, ref_zmp);
640 calcAlphaVector(alpha_vector, fz_alpha_vector, ee_pos, ee_rot, ee_name, new_refzmp, ref_zmp);
644 double norm_weight = 1e-7;
645 double cop_weight = 1e-3;
646 double ref_force_weight = 0;
648 total_fm(0) = total_fz;
651 size_t state_dim = 4*ee_num, state_dim_one = 4;
653 std::vector<hrp::dvector> ff(ee_num,
hrp::dvector(state_dim_one));
654 std::vector<hrp::dmatrix> mm(ee_num,
hrp::dmatrix(3, state_dim_one));
656 hrp::dmatrix Hmat = hrp::dmatrix::Zero(state_dim,state_dim);
658 double alpha_thre = 1e-20;
660 for (
size_t i = 0;
i < fz_alpha_vector.size();
i++) {
661 fz_alpha_vector[
i] *= limb_gains[
i];
662 fz_alpha_vector[
i] = (fz_alpha_vector[
i] < alpha_thre) ? 1/alpha_thre : 1/fz_alpha_vector[
i];
664 for (
size_t j = 0;
j < fz_alpha_vector.size();
j++) {
665 for (
size_t i = 0;
i < state_dim_one;
i++) {
666 Hmat(
i+
j*state_dim_one,
i+
j*state_dim_one) = norm_weight * fz_alpha_vector[
j];
670 for (
size_t i = 0;
i < state_dim;
i++) {
673 for (
size_t fidx = 0; fidx < ee_num; fidx++) {
674 for (
size_t i = 0;
i < state_dim_one;
i++) {
677 mm[fidx](1,
i) = -(fpos(1)-cop_pos[fidx](1));
678 mm[fidx](2,
i) = (fpos(0)-cop_pos[fidx](0));
679 Gmat(1,
i+state_dim_one*fidx) = -(fpos(1)-new_refzmp(1));
680 Gmat(2,
i+state_dim_one*fidx) = (fpos(0)-new_refzmp(0));
684 Hmat += Gmat.transpose() * Gmat;
685 gvec += -1 * Gmat.transpose() * total_fm;
692 hrp::dmatrix Kmat = hrp::dmatrix::Zero(ee_num,state_dim);
695 for (
size_t j = 0;
j < ee_num;
j++) {
696 for (
size_t i = 0;
i < state_dim_one;
i++) {
697 Kmat(
j,
i+
j*state_dim_one) = 1.0;
699 reff(
j) = ref_foot_force[
j](2);
700 KW(
j,
j) = ref_force_weight;
702 Hmat += Kmat.transpose() * KW * Kmat;
703 gvec += -1 * Kmat.transpose() * KW * reff;
706 hrp::dmatrix Cmat = hrp::dmatrix::Zero(ee_num*2,state_dim);
707 hrp::dmatrix CW = hrp::dmatrix::Zero(ee_num*2,ee_num*2);
709 for (
size_t j = 0;
j < ee_num;
j++) {
710 for (
size_t i = 0;
i < state_dim_one;
i++) {
712 Cmat(
j*2,
i+
j*state_dim_one) = fpos(0) - cop_pos[
j](0);
713 Cmat(
j*2+1,
i+
j*state_dim_one) = fpos(1) - cop_pos[
j](1);
715 CW(
j*2,
j*2) = CW(
j*2+1,
j*2+1) = cop_weight;
717 Hmat += Cmat.transpose() * CW * Cmat;
721 solveForceMomentQPOASES(ff, state_dim, ee_num, Hmat, gvec);
723 for (
size_t fidx = 0; fidx < ee_num; fidx++) {
724 tmpv = mm[fidx] * ff[fidx];
726 ref_foot_moment[fidx] = -1*
hrp::Vector3(tmpv(1),tmpv(2),0);
729 std::cerr <<
"[" << print_str <<
"] force moment distribution " << (use_cop_distribution ?
"(QP COP)" :
"(QP)") << std::endl;
733 for (
size_t i = 0;
i < ee_num;
i++) {
734 std::cerr <<
"[" << print_str <<
"] " 735 <<
"ref_force [" << ee_name[
i] <<
"] " <<
hrp::Vector3(ref_foot_force[
i]).format(Eigen::IOFormat(Eigen::StreamPrecision, 0,
", ",
", ",
"",
"",
"[",
"]")) <<
"[N]" << std::endl;
736 std::cerr <<
"[" << print_str <<
"] " 737 <<
"ref_moment [" << ee_name[i] <<
"] " <<
hrp::Vector3(ref_foot_moment[i]).format(Eigen::IOFormat(Eigen::StreamPrecision, 0,
", ",
", ",
"",
"",
"[",
"]")) <<
"[Nm]" << std::endl;
743 const std::vector<hrp::Vector3>& ee_pos,
744 const std::vector<hrp::Vector3>& cop_pos,
745 const std::vector<hrp::Matrix33>& ee_rot,
746 const std::vector<std::string>& ee_name,
747 const std::vector<double>& limb_gains,
748 const std::vector<double>& toeheel_ratio,
750 const double total_fz,
const double dt,
const bool printp =
true,
const std::string& print_str =
"",
751 const bool use_cop_distribution =
false)
753 distributeZMPToForceMoments(ref_foot_force, ref_foot_moment,
754 ee_pos, cop_pos, ee_rot, ee_name, limb_gains, toeheel_ratio,
756 total_fz, dt, printp, print_str);
758 #endif // USE_QPOASES 764 hrp::dmatrix W2 = hrp::dmatrix::Zero(W.rows(), W.cols());
765 for (
size_t i = 0;
i < W.rows();
i++) W2(
i,
i) = std::sqrt(W(
i,
i));
767 hrp::dmatrix Aw_inv = hrp::dmatrix::Zero(A.cols(), A.rows());
769 ret = W2 * Aw_inv *
b;
774 const std::vector<hrp::Vector3>& ee_pos,
775 const std::vector<hrp::Vector3>& cop_pos,
776 const std::vector<hrp::Matrix33>& ee_rot,
777 const std::vector<std::string>& ee_name,
778 const std::vector<double>& limb_gains,
779 const std::vector<double>& toeheel_ratio,
781 const double total_fz,
const double dt,
const bool printp =
true,
const std::string& print_str =
"",
782 const bool use_cop_distribution =
true,
const std::vector<bool> is_contact_list = std::vector<bool>())
784 size_t ee_num = ee_name.size();
785 std::vector<double> alpha_vector(ee_num), fz_alpha_vector(ee_num);
786 calcAlphaVectorFromCOPDistance(alpha_vector, fz_alpha_vector, cop_pos, ee_name, new_refzmp, ref_zmp);
788 std::cerr <<
"[" << print_str <<
"] force moment distribution (Pinv)" << std::endl;
792 double norm_weight = 1e-7;
793 double norm_moment_weight = 1e2;
794 size_t total_wrench_dim = 5;
795 size_t state_dim = 6*ee_num;
799 size_t total_wrench_dim = 5;
801 hrp::dmatrix Wmat = hrp::dmatrix::Identity(state_dim/2, state_dim/2);
802 hrp::dmatrix Gmat = hrp::dmatrix::Zero(total_wrench_dim, state_dim/2);
803 for (
size_t j = 0;
j < ee_num;
j++) {
804 if (total_wrench_dim == 3) {
807 for (
size_t k = 0; k < 3; k++) Gmat(k,3*
j+k) = 1.0;
810 for (
size_t i = 0;
i < total_wrench_dim;
i++) {
811 for (
size_t j = 0;
j < ee_num;
j++) {
812 if (
i == total_wrench_dim-2 ) {
813 Gmat(
i,3*
j+1) = -(cop_pos[
j](2) - ref_zmp(2));
814 Gmat(
i,3*
j+2) = (cop_pos[
j](1) - ref_zmp(1));
815 }
else if (
i == total_wrench_dim-1 ) {
816 Gmat(
i,3*
j) = (cop_pos[
j](2) - ref_zmp(2));
817 Gmat(
i,3*
j+2) = -(cop_pos[
j](0) - ref_zmp(0));
821 for (
size_t j = 0;
j < ee_num;
j++) {
822 for (
size_t i = 0;
i < 3;
i++) {
823 if (
i != 2 && ee_num == 2)
824 Wmat(
i+
j*3,
i+
j*3) = 0;
826 Wmat(
i+
j*3,
i+
j*3) = Wmat(
i+
j*3,
i+
j*3) * limb_gains[
j];
830 std::cerr <<
"[" << print_str <<
"] Wmat(diag) = [";
831 for (
size_t j = 0;
j < ee_num;
j++) {
832 for (
size_t i = 0;
i < 3;
i++) {
833 std::cerr << Wmat(
i+
j*3,
i+
j*3) <<
" ";
836 std::cerr <<
"]" << std::endl;
839 hrp::dvector total_wrench = hrp::dvector::Zero(total_wrench_dim);
840 total_wrench(total_wrench_dim-3) = total_fz;
842 for (
size_t fidx = 0; fidx < ee_num; fidx++) {
843 ref_foot_force[fidx] =
hrp::Vector3(ret(3*fidx), ret(3*fidx+1), ret(3*fidx+2));
844 ref_foot_moment[fidx] = hrp::Vector3::Zero();
854 for (
size_t i = 0;
i < ee_num;
i++) {
855 std::cerr <<
"[" << print_str <<
"] " 856 <<
"ref_force [" << ee_name[
i] <<
"] " <<
hrp::Vector3(ref_foot_force[
i]).format(Eigen::IOFormat(Eigen::StreamPrecision, 0,
", ",
", ",
"",
"",
"[",
"]")) <<
"[N], " 857 <<
"ref_moment [" << ee_name[i] <<
"] " <<
hrp::Vector3(ref_foot_moment[i]).format(Eigen::IOFormat(Eigen::StreamPrecision, 0,
", ",
", ",
"",
"",
"[",
"]")) <<
"[Nm]" << std::endl;
864 hrp::dvector total_wrench = hrp::dvector::Zero(total_wrench_dim);
866 for (
size_t fidx = 0; fidx < ee_num; fidx++) {
867 double tmp_tau_x = -(cop_pos[fidx](2)-ref_zmp(2)) * ref_foot_force[fidx](1)
868 + (cop_pos[fidx](1)-ref_zmp(1)) * ref_foot_force[fidx](2)
869 + ref_foot_moment[fidx](0);
870 total_wrench(3) -= tmp_tau_x;
871 double tmp_tau_y = (cop_pos[fidx](2)-ref_zmp(2)) * ref_foot_force[fidx](0)
872 - (cop_pos[fidx](0)-ref_zmp(0)) * ref_foot_force[fidx](2)
873 + ref_foot_moment[fidx](1);
874 total_wrench(4) -= tmp_tau_y;
875 ref_total_force += ref_foot_force[fidx];
877 total_wrench(3) -= -(ref_zmp(2) - new_refzmp(2)) * ref_total_force(1) + (ref_zmp(1) - new_refzmp(1)) * ref_total_force(2);
878 total_wrench(4) -= (ref_zmp(2) - new_refzmp(2)) * ref_total_force(0) - (ref_zmp(0) - new_refzmp(0)) * ref_total_force(2);
880 hrp::dmatrix Gmat = hrp::dmatrix::Zero(total_wrench_dim, state_dim);
881 for (
size_t j = 0;
j < ee_num;
j++) {
882 for (
size_t k = 0; k < total_wrench_dim; k++) Gmat(k,6*
j+k) = 1.0;
884 for (
size_t i = 0;
i < total_wrench_dim;
i++) {
885 for (
size_t j = 0;
j < ee_num;
j++) {
887 Gmat(
i,6*
j+1) = -(cop_pos[
j](2) - new_refzmp(2));
888 Gmat(
i,6*
j+2) = (cop_pos[
j](1) - new_refzmp(1));
889 }
else if (
i == 4) {
890 Gmat(
i,6*
j) = (cop_pos[
j](2) - new_refzmp(2));
891 Gmat(
i,6*
j+2) = -(cop_pos[
j](0) - new_refzmp(0));
902 hrp::dmatrix tmpsubG = hrp::dmatrix::Zero(total_wrench_dim, 6);
904 for (
size_t ei = 0; ei < ee_num; ei++) {
905 for (
size_t i = 0;
i < total_wrench_dim;
i++) {
906 for (
size_t j = 0;
j < 6;
j++) {
907 tmpsubG(
i,
j) = Gmat(
i,6*ei+
j);
910 for (
size_t i = 0;
i < 3;
i++) {
911 for (
size_t j = 0;
j < 3;
j++) {
912 tmpR(
i,
j) = tmpR(
i+3,
j+3) = ee_rot[ei](
i,
j);
915 tmpsubG = tmpsubG * tmpR;
916 for (
size_t i = 0;
i < total_wrench_dim;
i++) {
917 for (
size_t j = 0;
j < 6;
j++) {
918 Gmat(
i,6*ei+
j) = tmpsubG(
i,
j);
924 hrp::dmatrix Wmat = hrp::dmatrix::Zero(state_dim, state_dim);
925 for (
size_t j = 0;
j < ee_num;
j++) {
926 for (
size_t i = 0;
i < 3;
i++) {
927 Wmat(
i+
j*6,
i+
j*6) = fz_alpha_vector[
j] * limb_gains[
j];
928 Wmat(
i+
j*6+3,
i+
j*6+3) = (1.0/norm_moment_weight) * fz_alpha_vector[
j] * limb_gains[
j];
932 Wmat(
i+
j*6+3,
i+
j*6+3) = toeheel_ratio[
j] * Wmat(
i+
j*6+3,
i+
j*6+3);
935 if (!is_contact_list.empty()) {
936 if (!is_contact_list[
j]) Wmat(
i+j*6+3,
i+j*6+3) = 0;
941 std::cerr <<
"[" << print_str <<
"] newWmat(diag) = [";
942 for (
size_t j = 0;
j < ee_num;
j++) {
943 for (
size_t i = 0;
i < 6;
i++) {
944 std::cerr << Wmat(
i+
j*6,
i+
j*6) <<
" ";
947 std::cerr <<
"]" << std::endl;
961 for (
size_t fidx = 0; fidx < ee_num; fidx++) {
962 ref_foot_force[fidx] += ee_rot[fidx] *
hrp::Vector3(ret(6*fidx), ret(6*fidx+1), ret(6*fidx+2));
963 ref_foot_moment[fidx] += ee_rot[fidx] *
hrp::Vector3(ret(6*fidx+3), ret(6*fidx+4), ret(6*fidx+5));
966 for (
size_t i = 0;
i < ee_num;
i++) {
967 std::cerr <<
"[" << print_str <<
"] " 968 <<
"new_ref_force [" << ee_name[
i] <<
"] " <<
hrp::Vector3(ref_foot_force[
i]).format(Eigen::IOFormat(Eigen::StreamPrecision, 0,
", ",
", ",
"",
"",
"[",
"]")) <<
"[N], " 969 <<
"new_ref_moment [" << ee_name[i] <<
"] " <<
hrp::Vector3(ref_foot_moment[i]).format(Eigen::IOFormat(Eigen::StreamPrecision, 0,
", ",
", ",
"",
"",
"[",
"]")) <<
"[Nm]" << std::endl;
975 const std::vector<hrp::Vector3>& ee_pos,
976 const std::vector<hrp::Vector3>& cop_pos,
977 const std::vector<hrp::Matrix33>& ee_rot,
978 const std::vector<std::string>& ee_name,
979 const std::vector<double>& limb_gains,
980 const std::vector<double>& toeheel_ratio,
983 const std::vector<hrp::dvector6>& ee_forcemoment_distribution_weight,
984 const double total_fz,
const double dt,
const bool printp =
true,
const std::string& print_str =
"")
986 #define FORCE_MOMENT_DIFF_CONTROL 988 size_t ee_num = ee_name.size();
989 std::vector<double> alpha_vector(ee_num), fz_alpha_vector(ee_num);
990 calcAlphaVectorFromCOPDistance(alpha_vector, fz_alpha_vector, cop_pos, ee_name, new_refzmp, ref_zmp);
992 std::cerr <<
"[" << print_str <<
"] force moment distribution (Pinv2) ";
993 #ifdef FORCE_MOMENT_DIFF_CONTROL 994 std::cerr <<
"(FORCE_MOMENT_DIFF_CONTROL)" << std::endl;
996 std::cerr <<
"(NOT FORCE_MOMENT_DIFF_CONTROL)" << std::endl;
1000 size_t state_dim = 6*ee_num;
1002 std::cerr <<
"[" << print_str <<
"] fz_alpha_vector [";
1003 for (
size_t j = 0;
j < ee_num;
j++) {
1004 std::cerr << fz_alpha_vector[
j] <<
" ";
1006 std::cerr << std::endl;
1010 #ifndef FORCE_MOMENT_DIFF_CONTROL 1011 total_wrench(0) = total_force(0);
1012 total_wrench(1) = total_force(1);
1013 total_wrench(2) = total_force(2);
1015 total_wrench(3) = total_moment(0);
1016 total_wrench(4) = total_moment(1);
1017 total_wrench(5) = total_moment(2);
1018 #ifdef FORCE_MOMENT_DIFF_CONTROL 1019 for (
size_t fidx = 0; fidx < ee_num; fidx++) {
1020 double tmp_tau_x = -(cop_pos[fidx](2)-new_refzmp(2)) * ref_foot_force[fidx](1) + (cop_pos[fidx](1)-new_refzmp(1)) * ref_foot_force[fidx](2);
1021 total_wrench(3) -= tmp_tau_x;
1022 double tmp_tau_y = (cop_pos[fidx](2)-new_refzmp(2)) * ref_foot_force[fidx](0) - (cop_pos[fidx](0)-new_refzmp(0)) * ref_foot_force[fidx](2);
1023 total_wrench(4) -= tmp_tau_y;
1027 hrp::dmatrix Wmat = hrp::dmatrix::Zero(state_dim, state_dim);
1029 for (
size_t j = 0;
j < ee_num;
j++) {
1030 for (
size_t k = 0; k < 6; k++) Gmat(k,6*
j+k) = 1.0;
1032 for (
size_t i = 0;
i < 6;
i++) {
1033 for (
size_t j = 0;
j < ee_num;
j++) {
1035 Gmat(
i,6*
j+1) = -(cop_pos[
j](2) - new_refzmp(2));
1036 Gmat(
i,6*
j+2) = (cop_pos[
j](1) - new_refzmp(1));
1037 }
else if (
i == 4 ) {
1038 Gmat(
i,6*
j) = (cop_pos[
j](2) - new_refzmp(2));
1039 Gmat(
i,6*
j+2) = -(cop_pos[
j](0) - new_refzmp(0));
1043 for (
size_t j = 0;
j < ee_num;
j++) {
1044 for (
size_t i = 0;
i < 3;
i++) {
1045 Wmat(
i+
j*6,
i+
j*6) = ee_forcemoment_distribution_weight[
j][
i] * fz_alpha_vector[
j] * limb_gains[
j];
1048 Wmat(
i+
j*6+3,
i+
j*6+3) = ee_forcemoment_distribution_weight[
j][
i+3] * fz_alpha_vector[
j] * limb_gains[
j];
1052 std::cerr <<
"[" << print_str <<
"] newWmat(diag) = [";
1053 for (
size_t j = 0;
j < ee_num;
j++) {
1054 for (
size_t i = 0;
i < 6;
i++) {
1055 std::cerr << Wmat(
i+
j*6,
i+
j*6) <<
" ";
1058 std::cerr << std::endl;
1067 hrp::dmatrix selection_matrix = hrp::dmatrix::Identity(6,6);
1074 hrp::dvector selected_total_wrench = hrp::dvector::Zero(selection_matrix.rows());
1075 hrp::dmatrix selected_Gmat = hrp::dmatrix::Zero(selection_matrix.rows(), Gmat.cols());
1076 selected_total_wrench = selection_matrix * total_wrench;
1077 selected_Gmat = selection_matrix * Gmat;
1083 tmpretv = Gmat * ret - total_wrench;
1084 std::cerr <<
"[" << print_str <<
"] " 1085 <<
"test_diff " << tmpretv.format(Eigen::IOFormat(Eigen::StreamPrecision, 0,
", ",
", ",
"",
"",
"[",
"]")) <<
"[N][Nm]" << std::endl;
1086 std::cerr <<
"[" << print_str <<
"] " 1087 <<
"total_wrench " << total_wrench.format(Eigen::IOFormat(Eigen::StreamPrecision, 0,
", ",
", ",
"",
"",
"[",
"]")) <<
"[N][Nm]" << std::endl;
1088 for (
size_t i = 0;
i < ee_num;
i++) {
1089 std::cerr <<
"[" << print_str <<
"] " 1090 <<
"ref_force [" << ee_name[
i] <<
"] " <<
hrp::Vector3(ref_foot_force[
i]).format(Eigen::IOFormat(Eigen::StreamPrecision, 0,
", ",
", ",
"",
"",
"[",
"]")) <<
"[N], " 1091 <<
"ref_moment [" << ee_name[i] <<
"] " <<
hrp::Vector3(ref_foot_moment[i]).format(Eigen::IOFormat(Eigen::StreamPrecision, 0,
", ",
", ",
"",
"",
"[",
"]")) <<
"[Nm]" << std::endl;
1093 for (
size_t i = 0;
i < ee_num;
i++) {
1094 #ifdef FORCE_MOMENT_DIFF_CONTROL 1095 std::cerr <<
"[" << print_str <<
"] " 1096 <<
"dif_ref_force [" << ee_name[
i] <<
"] " <<
hrp::Vector3(
hrp::Vector3(ret(6*
i), ret(6*
i+1), ret(6*
i+2))).format(Eigen::IOFormat(Eigen::StreamPrecision, 0,
", ",
", ",
"",
"",
"[",
"]")) <<
"[N], " 1097 <<
"dif_ref_moment [" << ee_name[
i] <<
"] " <<
hrp::Vector3(
hrp::Vector3(ret(6*
i+3), ret(6*
i+4), ret(6*
i+5))).format(Eigen::IOFormat(Eigen::StreamPrecision, 0,
", ",
", ",
"",
"",
"[",
"]")) <<
"[Nm]" << std::endl;
1099 std::cerr <<
"[" << print_str <<
"] " 1100 <<
"dif_ref_force [" << ee_name[
i] <<
"] " <<
hrp::Vector3(
hrp::Vector3(ret(6*
i), ret(6*
i+1), ret(6*
i+2))-ref_foot_force[
i]).format(Eigen::IOFormat(Eigen::StreamPrecision, 0,
", ",
", ",
"",
"",
"[",
"]")) <<
"[N], " 1101 <<
"dif_ref_moment [" << ee_name[i] <<
"] " <<
hrp::Vector3(
hrp::Vector3(ret(6*i+3), ret(6*i+4), ret(6*i+5))-ref_foot_moment[i]).format(Eigen::IOFormat(Eigen::StreamPrecision, 0,
", ",
", ",
"",
"",
"[",
"]")) <<
"[Nm]" << std::endl;
1105 for (
size_t fidx = 0; fidx < ee_num; fidx++) {
1106 #ifdef FORCE_MOMENT_DIFF_CONTROL 1107 ref_foot_force[fidx] +=
hrp::Vector3(ret(6*fidx), ret(6*fidx+1), ret(6*fidx+2));
1108 ref_foot_moment[fidx] +=
hrp::Vector3(ret(6*fidx+3), ret(6*fidx+4), ret(6*fidx+5));
1110 ref_foot_force[fidx] =
hrp::Vector3(ret(6*fidx), ret(6*fidx+1), ret(6*fidx+2));
1111 ref_foot_moment[fidx] =
hrp::Vector3(ret(6*fidx+3), ret(6*fidx+4), ret(6*fidx+5));
1115 for (
size_t i = 0;
i < ee_num;
i++) {
1116 std::cerr <<
"[" << print_str <<
"] " 1117 <<
"new_ref_force [" << ee_name[
i] <<
"] " <<
hrp::Vector3(ref_foot_force[
i]).format(Eigen::IOFormat(Eigen::StreamPrecision, 0,
", ",
", ",
"",
"",
"[",
"]")) <<
"[N], " 1118 <<
"new_ref_moment [" << ee_name[i] <<
"] " <<
hrp::Vector3(ref_foot_moment[i]).format(Eigen::IOFormat(Eigen::StreamPrecision, 0,
", ",
", ",
"",
"",
"[",
"]")) <<
"[Nm]" << std::endl;
1125 return (
a(0) - o(0)) * (
b(1) - o(1)) - (
a(1) - o(1)) * (
b(0) - o(0));
1129 Eigen::Vector2d v1 = target -
b;
1130 Eigen::Vector2d v2 = a -
b;
1131 double v2_norm = v2.norm();
1132 if ( v2_norm == 0 ) {
1136 double ratio = v1.dot(v2) / (v2_norm * v2_norm);
1140 }
else if (ratio > 1){
1144 ret = b + ratio * v2;
1151 #endif // ZMP_DISTRIBUTOR_H double get_alpha_cutoff_freq()
double calcCrossProduct(const Eigen::Vector2d &a, const Eigen::Vector2d &b, const Eigen::Vector2d &o)
void calc_convex_hull(const std::vector< std::vector< Eigen::Vector2d > > &vs, const std::vector< bool > &cs, const std::vector< hrp::Vector3 > &ee_pos, const std::vector< hrp::Matrix33 > &ee_rot)
projected_point_region calcProjectedPoint(Eigen::Vector2d &ret, const Eigen::Vector2d &target, const Eigen::Vector2d &a, const Eigen::Vector2d &b)
double wrench_alpha_blending
bool is_inside_foot(const hrp::Vector3 &leg_pos, const bool is_lleg, const double margin=0.0)
void set_wrench_alpha_blending(const double a)
bool is_front_of_foot(const hrp::Vector3 &leg_pos, const double margin=0.0)
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
bool calc_closest_boundary_point(Eigen::Vector2d &p, size_t &right_idx, size_t &left_idx)
void calcAlphaVectorFromCOPDistanceCommon(std::vector< double > &alpha_vector, const std::vector< hrp::Vector3 > &cop_pos, const std::vector< std::string > &ee_name, const hrp::Vector3 &ref_zmp)
bool is_rear_of_foot(const hrp::Vector3 &leg_pos, const double margin=0.0)
void calcAlphaVectorFromCOP(std::vector< double > &alpha_vector, std::vector< double > &fz_alpha_vector, const std::vector< hrp::Vector3 > &cop_pos, const std::vector< std::string > &ee_name, const hrp::Vector3 &new_refzmp, const hrp::Vector3 &ref_zmp)
void distributeZMPToForceMomentsQP(std::vector< hrp::Vector3 > &ref_foot_force, std::vector< hrp::Vector3 > &ref_foot_moment, const std::vector< hrp::Vector3 > &ee_pos, const std::vector< hrp::Vector3 > &cop_pos, const std::vector< hrp::Matrix33 > &ee_rot, const std::vector< std::string > &ee_name, const std::vector< double > &limb_gains, const std::vector< double > &toeheel_ratio, const hrp::Vector3 &new_refzmp, const hrp::Vector3 &ref_zmp, const double total_fz, const double dt, const bool printp=true, const std::string &print_str="", const bool use_cop_distribution=false)
double calcAlpha(const hrp::Vector3 &tmprefzmp, const std::vector< hrp::Vector3 > &ee_pos, const std::vector< hrp::Matrix33 > &ee_rot, const std::vector< std::string > &ee_name)
double calcAlphaFromCOP(const hrp::Vector3 &tmprefzmp, const std::vector< hrp::Vector3 > &cop_pos, const std::vector< std::string > &ee_name)
static bool compare_eigen2d(const Eigen::Vector2d &lv, const Eigen::Vector2d &rv)
void calcWeightedLinearEquation(hrp::dvector &ret, const hrp::dmatrix &A, const hrp::dmatrix &W, const hrp::dvector &b)
boost::shared_ptr< FirstOrderLowPassFilter< double > > alpha_filter
void set_leg_inside_margin(const double a)
void set_leg_front_margin(const double a)
def j(str, encoding="cp932")
int calcSRInverse(const dmatrix &_a, dmatrix &_a_sr, double _sr_ratio, dmatrix _w)
double get_leg_front_margin()
std::vector< Eigen::Vector2d > convex_hull
double get_leg_outside_margin()
void set_vertices_from_margin_params()
double get_leg_rear_margin()
int calcPseudoInverse(const dmatrix &_a, dmatrix &_a_pseu, double _sv_ratio)
double get_wrench_alpha_blending()
void distributeZMPToForceMomentsPseudoInverse2(std::vector< hrp::Vector3 > &ref_foot_force, std::vector< hrp::Vector3 > &ref_foot_moment, const std::vector< hrp::Vector3 > &ee_pos, const std::vector< hrp::Vector3 > &cop_pos, const std::vector< hrp::Matrix33 > &ee_rot, const std::vector< std::string > &ee_name, const std::vector< double > &limb_gains, const std::vector< double > &toeheel_ratio, const hrp::Vector3 &new_refzmp, const hrp::Vector3 &ref_zmp, const hrp::Vector3 &total_force, const hrp::Vector3 &total_moment, const std::vector< hrp::dvector6 > &ee_forcemoment_distribution_weight, const double total_fz, const double dt, const bool printp=true, const std::string &print_str="")
void get_margined_vertices(std::vector< std::vector< Eigen::Vector2d > > &vs)
Vector3 cross(const Vector3 &v1, const Vector3 &v2)
void calcAlphaVectorFromCOPDistance(std::vector< double > &alpha_vector, std::vector< double > &fz_alpha_vector, const std::vector< hrp::Vector3 > &cop_pos, const std::vector< std::string > &ee_name, const hrp::Vector3 &new_refzmp, const hrp::Vector3 &ref_zmp)
void distributeZMPToForceMoments(std::vector< hrp::Vector3 > &ref_foot_force, std::vector< hrp::Vector3 > &ref_foot_moment, const std::vector< hrp::Vector3 > &ee_pos, const std::vector< hrp::Vector3 > &cop_pos, const std::vector< hrp::Matrix33 > &ee_rot, const std::vector< std::string > &ee_name, const std::vector< double > &limb_gains, const std::vector< double > &toeheel_ratio, const hrp::Vector3 &new_refzmp, const hrp::Vector3 &ref_zmp, const double total_fz, const double dt, const bool printp=true, const std::string &print_str="")
void print_params(const std::string &str)
bool is_inside_support_polygon(Eigen::Vector2d &p, const hrp::Vector3 &offset=hrp::Vector3::Zero(), const bool &truncate_p=false, const std::string &str="")
void calcAlphaVector(std::vector< double > &alpha_vector, std::vector< double > &fz_alpha_vector, const std::vector< hrp::Vector3 > &ee_pos, const std::vector< hrp::Matrix33 > &ee_rot, const std::vector< std::string > &ee_name, const hrp::Vector3 &new_refzmp, const hrp::Vector3 &ref_zmp)
void set_leg_outside_margin(const double a)
void get_vertices(std::vector< std::vector< Eigen::Vector2d > > &vs)
void set_vertices_from_margin_params(const std::vector< double > &margin)
void set_vertices(const std::vector< std::vector< Eigen::Vector2d > > &vs)
void set_alpha_cutoff_freq(const double a)
double get_leg_inside_margin()
void calcWeightedLinearEquation(hrp::dvector &ret, const hrp::dmatrix &A, const hrp::dmatrix &W, const hrp::dvector &b)
void set_leg_rear_margin(const double a)
void print_vertices(const std::string &str)
FootSupportPolygon fs_mgn
void distributeZMPToForceMomentsPseudoInverse(std::vector< hrp::Vector3 > &ref_foot_force, std::vector< hrp::Vector3 > &ref_foot_moment, const std::vector< hrp::Vector3 > &ee_pos, const std::vector< hrp::Vector3 > &cop_pos, const std::vector< hrp::Matrix33 > &ee_rot, const std::vector< std::string > &ee_name, const std::vector< double > &limb_gains, const std::vector< double > &toeheel_ratio, const hrp::Vector3 &new_refzmp, const hrp::Vector3 &ref_zmp, const double total_fz, const double dt, const bool printp=true, const std::string &print_str="", const bool use_cop_distribution=true, const std::vector< bool > is_contact_list=std::vector< bool >())
SimpleZMPDistributor(const double _dt)