admittance-control-op-point.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2019
3  *
4  * LAAS-CNRS
5  *
6  * NoĆ«lie Ramuzat
7  * This file is part of sot-core.
8  * See license file.
9  */
10 
12 
14 #include <dynamic-graph/factory.h>
15 
16 #include <sot/core/debug.hh>
17 #include <sot/core/stop-watch.hh>
18 
19 namespace dynamicgraph {
20 namespace sot {
21 namespace core {
22 namespace dg = ::dynamicgraph;
23 using namespace dg;
24 using namespace pinocchio;
25 using namespace dg::command;
26 
27 #define PROFILE_ADMITTANCECONTROLOPPOINT_WFORCE_COMPUTATION \
28  "AdmittanceControlOpPoint: w_force computation "
29 
30 #define PROFILE_ADMITTANCECONTROLOPPOINT_WDQ_COMPUTATION \
31  "AdmittanceControlOpPoint: w_dq computation "
32 
33 #define PROFILE_ADMITTANCECONTROLOPPOINT_DQ_COMPUTATION \
34  "AdmittanceControlOpPoint: dq computation "
35 
36 #define INPUT_SIGNALS \
37  m_KpSIN << m_KdSIN << m_dqSaturationSIN << m_forceSIN << m_w_forceDesSIN \
38  << m_opPoseSIN << m_sensorPoseSIN
39 
40 #define INNER_SIGNALS m_w_forceSINNER << m_w_dqSINNER
41 
42 #define OUTPUT_SIGNALS m_dqSOUT
43 
47 
48 /* --- DG FACTORY ---------------------------------------------------- */
50  "AdmittanceControlOpPoint");
51 
52 /* ------------------------------------------------------------------- */
53 /* --- CONSTRUCTION -------------------------------------------------- */
54 /* ------------------------------------------------------------------- */
56  : Entity(name),
59  CONSTRUCT_SIGNAL_IN(dqSaturation, dynamicgraph::Vector),
64  CONSTRUCT_SIGNAL_INNER(w_force, dynamicgraph::Vector, m_forceSIN),
66  INPUT_SIGNALS << m_w_forceSINNER),
67  CONSTRUCT_SIGNAL_OUT(dq, dynamicgraph::Vector, m_w_dqSINNER),
68  m_initSucceeded(false) {
70 
71  /* Commands. */
73  docCommandVoid1("Initialize the entity.",
74  "time step")));
75  addCommand("resetDq",
77  docCommandVoid0("resetDq")));
78 }
79 
80 void AdmittanceControlOpPoint::init(const double &dt) {
81  if (!m_dqSaturationSIN.isPlugged())
82  return SEND_MSG("Init failed: signal dqSaturation is not plugged",
84  if (!m_KpSIN.isPlugged())
85  return SEND_MSG("Init failed: signal Kp is not plugged", MSG_TYPE_ERROR);
86  if (!m_KdSIN.isPlugged())
87  return SEND_MSG("Init failed: signal Kd is not plugged", MSG_TYPE_ERROR);
88  if (!m_forceSIN.isPlugged())
89  return SEND_MSG("Init failed: signal force is not plugged", MSG_TYPE_ERROR);
90  if (!m_w_forceDesSIN.isPlugged())
91  return SEND_MSG("Init failed: signal w_forceDes is not plugged",
93  if (!m_opPoseSIN.isPlugged())
94  return SEND_MSG("Init failed: signal opPose is not plugged",
96  if (!m_sensorPoseSIN.isPlugged())
97  return SEND_MSG("Init failed: signal sensorPose is not plugged",
99 
100  m_n = 6;
101  m_dt = dt;
102  m_w_dq.setZero(m_n);
103  m_initSucceeded = true;
104 }
105 
107  m_w_dq.setZero(m_n);
108  return;
109 }
110 
111 /* ------------------------------------------------------------------- */
112 /* --- SIGNALS ------------------------------------------------------- */
113 /* ------------------------------------------------------------------- */
115  if (!m_initSucceeded) {
117  "Cannot compute signal w_force before initialization!");
118  return s;
119  }
120  if (s.size() != 6) s.resize(6);
121 
123 
124  const Vector &force = m_forceSIN(iter);
125  const MatrixHomogeneous &sensorPose = m_sensorPoseSIN(iter);
126  assert(force.size() == m_n && "Unexpected size of signal force");
127  pinocchio::SE3 sensorPlacement(
128  sensorPose.matrix()); // homogeneous matrix to SE3
129  s = sensorPlacement.act(pinocchio::Force(force)).toVector();
130 
132 
133  return s;
134 }
135 
137  if (!m_initSucceeded) {
139  "Cannot compute signal w_dq before initialization!");
140  return s;
141  }
142  if (s.size() != 6) s.resize(6);
143 
145 
146  const Vector &w_forceDes = m_w_forceDesSIN(iter);
147  const Vector &w_force = m_w_forceSINNER(iter);
148  const Vector &Kp = m_KpSIN(iter);
149  const Vector &Kd = m_KdSIN(iter);
150  const Vector &dqSaturation = m_dqSaturationSIN(iter);
151  assert(w_force.size() == m_n && "Unexpected size of signal force");
152  assert(w_forceDes.size() == m_n && "Unexpected size of signal w_forceDes");
153  assert(Kp.size() == m_n && "Unexpected size of signal Kp");
154  assert(Kd.size() == m_n && "Unexpected size of signal Kd");
155  assert(dqSaturation.size() == m_n &&
156  "Unexpected size of signal dqSaturation");
157 
158  m_w_dq = m_w_dq + m_dt * (Kp.cwiseProduct(w_forceDes - w_force)) -
159  Kd.cwiseProduct(m_w_dq);
160 
161  for (int i = 0; i < m_n; i++) {
162  if (m_w_dq[i] > dqSaturation[i]) m_w_dq[i] = dqSaturation[i];
163  if (m_w_dq[i] < -dqSaturation[i]) m_w_dq[i] = -dqSaturation[i];
164  }
165 
166  s = m_w_dq;
167 
169 
170  return s;
171 }
172 
174  if (!m_initSucceeded) {
175  SEND_WARNING_STREAM_MSG("Cannot compute signal dq before initialization!");
176  return s;
177  }
178  if (s.size() != 6) s.resize(6);
179 
181 
182  const Vector &w_dq = m_w_dqSINNER(iter);
183  const MatrixHomogeneous &opPose = m_opPoseSIN(iter);
184  assert(w_dq.size() == m_n && "Unexpected size of signal w_dq");
185  pinocchio::SE3 opPointPlacement(
186  opPose.matrix()); // homogeneous matrix to SE3
187  s = opPointPlacement.actInv(pinocchio::Motion(w_dq)).toVector();
188 
190 
191  return s;
192 }
193 
194 /* --- COMMANDS ---------------------------------------------------------- */
195 
196 /* ------------------------------------------------------------------- */
197 /* --- ENTITY -------------------------------------------------------- */
198 /* ------------------------------------------------------------------- */
199 void AdmittanceControlOpPoint::display(std::ostream &os) const {
200  os << "AdmittanceControlOpPoint " << getName();
201  try {
202  getProfiler().report_all(3, os);
203  } catch (const ExceptionSignal &e) {
204  }
205 }
206 } // namespace core
207 } // namespace sot
208 } // namespace dynamicgraph
Eigen::Transform< double, 3, Eigen::Affine > SOT_CORE_EXPORT MatrixHomogeneous
CommandVoid0< E > * makeCommandVoid0(E &entity, boost::function< void(void)> function, const std::string &docString)
Eigen::VectorXd Vector
s
int i
Admittance controller for an operational point wrt to a force sensor. It can be a point of the model ...
void stop(std::string perf_name)
Definition: stop-watch.cpp:123
#define OUTPUT_SIGNALS
#define PROFILE_ADMITTANCECONTROLOPPOINT_DQ_COMPUTATION
void signalRegistration(const SignalArray< int > &signals)
#define CONSTRUCT_SIGNAL_IN(name, type)
CommandVoid1< E, T > * makeCommandVoid1(E &entity, boost::function< void(const T &)> function, const std::string &docString)
bool m_initSucceeded
True if the entity has been successfully initialized.
std::string docCommandVoid1(const std::string &doc, const std::string &type)
EIGEN_MAKE_ALIGNED_OPERATOR_NEW AdmittanceControlOpPoint(const std::string &name)
DEFINE_SIGNAL_OUT_FUNCTION(dq, dynamicgraph::Vector)
std::string docCommandVoid0(const std::string &doc)
void init(const double &dt)
Initialize the entity.
int m_n
Dimension of the force signals and of the output.
#define SEND_MSG(msg, type)
#define CONSTRUCT_SIGNAL_OUT(name, type, dep)
#define CONSTRUCT_SIGNAL_INNER(name, type, dep)
Stopwatch & getProfiler()
Definition: stop-watch.cpp:46
#define INPUT_SIGNALS
#define INNER_SIGNALS
DEFINE_SIGNAL_INNER_FUNCTION(w_force, dynamicgraph::Vector)
const std::string & getName() const
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(AdmittanceControlOpPoint, "AdmittanceControlOpPoint")
#define SEND_WARNING_STREAM_MSG(msg)
dq
void start(std::string perf_name)
Definition: stop-watch.cpp:105
AdmittanceControlOpPoint EntityClassName
void addCommand(const std::string &name, command::Command *command)
#define PROFILE_ADMITTANCECONTROLOPPOINT_WFORCE_COMPUTATION
void report_all(int precision=2, std::ostream &output=std::cout)
Definition: stop-watch.cpp:185
#define PROFILE_ADMITTANCECONTROLOPPOINT_WDQ_COMPUTATION


sot-core
Author(s): Olivier Stasse, ostasse@laas.fr
autogenerated on Wed Jun 21 2023 02:51:26