sot-talos-balance  1.6.0
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 <sot/core/debug.hh>
20 #include <dynamic-graph/factory.h>
21 #include <dynamic-graph/command-bind.h>
22 
23 #include <dynamic-graph/all-commands.h>
24 #include <sot/core/stop-watch.hh>
25 
26 namespace dynamicgraph
27 {
28  namespace sot
29  {
30  namespace talos_balance
31  {
32  namespace dg = ::dynamicgraph;
33  using namespace dg;
34  using namespace dg::command;
35 
36 //Size to be aligned "-------------------------------------------------------"
37 #define PROFILE_SIMPLEREFERENCEFRAME_DCM_COMPUTATION "SimpleReferenceFrame: dcm computation "
38 
39 #define INPUT_SIGNALS m_footLeftSIN << m_footRightSIN << m_resetSIN
40 
41 #define OUTPUT_SIGNALS m_referenceFrameSOUT
42 
45  typedef SimpleReferenceFrame EntityClassName;
46 
47  /* --- DG FACTORY ---------------------------------------------------- */
48  DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(SimpleReferenceFrame,
49  "SimpleReferenceFrame");
50 
51  /* ------------------------------------------------------------------- */
52  /* --- CONSTRUCTION -------------------------------------------------- */
53  /* ------------------------------------------------------------------- */
55  : Entity(name)
56  , CONSTRUCT_SIGNAL_IN(footLeft, MatrixHomogeneous)
57  , CONSTRUCT_SIGNAL_IN(footRight, MatrixHomogeneous)
58  , CONSTRUCT_SIGNAL_IN(reset, bool)
59  , CONSTRUCT_SIGNAL_OUT(referenceFrame, MatrixHomogeneous, m_footLeftSIN << m_footRightSIN << m_resetSIN)
60  , m_first(true)
61  , m_initSucceeded(false)
62  {
63  Entity::signalRegistration( INPUT_SIGNALS << OUTPUT_SIGNALS );
64  m_referenceFrame.setIdentity();
65 
66  /* Commands. */
67  addCommand("init", makeCommandVoid1(*this, &SimpleReferenceFrame::init, docCommandVoid1("Initialize the entity.","Robot name")));
68  }
69 
70  void SimpleReferenceFrame::init(const std::string& robotName)
71  {
72  try
73  {
74  /* Retrieve m_robot_util informations */
75  std::string localName(robotName);
76  if (isNameInRobotUtil(localName))
77  {
78  m_robot_util = getRobotUtil(localName);
79  }
80  else
81  {
82  SEND_ERROR_STREAM_MSG("You should have a robotUtil pointer initialized before");
83  return;
84  }
85  }
86  catch (const std::exception& e)
87  {
88  SEND_ERROR_STREAM_MSG("Init failed: Could load URDF :" + m_robot_util->m_urdf_filename);
89  return;
90  }
91 
92  m_rightFootSoleXYZ = m_robot_util->m_foot_util.m_Right_Foot_Sole_XYZ;
93 
94  m_initSucceeded = true;
95  }
96 
97  /* ------------------------------------------------------------------- */
98  /* --- SIGNALS ------------------------------------------------------- */
99  /* ------------------------------------------------------------------- */
100 
101  DEFINE_SIGNAL_OUT_FUNCTION(referenceFrame, MatrixHomogeneous)
102  {
103  if(!m_initSucceeded)
104  {
105  SEND_WARNING_STREAM_MSG("Cannot compute signal referenceFrame before initialization!");
106  return s;
107  }
108 
109  const MatrixHomogeneous & footLeft = m_footLeftSIN(iter);
110  const MatrixHomogeneous & footRight = m_footRightSIN(iter);
111  const bool reset = m_resetSIN.isPlugged() ? m_resetSIN(iter) : false;
112 
113  if(reset||m_first)
114  {
115  Eigen::Vector3d centerTranslation = ( footLeft.translation() + footRight.translation() )/2 + m_rightFootSoleXYZ;
116  centerTranslation[2] = 0;
117 
118  m_referenceFrame.linear() = footRight.linear();
119  m_referenceFrame.translation() = centerTranslation;
120  m_first = false;
121  }
122 
123  s = m_referenceFrame;
124 
125  return s;
126  }
127 
128  /* --- COMMANDS ---------------------------------------------------------- */
129 
130  /* ------------------------------------------------------------------- */
131  /* --- ENTITY -------------------------------------------------------- */
132  /* ------------------------------------------------------------------- */
133 
134  void SimpleReferenceFrame::display(std::ostream& os) const
135  {
136  os << "SimpleReferenceFrame " << getName();
137  try
138  {
139  getProfiler().report_all(3, os);
140  }
141  catch (ExceptionSignal e) {}
142  }
143  } // namespace talos_balance
144  } // namespace sot
145 } // namespace dynamicgraph
146 
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(AdmittanceControllerEndEffector, "AdmittanceControllerEndEffector")
#define INPUT_SIGNALS
EIGEN_MAKE_ALIGNED_OPERATOR_NEW SimpleReferenceFrame(const std::string &name)
#define OUTPUT_SIGNALS