sot-talos-balance  2.0.5
Collection of dynamic-graph entities aimed at implementing balance control on talos.
distribute-wrench.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2018, Gepetto team, LAAS-CNRS
3  *
4  * This file is part of sot-talos-balance.
5  * sot-talos-balance 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-talos-balance 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-talos-balance. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #ifndef __sot_talos_balance_distribute_wrench_H__
18 #define __sot_talos_balance_distribute_wrench_H__
19 
20 /* --------------------------------------------------------------------- */
21 /* --- API ------------------------------------------------------------- */
22 /* --------------------------------------------------------------------- */
23 
24 #if defined(WIN32)
25 #if defined(position_controller_EXPORTS)
26 #define DISTRIBUTE_WRENCH_EXPORT __declspec(dllexport)
27 #else
28 #define DISTRIBUTE_WRENCH_EXPORT __declspec(dllimport)
29 #endif
30 #else
31 #define DISTRIBUTE_WRENCH_EXPORT
32 #endif
33 
34 /* --------------------------------------------------------------------- */
35 /* --- INCLUDE --------------------------------------------------------- */
36 /* --------------------------------------------------------------------- */
37 
38 #include <pinocchio/fwd.hpp>
39 // include pinochcio first
40 #include <dynamic-graph/signal-helper.h>
41 
42 #include <eiquadprog/eiquadprog-fast.hpp>
43 #include <map>
44 #include <pinocchio/multibody/data.hpp>
45 #include <pinocchio/multibody/model.hpp>
46 #include <sot/core/robot-utils.hh>
47 
48 #include "boost/assign.hpp"
49 
50 namespace dynamicgraph {
51 namespace sot {
52 namespace talos_balance {
53 
54 /* --------------------------------------------------------------------- */
55 /* --- CLASS ----------------------------------------------------------- */
56 /* --------------------------------------------------------------------- */
57 
59  : public ::dynamicgraph::Entity {
60  DYNAMIC_GRAPH_ENTITY_DECL();
61 
62  public:
63  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
64 
65  /* --- CONSTRUCTOR ---- */
66  DistributeWrench(const std::string& name);
67 
68  void init(const std::string& robotName);
69 
70  /* --- SIGNALS --- */
71  DECLARE_SIGNAL_IN(wrenchDes, dynamicgraph::Vector);
72  DECLARE_SIGNAL_IN(q, dynamicgraph::Vector);
73  DECLARE_SIGNAL_IN(rho, double);
74  DECLARE_SIGNAL_IN(phase, int);
75  DECLARE_SIGNAL_IN(frictionCoefficient, double);
76 
77  DECLARE_SIGNAL_IN(wSum, double);
78  DECLARE_SIGNAL_IN(wNorm, double);
79  DECLARE_SIGNAL_IN(wRatio, double);
80  DECLARE_SIGNAL_IN(wAnkle, dynamicgraph::Vector);
81 
82  DECLARE_SIGNAL_INNER(kinematics_computations, int);
83  DECLARE_SIGNAL_INNER(qp_computations, int);
84 
85  DECLARE_SIGNAL_OUT(wrenchLeft, dynamicgraph::Vector);
86  DECLARE_SIGNAL_OUT(ankleWrenchLeft, dynamicgraph::Vector);
87  DECLARE_SIGNAL_OUT(surfaceWrenchLeft, dynamicgraph::Vector);
88  DECLARE_SIGNAL_OUT(copLeft, dynamicgraph::Vector);
89  DECLARE_SIGNAL_OUT(wrenchRight, dynamicgraph::Vector);
90  DECLARE_SIGNAL_OUT(ankleWrenchRight, dynamicgraph::Vector);
91  DECLARE_SIGNAL_OUT(surfaceWrenchRight, dynamicgraph::Vector);
92  DECLARE_SIGNAL_OUT(copRight, dynamicgraph::Vector);
93 
94  DECLARE_SIGNAL_OUT(wrenchRef, dynamicgraph::Vector);
95  DECLARE_SIGNAL_OUT(zmpRef, dynamicgraph::Vector);
96  DECLARE_SIGNAL_OUT(emergencyStop, bool);
97 
98  public:
99  /* --- COMMANDS --- */
100  /* --- ENTITY INHERITANCE --- */
101  virtual void display(std::ostream& os) const;
102 
103  Eigen::Vector3d computeCoP(const dynamicgraph::Vector& wrench,
104  const pinocchio::SE3& pose) const;
105 
106  void set_right_foot_sizes(const dynamicgraph::Vector& s);
107  void set_left_foot_sizes(const dynamicgraph::Vector& s);
108 
109  double m_eps;
110 
111  protected:
112  bool
114  pinocchio::Model m_model;
115  pinocchio::Data m_data;
116  RobotUtilShrPtr m_robot_util;
117 
118  // pinocchio::SE3 m_ankle_M_ftSens; /// ankle to F/T sensor
119  // transformation
120  pinocchio::SE3 m_ankle_M_sole;
121 
122  pinocchio::FrameIndex m_left_foot_id;
123  pinocchio::FrameIndex m_right_foot_id;
124 
125  pinocchio::SE3 m_contactLeft;
126  pinocchio::SE3 m_contactRight;
127 
128  Eigen::Matrix<double, 6, 1> m_wrenchLeft;
129  Eigen::Matrix<double, 6, 1> m_wrenchRight;
130 
131  Eigen::Vector4d m_left_foot_sizes;
132  Eigen::Vector4d m_right_foot_sizes;
134 
136  void computeWrenchFaceMatrix(const double mu);
137  Eigen::Matrix<double, 16, 6> m_wrenchFaceMatrix; // for modelling contact
138 
139  eiquadprog::solvers::EiquadprogFast m_qp1; // saturate wrench
140  eiquadprog::solvers::EiquadprogFast m_qp2; // distribute wrench
141 
142  // QP problem matrices -- SSP
143  Eigen::MatrixXd m_Q1;
144  Eigen::VectorXd m_C1;
145 
146  Eigen::MatrixXd m_Aeq1;
147  Eigen::VectorXd m_Beq1;
148 
149  Eigen::MatrixXd m_Aineq1;
150  Eigen::VectorXd m_Bineq1;
151 
152  Eigen::VectorXd m_result1;
153 
154  // QP problem matrices -- DSP
155  Eigen::MatrixXd m_Q2;
156  Eigen::VectorXd m_C2;
157 
158  Eigen::MatrixXd m_Aeq2;
159  Eigen::VectorXd m_Beq2;
160 
161  Eigen::MatrixXd m_Aineq2;
162  Eigen::VectorXd m_Bineq2;
163 
164  Eigen::VectorXd m_result2;
165 
166  double m_wSum;
167  double m_wNorm;
168  double m_wRatio;
169  Eigen::VectorXd m_wAnkle;
170 
171  void distributeWrench(const Eigen::VectorXd& wrenchDes, const double rho,
172  const double mu);
173  void saturateWrench(const Eigen::VectorXd& wrenchDes, const int phase,
174  const double mu);
175 
177 }; // class DistributeWrench
178 
179 } // namespace talos_balance
180 } // namespace sot
181 } // namespace dynamicgraph
182 
183 #endif // #ifndef __sot_talos_balance_distribute_wrench_H__
sot_talos_balance.test.appli_admittance_end_effector.q
list q
Definition: appli_admittance_end_effector.py:30
dynamicgraph::sot::talos_balance::DistributeWrench::m_wRatio
double m_wRatio
Definition: distribute-wrench.hh:168
dynamicgraph::sot::talos_balance::DistributeWrench::m_C1
Eigen::VectorXd m_C1
Definition: distribute-wrench.hh:144
dynamicgraph::sot::talos_balance::DistributeWrench::m_Bineq2
Eigen::VectorXd m_Bineq2
Definition: distribute-wrench.hh:162
sot_talos_balance.test.appli_admittance_end_effector.sot
sot
Definition: appli_admittance_end_effector.py:117
sot_talos_balance.test.appli_ankle_admittance.robotName
string robotName
Definition: appli_ankle_admittance.py:33
dynamicgraph::sot::talos_balance::DistributeWrench::m_Q1
Eigen::MatrixXd m_Q1
Definition: distribute-wrench.hh:143
dynamicgraph::sot::talos_balance::DistributeWrench::m_data
pinocchio::Data m_data
Pinocchio robot model.
Definition: distribute-wrench.hh:115
dynamicgraph
Definition: treeview.dox:24
dynamicgraph::sot::talos_balance::DistributeWrench::m_left_foot_sizes
Eigen::Vector4d m_left_foot_sizes
Definition: distribute-wrench.hh:131
sot_talos_balance.talos.distribute_conf.wAnkle
list wAnkle
Definition: distribute_conf.py:13
dynamicgraph::sot::talos_balance::DistributeWrench::m_Beq1
Eigen::VectorXd m_Beq1
Definition: distribute-wrench.hh:147
sot_talos_balance.talos.distribute_conf.wNorm
float wNorm
Definition: distribute_conf.py:11
dynamicgraph::sot::talos_balance::DistributeWrench::m_emergency_stop_triggered
bool m_emergency_stop_triggered
Definition: distribute-wrench.hh:176
dynamicgraph::sot::talos_balance::DistributeWrench::m_Aeq2
Eigen::MatrixXd m_Aeq2
Definition: distribute-wrench.hh:158
dynamicgraph::sot::talos_balance::DistributeWrench::m_qp1
eiquadprog::solvers::EiquadprogFast m_qp1
Definition: distribute-wrench.hh:139
sot_talos_balance.talos.distribute_conf.frictionCoefficient
float frictionCoefficient
Definition: distribute_conf.py:8
dynamicgraph::sot::talos_balance::DistributeWrench::m_Aineq2
Eigen::MatrixXd m_Aineq2
Definition: distribute-wrench.hh:161
DISTRIBUTE_WRENCH_EXPORT
#define DISTRIBUTE_WRENCH_EXPORT
Definition: distribute-wrench.hh:31
dynamicgraph::sot::talos_balance::DistributeWrench::m_Q2
Eigen::MatrixXd m_Q2
Definition: distribute-wrench.hh:155
sot_talos_balance.talos.distribute_conf.wSum
float wSum
Definition: distribute_conf.py:10
dynamicgraph::sot::talos_balance::DistributeWrench::m_wNorm
double m_wNorm
Definition: distribute-wrench.hh:167
dynamicgraph::sot::talos_balance::DistributeWrench::m_contactRight
pinocchio::SE3 m_contactRight
Definition: distribute-wrench.hh:126
dynamicgraph::sot::talos_balance::DistributeWrench::m_wrenchRight
Eigen::Matrix< double, 6, 1 > m_wrenchRight
Definition: distribute-wrench.hh:129
dynamicgraph::sot::talos_balance::DistributeWrench::m_wrenchFaceMatrix
Eigen::Matrix< double, 16, 6 > m_wrenchFaceMatrix
Definition: distribute-wrench.hh:137
dynamicgraph::sot::talos_balance::DistributeWrench::m_result1
Eigen::VectorXd m_result1
Definition: distribute-wrench.hh:152
dynamicgraph::sot::talos_balance::DistributeWrench::m_ankle_M_sole
pinocchio::SE3 m_ankle_M_sole
Definition: distribute-wrench.hh:120
dynamicgraph::sot::talos_balance::DistributeWrench::m_wrenchLeft
Eigen::Matrix< double, 6, 1 > m_wrenchLeft
Definition: distribute-wrench.hh:128
sot_talos_balance.talos.balance_ctrl_conf.mu
mu
Definition: balance_ctrl_conf.py:71
dynamicgraph::sot::talos_balance::DistributeWrench::m_model
pinocchio::Model m_model
true if the entity has been successfully initialized
Definition: distribute-wrench.hh:114
dynamicgraph::sot::talos_balance::DistributeWrench
Definition: distribute-wrench.hh:58
dynamicgraph::sot::talos_balance::DistributeWrench::m_Aeq1
Eigen::MatrixXd m_Aeq1
Definition: distribute-wrench.hh:146
dynamicgraph::sot::talos_balance::DistributeWrench::m_C2
Eigen::VectorXd m_C2
Definition: distribute-wrench.hh:156
dynamicgraph::sot::talos_balance::DistributeWrench::m_right_foot_id
pinocchio::FrameIndex m_right_foot_id
Definition: distribute-wrench.hh:123
dynamicgraph::sot::talos_balance::math::Vector
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > Vector
Definition: fwd.hh:36
sot_talos_balance.test.script_test_end_effector.wrench
wrench
Definition: script_test_end_effector.py:9
dynamicgraph::sot::talos_balance::DistributeWrench::m_Beq2
Eigen::VectorXd m_Beq2
Definition: distribute-wrench.hh:159
dynamicgraph::sot::talos_balance::DistributeWrench::m_wAnkle
Eigen::VectorXd m_wAnkle
Definition: distribute-wrench.hh:169
dynamicgraph::sot::talos_balance::DistributeWrench::m_robot_util
RobotUtilShrPtr m_robot_util
Pinocchio robot data.
Definition: distribute-wrench.hh:116
dynamicgraph::sot::talos_balance::DistributeWrench::m_Aineq1
Eigen::MatrixXd m_Aineq1
Definition: distribute-wrench.hh:149
dynamicgraph::sot::talos_balance::DistributeWrench::m_Bineq1
Eigen::VectorXd m_Bineq1
Definition: distribute-wrench.hh:150
dynamicgraph::sot::talos_balance::DistributeWrench::m_initSucceeded
bool m_initSucceeded
Definition: distribute-wrench.hh:113
dynamicgraph::sot::talos_balance::DistributeWrench::m_result2
Eigen::VectorXd m_result2
Definition: distribute-wrench.hh:164
sot_talos_balance.talos.distribute_conf.wRatio
float wRatio
Definition: distribute_conf.py:12
dynamicgraph::sot::talos_balance::DistributeWrench::m_qp2
eiquadprog::solvers::EiquadprogFast m_qp2
Definition: distribute-wrench.hh:140
dynamicgraph::sot::talos_balance::DistributeWrench::m_left_foot_id
pinocchio::FrameIndex m_left_foot_id
ankle to sole transformation
Definition: distribute-wrench.hh:122
sot_talos_balance.test.appli_dcm_zmp_control.name
name
Definition: appli_dcm_zmp_control.py:298
dynamicgraph::sot::talos_balance::DistributeWrench::m_eps
double m_eps
Definition: distribute-wrench.hh:109
dynamicgraph::sot::talos_balance::DistributeWrench::m_wSum
double m_wSum
Definition: distribute-wrench.hh:166
dynamicgraph::sot::talos_balance::DistributeWrench::m_contactLeft
pinocchio::SE3 m_contactLeft
Definition: distribute-wrench.hh:125