op-point-modifier.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2010,
3  * François Bleibel,
4  * Olivier Stasse,
5  *
6  * CNRS/AIST
7  *
8  */
9 
12 #include <dynamic-graph/factory.h>
13 
16 
17 using namespace std;
18 using namespace dynamicgraph::sot;
19 using namespace dynamicgraph;
20 
22 
23 /* --------------------------------------------------------------------- */
24 /* --------------------------------------------------------------------- */
25 /* --------------------------------------------------------------------- */
26 
27 OpPointModifier::OpPointModifier(const std::string &name)
28  : Entity(name),
29  jacobianSIN(NULL,
30  "OpPointModifior(" + name + ")::input(matrix)::jacobianIN"),
31  positionSIN(
32  NULL, "OpPointModifior(" + name + ")::input(matrixhomo)::positionIN"),
33  jacobianSOUT(
34  boost::bind(&OpPointModifier::jacobianSOUT_function, this, _1, _2),
35  jacobianSIN,
36  "OpPointModifior(" + name + ")::output(matrix)::jacobian"),
37  positionSOUT(
38  boost::bind(&OpPointModifier::positionSOUT_function, this, _1, _2),
39  positionSIN,
40  "OpPointModifior(" + name + ")::output(matrixhomo)::position"),
41  transformation(),
42  isEndEffector(true) {
43  sotDEBUGIN(15);
44 
46  << positionSOUT);
47  {
48  using namespace dynamicgraph::command;
49  addCommand(
50  "getTransformation",
51  makeDirectGetter(*this, &transformation.matrix(),
52  docDirectGetter("transformation", "matrix 4x4 homo")));
53  addCommand(
54  "setTransformation",
55  makeDirectSetter(*this, &transformation.matrix(),
56  docDirectSetter("dimension", "matrix 4x4 homo")));
57  addCommand("getEndEffector",
59  docDirectGetter("end effector mode", "bool")));
60  addCommand("setEndEffector",
62  docDirectSetter("end effector mode", "bool")));
63  }
64 
65  sotDEBUGOUT(15);
66 }
67 
69  dynamicgraph::Matrix &res, const sigtime_t &iter) {
70  if (isEndEffector) {
71  const dynamicgraph::Matrix &aJa = jacobianSIN(iter);
72  const MatrixHomogeneous &aMb = transformation;
73 
74  MatrixTwist bVa;
75  buildFrom(aMb.inverse(), bVa);
76  res = bVa * aJa; // res := bJb
77  return res;
78  } else {
79  /* Consider that the jacobian of point A in frame A is given: J = aJa
80  * and that homogenous transformation from A to B is given aMb in
81  * getTransfo() and homo transfo from 0 to A is given oMa in positionSIN.
82  * Then return oJb, the jacobian of point B expressed in frame O:
83  * oJb = ( oRa 0 ; 0 oRa ) * bVa * aJa
84  * = [ I skew(oAB); 0 I ] * oJa
85  * with oAB = oRb bAB = oRb (-bRa aAB ) = -oRa aAB, and aAB =
86  * translation(aMb).
87  */
88 
89  const dynamicgraph::Matrix &oJa = jacobianSIN(iter);
90  const MatrixHomogeneous &aMb = transformation;
91  const MatrixHomogeneous &oMa = positionSIN(iter);
92  MatrixRotation oRa;
93  oRa = oMa.linear();
94  dynamicgraph::Vector aAB(3);
95  aAB = aMb.translation();
96  dynamicgraph::Vector oAB = oRa * aAB;
97 
98  const dynamicgraph::Matrix::Index nq = oJa.cols();
99  res.resize(6, oJa.cols());
100  for (size_type j = 0; j < nq; ++j) {
101  /* This is a I*Jtrans + skew*Jrot product, unrolled by hand ... */
102  res(0, j) = oJa(0, j) - oAB(1) * oJa(2 + 3, j) + oAB(2) * oJa(1 + 3, j);
103  res(1, j) = oJa(1, j) - oAB(2) * oJa(0 + 3, j) + oAB(0) * oJa(2 + 3, j);
104  res(2, j) = oJa(2, j) - oAB(0) * oJa(1 + 3, j) + oAB(1) * oJa(0 + 3, j);
105  for (size_type i = 0; i < 3; ++i) {
106  res(i + 3, j) = oJa(i + 3, j);
107  }
108  }
109  return res; // res := 0Jb
110  }
111 }
112 
114  MatrixHomogeneous &res, const sigtime_t &iter) {
115  sotDEBUGIN(15);
116  sotDEBUGIN(15) << iter << " " << positionSIN.getTime()
117  << positionSOUT.getTime() << endl;
118  const MatrixHomogeneous &position = positionSIN(iter);
119  res = position * transformation;
120  sotDEBUGOUT(15);
121  return res;
122 }
123 
124 void OpPointModifier::setTransformation(const Eigen::Matrix4d &tr) {
125  transformation.matrix() = tr;
126 }
127 const Eigen::Matrix4d &OpPointModifier::getTransformation(void) {
128  return transformation.matrix();
129 }
130 
131 /* The following function needs an access to a specific signal via
132  * the pool, using the signal path <entity.signal>. this functionnality
133  * is deprecated, and the following function will have to be removed
134  * in a near future. A similar functionality is available using
135  * the <setTransformation> mthod, bound in python.
136  */
137 #include <dynamic-graph/pool.h>
138 [[deprecated("use setTransformation")]] void
141  dynamic_cast<Signal<Eigen::Matrix4d, sigtime_t> &>(
142  PoolStorage::getInstance()->getSignal(cmdArgs));
143  setTransformation(sig.accessCopy());
144 }
dynamicgraph::sot::OpPointModifier::positionSOUT_function
MatrixHomogeneous & positionSOUT_function(MatrixHomogeneous &res, const sigtime_t &time)
Definition: op-point-modifier.cpp:113
op-point-modifier.hh
dynamicgraph::Signal
dynamicgraph::PoolStorage::getSignal
SignalBase< sigtime_t > & getSignal(std::istringstream &sigpath)
deprecated
def deprecated(instructions)
dynamicgraph::sot::MatrixHomogeneous
Eigen::Transform< double, 3, Eigen::Affine > SOT_CORE_EXPORT MatrixHomogeneous
Definition: matrix-geometry.hh:75
dynamicgraph::sot::OpPointModifier
Compute position and jacobian of a local frame attached to a joint.
Definition: op-point-modifier.hh:49
dynamicgraph
nq
int nq(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
dynamicgraph::command
i
int i
dynamicgraph::Entity
dynamicgraph::sot::OpPointModifier::setTransformation
void setTransformation(const Eigen::Matrix4d &tr)
Definition: op-point-modifier.cpp:124
dynamicgraph::sot::OpPointModifier::getTransformation
const Eigen::Matrix4d & getTransformation(void)
Definition: op-point-modifier.cpp:127
dynamicgraph::sot::OpPointModifier::isEndEffector
bool isEndEffector
Definition: op-point-modifier.hh:81
boost
dynamicgraph::Matrix
Eigen::MatrixXd Matrix
makeDirectGetter
DirectGetter< E, T > * makeDirectGetter(E &entity, T *ptr, const std::string &docString)
dynamicgraph::sot::buildFrom
void buildFrom(const MatrixHomogeneous &MH, MatrixTwist &MT)
Definition: matrix-geometry.hh:88
res
res
sotDEBUGOUT
#define sotDEBUGOUT(level)
Definition: debug.hh:215
dynamicgraph::SignalPtr::getTime
virtual const Time & getTime() const
dynamicgraph::sot::OpPointModifier::jacobianSIN
dynamicgraph::SignalPtr< dynamicgraph::Matrix, sigtime_t > jacobianSIN
Definition: op-point-modifier.hh:55
dynamicgraph::sigtime_t
int64_t sigtime_t
dynamicgraph::sot::OpPointModifier::jacobianSOUT_function
dynamicgraph::Matrix & jacobianSOUT_function(dynamicgraph::Matrix &res, const sigtime_t &time)
Definition: op-point-modifier.cpp:68
sotDEBUGIN
#define sotDEBUGIN(level)
Definition: debug.hh:214
Index
std::size_t Index
dynamicgraph::sot::OpPointModifier::positionSOUT
dynamicgraph::SignalTimeDependent< MatrixHomogeneous, sigtime_t > positionSOUT
Definition: op-point-modifier.hh:60
docDirectSetter
std::string docDirectSetter(const std::string &name, const std::string &type)
all-signals.h
dynamicgraph::size_type
Matrix::Index size_type
dynamicgraph::Vector
Eigen::VectorXd Vector
dynamicgraph::sot::OpPointModifier::transformation
MatrixHomogeneous transformation
Definition: op-point-modifier.hh:75
dynamicgraph::sot::MatrixTwist
Eigen::Matrix< double, 6, 6 > SOT_CORE_EXPORT MatrixTwist
Definition: matrix-geometry.hh:82
docDirectGetter
std::string docDirectGetter(const std::string &name, const std::string &type)
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(OpPointModifier, "OpPointModifier")
matrix-geometry.hh
dynamicgraph::sot::OpPointModifier::setTransformationBySignalName
void setTransformationBySignalName(std::istringstream &cmdArgs)
Definition: op-point-modifier.cpp:139
dynamicgraph::PoolStorage::getInstance
static PoolStorage * getInstance()
Definition: pool.cpp:147
dynamicgraph::sot
dynamicgraph::sot::MatrixRotation
Eigen::Matrix< double, 3, 3 > SOT_CORE_EXPORT MatrixRotation
Definition: matrix-geometry.hh:76
makeDirectSetter
DirectSetter< E, T > * makeDirectSetter(E &entity, T *ptr, const std::string &docString)
dynamicgraph::Entity::addCommand
void addCommand(const std::string &name, command::Command *command)
sig
Signal< dynamicgraph::Matrix, sigtime_t > sig("matrix")
all-commands.h
dynamicgraph::Entity::signalRegistration
void signalRegistration(const SignalArray< sigtime_t > &signals)
compile.name
name
Definition: compile.py:23
dynamicgraph::sot::OpPointModifier::positionSIN
dynamicgraph::SignalPtr< MatrixHomogeneous, sigtime_t > positionSIN
Definition: op-point-modifier.hh:56
dynamicgraph::sot::OpPointModifier::jacobianSOUT
dynamicgraph::SignalTimeDependent< dynamicgraph::Matrix, sigtime_t > jacobianSOUT
Definition: op-point-modifier.hh:59


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