sot-talos-balance  2.0.5
Collection of dynamic-graph entities aimed at implementing balance control on talos.
talos-base-estimator.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017, Thomas Flayols, LAAS-CNRS
3  *
4  * This file is part of sot-torque-control.
5  * sot-torque-control is free software: you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public License
7  * as published by the Free Software Foundation, either version 3 of
8  * the License, or (at your option) any later version.
9  * sot-torque-control is distributed in the hope that it will be
10  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
11  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details. You should
13  * have received a copy of the GNU Lesser General Public License along
14  * with sot-torque-control. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #include <dynamic-graph/all-commands.h>
18 #include <dynamic-graph/factory.h>
19 
20 #include <sot/core/debug.hh>
21 #include <sot/core/stop-watch.hh>
23 
24 #include "pinocchio/algorithm/frames.hpp"
25 
26 namespace dynamicgraph {
27 namespace sot {
28 namespace talos_balance {
29 namespace dg = ::dynamicgraph;
30 using namespace dg;
31 using namespace dg::command;
32 using namespace std;
33 using namespace pinocchio;
34 using boost::math::normal; // typedef provides default type is double.
35 
36 void se3Interp(const pinocchio::SE3& s1, const pinocchio::SE3& s2,
37  const double alpha, pinocchio::SE3& s12) {
38  const Eigen::Vector3d t_(s1.translation() * alpha +
39  s2.translation() * (1 - alpha));
40 
41  const Eigen::Vector3d w(pinocchio::log3(s1.rotation()) * alpha +
42  pinocchio::log3(s2.rotation()) * (1 - alpha));
43 
44  s12 = pinocchio::SE3(pinocchio::exp3(w), t_);
45 }
46 
47 void rpyToMatrix(double roll, double pitch, double yaw, Eigen::Matrix3d& R) {
48  Eigen::AngleAxisd rollAngle(roll, Eigen::Vector3d::UnitX());
49  Eigen::AngleAxisd pitchAngle(pitch, Eigen::Vector3d::UnitY());
50  Eigen::AngleAxisd yawAngle(yaw, Eigen::Vector3d::UnitZ());
51  Eigen::Quaternion<double> q = yawAngle * pitchAngle * rollAngle;
52  R = q.matrix();
53 }
54 
55 void rpyToMatrix(const Eigen::Vector3d& rpy, Eigen::Matrix3d& R) {
56  return rpyToMatrix(rpy[0], rpy[1], rpy[2], R);
57 }
58 
59 void matrixToRpy(const Eigen::Matrix3d& M, Eigen::Vector3d& rpy) {
60  double m = sqrt(M(2, 1) * M(2, 1) + M(2, 2) * M(2, 2));
61  rpy(1) = atan2(-M(2, 0), m);
62  if (fabs(fabs(rpy(1)) - 0.5 * M_PI) < 0.001) {
63  rpy(0) = 0.0;
64  rpy(2) = -atan2(M(0, 1), M(1, 1));
65  } else {
66  rpy(2) = atan2(M(1, 0), M(0, 0)); // alpha
67  rpy(0) = atan2(M(2, 1), M(2, 2)); // gamma
68  }
69 }
70 
71 /* // ATTENTION! Quaternion elements are assumed to be [w,x,y,z]
72  void quanternionMult(const Eigen::Vector4d & q1,
73  const Eigen::Vector4d & q2,
74  Eigen::Vector4d & q12)
75  {
76  q12(0) = q2(0)*q1(0)-q2(1)*q1(1)-q2(2)*q1(2)-q2(3)*q1(3);
77  q12(1) = q2(0)*q1(1)+q2(1)*q1(0)-q2(2)*q1(3)+q2(3)*q1(2);
78  q12(2) = q2(0)*q1(2)+q2(1)*q1(3)+q2(2)*q1(0)-q2(3)*q1(1);
79  q12(3) = q2(0)*q1(3)-q2(1)*q1(2)+q2(2)*q1(1)+q2(3)*q1(0);
80  }
81 
82  void pointRotationByQuaternion
83  (const Eigen::Vector3d & point,
84  const Eigen::Vector4d & quat,
85  Eigen::Vector3d & rotatedPoint)
86  {
87  const Eigen::Vector4d p4(0.0, point(0),point(1),point(2));
88  const Eigen::Vector4d quat_conj(quat(0),-quat(1),-quat(2),-quat(3));
89  Eigen::Vector4d q_tmp1,q_tmp2;
90  quanternionMult(quat,p4,q_tmp1);
91  quanternionMult(q_tmp1,quat_conj,q_tmp2);
92  rotatedPoint(0) = q_tmp2(1);
93  rotatedPoint(1) = q_tmp2(2);
94  rotatedPoint(2) = q_tmp2(3);
95  }
96 */
97 
98 inline double eulerMean(double a1, double a2) {
99  double mean = (a1 + a2) / 2.;
100  if ((a1 - a2) > EIGEN_PI || (a1 - a2) < -EIGEN_PI) {
101  return mean > 0 ? -EIGEN_PI + mean : EIGEN_PI + mean;
102  }
103  return mean;
104 }
105 
106 inline double wEulerMean(double a1, double a2, double w1, double w2) {
107  double wMean = (a1 * w1 + a2 * w2) / (w1 + w2);
108  if (a1 - a2 >= EIGEN_PI)
109  return (EIGEN_PI * (w1 - w2) / (w2 + w1) - wMean) < 0
110  ? -EIGEN_PI + wMean - EIGEN_PI * (w1 - w2) / (w2 + w1)
111  : EIGEN_PI + wMean - EIGEN_PI * (w1 - w2) / (w2 + w1);
112  else if (a1 - a2 < -EIGEN_PI)
113  return (EIGEN_PI * (w2 - w1) / (w1 + w2) - wMean) < 0
114  ? -EIGEN_PI + wMean - EIGEN_PI * (w2 - w1) / (w1 + w2)
115  : EIGEN_PI + wMean - EIGEN_PI * (w2 - w1) / (w1 + w2);
116  return wMean;
117 }
118 
119 // inline
120 // double wEulerMean(double a1, double a2, double w1, double w2)
121 // {
122 // double wMean = (a1*w1+ a2*w2)/(w1+w2);
123 // double na,naw,pa,paw;
124 // if ( a1-a2 >= EIGEN_PI )
125 // {
126 // na = a2; //negative angle
127 // naw = w2; //negative angle weight
128 // pa = a1; //positive angle
129 // paw = w1; //positive angle weight
130 // double piFac = (paw-naw)/(naw+paw);
131 // return (EIGEN_PI*piFac - wMean) < 0 ? -EIGEN_PI +
132 // wMean - EIGEN_PI*piFac : EIGEN_PI + wMean - EIGEN_PI*piFac;
133 // }
134 // else if ( a1-a2 < -EIGEN_PI )
135 // {
136 // na = a1; //negative angle
137 // naw = w1; //negative angle weight
138 // pa = a2; //positive angle
139 // paw = w2; //positive angle weight
140 // double piFac = (paw-naw)/(naw+paw);
141 // return (EIGEN_PI*piFac - wMean) < 0 ? -EIGEN_PI + wMean -
142 // EIGEN_PI*piFac : EIGEN_PI + wMean - EIGEN_PI*piFac;
143 // }
144 // return wMean;
145 // }
146 
147 #define PROFILE_BASE_POSITION_ESTIMATION "base-est position estimation"
148 #define PROFILE_BASE_VELOCITY_ESTIMATION "base-est velocity estimation"
149 #define PROFILE_BASE_KINEMATICS_COMPUTATION "base-est kinematics computation"
150 
151 #define INPUT_SIGNALS \
152  m_joint_positionsSIN << m_joint_velocitiesSIN << m_imu_quaternionSIN \
153  << m_forceLLEGSIN << m_forceRLEGSIN << m_dforceLLEGSIN \
154  << m_dforceRLEGSIN << m_w_lf_inSIN << m_w_rf_inSIN \
155  << m_K_fb_feet_posesSIN << m_lf_ref_xyzquatSIN \
156  << m_rf_ref_xyzquatSIN << m_accelerometerSIN \
157  << m_gyroscopeSIN
158 #define OUTPUT_SIGNALS \
159  m_qSOUT << m_vSOUT << m_q_lfSOUT << m_q_rfSOUT << m_q_imuSOUT << m_w_lfSOUT \
160  << m_w_rfSOUT << m_w_lf_filteredSOUT << m_w_rf_filteredSOUT \
161  << m_lf_xyzquatSOUT << m_rf_xyzquatSOUT << m_v_acSOUT << m_a_acSOUT \
162  << m_v_kinSOUT << m_v_imuSOUT << m_v_gyrSOUT << m_v_flexSOUT
163 
166 typedef TalosBaseEstimator EntityClassName;
167 
168 /* --- DG FACTORY ---------------------------------------------------- */
169 DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(TalosBaseEstimator, "TalosBaseEstimator");
170 
171 /* ------------------------------------------------------------------- */
172 /* --- CONSTRUCTION -------------------------------------------------- */
173 /* ------------------------------------------------------------------- */
175  : Entity(name),
176  CONSTRUCT_SIGNAL_IN(joint_positions, dynamicgraph::Vector),
177  CONSTRUCT_SIGNAL_IN(joint_velocities, dynamicgraph::Vector),
178  CONSTRUCT_SIGNAL_IN(imu_quaternion, dynamicgraph::Vector),
179  CONSTRUCT_SIGNAL_IN(forceLLEG, dynamicgraph::Vector),
180  CONSTRUCT_SIGNAL_IN(forceRLEG, dynamicgraph::Vector),
181  CONSTRUCT_SIGNAL_IN(dforceLLEG, dynamicgraph::Vector),
182  CONSTRUCT_SIGNAL_IN(dforceRLEG, dynamicgraph::Vector),
183  CONSTRUCT_SIGNAL_IN(w_lf_in, double),
184  CONSTRUCT_SIGNAL_IN(w_rf_in, double),
185  CONSTRUCT_SIGNAL_IN(K_fb_feet_poses, double),
186  CONSTRUCT_SIGNAL_IN(lf_ref_xyzquat, dynamicgraph::Vector),
187  CONSTRUCT_SIGNAL_IN(rf_ref_xyzquat, dynamicgraph::Vector),
188  CONSTRUCT_SIGNAL_IN(accelerometer, dynamicgraph::Vector),
189  CONSTRUCT_SIGNAL_IN(gyroscope, dynamicgraph::Vector),
190  CONSTRUCT_SIGNAL_INNER(kinematics_computations, dynamicgraph::Vector,
191  m_joint_positionsSIN << m_joint_velocitiesSIN),
192  CONSTRUCT_SIGNAL_OUT(q, dynamicgraph::Vector,
193  m_kinematics_computationsSINNER
194  << m_joint_positionsSIN << m_imu_quaternionSIN
195  << m_forceLLEGSIN << m_forceRLEGSIN
196  << m_w_lf_inSIN << m_w_rf_inSIN
197  << m_K_fb_feet_posesSIN << m_w_lf_filteredSOUT
198  << m_w_rf_filteredSOUT << m_lf_ref_xyzquatSIN
199  << m_rf_ref_xyzquatSIN),
200  CONSTRUCT_SIGNAL_OUT(v, dynamicgraph::Vector,
201  m_kinematics_computationsSINNER
202  << m_accelerometerSIN << m_gyroscopeSIN
203  << m_qSOUT << m_dforceLLEGSIN
204  << m_dforceRLEGSIN),
205  CONSTRUCT_SIGNAL_OUT(v_kin, dynamicgraph::Vector, m_vSOUT),
206  CONSTRUCT_SIGNAL_OUT(v_flex, dynamicgraph::Vector, m_vSOUT),
207  CONSTRUCT_SIGNAL_OUT(v_imu, dynamicgraph::Vector, m_vSOUT),
208  CONSTRUCT_SIGNAL_OUT(v_gyr, dynamicgraph::Vector, m_vSOUT),
209  CONSTRUCT_SIGNAL_OUT(lf_xyzquat, dynamicgraph::Vector, m_qSOUT),
210  CONSTRUCT_SIGNAL_OUT(rf_xyzquat, dynamicgraph::Vector, m_qSOUT),
211  CONSTRUCT_SIGNAL_OUT(a_ac, dynamicgraph::Vector, m_vSOUT),
212  CONSTRUCT_SIGNAL_OUT(v_ac, dynamicgraph::Vector, m_vSOUT),
213  CONSTRUCT_SIGNAL_OUT(q_lf, dynamicgraph::Vector, m_qSOUT),
214  CONSTRUCT_SIGNAL_OUT(q_rf, dynamicgraph::Vector, m_qSOUT),
215  CONSTRUCT_SIGNAL_OUT(q_imu, dynamicgraph::Vector,
216  m_qSOUT << m_imu_quaternionSIN),
217  CONSTRUCT_SIGNAL_OUT(w_lf, double, m_forceLLEGSIN),
218  CONSTRUCT_SIGNAL_OUT(w_rf, double, m_forceRLEGSIN),
219  CONSTRUCT_SIGNAL_OUT(w_lf_filtered, double, m_w_lfSOUT),
220  CONSTRUCT_SIGNAL_OUT(w_rf_filtered, double, m_w_rfSOUT),
221  m_initSucceeded(false),
222  m_reset_foot_pos(true),
223  m_w_imu(0.0),
224  m_zmp_std_dev_rf(1.0),
225  m_zmp_std_dev_lf(1.0),
226  m_fz_std_dev_rf(1.0),
227  m_fz_std_dev_lf(1.0),
228  m_zmp_margin_lf(0.0),
229  m_zmp_margin_rf(0.0) {
230  Entity::signalRegistration(INPUT_SIGNALS << OUTPUT_SIGNALS);
231 
232  // m_K_rf << 4034,23770,239018,707,502,936;
233  // m_K_lf << 4034,23770,239018,707,502,936;
234  m_left_foot_sizes << 0.130, -0.100, 0.075, -0.056;
235  m_right_foot_sizes << 0.130, -0.100, 0.056, -0.075;
236 
237  /* Commands. */
238  addCommand("init",
239  makeCommandVoid2(
240  *this, &TalosBaseEstimator::init,
241  docCommandVoid2("Initialize the entity.", "time step (double)",
242  "URDF file path (string)")));
243 
244  addCommand("set_fz_stable_windows_size",
245  makeCommandVoid1(
247  docCommandVoid1(
248  "Set the windows size used to detect that feet is stable",
249  "int")));
250  addCommand("set_alpha_w_filter",
251  makeCommandVoid1(
253  docCommandVoid1("Set the filter parameter to filter weights",
254  "double")));
255  addCommand(
256  "set_alpha_DC_acc",
257  makeCommandVoid1(*this, &TalosBaseEstimator::set_alpha_DC_acc,
258  docCommandVoid1("Set the filter parameter for removing "
259  "DC from accelerometer data",
260  "double")));
261  addCommand("set_alpha_DC_vel",
262  makeCommandVoid1(
264  docCommandVoid1("Set the filter parameter for removing DC "
265  "from velocity integrated from acceleration",
266  "double")));
267  addCommand(
268  "reset_foot_positions",
269  makeCommandVoid0(*this, &TalosBaseEstimator::reset_foot_positions,
270  docCommandVoid0("Reset the position of the feet.")));
271  addCommand(
272  "get_imu_weight",
273  makeDirectGetter(
274  *this, &m_w_imu,
275  docDirectGetter("Weight of imu-based orientation in sensor fusion",
276  "double")));
277  addCommand("set_imu_weight",
278  makeCommandVoid1(
280  docCommandVoid1(
281  "Set the weight of imu-based orientation in sensor fusion",
282  "double")));
283  addCommand(
284  "set_zmp_std_dev_right_foot",
285  makeCommandVoid1(*this, &TalosBaseEstimator::set_zmp_std_dev_right_foot,
286  docCommandVoid1("Set the standard deviation of the ZMP "
287  "measurement errors for the right foot",
288  "double")));
289  addCommand(
290  "set_zmp_std_dev_left_foot",
291  makeCommandVoid1(*this, &TalosBaseEstimator::set_zmp_std_dev_left_foot,
292  docCommandVoid1("Set the standard deviation of the ZMP "
293  "measurement errors for the left foot",
294  "double")));
295  addCommand(
296  "set_normal_force_std_dev_right_foot",
297  makeCommandVoid1(
299  docCommandVoid1("Set the standard deviation of the normal force "
300  "measurement errors for the right foot",
301  "double")));
302  addCommand("set_normal_force_std_dev_left_foot",
303  makeCommandVoid1(
305  docCommandVoid1("Set the standard deviation of the normal "
306  "force measurement errors for the left foot",
307  "double")));
308  addCommand("set_stiffness_right_foot",
309  makeCommandVoid1(
311  docCommandVoid1(
312  "Set the 6d stiffness of the spring at the right foot",
313  "vector")));
314  addCommand(
315  "set_stiffness_left_foot",
316  makeCommandVoid1(
318  docCommandVoid1("Set the 6d stiffness of the spring at the left foot",
319  "vector")));
320  addCommand(
321  "set_right_foot_sizes",
322  makeCommandVoid1(
324  docCommandVoid1(
325  "Set the size of the right foot (pos x, neg x, pos y, neg y)",
326  "4d vector")));
327  addCommand(
328  "set_left_foot_sizes",
329  makeCommandVoid1(
331  docCommandVoid1(
332  "Set the size of the left foot (pos x, neg x, pos y, neg y)",
333  "4d vector")));
334  addCommand(
335  "set_zmp_margin_right_foot",
336  makeCommandVoid1(
338  docCommandVoid1("Set the ZMP margin for the right foot", "double")));
339  addCommand(
340  "set_zmp_margin_left_foot",
341  makeCommandVoid1(
343  docCommandVoid1("Set the ZMP margin for the left foot", "double")));
344  addCommand(
345  "set_normal_force_margin_right_foot",
346  makeCommandVoid1(
348  docCommandVoid1("Set the normal force margin for the right foot",
349  "double")));
350  addCommand(
351  "set_normal_force_margin_left_foot",
352  makeCommandVoid1(
354  docCommandVoid1("Set the normal force margin for the left foot",
355  "double")));
356 }
357 
358 void TalosBaseEstimator::init(const double& dt, const std::string& robotRef) {
359  m_dt = dt;
360  try {
361  /* Retrieve m_robot_util informations */
362  std::string localName(robotRef);
363  if (isNameInRobotUtil(localName)) {
364  m_robot_util = getRobotUtil(localName);
365  std::cerr << "m_robot_util:" << m_robot_util << std::endl;
366  } else {
367  SEND_MSG("You should have a robotUtil pointer initialized before",
368  MSG_TYPE_ERROR);
369  return;
370  }
371 
372  pinocchio::urdf::buildModel(m_robot_util->m_urdf_filename,
373  pinocchio::JointModelFreeFlyer(), m_model);
374 
375  assert(
376  m_model.existFrame(m_robot_util->m_foot_util.m_Left_Foot_Frame_Name));
377  assert(
378  m_model.existFrame(m_robot_util->m_foot_util.m_Right_Foot_Frame_Name));
379  assert(
380  m_model.existFrame(m_robot_util->m_foot_util.m_Right_Foot_Frame_Name));
382  m_model.getFrameId(m_robot_util->m_foot_util.m_Left_Foot_Frame_Name);
384  m_model.getFrameId(m_robot_util->m_foot_util.m_Right_Foot_Frame_Name);
385  m_IMU_frame_id = m_model.getFrameId(m_robot_util->m_imu_joint_name);
386  m_torso_id = m_model.frames[m_IMU_frame_id].parent;
387  m_torsoMimu = m_model.frames[m_IMU_frame_id].placement;
388  std::cerr << "IMU in Torso" << m_torsoMimu << std::endl;
389 
390  m_q_pin.setZero(m_model.nq);
391  m_q_pin[6] = 1.; // for quaternion
392  m_q_sot.setZero(m_robot_util->m_nbJoints + 6);
393  m_v_pin.setZero(m_robot_util->m_nbJoints + 6);
394  m_v_sot.setZero(m_robot_util->m_nbJoints + 6);
395  m_v_kin.setZero(m_robot_util->m_nbJoints + 6);
396  m_v_flex.setZero(m_robot_util->m_nbJoints + 6);
397  m_v_imu.setZero(m_robot_util->m_nbJoints + 6);
398  m_v_gyr.setZero(m_robot_util->m_nbJoints + 6);
400  SE3(Matrix3::Identity(),
401  -Eigen::Map<const Vector3>(
402  &m_robot_util->m_foot_util.m_Right_Foot_Force_Sensor_XYZ(0)));
403 
404  m_last_vel.setZero();
405  m_last_DCvel.setZero();
407  .setZero(); // this is to replace by acceleration at 1st iteration
408 
409  m_alpha_DC_acc = 0.9995;
410  m_alpha_DC_vel = 0.9995;
411  m_alpha_w_filter = 1.0;
412  m_left_foot_is_stable = true;
413  m_right_foot_is_stable = true;
417  m_isFirstIterFlag = true;
418  } catch (const std::exception& e) {
419  std::cout << e.what();
420  SEND_MSG("Init failed: Could load URDF :" + m_robot_util->m_urdf_filename,
421  MSG_TYPE_ERROR);
422  return;
423  }
424  m_data = new pinocchio::Data(m_model);
425  m_initSucceeded = true;
426 }
427 
429  if (ws < 0.0)
430  return SEND_MSG("windows_size should be a positive integer",
431  MSG_TYPE_ERROR);
433 }
434 
436  if (a < 0.0 || a > 1.0)
437  return SEND_MSG("alpha should be in [0..1]", MSG_TYPE_ERROR);
438  m_alpha_w_filter = a;
439 }
440 
442  if (a < 0.0 || a > 1.0)
443  return SEND_MSG("alpha should be in [0..1]", MSG_TYPE_ERROR);
444  m_alpha_DC_acc = a;
445 }
446 
448  if (a < 0.0 || a > 1.0)
449  return SEND_MSG("alpha should be in [0..1]", MSG_TYPE_ERROR);
450  m_alpha_DC_vel = a;
451 }
452 
454 
455 void TalosBaseEstimator::set_imu_weight(const double& w) {
456  if (w < 0.0)
457  return SEND_MSG("Imu weight must be nonnegative", MSG_TYPE_ERROR);
458  m_w_imu = w;
459 }
460 
462  const dynamicgraph::Vector& k) {
463  if (k.size() != 6)
464  return SEND_MSG(
465  "Stiffness vector should have size 6, not " + toString(k.size()),
466  MSG_TYPE_ERROR);
467  m_K_rf = k;
468 }
469 
471  const dynamicgraph::Vector& k) {
472  if (k.size() != 6)
473  return SEND_MSG(
474  "Stiffness vector should have size 6, not " + toString(k.size()),
475  MSG_TYPE_ERROR);
476  m_K_lf = k;
477 }
478 
480  if (std_dev <= 0.0)
481  return SEND_MSG("Standard deviation must be a positive number",
482  MSG_TYPE_ERROR);
483  m_zmp_std_dev_rf = std_dev;
484 }
485 
487  if (std_dev <= 0.0)
488  return SEND_MSG("Standard deviation must be a positive number",
489  MSG_TYPE_ERROR);
490  m_zmp_std_dev_lf = std_dev;
491 }
492 
494  const double& std_dev) {
495  if (std_dev <= 0.0)
496  return SEND_MSG("Standard deviation must be a positive number",
497  MSG_TYPE_ERROR);
498  m_fz_std_dev_rf = std_dev;
499 }
500 
502  const double& std_dev) {
503  if (std_dev <= 0.0)
504  return SEND_MSG("Standard deviation must be a positive number",
505  MSG_TYPE_ERROR);
506  m_fz_std_dev_lf = std_dev;
507 }
508 
510  if (s.size() != 4)
511  return SEND_MSG(
512  "Foot size vector should have size 4, not " + toString(s.size()),
513  MSG_TYPE_ERROR);
514  m_right_foot_sizes = s;
515 }
516 
518  if (s.size() != 4)
519  return SEND_MSG(
520  "Foot size vector should have size 4, not " + toString(s.size()),
521  MSG_TYPE_ERROR);
522  m_left_foot_sizes = s;
523 }
524 
526  m_zmp_margin_rf = margin;
527 }
528 
530  m_zmp_margin_lf = margin;
531 }
532 
534  const double& margin) {
535  m_fz_margin_rf = margin;
536 }
537 
539  const double& margin) {
540  m_fz_margin_lf = margin;
541 }
542 
543 void TalosBaseEstimator::compute_zmp(const Vector6& w, Vector2& zmp) {
544  pinocchio::Force f(w);
545  f = m_sole_M_ftSens.act(f);
546  if (f.linear()[2] == 0.0) return;
547  zmp[0] = -f.angular()[1] / f.linear()[2];
548  zmp[1] = f.angular()[0] / f.linear()[2];
549 }
550 
551 double TalosBaseEstimator::compute_zmp_weight(const Vector2& zmp,
552  const Vector4& foot_sizes,
553  double std_dev, double margin) {
554  double fs0 = foot_sizes[0] - margin;
555  double fs1 = foot_sizes[1] + margin;
556  double fs2 = foot_sizes[2] - margin;
557  double fs3 = foot_sizes[3] + margin;
558 
559  if (zmp[0] > fs0 || zmp[0] < fs1 || zmp[1] > fs2 || zmp[1] < fs3) return 0;
560 
561  double cdx = ((cdf(m_normal, (fs0 - zmp[0]) / std_dev) -
562  cdf(m_normal, (fs1 - zmp[0]) / std_dev)) -
563  0.5) *
564  2.0;
565  double cdy = ((cdf(m_normal, (fs2 - zmp[1]) / std_dev) -
566  cdf(m_normal, (fs3 - zmp[1]) / std_dev)) -
567  0.5) *
568  2.0;
569  return cdx * cdy;
570 }
571 
572 double TalosBaseEstimator::compute_force_weight(double fz, double std_dev,
573  double margin) {
574  if (fz < margin) return 0.0;
575  return (cdf(m_normal, (fz - margin) / std_dev) - 0.5) * 2.0;
576 }
577 
579  const Vector6& ftrf) {
580  // compute the base position wrt each foot
581  SE3 dummy, dummy1, lfMff, rfMff;
582  m_oMrfs = SE3::Identity();
583  m_oMlfs = SE3::Identity();
584  kinematics_estimation(ftrf, m_K_rf, m_oMrfs, m_right_foot_id, rfMff, dummy,
585  dummy1); // rfMff is obtained reading oMff becaused
586  // oMrfs is here set to Identity
587  kinematics_estimation(ftlf, m_K_lf, m_oMlfs, m_left_foot_id, lfMff, dummy,
588  dummy1);
589 
590  // distance from ankle to ground
591  const Vector3& ankle_2_sole_xyz =
592  m_robot_util->m_foot_util.m_Right_Foot_Sole_XYZ;
593  const SE3 groundMfoot(Matrix3::Identity(), -1.0 * ankle_2_sole_xyz);
594  lfMff = groundMfoot * lfMff;
595  rfMff = groundMfoot * rfMff;
596 
597  // set the world frame in between the feet
598  const Vector3 w(0.5 * (pinocchio::log3(lfMff.rotation()) +
599  pinocchio::log3(rfMff.rotation())));
600  SE3 oMff = SE3(pinocchio::exp3(w),
601  0.5 * (lfMff.translation() + rfMff.translation()));
602  // add a constant offset to make the world frame match the one in OpenHRP
603  // oMff.translation()(0) += 9.562e-03;
604 
605  m_oMlfs = oMff * lfMff.inverse() * groundMfoot;
606  m_oMrfs = oMff * rfMff.inverse() * groundMfoot;
607 
608  m_oMlfs_xyzquat.head<3>() = m_oMlfs.translation();
609  Eigen::Quaternion<double> quat_lf(m_oMlfs.rotation());
610  m_oMlfs_xyzquat(3) = quat_lf.x();
611  m_oMlfs_xyzquat(4) = quat_lf.y();
612  m_oMlfs_xyzquat(5) = quat_lf.z();
613  m_oMlfs_xyzquat(6) = quat_lf.w();
614 
615  m_oMrfs_xyzquat.head<3>() = m_oMrfs.translation();
616  Eigen::Quaternion<double> quat_rf(m_oMrfs.rotation());
617  m_oMrfs_xyzquat(3) = quat_rf.x();
618  m_oMrfs_xyzquat(4) = quat_rf.y();
619  m_oMrfs_xyzquat(5) = quat_rf.z();
620  m_oMrfs_xyzquat(6) = quat_rf.w();
621 
622  // save this poses to use it if no ref is provided
625 
626  sendMsg("Reference pos of left foot:\n" + toString(m_oMlfs), MSG_TYPE_INFO);
627  sendMsg("Reference pos of right foot:\n" + toString(m_oMrfs), MSG_TYPE_INFO);
628 
629  // kinematics_estimation(ftrf, m_K_rf, m_oMrfs, m_right_foot_id,
630  // m_oMff_rf, dummy); kinematics_estimation(ftlf, m_K_lf, m_oMlfs,
631  // m_left_foot_id, m_oMff_lf, dummy); sendMsg("Base estimation left
632  // foot:\n"+toString(m_oMff_lf), MSG_TYPE_DEBUG); sendMsg("Base
633  // estimation right foot:\n"+toString(m_oMff_rf), MSG_TYPE_DEBUG);
634  // sendMsg("Difference base estimation left-right
635  // foot:\n"+toString(m_oMff_rf.inverse()*m_oMff_lf), MSG_TYPE_DEBUG);
636 
637  m_reset_foot_pos = false;
638 }
639 
641  const Vector6& ft, const Vector6& K, const SE3& oMfs,
642  const pinocchio::FrameIndex foot_id, SE3& oMff, SE3& oMfa, SE3& fsMff) {
643  Vector3 xyz;
644  xyz << -ft[0] / K(0), -ft[1] / K(1), -ft[2] / K(2);
645  Matrix3 R;
646  rpyToMatrix(-ft[3] / K(3), -ft[4] / K(4), -ft[5] / K(5), R);
647  const SE3 fsMfa(R, xyz); // foot sole to foot ankle
648  oMfa = oMfs * fsMfa; // world to foot ankle
649  const SE3 faMff(m_data->oMf[foot_id].inverse()); // foot ankle to free flyer
650  //~ sendMsg("faMff (foot_id="+toString(foot_id)+"):\n" + toString(faMff),
651  // MSG_TYPE_INFO); ~ sendMsg("fsMfa (foot_id="+toString(foot_id)+"):\n" +
652  // toString(fsMfa), MSG_TYPE_INFO);
653  oMff = oMfa * faMff; // world to free flyer
654  fsMff = fsMfa * faMff; // foot sole to free flyer
655 }
656 
657 /* ------------------------------------------------------------------- */
658 /* --- SIGNALS ------------------------------------------------------- */
659 /* ------------------------------------------------------------------- */
660 
662  if (!m_initSucceeded) {
663  SEND_WARNING_STREAM_MSG(
664  "Cannot compute signal kinematics_computations before initialization!");
665  return s;
666  }
667 
668  const Eigen::VectorXd& qj = m_joint_positionsSIN(iter); // n+6
669  const Eigen::VectorXd& dq = m_joint_velocitiesSIN(iter);
670  assert(qj.size() == m_robot_util->m_nbJoints &&
671  "Unexpected size of signal joint_positions");
672  assert(dq.size() == m_robot_util->m_nbJoints &&
673  "Unexpected size of signal joint_velocities");
674 
675  /* convert sot to pinocchio joint order */
676  m_robot_util->joints_sot_to_urdf(qj, m_q_pin.tail(m_robot_util->m_nbJoints));
677  m_robot_util->joints_sot_to_urdf(dq, m_v_pin.tail(m_robot_util->m_nbJoints));
678 
679  getProfiler().start(PROFILE_BASE_KINEMATICS_COMPUTATION);
680 
681  /* Compute kinematics assuming world is at free-flyer frame */
682  m_q_pin.head<6>().setZero();
683  m_q_pin(6) = 1.0;
684  m_v_pin.head<6>().setZero();
685  pinocchio::forwardKinematics(m_model, *m_data, m_q_pin, m_v_pin);
686  pinocchio::framesForwardKinematics(m_model, *m_data);
687 
688  getProfiler().stop(PROFILE_BASE_KINEMATICS_COMPUTATION);
689 
690  return s;
691 }
692 
694  if (!m_initSucceeded) {
695  SEND_WARNING_STREAM_MSG("Cannot compute signal q before initialization!");
696  return s;
697  }
698  if (s.size() != static_cast<Eigen::Index>(m_robot_util->m_nbJoints + 6))
699  s.resize(m_robot_util->m_nbJoints + 6);
700 
701  const Eigen::VectorXd& qj = m_joint_positionsSIN(iter); // n+6
702  const Eigen::Vector4d& quatIMU_vec = m_imu_quaternionSIN(iter);
703  const Vector6& ftrf = m_forceRLEGSIN(iter);
704  const Vector6& ftlf = m_forceLLEGSIN(iter);
705 
706  // if the weights are not specified by the user through the input signals
707  // w_lf, w_rf then compute them if one feet is not stable, force weight to 0.0
708  double wL, wR;
709  if (m_w_lf_inSIN.isPlugged()) {
710  wL = m_w_lf_inSIN(iter);
711  } else {
712  wL = m_w_lf_filteredSOUT(iter);
713  if (m_left_foot_is_stable == false) wL = 0.0;
714  }
715  if (m_w_rf_inSIN.isPlugged()) {
716  wR = m_w_rf_inSIN(iter);
717  } else {
718  wR = m_w_rf_filteredSOUT(iter);
719  if (m_right_foot_is_stable == false) wR = 0.0;
720  }
721 
722  assert(qj.size() == m_robot_util->m_nbJoints &&
723  "Unexpected size of signal joint_positions");
724 
725  // if both weights are zero set them to a small positive value to avoid
726  // division by zero
727  if (wR == 0.0 && wL == 0.0) {
728  SEND_WARNING_STREAM_MSG(
729  "The robot is flying!" +
730  ("- forceRLEG: " + toString(ftrf.transpose())) +
731  "- forceLLEG: " + toString(ftlf.transpose()) +
732  "- m_right_foot_is_stable: " + toString(m_right_foot_is_stable) +
733  "- m_left_foot_is_stable: " + toString(m_left_foot_is_stable));
734  wR = 1e-3;
735  wL = 1e-3;
736  }
737 
738  m_kinematics_computationsSINNER(iter);
739 
740  if (m_reset_foot_pos) reset_foot_positions_impl(ftlf, ftrf);
741 
742  getProfiler().start(PROFILE_BASE_POSITION_ESTIMATION);
743  {
744  SE3 oMlfa, oMrfa, lfsMff, rfsMff;
745  kinematics_estimation(ftrf, m_K_rf, m_oMrfs, m_right_foot_id, m_oMff_rf,
746  oMrfa, rfsMff);
747  kinematics_estimation(ftlf, m_K_lf, m_oMlfs, m_left_foot_id, m_oMff_lf,
748  oMlfa, lfsMff);
749 
750  // get rpy
751  const SE3 ffMtorso(
752  m_data->oMi[m_torso_id]); // transform between freeflyer and body
753  // attached to IMU sensor (torso)
754  const SE3 torsoMff(
755  ffMtorso.inverse()); // transform between body attached to IMU sensor
756  // (torso) and freeflyer
757 
758  Vector3 rpy_torso, rpy_torso_lf, rpy_torso_rf,
759  rpy_torso_imu; // orientation of the body which imu is attached to.
760  // (fusion, from left kine, from right kine, from imu)
761 
762  matrixToRpy((m_oMff_lf * ffMtorso).rotation(), rpy_torso_lf);
763  matrixToRpy((m_oMff_rf * ffMtorso).rotation(), rpy_torso_rf);
764  Eigen::Quaterniond quatIMU(quatIMU_vec[0], quatIMU_vec[1], quatIMU_vec[2],
765  quatIMU_vec[3]);
766  Eigen::Quaterniond quat_torsoMimu(
767  m_torsoMimu.rotation()); // transform between torso and IMU
768  Eigen::Quaterniond quat_torso_imu(
769  quatIMU * quat_torsoMimu); // quatIMU expressed in torso frame
770  // Eigen::Quaterniond quat_torso_imu(quatIMU); // quatIMU expressed in torso
771  // frame
772  matrixToRpy(quat_torso_imu.toRotationMatrix(), rpy_torso_imu);
773 
774  // average (we do not take into account the IMU yaw)
775  // double wSum = wL + wR + m_w_imu;
776  rpy_torso[0] = wEulerMean(rpy_torso_lf[0], rpy_torso_rf[0], wL, wR);
777  rpy_torso[0] = wEulerMean(rpy_torso[0], rpy_torso_imu[0], wL + wR, m_w_imu);
778  rpy_torso[1] = wEulerMean(rpy_torso_lf[1], rpy_torso_rf[1], wL, wR);
779  rpy_torso[1] = wEulerMean(rpy_torso[1], rpy_torso_imu[1], wL + wR, m_w_imu);
780  rpy_torso[2] = wEulerMean(rpy_torso_lf[2], rpy_torso_rf[2], wL, wR);
781 
782  rpyToMatrix(rpy_torso, m_oRtorso);
783  m_oRff = m_oRtorso * torsoMff.rotation();
784 
785  // translation to get foot at the right position
786  // evaluate Mrl Mlf for q with the good orientation and zero translation for
787  // freeflyer
788  const Vector3 pos_lf_ff =
789  m_oRff * m_data->oMf[m_left_foot_id].translation();
790  const Vector3 pos_rf_ff =
791  m_oRff * m_data->oMf[m_right_foot_id].translation();
792  // get average translation
793  m_q_pin.head<3>() = ((oMlfa.translation() - pos_lf_ff) * wL +
794  (oMrfa.translation() - pos_rf_ff) * wR) /
795  (wL + wR);
796 
797  m_q_sot.tail(m_robot_util->m_nbJoints) = qj;
798  base_se3_to_sot(m_q_pin.head<3>(), m_oRff, m_q_sot.head<6>());
799 
800  s = m_q_sot;
801 
802  // store estimation of the base pose in SE3 format
803  const SE3 oMff_est(m_oRff, m_q_pin.head<3>());
804 
805  // feedback on feet poses
806  if (m_K_fb_feet_posesSIN.isPlugged()) {
807  const double K_fb = m_K_fb_feet_posesSIN(iter);
808  if (K_fb > 0.0 && m_w_imu > 0.0) {
809  assert(m_w_imu > 0.0 &&
810  "Update of the feet 6d poses should not be done if wIMU = 0.0");
811  assert(K_fb < 1.0 &&
812  "Feedback gain on foot correction should be less than 1.0 "
813  "(K_fb_feet_poses>1.0)");
814  // feet positions in the world according to current base estimation
815  const SE3 oMlfs_est(oMff_est * (lfsMff.inverse()));
816  const SE3 oMrfs_est(oMff_est * (rfsMff.inverse()));
817  // error in current foot position
818  SE3 leftDrift = m_oMlfs.inverse() * oMlfs_est;
819  SE3 rightDrift = m_oMrfs.inverse() * oMrfs_est;
820 
822  SE3 leftDrift_delta;
823  SE3 rightDrift_delta;
824  se3Interp(leftDrift, SE3::Identity(), K_fb * wR, leftDrift_delta);
825  se3Interp(rightDrift, SE3::Identity(), K_fb * wL, rightDrift_delta);
826  // if a feet is not stable on the ground (aka flying), fully update his
827  // position
828  if (m_right_foot_is_stable == false) rightDrift_delta = rightDrift;
829  if (m_left_foot_is_stable == false) leftDrift_delta = leftDrift;
830  if (m_right_foot_is_stable == false && m_left_foot_is_stable == false) {
831  // robot is jumping, do not update any feet position
832  rightDrift_delta = SE3::Identity();
833  leftDrift_delta = SE3::Identity();
834  }
835  // std::cout <<
836  // "------------------------------------------------" <<
837  // std::endl; std::cout << "Initial m_oMlfs and m_oMrfs:"
838  // << std::endl; std::cout << m_oMlfs << std::endl;
839  // std::cout << m_oMrfs << std::endl;
840  // std::cout << "leftDrift_delta and rightDrift_delta:" <<
841  // std::endl; std::cout << leftDrift_delta << std::endl;
842  // std::cout << rightDrift_delta << std::endl;
843  m_oMlfs = m_oMlfs * leftDrift_delta;
844  m_oMrfs = m_oMrfs * rightDrift_delta;
845  // dedrift (x, y, z, yaw) using feet pose references
846  SE3 oMlfs_ref, oMrfs_ref;
847  if (m_lf_ref_xyzquatSIN.isPlugged() and
848  m_rf_ref_xyzquatSIN.isPlugged()) {
850  const Vector7& lf_ref_xyzquat_vec = m_lf_ref_xyzquatSIN(iter);
851  const Vector7& rf_ref_xyzquat_vec = m_rf_ref_xyzquatSIN(iter);
852  const Eigen::Quaterniond ql(
853  m_lf_ref_xyzquatSIN(iter)(6), m_lf_ref_xyzquatSIN(iter)(3),
854  m_lf_ref_xyzquatSIN(iter)(4), m_lf_ref_xyzquatSIN(iter)(5));
855  const Eigen::Quaterniond qr(
856  m_rf_ref_xyzquatSIN(iter)(6), m_rf_ref_xyzquatSIN(iter)(3),
857  m_rf_ref_xyzquatSIN(iter)(4), m_rf_ref_xyzquatSIN(iter)(5));
858  oMlfs_ref = SE3(ql.toRotationMatrix(), lf_ref_xyzquat_vec.head<3>());
859  oMrfs_ref = SE3(qr.toRotationMatrix(), rf_ref_xyzquat_vec.head<3>());
860  } else {
861  oMlfs_ref = m_oMlfs_default_ref;
862  oMrfs_ref = m_oMrfs_default_ref;
863  }
866  const Vector3 translation_feet_drift =
867  0.5 * ((oMlfs_ref.translation() - m_oMlfs.translation()) +
868  (oMrfs_ref.translation() - m_oMrfs.translation()));
870  const Vector3 V_ref = oMrfs_ref.translation() - oMlfs_ref.translation();
871  const Vector3 V_est = m_oMrfs.translation() - m_oMlfs.translation();
874  const double yaw_drift =
875  (atan2(V_ref(1), V_ref(0)) - atan2(V_est(1), V_est(0)));
876  //~ printf("yaw_drift=%lf\r\n",yaw_drift);
878  const Vector3 rpy_feet_drift(0., 0., yaw_drift);
879  Matrix3 rotation_feet_drift;
880  rpyToMatrix(rpy_feet_drift, rotation_feet_drift);
881  const SE3 drift_to_ref(rotation_feet_drift, translation_feet_drift);
882  // std::cout << "drift_to_ref:" << std::endl;
883  // std::cout << drift_to_ref << std::endl;
884  // std::cout << "leftDrift_delta*drift_to_ref and
885  // rightDrift_delta*drift_to_ref:" << std::endl; std::cout
886  // << leftDrift_delta * drift_to_ref << std::endl;
887  // std::cout << rightDrift_delta * drift_to_ref <<
888  // std::endl;
889  m_oMlfs = m_oMlfs * drift_to_ref;
890  m_oMrfs = m_oMrfs * drift_to_ref;
891  // std::cout << "Final m_oMlfs and m_oMrfs:" << std::endl;
892  // std::cout << m_oMlfs << std::endl;
893  // std::cout << m_oMrfs << std::endl;
894  // std::cout <<
895  // "++++++++++++++++++++++++++++++++++++++++++++++++" <<
896  // std::endl;
897  } else if (K_fb < -1e-3) // hack. If K_fb<0, disable drift compensation
898  {
899  if (m_lf_ref_xyzquatSIN.isPlugged() and
900  m_rf_ref_xyzquatSIN.isPlugged()) {
902  const Vector7& lf_ref_xyzquat_vec = m_lf_ref_xyzquatSIN(iter);
903  const Vector7& rf_ref_xyzquat_vec = m_rf_ref_xyzquatSIN(iter);
904  const Eigen::Quaterniond ql(
905  m_lf_ref_xyzquatSIN(iter)(6), m_lf_ref_xyzquatSIN(iter)(3),
906  m_lf_ref_xyzquatSIN(iter)(4), m_lf_ref_xyzquatSIN(iter)(5));
907  const Eigen::Quaterniond qr(
908  m_rf_ref_xyzquatSIN(iter)(6), m_rf_ref_xyzquatSIN(iter)(3),
909  m_rf_ref_xyzquatSIN(iter)(4), m_rf_ref_xyzquatSIN(iter)(5));
910  m_oMlfs = SE3(ql.toRotationMatrix(), lf_ref_xyzquat_vec.head<3>());
911  m_oMrfs = SE3(qr.toRotationMatrix(), rf_ref_xyzquat_vec.head<3>());
912  } else {
913  m_oMlfs = m_oMlfs_default_ref;
914  m_oMrfs = m_oMrfs_default_ref;
915  }
916  }
917  }
918 
919  // convert to xyz+quaternion format //Rq: this convertions could be done in
920  // outupt signals function?
921  m_oMlfs_xyzquat.head<3>() = m_oMlfs.translation();
922  Eigen::Quaternion<double> quat_lf(m_oMlfs.rotation());
923  m_oMlfs_xyzquat(3) = quat_lf.x();
924  m_oMlfs_xyzquat(4) = quat_lf.y();
925  m_oMlfs_xyzquat(5) = quat_lf.z();
926  m_oMlfs_xyzquat(6) = quat_lf.w();
927 
928  m_oMrfs_xyzquat.head<3>() = m_oMrfs.translation();
929  Eigen::Quaternion<double> quat_rf(m_oMrfs.rotation());
930  m_oMrfs_xyzquat(3) = quat_rf.x();
931  m_oMrfs_xyzquat(4) = quat_rf.y();
932  m_oMrfs_xyzquat(5) = quat_rf.z();
933  m_oMrfs_xyzquat(6) = quat_rf.w();
934  }
935  getProfiler().stop(PROFILE_BASE_POSITION_ESTIMATION);
936  return s;
937 }
938 
940  if (!m_initSucceeded) {
941  SEND_WARNING_STREAM_MSG(
942  "Cannot compute signal lf_xyzquat before initialization!");
943  return s;
944  }
945  if (s.size() != 7) s.resize(7);
946  const Eigen::VectorXd& q = m_qSOUT(iter);
947  (void)q; // disable unused variable warning
948  s = m_oMlfs_xyzquat;
949  return s;
950 }
951 
953  if (!m_initSucceeded) {
954  SEND_WARNING_STREAM_MSG(
955  "Cannot compute signal rf_xyzquat before initialization!");
956  return s;
957  }
958  if (s.size() != 7) s.resize(7);
959  const Eigen::VectorXd& q = m_qSOUT(iter);
960  (void)q; // disable unused variable warning
961  s = m_oMrfs_xyzquat;
962  return s;
963 }
964 
966  if (!m_initSucceeded) {
967  SEND_WARNING_STREAM_MSG(
968  "Cannot compute signal q_lf before initialization!");
969  return s;
970  }
971  if (s.size() != static_cast<Eigen::Index>(m_robot_util->m_nbJoints + 6))
972  s.resize(m_robot_util->m_nbJoints + 6);
973 
974  const Eigen::VectorXd& q = m_qSOUT(iter);
975  s.tail(m_robot_util->m_nbJoints) = q.tail(m_robot_util->m_nbJoints);
976  base_se3_to_sot(m_oMff_lf.translation(), m_oMff_lf.rotation(), s.head<6>());
977 
978  return s;
979 }
980 
982  if (!m_initSucceeded) {
983  SEND_WARNING_STREAM_MSG(
984  "Cannot compute signal q_rf before initialization!");
985  return s;
986  }
987  if (s.size() != static_cast<Eigen::Index>(m_robot_util->m_nbJoints + 6))
988  s.resize(m_robot_util->m_nbJoints + 6);
989 
990  const Eigen::VectorXd& q = m_qSOUT(iter);
991  s.tail(m_robot_util->m_nbJoints) = q.tail(m_robot_util->m_nbJoints);
992  base_se3_to_sot(m_oMff_rf.translation(), m_oMff_rf.rotation(), s.head<6>());
993 
994  return s;
995 }
996 
998  if (!m_initSucceeded) {
999  SEND_WARNING_STREAM_MSG(
1000  "Cannot compute signal q_imu before initialization!");
1001  return s;
1002  }
1003  if (s.size() != static_cast<Eigen::Index>(m_robot_util->m_nbJoints + 6))
1004  s.resize(m_robot_util->m_nbJoints + 6);
1005 
1006  const Eigen::VectorXd& q = m_qSOUT(iter);
1007  s.tail(m_robot_util->m_nbJoints) = q.tail(m_robot_util->m_nbJoints);
1008  const SE3 ffMtorso(
1009  m_data->oMi[m_torso_id]); // transform between freeflyer and body
1010  // attached to IMU sensor (torso)
1011  const SE3 torsoMff(ffMtorso.inverse()); // transform between body attached to
1012  // IMU sensor (torso) and freeflyer
1013  const Eigen::Vector4d& quatIMU_vec = m_imu_quaternionSIN(iter);
1014  // Eigen::Quaternion<double> quatIMU(quatIMU_vec);
1015  Eigen::Quaterniond quatIMU(quatIMU_vec[0], quatIMU_vec[1], quatIMU_vec[2],
1016  quatIMU_vec[3]);
1017  Eigen::Quaterniond quat_torsoMimu(m_torsoMimu.rotation());
1018  Eigen::Quaterniond quat_torso_imu(quatIMU * quat_torsoMimu);
1019  // m_oRff = quat_torso_imu.toRotationMatrix() * torsoMff.rotation();
1020  base_se3_to_sot(q.head<3>(), m_oRff, s.head<6>());
1021  // matrixToRpy(quat_torso_imu.toRotationMatrix(), rpy_torso_imu);
1022 
1023  return s;
1024 }
1025 
1027  if (!m_initSucceeded) {
1028  SEND_WARNING_STREAM_MSG(
1029  "Cannot compute signal w_lf before initialization!");
1030  return s;
1031  }
1032 
1033  const Vector6& wrench = m_forceLLEGSIN(iter);
1034  Vector2 zmp;
1035  zmp.setZero();
1036  compute_zmp(wrench, zmp);
1037  double w_zmp = compute_zmp_weight(zmp, m_left_foot_sizes, m_zmp_std_dev_lf,
1038  m_zmp_margin_lf);
1039  double w_fz =
1040  compute_force_weight(wrench(2), m_fz_std_dev_lf, m_fz_margin_lf);
1041  // check that foot is sensing a force greater than the margin treshold for
1042  // more than 'm_fz_stable_windows_size' samples
1043  if (wrench(2) > m_fz_margin_lf)
1044  m_lf_fz_stable_cpt++;
1045  else
1046  m_lf_fz_stable_cpt = 0;
1047 
1048  if (m_lf_fz_stable_cpt >= m_fz_stable_windows_size) {
1049  m_lf_fz_stable_cpt = m_fz_stable_windows_size;
1050  m_left_foot_is_stable = true;
1051  } else {
1052  m_left_foot_is_stable = false;
1053  }
1054  s = w_zmp * w_fz;
1055  return s;
1056 }
1057 
1059  if (!m_initSucceeded) {
1060  SEND_WARNING_STREAM_MSG(
1061  "Cannot compute signal w_rf before initialization!");
1062  return s;
1063  }
1064 
1065  const Vector6& wrench = m_forceRLEGSIN(iter);
1066  Vector2 zmp;
1067  zmp.setZero();
1068  compute_zmp(wrench, zmp);
1069  double w_zmp = compute_zmp_weight(zmp, m_right_foot_sizes, m_zmp_std_dev_rf,
1070  m_zmp_margin_rf);
1071  double w_fz =
1072  compute_force_weight(wrench(2), m_fz_std_dev_rf, m_fz_margin_rf);
1073  // check that foot is sensing a force greater than the margin treshold for
1074  // more than 'm_fz_stable_windows_size' samples
1075  if (wrench(2) > m_fz_margin_rf)
1076  m_rf_fz_stable_cpt++;
1077  else
1078  m_rf_fz_stable_cpt = 0;
1079 
1080  if (m_rf_fz_stable_cpt >= m_fz_stable_windows_size) {
1081  m_rf_fz_stable_cpt = m_fz_stable_windows_size;
1082  m_right_foot_is_stable = true;
1083  } else {
1084  m_right_foot_is_stable = false;
1085  }
1086  s = w_zmp * w_fz;
1087  return s;
1088 }
1089 
1090 DEFINE_SIGNAL_OUT_FUNCTION(w_rf_filtered, double) {
1091  if (!m_initSucceeded) {
1092  SEND_WARNING_STREAM_MSG(
1093  "Cannot compute signal w_rf_filtered before initialization!");
1094  return s;
1095  }
1096  double w_rf = m_w_rfSOUT(iter);
1097  m_w_rf_filtered =
1098  m_alpha_w_filter * w_rf +
1099  (1 - m_alpha_w_filter) * m_w_rf_filtered; // low pass filter
1100  s = m_w_rf_filtered;
1101  return s;
1102 }
1103 
1104 DEFINE_SIGNAL_OUT_FUNCTION(w_lf_filtered, double) {
1105  if (!m_initSucceeded) {
1106  SEND_WARNING_STREAM_MSG(
1107  "Cannot compute signal w_lf_filtered before initialization!");
1108  return s;
1109  }
1110  double w_lf = m_w_lfSOUT(iter);
1111  m_w_lf_filtered =
1112  m_alpha_w_filter * w_lf +
1113  (1 - m_alpha_w_filter) * m_w_lf_filtered; // low pass filter
1114  s = m_w_lf_filtered;
1115  return s;
1116 }
1117 
1119  if (!m_initSucceeded) {
1120  SEND_WARNING_STREAM_MSG("Cannot compute signal v before initialization!");
1121  return s;
1122  }
1123  if (s.size() != static_cast<Eigen::Index>(m_robot_util->m_nbJoints + 6))
1124  s.resize(m_robot_util->m_nbJoints + 6);
1125 
1126  m_kinematics_computationsSINNER(iter);
1127  m_qSOUT(iter);
1128 
1129  getProfiler().start(PROFILE_BASE_VELOCITY_ESTIMATION);
1130  {
1131  const Eigen::VectorXd& dq = m_joint_velocitiesSIN(iter);
1132  const Eigen::Vector3d& acc_imu = m_accelerometerSIN(iter);
1133  const Eigen::Vector3d& gyr_imu = m_gyroscopeSIN(iter);
1134  // const Eigen::Vector4d & quatIMU_vec = m_imu_quaternionSIN(iter);
1135  const Vector6& dftrf = m_dforceRLEGSIN(iter);
1136  const Vector6& dftlf = m_dforceLLEGSIN(iter);
1137  assert(dq.size() == m_robot_util->m_nbJoints &&
1138  "Unexpected size of signal joint_velocities");
1139 
1140  // if the weights are not specified by the user through the input signals
1141  // w_lf, w_rf then compute them if one feet is not stable, force weight to
1142  // 0.0
1143  double wL, wR;
1144  if (m_w_lf_inSIN.isPlugged()) {
1145  wL = m_w_lf_inSIN(iter);
1146  } else {
1147  wL = m_w_lf_filteredSOUT(iter);
1148  if (m_left_foot_is_stable == false) wL = 0.0;
1149  }
1150  if (m_w_rf_inSIN.isPlugged()) {
1151  wR = m_w_rf_inSIN(iter);
1152  } else {
1153  wR = m_w_rf_filteredSOUT(iter);
1154  if (m_right_foot_is_stable == false) wR = 0.0;
1155  }
1156  // if both weights are zero set them to a small positive value to avoid
1157  // division by zero
1158  if (wR == 0.0 && wL == 0.0) {
1159  wR = 1e-3;
1160  wL = 1e-3;
1161  }
1162 
1163  /* Compute foot velocities */
1164  const Frame& f_lf = m_model.frames[m_left_foot_id];
1165  const Motion& v_lf_local = m_data->v[f_lf.parent];
1166  const SE3& ffMlf = m_data->oMi[f_lf.parent];
1167  Vector6 v_kin_l =
1168  -ffMlf.act(v_lf_local).toVector(); // this is the velocity of the base
1169  // in the frame of the base.
1170  v_kin_l.head<3>() = m_oRff * v_kin_l.head<3>();
1171  v_kin_l.segment<3>(3) = m_oRff * v_kin_l.segment<3>(3);
1172 
1173  const Frame& f_rf = m_model.frames[m_right_foot_id];
1174  const Motion& v_rf_local = m_data->v[f_rf.parent];
1175  const SE3& ffMrf = m_data->oMi[f_rf.parent];
1176  Vector6 v_kin_r =
1177  -ffMrf.act(v_rf_local).toVector(); // this is the velocity of the base
1178  // in the frame of the base.
1179  v_kin_r.head<3>() = m_oRff * v_kin_r.head<3>();
1180  v_kin_r.segment<3>(3) = m_oRff * v_kin_r.segment<3>(3);
1181 
1182  m_v_kin.head<6>() = (wR * v_kin_r + wL * v_kin_l) / (wL + wR);
1183 
1184  /* Compute velocity induced by the flexibility */
1185  Vector6 v_flex_l;
1186  Vector6 v_flex_r;
1187  v_flex_l << -dftlf[0] / m_K_lf(0), -dftlf[1] / m_K_lf(1),
1188  -dftlf[2] / m_K_lf(2), -dftlf[3] / m_K_lf(3), -dftlf[4] / m_K_lf(4),
1189  -dftlf[5] / m_K_lf(5);
1190  v_flex_r << -dftrf[0] / m_K_rf(0), -dftrf[1] / m_K_rf(1),
1191  -dftrf[2] / m_K_rf(2), -dftrf[3] / m_K_rf(3), -dftrf[4] / m_K_rf(4),
1192  -dftrf[5] / m_K_rf(5);
1193  const Eigen::Matrix<double, 6, 6> lfAff = ffMlf.inverse().toActionMatrix();
1194  const Eigen::Matrix<double, 6, 6> rfAff = ffMrf.inverse().toActionMatrix();
1195  Eigen::Matrix<double, 12, 6> A;
1196  A << lfAff, rfAff;
1197  Eigen::Matrix<double, 12, 1> b;
1198  b << v_flex_l, v_flex_r;
1199  //~ m_v_flex.head<6>() = A.jacobiSvd(Eigen::ComputeThinU |
1200  // Eigen::ComputeThinV).solve(b);
1201  m_v_flex.head<6>() = (A.transpose() * A).ldlt().solve(A.transpose() * b);
1202  m_v_flex.head<3>() = m_oRff * m_v_flex.head<3>();
1203 
1204  /* Get an estimate of linear velocities from gyroscope only*/
1205  // we make the assumption that we are 'turning around the foot' with pure
1206  // angular velocity in the ankle measured by the gyro
1207  const SE3& ffMtorso =
1208  m_data->oMi[m_torso_id]; // transform between freeflyer and body
1209  // attached to IMU sensor
1210  const Matrix3& ffRtorso = ffMtorso.rotation();
1211  const Matrix3 ffRimu = ffRtorso * m_torsoMimu.rotation();
1212  // std::cerr << m_data->oMf[m_torso_id] << std::endl;
1213  // std::cerr << m_data->liMi[m_torso_id] << std::endl;
1214  // std::cerr << "m_torso_id" << m_torso_id << std::endl;
1215  const Matrix3 lfRimu = ffMlf.rotation().transpose() * ffRimu;
1216  const Matrix3 rfRimu = ffMrf.rotation().transpose() * ffRimu;
1217 
1218  // const SE3 torsoMimu(Matrix3::Identity(), Vector3(-0.13, 0.0, 0.118));
1219  // ///TODO Read this transform from setable parameter /// TODO chesk the
1220  // sign of the translation const SE3 ffMtorso(m_data->oMf[m_torso_id]);
1221  // const SE3 imuMff = (ffMtorso * m_torsoMimu).inverse(); gVw_a = gVo_g +
1222  // gHa.act(aVb_a)-gVb_g //angular velocity in the ankle from gyro and d_enc
1223  // const Frame & f_imu = m_model.frames[m_torso_id]; const Frame & f_imu =
1224  // m_model.frames[m_IMU_frame_id];
1225  Vector3 gVo_a_l =
1226  Vector3(gyr_imu(0), gyr_imu(1),
1227  gyr_imu(2)); //+ (imuMff*ffMlf).act(v_lf_local).angular() -
1228  // m_data->v[f_imu.parent].angular();
1229  Vector3 gVo_a_r =
1230  Vector3(gyr_imu(0), gyr_imu(1),
1231  gyr_imu(2)); //+ (imuMff*ffMrf).act(v_rf_local).angular() -
1232  // m_data->v[f_imu.parent].angular();
1233  Motion v_gyr_ankle_l(Vector3(0., 0., 0.), lfRimu * gVo_a_l);
1234  Motion v_gyr_ankle_r(Vector3(0., 0., 0.), rfRimu * gVo_a_r);
1235  Vector6 v_gyr_l = ffMlf.inverse().actInv(v_gyr_ankle_l).toVector();
1236  Vector6 v_gyr_r = ffMrf.inverse().actInv(v_gyr_ankle_r).toVector();
1237  m_v_gyr.head<6>() = (wL * v_gyr_l + wR * v_gyr_r) / (wL + wR);
1238 
1239  /* Get an estimate of linear velocities from filtered accelerometer
1240  * integration */
1241 
1242  /* rotate acceleration to express it in the world frame */
1243  //~ pointRotationByQuaternion(acc_imu,quatIMU_vec,acc_world); //this is
1244  // false because yaw from imuquat is drifting
1245  const Vector3 acc_world = m_oRtorso * acc_imu;
1246 
1247  /* now, the acceleration is expressed in the world frame,
1248  * so it can be written as the sum of the proper acceleration and the
1249  * constant gravity vector. We could remove this assuming a [0,0,9.81]
1250  * but we prefer to filter this signal with low frequency high pass
1251  * filter since it is robust to gravity norm error, and we know that
1252  * globaly the robot can not accelerate continuously. */
1253 
1255  if (m_isFirstIterFlag) {
1256  m_last_DCacc = acc_world; // Copy the first acceleration data
1257  m_isFirstIterFlag = false;
1258  sendMsg("iter:" + toString(iter) + "\n", MSG_TYPE_INFO);
1259  }
1260  const Vector3 DCacc =
1261  acc_world * (1 - m_alpha_DC_acc) + m_last_DCacc * (m_alpha_DC_acc);
1262  //~ sendMsg("acc_world :"+toString(acc_world)+"\n",
1263  // MSG_TYPE_INFO);
1264  m_last_DCacc = DCacc;
1265  const Vector3 ACacc = acc_world - DCacc;
1266  m_v_ac = ACacc;
1267  /* Then this acceleration is integrated. */
1268  const Vector3 vel = m_last_vel + ACacc * m_dt;
1269  m_last_vel = vel;
1270  /* To stabilise the integrated velocity, we add the
1271  * asumption that globaly, velocity is zero. So we remove DC again */
1272  const Vector3 DCvel =
1273  vel * (1 - m_alpha_DC_vel) + m_last_DCvel * (m_alpha_DC_vel);
1274  m_last_DCvel = DCvel;
1275  const Vector3 ACvel = vel - DCvel;
1276  m_v_ac = ACvel;
1277 
1278  /* Express back velocity in the imu frame to get a full 6d velocity with the
1279  * gyro*/
1280  const Vector3 imuVimu = m_oRtorso.transpose() * ACvel;
1281  /* Here we could remove dc from gyrometer to remove bias*/
1282  const Motion imuWimu(imuVimu, gyr_imu);
1283  // const Frame & f_imu = m_model.frames[m_torso_id];
1284  // const Motion & ffWtorso = m_data->v[f_imu.parent];
1285  // const SE3 ffMtorso(m_data->oMf[m_torso_id]);
1286  // const SE3 torsoMimu(Matrix3::Identity(), +1.0*Vector3(-0.13, 0.0,
1287  // 0.118)); ///TODO Read this transform from setable parameter /// TODO
1288  // chesk the sign of the translation
1289  const SE3 ffMimu = ffMtorso * m_torsoMimu;
1290  const Motion v = ffMimu.act(imuWimu); //- ffWtorso;
1291  m_v_imu.head<6>() = v.toVector();
1292  // m_v_imu.head<3>() = m_oRff * m_v_imu.head<3>();
1293 
1294  m_v_sot.head<6>() = m_v_kin.head<6>();
1295  //~ m_v_sot.head<6>() = m_v_flex.head<6>() + m_v_kin.head<6>();
1296  // m_v_sot.head<6>() = m_v_gyr.head<6>() + m_v_kin.head<6>();
1297  // m_v_sot.head<6>() = m_v_gyr.head<6>();
1298  //~ m_v_sot.head<6>() = m_v_imu.head<6>();
1299 
1300  m_v_sot.tail(m_robot_util->m_nbJoints) = dq;
1301  m_v_kin.tail(m_robot_util->m_nbJoints) = dq;
1302  m_v_flex.tail(m_robot_util->m_nbJoints) = dq;
1303  m_v_gyr.tail(m_robot_util->m_nbJoints) = dq;
1304  m_v_imu.tail(m_robot_util->m_nbJoints) = dq;
1305  s = m_v_sot;
1306  }
1307  getProfiler().stop(PROFILE_BASE_VELOCITY_ESTIMATION);
1308  return s;
1309 }
1310 
1312  if (!m_initSucceeded) {
1313  SEND_WARNING_STREAM_MSG(
1314  "Cannot compute signal v_kin before initialization!");
1315  return s;
1316  }
1317  m_vSOUT(iter);
1318  s = m_v_kin;
1319  return s;
1320 }
1321 
1323  if (!m_initSucceeded) {
1324  SEND_WARNING_STREAM_MSG(
1325  "Cannot compute signal v_flex before initialization!");
1326  return s;
1327  }
1328  m_vSOUT(iter);
1329  s = m_v_flex + m_v_kin;
1330  return s;
1331 }
1332 
1334  if (!m_initSucceeded) {
1335  SEND_WARNING_STREAM_MSG(
1336  "Cannot compute signal v_imu before initialization!");
1337  return s;
1338  }
1339  m_vSOUT(iter);
1340  s = m_v_imu;
1341  return s;
1342 }
1343 
1345  if (!m_initSucceeded) {
1346  SEND_WARNING_STREAM_MSG(
1347  "Cannot compute signal v_gyr before initialization!");
1348  return s;
1349  }
1350  m_vSOUT(iter);
1351  s = m_v_gyr;
1352  return s;
1353 }
1354 
1356  if (!m_initSucceeded) {
1357  SEND_WARNING_STREAM_MSG(
1358  "Cannot compute signal v_ac before initialization!");
1359  return s;
1360  }
1361  m_vSOUT(iter);
1362  s = m_v_ac;
1363  return s;
1364 }
1365 
1367  if (!m_initSucceeded) {
1368  SEND_WARNING_STREAM_MSG(
1369  "Cannot compute signal a_ac before initialization!");
1370  return s;
1371  }
1372  m_vSOUT(iter);
1373  s = m_a_ac;
1374  return s;
1375 }
1376 
1377 /* --- COMMANDS ---------------------------------------------------------- */
1378 
1379 /* ------------------------------------------------------------------- */
1380 /* --- ENTITY -------------------------------------------------------- */
1381 /* ------------------------------------------------------------------- */
1382 
1383 void TalosBaseEstimator::display(std::ostream& os) const {
1384  os << "TalosBaseEstimator " << getName();
1385  try {
1386  getProfiler().report_all(3, os);
1387  } catch (ExceptionSignal e) {
1388  }
1389 }
1390 } // namespace talos_balance
1391 } // namespace sot
1392 } // namespace dynamicgraph
dynamicgraph::sot::talos_balance::se3Interp
void se3Interp(const pinocchio::SE3 &s1, const pinocchio::SE3 &s2, const double alpha, pinocchio::SE3 &s12)
Definition: talos-base-estimator.cpp:36
sot_talos_balance.test.appli_admittance_end_effector.q
list q
Definition: appli_admittance_end_effector.py:30
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_zmp_margin_rf
double m_zmp_margin_rf
margin used for computing zmp weight
Definition: talos-base-estimator.hh:251
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_oMlfs_xyzquat
Vector7 m_oMlfs_xyzquat
transformation from world to right foot sole
Definition: talos-base-estimator.hh:293
PROFILE_BASE_POSITION_ESTIMATION
#define PROFILE_BASE_POSITION_ESTIMATION
Definition: talos-base-estimator.cpp:147
sot_talos_balance.test.appli_admittance_end_effector.sot
sot
Definition: appli_admittance_end_effector.py:117
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_q_pin
Eigen::VectorXd m_q_pin
Definition: talos-base-estimator.hh:311
dynamicgraph::sot::talos_balance::TalosBaseEstimator::display
virtual void display(std::ostream &os) const
filtered weight of the estimation coming from the right foot
Definition: talos-base-estimator.cpp:1383
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_fz_margin_lf
double m_fz_margin_lf
margin used for computing zmp weight
Definition: talos-base-estimator.hh:252
dynamicgraph
Definition: treeview.dox:24
dynamicgraph::sot::talos_balance::math::Vector6
Eigen::Matrix< Scalar, 6, 1 > Vector6
Definition: fwd.hh:42
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_last_DCacc
Vector3 m_last_DCacc
Definition: talos-base-estimator.hh:322
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_oMlfs_default_ref
SE3 m_oMlfs_default_ref
Definition: talos-base-estimator.hh:295
dynamicgraph::sot::talos_balance::TalosBaseEstimator::reset_foot_positions_impl
void reset_foot_positions_impl(const Vector6 &ftlf, const Vector6 &ftrf)
Definition: talos-base-estimator.cpp:578
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_zmp_std_dev_lf
double m_zmp_std_dev_lf
Definition: talos-base-estimator.hh:240
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_data
pinocchio::Data * m_data
Pinocchio robot model.
Definition: talos-base-estimator.hh:285
INPUT_SIGNALS
#define INPUT_SIGNALS
Definition: talos-base-estimator.cpp:151
dynamicgraph::sot::talos_balance::TalosBaseEstimator::set_imu_weight
void set_imu_weight(const double &w)
Definition: talos-base-estimator.cpp:455
sot_talos_balance.talos.base_estimator_conf.K
tuple K
Definition: base_estimator_conf.py:4
dynamicgraph::sot::talos_balance::TalosBaseEstimator::set_normal_force_std_dev_right_foot
void set_normal_force_std_dev_right_foot(const double &std_dev)
Definition: talos-base-estimator.cpp:493
dynamicgraph::sot::talos_balance::TalosBaseEstimator::set_fz_stable_windows_size
void set_fz_stable_windows_size(const int &ws)
Definition: talos-base-estimator.cpp:428
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_last_DCvel
Vector3 m_last_DCvel
Definition: talos-base-estimator.hh:321
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_v_flex
Eigen::VectorXd m_v_flex
Definition: talos-base-estimator.hh:259
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_dt
double m_dt
true after the command resetFootPositions is called
Definition: talos-base-estimator.hh:223
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_fz_std_dev_rf
double m_fz_std_dev_rf
Definition: talos-base-estimator.hh:242
dynamicgraph::sot::talos_balance::TalosBaseEstimator::set_stiffness_right_foot
void set_stiffness_right_foot(const dynamicgraph::Vector &k)
Definition: talos-base-estimator.cpp:461
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_fz_std_dev_lf
double m_fz_std_dev_lf
Definition: talos-base-estimator.hh:244
dynamicgraph::sot::talos_balance::rpyToMatrix
void rpyToMatrix(double r, double p, double y, Eigen::Matrix3d &R)
Definition: talos-base-estimator.cpp:47
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_robot_util
RobotUtilShrPtr m_robot_util
sampling time step
Definition: talos-base-estimator.hh:224
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_sole_M_ftSens
SE3 m_sole_M_ftSens
Definition: talos-base-estimator.hh:304
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_v_pin
Eigen::VectorXd m_v_pin
robot configuration according to SoT convention
Definition: talos-base-estimator.hh:314
dynamicgraph::sot::talos_balance::TalosBaseEstimator::compute_zmp_weight
double compute_zmp_weight(const Vector2 &zmp, const Vector4 &foot_sizes, double std_dev, double margin)
Definition: talos-base-estimator.cpp:551
dynamicgraph::sot::talos_balance::TalosBaseEstimator::TalosBaseEstimator
EIGEN_MAKE_ALIGNED_OPERATOR_NEW TalosBaseEstimator(const std::string &name)
Definition: talos-base-estimator.cpp:174
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_right_foot_id
pinocchio::FrameIndex m_right_foot_id
foot sole to F/T sensor transformation
Definition: talos-base-estimator.hh:306
dynamicgraph::sot::talos_balance::TalosBaseEstimator::set_right_foot_sizes
void set_right_foot_sizes(const dynamicgraph::Vector &s)
Definition: talos-base-estimator.cpp:509
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_reset_foot_pos
bool m_reset_foot_pos
true if the entity has been successfully initialized
Definition: talos-base-estimator.hh:222
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_zmp_std_dev_rf
double m_zmp_std_dev_rf
weight of IMU for sensor fusion
Definition: talos-base-estimator.hh:238
dynamicgraph::sot::talos_balance::TalosBaseEstimator::set_normal_force_margin_right_foot
void set_normal_force_margin_right_foot(const double &margin)
Definition: talos-base-estimator.cpp:533
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_isFirstIterFlag
bool m_isFirstIterFlag
Normal distribution.
Definition: talos-base-estimator.hh:301
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_alpha_DC_acc
double m_alpha_DC_acc
Definition: talos-base-estimator.hh:271
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_fz_stable_windows_size
int m_fz_stable_windows_size
Definition: talos-base-estimator.hh:230
dynamicgraph::sot::talos_balance::DEFINE_SIGNAL_OUT_FUNCTION
DEFINE_SIGNAL_OUT_FUNCTION(dq, dynamicgraph::Vector)
Definition: admittance-controller-end-effector.cpp:210
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_model
pinocchio::Model m_model
Definition: talos-base-estimator.hh:284
PROFILE_BASE_KINEMATICS_COMPUTATION
#define PROFILE_BASE_KINEMATICS_COMPUTATION
Definition: talos-base-estimator.cpp:149
dynamicgraph::sot::talos_balance::TalosBaseEstimator::init
void init(const double &dt, const std::string &urdfFile)
Definition: talos-base-estimator.cpp:358
dynamicgraph::sot::talos_balance::TalosBaseEstimator::set_zmp_margin_right_foot
void set_zmp_margin_right_foot(const double &margin)
Definition: talos-base-estimator.cpp:525
dynamicgraph::sot::talos_balance::math::Vector3
Eigen::Matrix< Scalar, 3, 1 > Vector3
Definition: fwd.hh:41
dynamicgraph::sot::talos_balance::TalosBaseEstimator::compute_force_weight
double compute_force_weight(double fz, double std_dev, double margin)
Definition: talos-base-estimator.cpp:572
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_torsoMimu
pinocchio::SE3 m_torsoMimu
Pinocchio robot data.
Definition: talos-base-estimator.hh:286
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_oMrfs_xyzquat
Vector7 m_oMrfs_xyzquat
Definition: talos-base-estimator.hh:294
dynamicgraph::sot::talos_balance::TalosBaseEstimator::set_normal_force_margin_left_foot
void set_normal_force_margin_left_foot(const double &margin)
Definition: talos-base-estimator.cpp:538
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_K_lf
Vector6 m_K_lf
6d stiffness of right foot spring
Definition: talos-base-estimator.hh:255
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_IMU_frame_id
pinocchio::FrameIndex m_IMU_frame_id
Definition: talos-base-estimator.hh:309
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_initSucceeded
bool m_initSucceeded
Definition: talos-base-estimator.hh:220
talos-base-estimator.hh
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_lf_fz_stable_cpt
int m_lf_fz_stable_cpt
Definition: talos-base-estimator.hh:232
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_v_kin
Eigen::VectorXd m_v_kin
6d stiffness of left foot spring
Definition: talos-base-estimator.hh:257
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_oMlfs
SE3 m_oMlfs
world-to-base transformation obtained through right foot
Definition: talos-base-estimator.hh:291
sot_talos_balance.talos.base_estimator_conf.w_lf_in
float w_lf_in
Definition: base_estimator_conf.py:22
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_fz_margin_rf
double m_fz_margin_rf
margin used for computing normal force weight
Definition: talos-base-estimator.hh:253
dynamicgraph::sot::talos_balance::math::Vector
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > Vector
Definition: fwd.hh:36
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_torso_id
pinocchio::FrameIndex m_torso_id
Definition: talos-base-estimator.hh:308
sot_talos_balance.test.script_test_end_effector.wrench
wrench
Definition: script_test_end_effector.py:9
OUTPUT_SIGNALS
#define OUTPUT_SIGNALS
Definition: talos-base-estimator.cpp:158
sot_talos_balance.test.appli_admittance_single_joint.dt
dt
Definition: appli_admittance_single_joint.py:17
dynamicgraph::sot::talos_balance::TalosBaseEstimator::set_zmp_margin_left_foot
void set_zmp_margin_left_foot(const double &margin)
Definition: talos-base-estimator.cpp:529
dynamicgraph::sot::talos_balance::wEulerMean
double wEulerMean(double a1, double a2, double w1, double w2)
Definition: talos-base-estimator.cpp:106
dynamicgraph::sot::talos_balance::math::Index
std::size_t Index
Definition: fwd.hh:54
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_right_foot_is_stable
bool m_right_foot_is_stable
Definition: talos-base-estimator.hh:228
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_alpha_DC_vel
double m_alpha_DC_vel
Definition: talos-base-estimator.hh:273
PROFILE_BASE_VELOCITY_ESTIMATION
#define PROFILE_BASE_VELOCITY_ESTIMATION
Definition: talos-base-estimator.cpp:148
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_left_foot_id
pinocchio::FrameIndex m_left_foot_id
Definition: talos-base-estimator.hh:307
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_alpha_w_filter
double m_alpha_w_filter
Definition: talos-base-estimator.hh:276
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_v_sot
Eigen::VectorXd m_v_sot
robot velocities according to pinocchio convention
Definition: talos-base-estimator.hh:315
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_normal
normal m_normal
Definition: talos-base-estimator.hh:299
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_last_vel
Vector3 m_last_vel
base orientation in the world
Definition: talos-base-estimator.hh:320
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_v_imu
Eigen::VectorXd m_v_imu
Definition: talos-base-estimator.hh:261
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_rf_fz_stable_cpt
int m_rf_fz_stable_cpt
Definition: talos-base-estimator.hh:234
dynamicgraph::sot::talos_balance::eulerMean
double eulerMean(double a1, double a2)
Definition: talos-base-estimator.cpp:98
dynamicgraph::sot::talos_balance::TalosBaseEstimator::set_normal_force_std_dev_left_foot
void set_normal_force_std_dev_left_foot(const double &std_dev)
Definition: talos-base-estimator.cpp:501
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_K_rf
Vector6 m_K_rf
margin used for computing normal force weight
Definition: talos-base-estimator.hh:254
dynamicgraph::sot::talos_balance::TalosBaseEstimator::set_alpha_w_filter
void set_alpha_w_filter(const double &a)
Definition: talos-base-estimator.cpp:435
sot_talos_balance.talos.base_estimator_conf.K_fb_feet_poses
float K_fb_feet_poses
Definition: base_estimator_conf.py:11
dynamicgraph::sot::talos_balance::TalosBaseEstimator::compute_zmp
void compute_zmp(const Vector6 &w, Vector2 &zmp)
Definition: talos-base-estimator.cpp:543
dynamicgraph::sot::talos_balance::DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(AdmittanceControllerEndEffector, "AdmittanceControllerEndEffector")
dynamicgraph::sot::talos_balance::TalosBaseEstimator::set_alpha_DC_acc
void set_alpha_DC_acc(const double &a)
Definition: talos-base-estimator.cpp:441
dynamicgraph::sot::talos_balance::TalosBaseEstimator::set_left_foot_sizes
void set_left_foot_sizes(const dynamicgraph::Vector &s)
Definition: talos-base-estimator.cpp:517
dynamicgraph::sot::talos_balance::TalosBaseEstimator::reset_foot_positions
void reset_foot_positions()
Definition: talos-base-estimator.cpp:453
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_right_foot_sizes
Vector4 m_right_foot_sizes
Definition: talos-base-estimator.hh:248
dynamicgraph::sot::talos_balance::DEFINE_SIGNAL_INNER_FUNCTION
DEFINE_SIGNAL_INNER_FUNCTION(w_force, dynamicgraph::Vector)
Definition: admittance-controller-end-effector.cpp:145
dynamicgraph::sot::talos_balance::TalosBaseEstimator::kinematics_estimation
void kinematics_estimation(const Vector6 &ft, const Vector6 &K, const SE3 &oMfs, const pinocchio::FrameIndex foot_id, SE3 &oMff, SE3 &oMfa, SE3 &fsMff)
Definition: talos-base-estimator.cpp:640
dynamicgraph::sot::talos_balance::TalosBaseEstimator::set_zmp_std_dev_right_foot
void set_zmp_std_dev_right_foot(const double &std_dev)
Definition: talos-base-estimator.cpp:479
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_w_imu
double m_w_imu
Definition: talos-base-estimator.hh:237
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_zmp_margin_lf
double m_zmp_margin_lf
Definition: talos-base-estimator.hh:250
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_q_sot
Eigen::VectorXd m_q_sot
robot configuration according to pinocchio convention
Definition: talos-base-estimator.hh:312
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_left_foot_is_stable
bool m_left_foot_is_stable
Definition: talos-base-estimator.hh:226
dynamicgraph::sot::talos_balance::TalosBaseEstimator::set_stiffness_left_foot
void set_stiffness_left_foot(const dynamicgraph::Vector &k)
Definition: talos-base-estimator.cpp:470
dynamicgraph::sot::talos_balance::EntityClassName
AdmittanceControllerEndEffector EntityClassName
Definition: admittance-controller-end-effector.cpp:46
sot_talos_balance.talos.base_estimator_conf.w_rf_in
float w_rf_in
Definition: base_estimator_conf.py:23
sot_talos_balance.test.appli_dcm_zmp_control.name
name
Definition: appli_dcm_zmp_control.py:298
dynamicgraph::sot::talos_balance::TalosBaseEstimator::set_alpha_DC_vel
void set_alpha_DC_vel(const double &a)
Definition: talos-base-estimator.cpp:447
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_left_foot_sizes
Vector4 m_left_foot_sizes
Definition: talos-base-estimator.hh:246
dynamicgraph::sot::talos_balance::TalosBaseEstimator::set_zmp_std_dev_left_foot
void set_zmp_std_dev_left_foot(const double &std_dev)
Definition: talos-base-estimator.cpp:486
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_oMrfs_default_ref
SE3 m_oMrfs_default_ref
Definition: talos-base-estimator.hh:297
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_oMrfs
SE3 m_oMrfs
transformation from world to left foot sole
Definition: talos-base-estimator.hh:292
dynamicgraph::sot::talos_balance::matrixToRpy
void matrixToRpy(const Eigen::Matrix3d &M, Eigen::Vector3d &rpy)
Definition: talos-base-estimator.cpp:59
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_v_gyr
Eigen::VectorXd m_v_gyr
Definition: talos-base-estimator.hh:263