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 (size_type 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
SEND_MSG
#define SEND_MSG(msg, type)
Stopwatch::stop
void stop(std::string perf_name)
Definition: stop-watch.cpp:123
dynamicgraph::sot::core::AdmittanceControlOpPoint::resetDq
void resetDq()
Reset the velocity.
Definition: admittance-control-op-point.cpp:106
dynamicgraph::sot::MatrixHomogeneous
Eigen::Transform< double, 3, Eigen::Affine > SOT_CORE_EXPORT MatrixHomogeneous
Definition: matrix-geometry.hh:75
CONSTRUCT_SIGNAL_IN
#define CONSTRUCT_SIGNAL_IN(name, type)
dynamicgraph::sot::core::AdmittanceControlOpPoint::m_dt
double m_dt
Time step of the control.
Definition: admittance-control-op-point.hh:117
dynamicgraph
SE3Tpl< double, 0 >
i
int i
dynamicgraph::Entity
docCommandVoid0
std::string docCommandVoid0(const std::string &doc)
dynamicgraph::sot::core::AdmittanceControlOpPoint::display
virtual void display(std::ostream &os) const
Definition: admittance-control-op-point.cpp:199
dynamicgraph::sot::core::EntityClassName
AdmittanceControlOpPoint EntityClassName
Definition: admittance-control-op-point.cpp:46
dynamicgraph::sot::core::DEFINE_SIGNAL_OUT_FUNCTION
DEFINE_SIGNAL_OUT_FUNCTION(dq, dynamicgraph::Vector)
Definition: admittance-control-op-point.cpp:173
dynamicgraph::sot::core::DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(AdmittanceControlOpPoint, "AdmittanceControlOpPoint")
dynamicgraph::sot::core::DEFINE_SIGNAL_INNER_FUNCTION
DEFINE_SIGNAL_INNER_FUNCTION(w_force, dynamicgraph::Vector)
Definition: admittance-control-op-point.cpp:114
dynamicgraph::MSG_TYPE_ERROR
MSG_TYPE_ERROR
dynamicgraph::Entity::getName
const std::string & getName() const
makeCommandVoid0
CommandVoid0< E > * makeCommandVoid0(E &entity, boost::function< void(E *)> function, const std::string &docString)
debug.hh
dynamicgraph::sot::core::AdmittanceControlOpPoint::m_w_dq
dynamicgraph::Vector m_w_dq
Internal state.
Definition: admittance-control-op-point.hh:115
INPUT_SIGNALS
#define INPUT_SIGNALS
Definition: admittance-control-op-point.cpp:36
s
s
docCommandVoid1
std::string docCommandVoid1(const std::string &doc, const std::string &type)
dynamicgraph::sot::core::AdmittanceControlOpPoint::m_initSucceeded
bool m_initSucceeded
True if the entity has been successfully initialized.
Definition: admittance-control-op-point.hh:113
dynamicgraph::sot::core::AdmittanceControlOpPoint::AdmittanceControlOpPoint
EIGEN_MAKE_ALIGNED_OPERATOR_NEW AdmittanceControlOpPoint(const std::string &name)
Definition: admittance-control-op-point.cpp:55
SEND_WARNING_STREAM_MSG
#define SEND_WARNING_STREAM_MSG(msg)
admittance-control-op-point.hh
pinocchio::ForceTpl
stop-watch.hh
dynamicgraph::size_type
Matrix::Index size_type
CONSTRUCT_SIGNAL_INNER
#define CONSTRUCT_SIGNAL_INNER(name, type, dep)
dynamicgraph::Vector
Eigen::VectorXd Vector
getProfiler
Stopwatch & getProfiler()
Definition: stop-watch.cpp:46
dynamicgraph::ExceptionSignal
dynamicgraph::sot::core::AdmittanceControlOpPoint
Admittance controller for an operational point wrt to a force sensor. It can be a point of the model ...
Definition: admittance-control-op-point.hh:59
CONSTRUCT_SIGNAL_OUT
#define CONSTRUCT_SIGNAL_OUT(name, type, dep)
test-parameter-server.dt
float dt
Definition: test-parameter-server.py:14
INNER_SIGNALS
#define INNER_SIGNALS
Definition: admittance-control-op-point.cpp:40
dynamicgraph::Entity::addCommand
void addCommand(const std::string &name, command::Command *command)
dynamicgraph::sot::core::AdmittanceControlOpPoint::init
void init(const double &dt)
Initialize the entity.
Definition: admittance-control-op-point.cpp:80
PROFILE_ADMITTANCECONTROLOPPOINT_WFORCE_COMPUTATION
#define PROFILE_ADMITTANCECONTROLOPPOINT_WFORCE_COMPUTATION
Definition: admittance-control-op-point.cpp:27
all-commands.h
pinocchio::MotionTpl
dq
dq
PROFILE_ADMITTANCECONTROLOPPOINT_WDQ_COMPUTATION
#define PROFILE_ADMITTANCECONTROLOPPOINT_WDQ_COMPUTATION
Definition: admittance-control-op-point.cpp:30
dynamicgraph::Entity::signalRegistration
void signalRegistration(const SignalArray< sigtime_t > &signals)
Stopwatch::start
void start(std::string perf_name)
Definition: stop-watch.cpp:105
Stopwatch::report_all
void report_all(int precision=2, std::ostream &output=std::cout)
Definition: stop-watch.cpp:185
makeCommandVoid1
CommandVoid1< E, T > * makeCommandVoid1(E &entity, boost::function< void(const T &)> function, const std::string &docString)
compile.name
name
Definition: compile.py:23
pinocchio
OUTPUT_SIGNALS
#define OUTPUT_SIGNALS
Definition: admittance-control-op-point.cpp:42
dynamicgraph::sot::core::AdmittanceControlOpPoint::m_n
size_type m_n
Dimension of the force signals and of the output.
Definition: admittance-control-op-point.hh:111
PROFILE_ADMITTANCECONTROLOPPOINT_DQ_COMPUTATION
#define PROFILE_ADMITTANCECONTROLOPPOINT_DQ_COMPUTATION
Definition: admittance-control-op-point.cpp:33


sot-core
Author(s): Olivier Stasse, ostasse@laas.fr
autogenerated on Tue Oct 24 2023 02:26:31