sot-talos-balance  2.0.5
Collection of dynamic-graph entities aimed at implementing balance control on talos.
euler-to-quat.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/factory.h>
21 
22 #include <Eigen/Core>
23 #include <sot/core/debug.hh>
24 #include <sot/core/stop-watch.hh>
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 
33 // Size to be aligned "-------------------------------------------------------"
34 #define PROFILE_EULERTOQUAT_COMPUTATION \
35  "EulerToQuat computation "
36 
37 #define INPUT_SIGNALS m_eulerSIN
38 
39 #define OUTPUT_SIGNALS m_quaternionSOUT
40 
43 typedef EulerToQuat EntityClassName;
44 
45 /* --- DG FACTORY ---------------------------------------------------- */
46 DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(EulerToQuat, "EulerToQuat");
47 
48 /* ------------------------------------------------------------------- */
49 /* --- CONSTRUCTION -------------------------------------------------- */
50 /* ------------------------------------------------------------------- */
51 EulerToQuat::EulerToQuat(const std::string& name)
52  : Entity(name),
53  CONSTRUCT_SIGNAL_IN(euler, dynamicgraph::Vector),
54  CONSTRUCT_SIGNAL_OUT(quaternion, dynamicgraph::Vector, INPUT_SIGNALS) {
55  Entity::signalRegistration(INPUT_SIGNALS << OUTPUT_SIGNALS);
56 
57  /* Commands. */
58  addCommand("init",
59  makeCommandVoid0(*this, &EulerToQuat::init,
60  docCommandVoid0("Initialize the entity.")));
61 }
62 
63 /* ------------------------------------------------------------------- */
64 /* --- SIGNALS ------------------------------------------------------- */
65 /* ------------------------------------------------------------------- */
66 
68  const dynamicgraph::Vector& input = m_eulerSIN(iter);
69  const size_t sz = input.size();
70  if ((size_t)(s.size()) != (sz + 1)) s.resize(sz + 1);
71 
72  getProfiler().start(PROFILE_EULERTOQUAT_COMPUTATION);
73 
74  const Eigen::Vector3d& euler = input.segment<3>(3);
75 
76  const double roll = euler[0];
77  const double pitch = euler[1];
78  const double yaw = euler[2];
79 
80  Eigen::Quaterniond quat;
81  quat = Eigen::AngleAxisd(yaw, Eigen::Vector3d::UnitZ()) *
82  Eigen::AngleAxisd(pitch, Eigen::Vector3d::UnitY()) *
83  Eigen::AngleAxisd(roll, Eigen::Vector3d::UnitX());
84 
85  s.head<3>() = input.head<3>();
86 
87  s.segment<4>(3) = quat.coeffs();
88 
89  if (sz > 6) s.tail(sz - 6) = input.tail(sz - 6);
90 
91  getProfiler().stop(PROFILE_EULERTOQUAT_COMPUTATION);
92 
93  return s;
94 }
95 
96 /* --- COMMANDS ---------------------------------------------------------- */
97 
98 /* ------------------------------------------------------------------- */
99 /* --- ENTITY -------------------------------------------------------- */
100 /* ------------------------------------------------------------------- */
101 
102 void EulerToQuat::display(std::ostream& os) const {
103  os << "EulerToQuat " << getName();
104  try {
105  getProfiler().report_all(3, os);
106  } catch (ExceptionSignal e) {
107  }
108 }
109 
110 } // namespace talos_balance
111 } // namespace sot
112 } // namespace dynamicgraph
euler-to-quat.hh
sot_talos_balance.test.appli_admittance_end_effector.sot
sot
Definition: appli_admittance_end_effector.py:117
dynamicgraph
Definition: treeview.dox:24
dynamicgraph::sot::talos_balance::EulerToQuat::display
virtual void display(std::ostream &os) const
Definition: euler-to-quat.cpp:102
dynamicgraph::sot::talos_balance::EulerToQuat::init
void init()
Definition: euler-to-quat.hh:63
sot_talos_balance.test.test_admittance_end_effector.input
input
Definition: test_admittance_end_effector.py:11
OUTPUT_SIGNALS
#define OUTPUT_SIGNALS
Definition: euler-to-quat.cpp:39
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::EulerToQuat::EulerToQuat
EIGEN_MAKE_ALIGNED_OPERATOR_NEW EulerToQuat(const std::string &name)
Definition: euler-to-quat.cpp:51
INPUT_SIGNALS
#define INPUT_SIGNALS
Definition: euler-to-quat.cpp:37
dynamicgraph::sot::talos_balance::math::Vector
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > Vector
Definition: fwd.hh:36
dynamicgraph::sot::talos_balance::DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(AdmittanceControllerEndEffector, "AdmittanceControllerEndEffector")
dynamicgraph::sot::talos_balance::EntityClassName
AdmittanceControllerEndEffector EntityClassName
Definition: admittance-controller-end-effector.cpp:46
sot_talos_balance.test.appli_dcm_zmp_control.name
name
Definition: appli_dcm_zmp_control.py:298
PROFILE_EULERTOQUAT_COMPUTATION
#define PROFILE_EULERTOQUAT_COMPUTATION
Definition: euler-to-quat.cpp:34