sot-talos-balance  2.0.5
Collection of dynamic-graph entities aimed at implementing balance control on talos.
talos-base-estimator.hh
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 #ifndef __sot_torque_control_base_estimator_H__
18 #define __sot_torque_control_base_estimator_H__
19 
20 /* --------------------------------------------------------------------- */
21 /* --- API ------------------------------------------------------------- */
22 /* --------------------------------------------------------------------- */
23 
24 #if defined(WIN32)
25 #if defined(base_estimator_EXPORTS)
26 #define TALOS_BASE_ESTIMATOR_EXPORT __declspec(dllexport)
27 #else
28 #define TALOS_BASE_ESTIMATOR_EXPORT __declspec(dllimport)
29 #endif
30 #else
31 #define TALOS_BASE_ESTIMATOR_EXPORT
32 #endif
33 
34 /* --------------------------------------------------------------------- */
35 /* --- INCLUDE --------------------------------------------------------- */
36 /* --------------------------------------------------------------------- */
37 #include <pinocchio/fwd.hpp>
38 // include pinocchio first
39 #include <dynamic-graph/signal-helper.h>
40 
41 #include <map>
42 #include <sot/core/matrix-geometry.hh>
43 #include <sot/core/robot-utils.hh>
44 
45 #include "boost/assign.hpp"
46 // #include <boost/random/normal_distribution.hpp>
47 #include <boost/math/distributions/normal.hpp> // for normal_distribution
48 
49 /* Pinocchio */
50 #include <pinocchio/algorithm/kinematics.hpp>
51 #include <pinocchio/multibody/model.hpp>
52 #include <pinocchio/parsers/urdf.hpp>
53 
54 namespace dynamicgraph {
55 namespace sot {
56 namespace talos_balance {
57 
58 /* --------------------------------------------------------------------- */
59 /* --- CLASS ----------------------------------------------------------- */
60 /* --------------------------------------------------------------------- */
61 
63 void se3Interp(const pinocchio::SE3& s1, const pinocchio::SE3& s2,
64  const double alpha, pinocchio::SE3& s12);
65 
67 void rpyToMatrix(double r, double p, double y, Eigen::Matrix3d& R);
68 
70 void rpyToMatrix(const Eigen::Vector3d& rpy, Eigen::Matrix3d& R);
71 
73 void matrixToRpy(const Eigen::Matrix3d& M, Eigen::Vector3d& rpy);
74 
76 // void quanternionMult(const Eigen::Vector4d & q1, const Eigen::Vector4d & q2,
77 // Eigen::Vector4d & q12);
78 
80 // void pointRotationByQuaternion(const Eigen::Vector3d & point,const
81 // Eigen::Vector4d & quat, Eigen::Vector3d & rotatedPoint);
82 
84 double eulerMean(double a1, double a2);
85 
87 double wEulerMean(double a1, double a2, double w1, double w2);
88 
90  : public ::dynamicgraph::Entity {
92  typedef pinocchio::SE3 SE3;
93  typedef Eigen::Vector2d Vector2;
94  typedef Eigen::Vector3d Vector3;
95  typedef Eigen::Vector4d Vector4;
96  typedef Vector6d Vector6;
97  typedef Vector7d Vector7;
98  typedef Eigen::Matrix3d Matrix3;
99  typedef boost::math::normal normal;
100 
101  DYNAMIC_GRAPH_ENTITY_DECL();
102 
103  public:
104  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
105 
106  /* --- CONSTRUCTOR ---- */
107  TalosBaseEstimator(const std::string& name);
108 
109  void init(const double& dt, const std::string& urdfFile);
110 
111  void set_fz_stable_windows_size(const int& ws);
112  void set_alpha_w_filter(const double& a);
113  void set_alpha_DC_acc(const double& a);
114  void set_alpha_DC_vel(const double& a);
115  void reset_foot_positions();
116  void set_imu_weight(const double& w);
117  void set_zmp_std_dev_right_foot(const double& std_dev);
118  void set_zmp_std_dev_left_foot(const double& std_dev);
119  void set_normal_force_std_dev_right_foot(const double& std_dev);
120  void set_normal_force_std_dev_left_foot(const double& std_dev);
121  void set_stiffness_right_foot(const dynamicgraph::Vector& k);
122  void set_stiffness_left_foot(const dynamicgraph::Vector& k);
123  void set_right_foot_sizes(const dynamicgraph::Vector& s);
124  void set_left_foot_sizes(const dynamicgraph::Vector& s);
125  void set_zmp_margin_right_foot(const double& margin);
126  void set_zmp_margin_left_foot(const double& margin);
127  void set_normal_force_margin_right_foot(const double& margin);
128  void set_normal_force_margin_left_foot(const double& margin);
129 
130  void reset_foot_positions_impl(const Vector6& ftlf, const Vector6& ftrf);
131  void compute_zmp(const Vector6& w, Vector2& zmp);
132  double compute_zmp_weight(const Vector2& zmp, const Vector4& foot_sizes,
133  double std_dev, double margin);
134  double compute_force_weight(double fz, double std_dev, double margin);
135  void kinematics_estimation(const Vector6& ft, const Vector6& K,
136  const SE3& oMfs,
137  const pinocchio::FrameIndex foot_id, SE3& oMff,
138  SE3& oMfa, SE3& fsMff);
139 
140  /* --- SIGNALS --- */
141  DECLARE_SIGNAL_IN(joint_positions, dynamicgraph::Vector);
142  DECLARE_SIGNAL_IN(joint_velocities, dynamicgraph::Vector);
143  DECLARE_SIGNAL_IN(imu_quaternion, dynamicgraph::Vector);
144  DECLARE_SIGNAL_IN(forceLLEG, dynamicgraph::Vector);
145  DECLARE_SIGNAL_IN(forceRLEG, dynamicgraph::Vector);
146  DECLARE_SIGNAL_IN(
147  dforceLLEG,
149  DECLARE_SIGNAL_IN(
150  dforceRLEG,
152  DECLARE_SIGNAL_IN(
153  w_lf_in, double);
154  DECLARE_SIGNAL_IN(
155  w_rf_in, double);
156  DECLARE_SIGNAL_IN(
158  double);
159  DECLARE_SIGNAL_IN(lf_ref_xyzquat, dynamicgraph::Vector);
161  DECLARE_SIGNAL_IN(rf_ref_xyzquat, dynamicgraph::Vector);
162  DECLARE_SIGNAL_IN(accelerometer, dynamicgraph::Vector);
163  DECLARE_SIGNAL_IN(gyroscope, dynamicgraph::Vector);
164 
165  DECLARE_SIGNAL_INNER(kinematics_computations, dynamicgraph::Vector);
166 
167  DECLARE_SIGNAL_OUT(
169  DECLARE_SIGNAL_OUT(v, dynamicgraph::Vector);
170  DECLARE_SIGNAL_OUT(
171  v_kin, dynamicgraph::Vector);
172  DECLARE_SIGNAL_OUT(
174  v_flex,
176  DECLARE_SIGNAL_OUT(
178  v_imu,
180  DECLARE_SIGNAL_OUT(
182  v_gyr, dynamicgraph::Vector);
183  DECLARE_SIGNAL_OUT(lf_xyzquat, dynamicgraph::Vector);
186  DECLARE_SIGNAL_OUT(rf_xyzquat, dynamicgraph::Vector);
187  DECLARE_SIGNAL_OUT(a_ac,
189  DECLARE_SIGNAL_OUT(v_ac,
192 
194  DECLARE_SIGNAL_OUT(
195  q_lf,
197  DECLARE_SIGNAL_OUT(
198  q_rf,
200  DECLARE_SIGNAL_OUT(
201  q_imu,
203  DECLARE_SIGNAL_OUT(
204  w_lf, double);
205  DECLARE_SIGNAL_OUT(
206  w_rf, double);
207  DECLARE_SIGNAL_OUT(
208  w_lf_filtered,
209  double);
210  DECLARE_SIGNAL_OUT(
211  w_rf_filtered,
212  double);
213 
214  /* --- COMMANDS --- */
215  /* --- ENTITY INHERITANCE --- */
216  virtual void display(std::ostream& os) const;
217 
218  protected:
219  bool
221  bool
223  double m_dt;
224  RobotUtilShrPtr m_robot_util;
225 
227  bool m_right_foot_is_stable;
229  int m_fz_stable_windows_size;
231  int m_lf_fz_stable_cpt;
233  int m_rf_fz_stable_cpt;
235  /* Estimator parameters */
237  double m_w_imu;
239  double m_zmp_std_dev_lf;
241  double m_fz_std_dev_rf;
243  double m_fz_std_dev_lf;
245  Vector4 m_left_foot_sizes;
247  Vector4 m_right_foot_sizes;
249  double m_zmp_margin_lf;
252  double m_fz_margin_lf;
253  double m_fz_margin_rf;
254  Vector6 m_K_rf;
255  Vector6 m_K_lf;
256 
257  Eigen::VectorXd m_v_kin;
258  Eigen::VectorXd m_v_flex;
260  Eigen::VectorXd m_v_imu;
262  Eigen::VectorXd m_v_gyr;
264 
266  Vector3
268  Vector3 m_a_ac;
269 
271  double m_alpha_DC_acc;
272  double m_alpha_DC_vel;
274 
277 
280  double m_w_rf_filtered;
282 
284  pinocchio::Model m_model;
285  pinocchio::Data* m_data;
286  pinocchio::SE3 m_torsoMimu;
287  pinocchio::SE3
289  pinocchio::SE3
291  SE3 m_oMlfs;
292  SE3 m_oMrfs;
296  SE3 m_oMrfs_default_ref;
298  normal m_normal;
300 
302 
305 
306  pinocchio::FrameIndex m_right_foot_id;
307  pinocchio::FrameIndex m_left_foot_id;
308  pinocchio::FrameIndex m_torso_id;
309  pinocchio::FrameIndex m_IMU_frame_id;
310  Eigen::VectorXd
312  Eigen::VectorXd m_q_sot;
313  Eigen::VectorXd
315  Eigen::VectorXd m_v_sot;
316  Matrix3 m_oRtorso;
317  Matrix3 m_oRff;
318 
319  /* Filter buffers*/
320  Vector3 m_last_vel;
321  Vector3 m_last_DCvel;
322  Vector3 m_last_DCacc;
323 
324 }; // class TalosBaseEstimator
325 
326 } // namespace talos_balance
327 } // namespace sot
328 } // namespace dynamicgraph
329 
330 #endif // #ifndef __sot_torque_control_free_flyer_locator_H__
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
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::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::m_a_ac
Vector3 m_a_ac
velocity of the base in the world with DC component removed
Definition: talos-base-estimator.hh:268
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_data
pinocchio::Data * m_data
Pinocchio robot model.
Definition: talos-base-estimator.hh:285
sot_talos_balance.talos.base_estimator_conf.K
tuple K
Definition: base_estimator_conf.py:4
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_oMff_lf
pinocchio::SE3 m_oMff_lf
chest to imu transformation
Definition: talos-base-estimator.hh:288
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_v_ac
Vector3 m_v_ac
Definition: talos-base-estimator.hh:267
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_last_DCvel
Vector3 m_last_DCvel
Definition: talos-base-estimator.hh:321
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::rpyToMatrix
void rpyToMatrix(double r, double p, double y, Eigen::Matrix3d &R)
Definition: talos-base-estimator.cpp:47
dynamicgraph::sot::talos_balance::TalosBaseEstimator
Definition: talos-base-estimator.hh:89
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::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::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::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
sot_talos_balance.test.script_test_end_effector.y
y
Definition: script_test_end_effector.py:11
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_model
pinocchio::Model m_model
Definition: talos-base-estimator.hh:284
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_oRff
Matrix3 m_oRff
chest orientation in the world from angular fusion
Definition: talos-base-estimator.hh:317
dynamicgraph::sot::talos_balance::math::Vector3
Eigen::Matrix< Scalar, 3, 1 > Vector3
Definition: fwd.hh:41
TALOS_BASE_ESTIMATOR_EXPORT
#define TALOS_BASE_ESTIMATOR_EXPORT
Definition: talos-base-estimator.hh:31
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::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
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.appli_admittance_single_joint.dt
dt
Definition: appli_admittance_single_joint.py:17
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_oMff_rf
pinocchio::SE3 m_oMff_rf
world-to-base transformation obtained through left foot
Definition: talos-base-estimator.hh:290
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::TalosBaseEstimator::m_left_foot_id
pinocchio::FrameIndex m_left_foot_id
Definition: talos-base-estimator.hh:307
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_alpha_w_filter
double m_alpha_w_filter
Definition: talos-base-estimator.hh:276
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::eulerMean
double eulerMean(double a1, double a2)
Definition: talos-base-estimator.cpp:98
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
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::m_w_lf_filtered
double m_w_lf_filtered
Definition: talos-base-estimator.hh:279
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_w_imu
double m_w_imu
Definition: talos-base-estimator.hh:237
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::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
dynamicgraph::sot::talos_balance::TalosBaseEstimator::m_oRtorso
Matrix3 m_oRtorso
robot velocities according to SoT convention
Definition: talos-base-estimator.hh:316
sot_talos_balance.test.appli_dcm_zmp_control.name
name
Definition: appli_dcm_zmp_control.py:298
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