sot-talos-balance  2.0.5
Collection of dynamic-graph entities aimed at implementing balance control on talos.
simple-reference-frame.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 #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_SIMPLEREFERENCEFRAME_DCM_COMPUTATION \
35  "SimpleReferenceFrame: dcm computation "
36 
37 #define INPUT_SIGNALS m_footLeftSIN << m_footRightSIN << m_resetSIN
38 
39 #define OUTPUT_SIGNALS m_referenceFrameSOUT
40 
43 typedef SimpleReferenceFrame EntityClassName;
44 
45 /* --- DG FACTORY ---------------------------------------------------- */
46 DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(SimpleReferenceFrame,
47  "SimpleReferenceFrame");
48 
49 /* ------------------------------------------------------------------- */
50 /* --- CONSTRUCTION -------------------------------------------------- */
51 /* ------------------------------------------------------------------- */
53  : Entity(name),
54  CONSTRUCT_SIGNAL_IN(footLeft, MatrixHomogeneous),
55  CONSTRUCT_SIGNAL_IN(footRight, MatrixHomogeneous),
56  CONSTRUCT_SIGNAL_IN(reset, bool),
57  CONSTRUCT_SIGNAL_OUT(referenceFrame, MatrixHomogeneous,
58  m_footLeftSIN << m_footRightSIN << m_resetSIN),
59  m_first(true),
60  m_initSucceeded(false) {
61  Entity::signalRegistration(INPUT_SIGNALS << OUTPUT_SIGNALS);
62  m_referenceFrame.setIdentity();
63 
64  /* Commands. */
65  addCommand("init", makeCommandVoid1(*this, &SimpleReferenceFrame::init,
66  docCommandVoid1("Initialize the entity.",
67  "Robot name")));
68 }
69 
70 void SimpleReferenceFrame::init(const std::string& robotName) {
71  try {
72  /* Retrieve m_robot_util informations */
73  std::string localName(robotName);
74  if (isNameInRobotUtil(localName)) {
75  m_robot_util = getRobotUtil(localName);
76  } else {
77  SEND_ERROR_STREAM_MSG(
78  "You should have a robotUtil pointer initialized before");
79  return;
80  }
81  } catch (const std::exception& e) {
82  SEND_ERROR_STREAM_MSG("Init failed: Could load URDF :" +
83  m_robot_util->m_urdf_filename);
84  return;
85  }
86 
87  m_rightFootSoleXYZ = m_robot_util->m_foot_util.m_Right_Foot_Sole_XYZ;
88 
89  m_initSucceeded = true;
90 }
91 
92 /* ------------------------------------------------------------------- */
93 /* --- SIGNALS ------------------------------------------------------- */
94 /* ------------------------------------------------------------------- */
95 
96 DEFINE_SIGNAL_OUT_FUNCTION(referenceFrame, MatrixHomogeneous) {
97  if (!m_initSucceeded) {
98  SEND_WARNING_STREAM_MSG(
99  "Cannot compute signal referenceFrame before initialization!");
100  return s;
101  }
102 
103  const MatrixHomogeneous& footLeft = m_footLeftSIN(iter);
104  const MatrixHomogeneous& footRight = m_footRightSIN(iter);
105  const bool reset = m_resetSIN.isPlugged() ? m_resetSIN(iter) : false;
106 
107  if (reset || m_first) {
108  Eigen::Vector3d centerTranslation =
109  (footLeft.translation() + footRight.translation()) / 2 +
110  m_rightFootSoleXYZ;
111  centerTranslation[2] = 0;
112 
113  m_referenceFrame.linear() = footRight.linear();
114  m_referenceFrame.translation() = centerTranslation;
115  m_first = false;
116  }
117 
118  s = m_referenceFrame;
119 
120  return s;
121 }
122 
123 /* --- COMMANDS ---------------------------------------------------------- */
124 
125 /* ------------------------------------------------------------------- */
126 /* --- ENTITY -------------------------------------------------------- */
127 /* ------------------------------------------------------------------- */
128 
129 void SimpleReferenceFrame::display(std::ostream& os) const {
130  os << "SimpleReferenceFrame " << getName();
131  try {
132  getProfiler().report_all(3, os);
133  } catch (ExceptionSignal e) {
134  }
135 }
136 } // namespace talos_balance
137 } // namespace sot
138 } // namespace dynamicgraph
dynamicgraph::sot::talos_balance::SimpleReferenceFrame::SimpleReferenceFrame
EIGEN_MAKE_ALIGNED_OPERATOR_NEW SimpleReferenceFrame(const std::string &name)
Definition: simple-reference-frame.cpp:52
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
OUTPUT_SIGNALS
#define OUTPUT_SIGNALS
Definition: simple-reference-frame.cpp:39
dynamicgraph
Definition: treeview.dox:24
dynamicgraph::sot::talos_balance::SimpleReferenceFrame::m_initSucceeded
bool m_initSucceeded
Definition: simple-reference-frame.hh:87
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::SimpleReferenceFrame::m_robot_util
RobotUtilShrPtr m_robot_util
Definition: simple-reference-frame.hh:82
dynamicgraph::sot::talos_balance::SimpleReferenceFrame::display
virtual void display(std::ostream &os) const
Definition: simple-reference-frame.cpp:129
simple-reference-frame.hh
INPUT_SIGNALS
#define INPUT_SIGNALS
Definition: simple-reference-frame.cpp:37
dynamicgraph::sot::talos_balance::SimpleReferenceFrame::init
void init(const std::string &robotName)
Definition: simple-reference-frame.cpp:70
dynamicgraph::sot::talos_balance::DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(AdmittanceControllerEndEffector, "AdmittanceControllerEndEffector")
dynamicgraph::sot::talos_balance::SimpleReferenceFrame::m_referenceFrame
MatrixHomogeneous m_referenceFrame
Definition: simple-reference-frame.hh:84
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
dynamicgraph::sot::talos_balance::SimpleReferenceFrame::m_rightFootSoleXYZ
Vector m_rightFootSoleXYZ
Definition: simple-reference-frame.hh:83