feature-line-distance.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 
10 /* --------------------------------------------------------------------- */
11 /* --- INCLUDE --------------------------------------------------------- */
12 /* --------------------------------------------------------------------- */
13 
14 /* --- SOT --- */
15 #include <sot/core/debug.hh>
19 
20 using namespace std;
21 
22 using namespace dynamicgraph::sot;
23 using namespace dynamicgraph;
24 
25 #include <sot/core/factory.hh>
27 
28 /* --------------------------------------------------------------------- */
29 /* --- CLASS ----------------------------------------------------------- */
30 /* --------------------------------------------------------------------- */
31 
32 FeatureLineDistance::FeatureLineDistance(const string &pointName)
33  : FeatureAbstract(pointName),
34  positionSIN(NULL, "sotFeatureLineDistance(" + name +
35  ")::input(matrixHomo)::position"),
36  articularJacobianSIN(
37  NULL, "sotFeatureLineDistance(" + name + ")::input(matrix)::Jq"),
38  positionRefSIN(NULL, "sotFeatureLineDistance(" + name +
39  ")::input(vector)::positionRef"),
40  vectorSIN(NULL,
41  "sotFeatureVector3(" + name + ")::input(vector3)::vector"),
42  lineSOUT(boost::bind(&FeatureLineDistance::computeLineCoordinates, this,
43  _1, _2),
44  positionSIN << positionRefSIN,
45  "sotFeatureAbstract(" + name + ")::output(vector)::line") {
48 
50 
52  << lineSOUT << vectorSIN);
53 }
54 
55 /* --------------------------------------------------------------------- */
56 /* --------------------------------------------------------------------- */
57 /* --------------------------------------------------------------------- */
58 
60  sigtime_t /*time*/) {
61  sotDEBUG(25) << "# In {" << endl;
62 
63  return dim = 1;
64 }
65 
66 /* --------------------------------------------------------------------- */
68  sigtime_t time) {
69  sotDEBUGIN(15);
70 
71  cood.resize(6);
72 
73  /* Line coordinates */
74  const MatrixHomogeneous &pos = positionSIN(time);
75  const Vector &vect = vectorSIN(time);
77  R = pos.linear();
78  Vector v(3);
79  v = R * vect;
80 
81  cood(0) = pos(0, 3);
82  cood(1) = pos(1, 3);
83  cood(2) = pos(2, 3);
84  cood(3) = v(0);
85  cood(4) = v(1);
86  cood(5) = v(2);
87 
88  sotDEBUGOUT(15);
89  return cood;
90 }
91 
92 /* --------------------------------------------------------------------- */
97  sotDEBUG(15) << "# In {" << endl;
98 
99  /* --- Compute the jacobian of the line coordinates --- */
100  Matrix Jline;
101  {
102  const Matrix &Jq = articularJacobianSIN(time);
103 
104  const Vector &vect = vectorSIN(time);
105  const MatrixHomogeneous &M = positionSIN(time);
107  R = M.linear(); // wRh
108 
109  Matrix Skew(3, 3);
110  Skew(0, 0) = 0;
111  Skew(0, 1) = -vect(2);
112  Skew(0, 2) = vect(1);
113  Skew(1, 0) = vect(2);
114  Skew(1, 1) = 0;
115  Skew(1, 2) = -vect(0);
116  Skew(2, 0) = -vect(1);
117  Skew(2, 1) = vect(0);
118  Skew(2, 2) = 0;
119 
120  Matrix RSk(3, 3);
121  RSk = R * Skew;
122 
123  Jline.resize(6, Jq.cols());
124  for (std::size_t i = 0; i < 3; ++i)
125  for (size_type j = 0; j < Jq.cols(); ++j) {
126  Jline(i, j) = 0;
127  Jline(i + 3, j) = 0;
128  for (std::size_t k = 0; k < 3; ++k) {
129  Jline(i, j) += R(i, k) * Jq(k, j);
130  Jline(i + 3, j) += -RSk(i, k) * Jq(k + 3, j);
131  }
132  }
133  }
134 
135  /* --- Compute the jacobian wrt the line coordinates --- */
136  const Vector &line = lineSOUT(time);
137  const double &x0 = line(0);
138  const double &y0 = line(1);
139  const double &z0 = line(2);
140  const double &a0 = line(3);
141  const double &b0 = line(4);
142  const double &c0 = line(5);
143 
144  const Vector &posRef = positionRefSIN(time);
145  const double &x1 = posRef(0);
146  const double &y1 = posRef(1);
147  const double &z1 = posRef(2);
148  const double &a1 = posRef(3);
149  const double &b1 = posRef(4);
150  const double &c1 = posRef(5);
151 
152  /* Differential */
153  const double a1_3 = a1 * a1 * a1;
154  const double b1_3 = b1 * b1 * b1;
155  const double c1_3 = c1 * c1 * c1;
156 
157  double K = c0 * c0 * a1 * a1 - 2 * c0 * a1 * a0 * c1 - 2 * c0 * b1 * b0 * c1 +
158  c0 * c0 * b1 * b1 - 2 * b0 * a1 * a0 * b1 + b0 * b0 * a1 * a1 +
159  b0 * b0 * c1 * c1 + a0 * a0 * b1 * b1 + a0 * a0 * c1 * c1;
160 
161  const double diffx0 = -b0 * c1 + c0 * b1;
162  const double diffy0 = a0 * c1 - c0 * a1;
163  const double diffz0 = -a0 * b1 + b0 * a1;
164 
165  const double diffa0 =
166  2 * b0 * c1 * x0 * a0 * b1 * b1 + 2 * c0 * b1 * b1 * x0 * b0 * a1 +
167  2 * c0 * c0 * b1 * x0 * c1 * a1 + 2 * c1 * c1 * y0 * c0 * a1 * a0 -
168  2 * b0 * c1 * c1 * x0 * c0 * a1 - 2 * b0 * b0 * c1 * x0 * b1 * a1 -
169  2 * c1 * c1 * y0 * c0 * b1 * b0 + 2 * b0 * b0 * c1 * x1 * b1 * a1 +
170  2 * b0 * c1 * c1 * x1 * c0 * a1 - 2 * b0 * c1 * x1 * a0 * b1 * b1 -
171  c1 * y0 * c0 * c0 * a1 * a1 + c1 * y0 * c0 * c0 * b1 * b1 +
172  c1 * y0 * b0 * b0 * a1 * a1 - c1 * y0 * a0 * a0 * b1 * b1 +
173  c1 * y1 * c0 * c0 * a1 * a1 - c1 * y1 * c0 * c0 * b1 * b1 -
174  c1 * y1 * b0 * b0 * a1 * a1 + c1 * y1 * a0 * a0 * b1 * b1 -
175  b1 * z0 * c0 * c0 * a1 * a1 + b1 * z0 * b0 * b0 * a1 * a1 -
176  b1 * z0 * b0 * b0 * c1 * c1 + b1 * z0 * a0 * a0 * c1 * c1 +
177  b1 * z1 * c0 * c0 * a1 * a1 - b1 * z1 * b0 * b0 * a1 * a1 +
178  b1 * z1 * b0 * b0 * c1 * c1 - b1 * z1 * a0 * a0 * c1 * c1 +
179  2 * b0 * c1_3 * x0 * a0 - 2 * b0 * c1_3 * x1 * a0 -
180  2 * c0 * b1_3 * x0 * a0 + 2 * c0 * b1_3 * x1 * a0 + c1_3 * y0 * b0 * b0 -
181  c1_3 * y0 * a0 * a0 - c1_3 * y1 * b0 * b0 + c1_3 * y1 * a0 * a0 -
182  b1_3 * z0 * c0 * c0 + b1_3 * z0 * a0 * a0 + b1_3 * z1 * c0 * c0 -
183  b1_3 * z1 * a0 * a0 - 2 * c1 * c1 * y1 * c0 * a1 * a0 +
184  2 * c1 * c1 * y1 * c0 * b1 * b0 + 2 * b1 * b1 * z0 * c0 * b0 * c1 -
185  2 * b1 * b1 * z0 * b0 * a1 * a0 - 2 * b1 * b1 * z1 * c0 * b0 * c1 +
186  2 * b1 * b1 * z1 * b0 * a1 * a0 - 2 * c0 * b1 * x0 * a0 * c1 * c1 -
187  2 * c0 * b1 * b1 * x1 * b0 * a1 - 2 * c0 * c0 * b1 * x1 * c1 * a1 +
188  2 * c0 * b1 * x1 * a0 * c1 * c1 + 2 * c0 * a1 * y0 * a0 * b1 * b1 -
189  2 * c0 * a1 * a1 * y0 * b1 * b0 - 2 * c0 * a1 * y1 * a0 * b1 * b1 +
190  2 * c0 * a1 * a1 * y1 * b1 * b0 + 2 * b0 * a1 * a1 * z0 * c1 * c0 -
191  2 * b0 * a1 * z0 * a0 * c1 * c1 - 2 * b0 * a1 * a1 * z1 * c1 * c0 +
192  2 * b0 * a1 * z1 * a0 * c1 * c1;
193  const double diffb0 =
194  -2 * c1 * c1 * x0 * c0 * b1 * b0 + 2 * c1 * c1 * x0 * c0 * a1 * a0 -
195  c1 * x0 * c0 * c0 * a1 * a1 + c1 * x0 * c0 * c0 * b1 * b1 +
196  c1 * x0 * b0 * b0 * a1 * a1 - c1 * x0 * a0 * a0 * b1 * b1 +
197  c1 * x1 * c0 * c0 * a1 * a1 - c1 * x1 * c0 * c0 * b1 * b1 -
198  c1 * x1 * b0 * b0 * a1 * a1 + c1 * x1 * a0 * a0 * b1 * b1 +
199  a1 * z0 * c0 * c0 * b1 * b1 - a1 * z0 * b0 * b0 * c1 * c1 -
200  a1 * z0 * a0 * a0 * b1 * b1 + a1 * z0 * a0 * a0 * c1 * c1 -
201  a1 * z1 * c0 * c0 * b1 * b1 + a1 * z1 * b0 * b0 * c1 * c1 +
202  a1 * z1 * a0 * a0 * b1 * b1 - a1 * z1 * a0 * a0 * c1 * c1 -
203  2 * a0 * c1_3 * y0 * b0 + 2 * a0 * c1_3 * y1 * b0 + c1_3 * x0 * b0 * b0 -
204  c1_3 * x0 * a0 * a0 - c1_3 * x1 * b0 * b0 + c1_3 * x1 * a0 * a0 +
205  a1_3 * z0 * c0 * c0 - 2 * c1 * c1 * x1 * c0 * a1 * a0 +
206  2 * c1 * c1 * x1 * c0 * b1 * b0 - 2 * a1 * a1 * z0 * c0 * a0 * c1 +
207  2 * a1 * a1 * z0 * b0 * a0 * b1 - a1_3 * z0 * b0 * b0 -
208  a1_3 * z1 * c0 * c0 + a1_3 * z1 * b0 * b0 +
209  2 * a1 * a1 * z1 * c0 * a0 * c1 - 2 * a1 * a1 * z1 * b0 * a0 * b1 +
210  2 * c0 * b1 * b1 * x0 * a1 * a0 - 2 * c0 * b1 * x0 * b0 * a1 * a1 -
211  2 * c0 * b1 * b1 * x1 * a1 * a0 + 2 * c0 * b1 * x1 * b0 * a1 * a1 +
212  2 * a0 * a0 * c1 * y0 * a1 * b1 - 2 * a0 * c1 * y0 * b0 * a1 * a1 +
213  2 * a0 * c1 * c1 * y0 * c0 * b1 - 2 * a0 * a0 * c1 * y1 * a1 * b1 +
214  2 * a0 * c1 * y1 * b0 * a1 * a1 - 2 * a0 * c1 * c1 * y1 * c0 * b1 -
215  2 * c0 * a1 * a1 * y0 * a0 * b1 + 2 * c0 * a1_3 * y0 * b0 -
216  2 * c0 * a1_3 * y1 * b0 + 2 * c0 * a1 * y0 * b0 * c1 * c1 -
217  2 * c0 * c0 * a1 * y0 * c1 * b1 + 2 * c0 * a1 * a1 * y1 * a0 * b1 -
218  2 * c0 * a1 * y1 * b0 * c1 * c1 + 2 * c0 * c0 * a1 * y1 * c1 * b1 +
219  2 * a0 * b1 * z0 * b0 * c1 * c1 - 2 * a0 * b1 * b1 * z0 * c1 * c0 -
220  2 * a0 * b1 * z1 * b0 * c1 * c1 + 2 * a0 * b1 * b1 * z1 * c1 * c0;
221 
222  Matrix diffh(1, 6);
223  diffh(0, 0) = diffx0 / K;
224  diffh(0, 1) = diffy0 / K;
225  diffh(0, 2) = diffz0 / K;
226  K *= K;
227  diffh(0, 3) = diffa0 / K;
228  diffh(0, 4) = diffb0 / K;
229  diffh(0, 5) = 0;
230 
231  /* --- Multiply Jline=dline/dq with diffh=de/dline --- */
232  J.resize(1, J.cols());
233  J = diffh * Jline;
234  // J=Jline;
235 
236  sotDEBUG(15) << "# Out }" << endl;
237  return J;
238 }
239 
244  sotDEBUGIN(15);
245 
246  /* Line coordinates */
247  const Vector &line = lineSOUT(time);
248  const double &x0 = line(0);
249  const double &y0 = line(1);
250  const double &z0 = line(2);
251  const double &a0 = line(3);
252  const double &b0 = line(4);
253  const double &c0 = line(5);
254 
255  const Vector &posRef = positionRefSIN(time);
256  const double &x1 = posRef(0);
257  const double &y1 = posRef(1);
258  const double &z1 = posRef(2);
259  const double &a1 = posRef(3);
260  const double &b1 = posRef(4);
261  const double &c1 = posRef(5);
262 
263  error.resize(1);
264  double K = c0 * c0 * a1 * a1 - 2 * c0 * a1 * a0 * c1 - 2 * c0 * b1 * b0 * c1 +
265  c0 * c0 * b1 * b1 - 2 * b0 * a1 * a0 * b1 + b0 * b0 * a1 * a1 +
266  b0 * b0 * c1 * c1 + a0 * a0 * b1 * b1 + a0 * a0 * c1 * c1;
267  error(0) = (-b0 * c1 * x0 + b0 * c1 * x1 + c0 * b1 * x0 - c0 * b1 * x1 +
268  a0 * c1 * y0 - a0 * c1 * y1 - c0 * a1 * y0 + c0 * a1 * y1 -
269  a0 * b1 * z0 + a0 * b1 * z1 + b0 * a1 * z0 - b0 * a1 * z1) /
270  K;
271 
272  /* --- DEBUG --- */
273  // error.resize(6);
274  // error=line-posRef;
275 
276  sotDEBUGOUT(15);
277  return error;
278 }
279 
280 void FeatureLineDistance::display(std::ostream &os) const {
281  os << "LineDistance <" << name << ">";
282 }
dynamicgraph::sot::FeatureLineDistance::articularJacobianSIN
dynamicgraph::SignalPtr< dynamicgraph::Matrix, sigtime_t > articularJacobianSIN
Definition: feature-line-distance.hh:56
factory.hh
dynamicgraph::sot::MatrixHomogeneous
Eigen::Transform< double, 3, Eigen::Affine > SOT_CORE_EXPORT MatrixHomogeneous
Definition: matrix-geometry.hh:75
dynamicgraph::sot::FeatureAbstract::errorSOUT
SignalTimeDependent< dynamicgraph::Vector, sigtime_t > errorSOUT
This signal returns the error between the desired value and the current value : .
Definition: feature-abstract.hh:185
dynamicgraph
J
J
i
int i
dynamicgraph::sot::FeatureLineDistance::computeJacobian
virtual dynamicgraph::Matrix & computeJacobian(dynamicgraph::Matrix &res, sigtime_t time)
Definition: feature-line-distance.cpp:96
boost
dynamicgraph::sot::FeatureLineDistance::computeError
virtual dynamicgraph::Vector & computeError(dynamicgraph::Vector &res, sigtime_t time)
Definition: feature-line-distance.cpp:243
dynamicgraph::Entity::name
std::string name
dynamicgraph::Matrix
Eigen::MatrixXd Matrix
R
R
dynamicgraph::sot::FeatureAbstract::jacobianSOUT
SignalTimeDependent< dynamicgraph::Matrix, sigtime_t > jacobianSOUT
Jacobian of the error wrt the robot state: .
Definition: feature-abstract.hh:193
dynamicgraph::sot::FeatureAbstract
This class gives the abstract definition of a feature.
Definition: feature-abstract.hh:76
feature-line-distance.hh
dynamicgraph::sot::FeatureLineDistance
Class that defines point-3d control feature.
Definition: feature-line-distance.hh:46
debug.hh
sotDEBUGOUT
#define sotDEBUGOUT(level)
Definition: debug.hh:215
dim
int dim
dynamicgraph::sigtime_t
int64_t sigtime_t
dynamicgraph::sot::FeatureLineDistance::display
virtual void display(std::ostream &os) const
Definition: feature-line-distance.cpp:280
dynamicgraph::sot::FeatureLineDistance::vectorSIN
dynamicgraph::SignalPtr< dynamicgraph::Vector, sigtime_t > vectorSIN
Definition: feature-line-distance.hh:58
dynamicgraph::SignalTimeDependent::addDependency
virtual void addDependency(const SignalBase< Time > &signal)
sotDEBUGIN
#define sotDEBUGIN(level)
Definition: debug.hh:214
dynamicgraph::sot::FeatureLineDistance::positionSIN
dynamicgraph::SignalPtr< MatrixHomogeneous, sigtime_t > positionSIN
Definition: feature-line-distance.hh:55
pos
pos
M
M
dynamicgraph::size_type
Matrix::Index size_type
dynamicgraph::Vector
Eigen::VectorXd Vector
dynamicgraph::sot::FeatureLineDistance::lineSOUT
dynamicgraph::SignalTimeDependent< dynamicgraph::Vector, sigtime_t > lineSOUT
Definition: feature-line-distance.hh:59
exception-feature.hh
a0
a0
matrix-geometry.hh
dynamicgraph::sot::FeatureLineDistance::computeLineCoordinates
dynamicgraph::Vector & computeLineCoordinates(dynamicgraph::Vector &cood, sigtime_t time)
Definition: feature-line-distance.cpp:67
dynamicgraph::sot
dynamicgraph::sot::FeatureAbstract::getDimension
size_type getDimension(void) const
Shortest method.
Definition: feature-abstract.hh:121
x0
x0
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(FeatureLineDistance, "FeatureLineDistance")
v
v
dynamicgraph::sot::MatrixRotation
Eigen::Matrix< double, 3, 3 > SOT_CORE_EXPORT MatrixRotation
Definition: matrix-geometry.hh:76
dynamicgraph::sot::FeatureLineDistance::positionRefSIN
dynamicgraph::SignalPtr< dynamicgraph::Vector, sigtime_t > positionRefSIN
Definition: feature-line-distance.hh:57
dynamicgraph::Entity::signalRegistration
void signalRegistration(const SignalArray< sigtime_t > &signals)
line
int line
compile.name
name
Definition: compile.py:23
sotDEBUG
#define sotDEBUG(level)
Definition: debug.hh:168


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