sot-talos-balance  2.0.5
Collection of dynamic-graph entities aimed at implementing balance control on talos.
simple-controller-6d.cpp
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 
18 
19 #include <dynamic-graph/all-commands.h>
20 #include <dynamic-graph/command-bind.h>
21 #include <dynamic-graph/factory.h>
22 
23 #include <sot/core/debug.hh>
24 
25 #include "sot/core/stop-watch.hh"
26 
27 namespace dynamicgraph {
28 namespace sot {
29 namespace talos_balance {
30 namespace dg = ::dynamicgraph;
31 using namespace dg;
32 using namespace dg::command;
33 
34 // Size to be aligned "-------------------------------------------------------"
35 #define PROFILE_SIMPLE_CONTROLLER_6D_DX_REF_COMPUTATION \
36  "SimpleController6d: v_ref computation "
37 
38 #define INPUT_SIGNALS m_KpSIN << m_xSIN << m_x_desSIN << m_v_desSIN
39 
40 #define OUTPUT_SIGNALS m_v_refSOUT
41 
44 typedef SimpleController6d EntityClassName;
45 
46 /* --- DG FACTORY ---------------------------------------------------- */
47 DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(SimpleController6d, "SimpleController6d");
48 
49 /* ------------------------------------------------------------------- */
50 /* --- CONSTRUCTION -------------------------------------------------- */
51 /* ------------------------------------------------------------------- */
53  : Entity(name),
54  CONSTRUCT_SIGNAL_IN(Kp, dynamicgraph::Vector),
55  CONSTRUCT_SIGNAL_IN(x, dynamicgraph::Vector),
56  CONSTRUCT_SIGNAL_IN(x_des, dynamicgraph::Vector),
57  CONSTRUCT_SIGNAL_IN(v_des, dynamicgraph::Vector),
58  CONSTRUCT_SIGNAL_OUT(v_ref, dynamicgraph::Vector, INPUT_SIGNALS),
59  m_initSucceeded(false) {
60  Entity::signalRegistration(INPUT_SIGNALS << OUTPUT_SIGNALS);
61 
62  /* Commands. */
63  addCommand("init",
64  makeCommandVoid0(*this, &SimpleController6d::init,
65  docCommandVoid0("Initialize the entity.")));
66 }
67 
69 
70 template <typename Derived>
71 Eigen::Matrix3d SimpleController6d::skew(const Eigen::MatrixBase<Derived>& v) {
72  Eigen::Matrix3d M;
73  M << 0, -v[2], v[1], v[2], 0, -v[0], -v[1], v[0], 0;
74  return M;
75 }
76 
77 /* ------------------------------------------------------------------- */
78 /* --- SIGNALS ------------------------------------------------------- */
79 /* ------------------------------------------------------------------- */
80 
82  if (!m_initSucceeded) {
83  SEND_WARNING_STREAM_MSG(
84  "Cannot compute signal v_ref before initialization!");
85  return s;
86  }
87  if (s.size() != 6) s.resize(6);
88 
90 
91  const Vector& Kp = m_KpSIN(iter);
92 
93  const MatrixHomogeneous& x = m_xSIN(iter);
94  const MatrixHomogeneous& x_des = m_x_desSIN(iter);
95 
96  // const MatrixHomogeneous & x_err = x_des * x.inverse();
97 
98  const Eigen::Vector3d e_O =
99  0.5 * (x.linear().col(0).cross(x_des.linear().col(0)) +
100  x.linear().col(1).cross(x_des.linear().col(1)) +
101  x.linear().col(2).cross(x_des.linear().col(2)));
102 
103  const Eigen::Matrix3d L =
104  -0.5 * (skew(x_des.linear().col(0)) * skew(x.linear().col(0)) +
105  skew(x_des.linear().col(1)) * skew(x.linear().col(1)) +
106  skew(x_des.linear().col(2)) * skew(x.linear().col(2)));
107 
108  Eigen::Matrix<double, 6, 1> dv_ref;
109 
110  // dv_ref.head<3>() = Kp.head<3>().cwiseProduct(x_err.translation());
111  dv_ref.head<3>() =
112  x.linear().transpose() *
113  Kp.head<3>().cwiseProduct(x_des.translation() - x.translation());
114 
115  dv_ref.tail<3>() =
116  x.linear().transpose() * L.inverse() * Kp.tail<3>().cwiseProduct(e_O);
117 
118  if (m_v_desSIN.isPlugged()) {
119  const dynamicgraph::Vector& v_des = m_v_desSIN(iter);
120  s = v_des + dv_ref;
121  } else {
122  s = dv_ref;
123  }
124 
126 
127  return s;
128 }
129 
130 /* --- COMMANDS ---------------------------------------------------------- */
131 
132 /* ------------------------------------------------------------------- */
133 /* --- ENTITY -------------------------------------------------------- */
134 /* ------------------------------------------------------------------- */
135 
136 void SimpleController6d::display(std::ostream& os) const {
137  os << "SimpleController6d " << getName();
138  try {
139  getProfiler().report_all(3, os);
140  } catch (ExceptionSignal e) {
141  }
142 }
143 } // namespace talos_balance
144 } // namespace sot
145 } // namespace dynamicgraph
sot_talos_balance.test.appli_admittance_end_effector.sot
sot
Definition: appli_admittance_end_effector.py:117
dynamicgraph
Definition: treeview.dox:24
OUTPUT_SIGNALS
#define OUTPUT_SIGNALS
Definition: simple-controller-6d.cpp:40
dynamicgraph::sot::talos_balance::SimpleController6d::init
void init()
Definition: simple-controller-6d.cpp:68
dynamicgraph::sot::talos_balance::SimpleController6d::m_initSucceeded
bool m_initSucceeded
Definition: simple-controller-6d.hh:84
dynamicgraph::sot::talos_balance::SimpleController6d::SimpleController6d
EIGEN_MAKE_ALIGNED_OPERATOR_NEW SimpleController6d(const std::string &name)
Definition: simple-controller-6d.cpp:52
dynamicgraph::sot::talos_balance::DEFINE_SIGNAL_OUT_FUNCTION
DEFINE_SIGNAL_OUT_FUNCTION(dq, dynamicgraph::Vector)
Definition: admittance-controller-end-effector.cpp:210
sot_talos_balance.test.script_test_end_effector.x
x
Definition: script_test_end_effector.py:10
sot_talos_balance.test.appli_admittance_single_joint.Kp
list Kp
Definition: appli_admittance_single_joint.py:33
dynamicgraph::sot::talos_balance::math::Vector
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > Vector
Definition: fwd.hh:36
dynamicgraph::sot::talos_balance::SimpleController6d::skew
Eigen::Matrix3d skew(const Eigen::MatrixBase< Derived > &v)
Definition: simple-controller-6d.cpp:71
dynamicgraph::sot::talos_balance::DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(AdmittanceControllerEndEffector, "AdmittanceControllerEndEffector")
simple-controller-6d.hh
PROFILE_SIMPLE_CONTROLLER_6D_DX_REF_COMPUTATION
#define PROFILE_SIMPLE_CONTROLLER_6D_DX_REF_COMPUTATION
Definition: simple-controller-6d.cpp:35
dynamicgraph::sot::talos_balance::EntityClassName
AdmittanceControllerEndEffector EntityClassName
Definition: admittance-controller-end-effector.cpp:46
INPUT_SIGNALS
#define INPUT_SIGNALS
Definition: simple-controller-6d.cpp:38
sot_talos_balance.test.appli_dcm_zmp_control.name
name
Definition: appli_dcm_zmp_control.py:298
dynamicgraph::sot::talos_balance::SimpleController6d::display
virtual void display(std::ostream &os) const
Definition: simple-controller-6d.cpp:136