Drake
drakeGeometryUtil.h
Go to the documentation of this file.
1 
5 #pragma once
6 
7 #include <Eigen/Dense>
8 #include <cstring>
9 #include <cmath>
10 #include <random>
11 
12 #include "drake/common/constants.h"
16 #include "drake/drakeGeometryUtil_export.h"
17 #include "drake/math/gradient.h"
18 #include "drake/math/quaternion.h"
20 
22 
23 DRAKE_DEPRECATED("Use drake::kQuaternionSize instead.")
24 const int QUAT_SIZE = 4;
25 DRAKE_DEPRECATED("Use drake::kRpySize instead.")
26 const int RPY_SIZE = 3;
27 DRAKE_DEPRECATED("Use drake::kSpaceDimension instead.")
28 const int SPACE_DIMENSION = 3;
29 
31 
32 DRAKEGEOMETRYUTIL_EXPORT double angleDiff(double phi1, double phi2);
33 
34 DRAKEGEOMETRYUTIL_EXPORT Eigen::Vector4d uniformlyRandomAxisAngle(
35  std::default_random_engine& generator);
36 DRAKEGEOMETRYUTIL_EXPORT Eigen::Vector4d uniformlyRandomQuat(
37  std::default_random_engine& generator);
38 DRAKEGEOMETRYUTIL_EXPORT Eigen::Matrix3d uniformlyRandomRotmat(
39  std::default_random_engine& generator);
40 DRAKEGEOMETRYUTIL_EXPORT Eigen::Vector3d uniformlyRandomRPY(
41  std::default_random_engine& generator);
42 
43 // NOTE: not reshaping second derivative to Matlab geval output format!
44 template <typename Derived>
46  const Eigen::MatrixBase<Derived>& x, typename Derived::PlainObject& x_norm,
47  typename drake::math::Gradient<Derived, Derived::RowsAtCompileTime,
48  1>::type* dx_norm = nullptr,
49  typename drake::math::Gradient<Derived, Derived::RowsAtCompileTime,
50  2>::type* ddx_norm = nullptr) {
51  typename Derived::Scalar xdotx = x.squaredNorm();
52  typename Derived::Scalar norm_x = sqrt(xdotx);
53  x_norm = x / norm_x;
54 
55  if (dx_norm) {
56  dx_norm->setIdentity(x.rows(), x.rows());
57  (*dx_norm) -= x * x.transpose() / xdotx;
58  (*dx_norm) /= norm_x;
59 
60  if (ddx_norm) {
61  auto dx_norm_transpose = transposeGrad(*dx_norm, x.rows());
62  auto ddx_norm_times_norm = -matGradMultMat(x_norm, x_norm.transpose(),
63  (*dx_norm), dx_norm_transpose);
64  auto dnorm_inv = -x.transpose() / (xdotx * norm_x);
65  (*ddx_norm) = ddx_norm_times_norm / norm_x;
66  auto temp = (*dx_norm) * norm_x;
67  typename Derived::Index n = x.rows();
68  for (int col = 0; col < n; col++) {
69  auto column_as_matrix = (dnorm_inv(0, col) * temp);
70  for (int row_block = 0; row_block < n; row_block++) {
71  ddx_norm->block(row_block * n, col, n, 1) +=
72  column_as_matrix.col(row_block);
73  }
74  }
75  }
76  }
77 }
78 
79 DRAKEGEOMETRYUTIL_EXPORT int rotationRepresentationSize(int rotation_type);
80 
81 /*
82  * rotation conversion gradient functions
83  */
84 template <typename Derived>
87 dquat2rotmat(const Eigen::MatrixBase<Derived>& q) {
88  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Eigen::MatrixBase<Derived>,
90 
92  drake::kQuaternionSize>::type ret;
93  typename Eigen::MatrixBase<Derived>::PlainObject qtilde;
95  normalizeVec(q, qtilde, &dqtilde);
96 
97  typedef typename Derived::Scalar Scalar;
98  Scalar w = qtilde(0);
99  Scalar x = qtilde(1);
100  Scalar y = qtilde(2);
101  Scalar z = qtilde(3);
102 
103  ret << w, x, -y, -z, z, y, x, w, -y, z, -w, x, -z, y, x, -w, w, -x, y, -z, x,
104  w, z, y, y, z, w, x, -x, -w, z, y, w, -x, -y, z;
105  ret *= 2.0;
106  ret *= dqtilde;
107  return ret;
108 }
109 
110 template <typename DerivedR, typename DerivedDR>
111 typename drake::math::Gradient<
112  Eigen::Matrix<typename DerivedR::Scalar, drake::kRpySize, 1>,
113  DerivedDR::ColsAtCompileTime>::type
114 drotmat2rpy(const Eigen::MatrixBase<DerivedR>& R,
115  const Eigen::MatrixBase<DerivedDR>& dR) {
116  EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Eigen::MatrixBase<DerivedR>,
119  EIGEN_STATIC_ASSERT(
120  Eigen::MatrixBase<DerivedDR>::RowsAtCompileTime == RotmatSize,
121  THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE);
122 
123  typename DerivedDR::Index nq = dR.cols();
124  typedef typename DerivedR::Scalar Scalar;
125  typedef typename drake::math::Gradient<
126  Eigen::Matrix<Scalar, drake::kRpySize, 1>,
127  DerivedDR::ColsAtCompileTime>::type ReturnType;
128  ReturnType drpy(drake::kRpySize, nq);
129 
130  auto dR11_dq =
131  getSubMatrixGradient<DerivedDR::ColsAtCompileTime>(dR, 0, 0, R.rows());
132  auto dR21_dq =
133  getSubMatrixGradient<DerivedDR::ColsAtCompileTime>(dR, 1, 0, R.rows());
134  auto dR31_dq =
135  getSubMatrixGradient<DerivedDR::ColsAtCompileTime>(dR, 2, 0, R.rows());
136  auto dR32_dq =
137  getSubMatrixGradient<DerivedDR::ColsAtCompileTime>(dR, 2, 1, R.rows());
138  auto dR33_dq =
139  getSubMatrixGradient<DerivedDR::ColsAtCompileTime>(dR, 2, 2, R.rows());
140 
141  Scalar sqterm = R(2, 1) * R(2, 1) + R(2, 2) * R(2, 2);
142 
143  using namespace std;
144  // droll_dq
145  drpy.row(0) = (R(2, 2) * dR32_dq - R(2, 1) * dR33_dq) / sqterm;
146 
147  // dpitch_dq
148  Scalar sqrt_sqterm = sqrt(sqterm);
149  drpy.row(1) =
150  (-sqrt_sqterm * dR31_dq +
151  R(2, 0) / sqrt_sqterm * (R(2, 1) * dR32_dq + R(2, 2) * dR33_dq)) /
152  (R(2, 0) * R(2, 0) + R(2, 1) * R(2, 1) + R(2, 2) * R(2, 2));
153 
154  // dyaw_dq
155  sqterm = R(0, 0) * R(0, 0) + R(1, 0) * R(1, 0);
156  drpy.row(2) = (R(0, 0) * dR21_dq - R(1, 0) * dR11_dq) / sqterm;
157  return drpy;
158 }
159 
160 template <typename DerivedR, typename DerivedDR>
161 typename drake::math::Gradient<
162  Eigen::Matrix<typename DerivedR::Scalar, drake::kQuaternionSize, 1>,
163  DerivedDR::ColsAtCompileTime>::type
164 drotmat2quat(const Eigen::MatrixBase<DerivedR>& R,
165  const Eigen::MatrixBase<DerivedDR>& dR) {
166  EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Eigen::MatrixBase<DerivedR>,
169  EIGEN_STATIC_ASSERT(
170  Eigen::MatrixBase<DerivedDR>::RowsAtCompileTime == RotmatSize,
171  THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE);
172 
173  typedef typename DerivedR::Scalar Scalar;
174  typedef typename drake::math::Gradient<
175  Eigen::Matrix<Scalar, drake::kQuaternionSize, 1>,
176  DerivedDR::ColsAtCompileTime>::type ReturnType;
177  typename DerivedDR::Index nq = dR.cols();
178 
179  auto dR11_dq =
180  getSubMatrixGradient<DerivedDR::ColsAtCompileTime>(dR, 0, 0, R.rows());
181  auto dR12_dq =
182  getSubMatrixGradient<DerivedDR::ColsAtCompileTime>(dR, 0, 1, R.rows());
183  auto dR13_dq =
184  getSubMatrixGradient<DerivedDR::ColsAtCompileTime>(dR, 0, 2, R.rows());
185  auto dR21_dq =
186  getSubMatrixGradient<DerivedDR::ColsAtCompileTime>(dR, 1, 0, R.rows());
187  auto dR22_dq =
188  getSubMatrixGradient<DerivedDR::ColsAtCompileTime>(dR, 1, 1, R.rows());
189  auto dR23_dq =
190  getSubMatrixGradient<DerivedDR::ColsAtCompileTime>(dR, 1, 2, R.rows());
191  auto dR31_dq =
192  getSubMatrixGradient<DerivedDR::ColsAtCompileTime>(dR, 2, 0, R.rows());
193  auto dR32_dq =
194  getSubMatrixGradient<DerivedDR::ColsAtCompileTime>(dR, 2, 1, R.rows());
195  auto dR33_dq =
196  getSubMatrixGradient<DerivedDR::ColsAtCompileTime>(dR, 2, 2, R.rows());
197 
198  Eigen::Matrix<Scalar, 4, 3> A;
199  A.row(0) << 1.0, 1.0, 1.0;
200  A.row(1) << 1.0, -1.0, -1.0;
201  A.row(2) << -1.0, 1.0, -1.0;
202  A.row(3) << -1.0, -1.0, 1.0;
203  Eigen::Matrix<Scalar, 4, 1> B = A * R.diagonal();
204  typename Eigen::Matrix<Scalar, 4, 1>::Index ind, max_col;
205  Scalar val = B.maxCoeff(&ind, &max_col);
206 
207  ReturnType dq(drake::kQuaternionSize, nq);
208  using namespace std;
209  switch (ind) {
210  case 0: {
211  // val = trace(M)
212  auto dvaldq = dR11_dq + dR22_dq + dR33_dq;
213  auto dwdq = dvaldq / (4.0 * sqrt(1.0 + val));
214  auto w = sqrt(1.0 + val) / 2.0;
215  auto wsquare4 = 4.0 * w * w;
216  dq.row(0) = dwdq;
217  dq.row(1) =
218  ((dR32_dq - dR23_dq) * w - (R(2, 1) - R(1, 2)) * dwdq) / wsquare4;
219  dq.row(2) =
220  ((dR13_dq - dR31_dq) * w - (R(0, 2) - R(2, 0)) * dwdq) / wsquare4;
221  dq.row(3) =
222  ((dR21_dq - dR12_dq) * w - (R(1, 0) - R(0, 1)) * dwdq) / wsquare4;
223  break;
224  }
225  case 1: {
226  // val = M(1, 1) - M(2, 2) - M(3, 3)
227  auto dvaldq = dR11_dq - dR22_dq - dR33_dq;
228  auto s = 2.0 * sqrt(1.0 + val);
229  auto ssquare = s * s;
230  auto dsdq = dvaldq / sqrt(1.0 + val);
231  dq.row(0) =
232  ((dR32_dq - dR23_dq) * s - (R(2, 1) - R(1, 2)) * dsdq) / ssquare;
233  dq.row(1) = .25 * dsdq;
234  dq.row(2) =
235  ((dR12_dq + dR21_dq) * s - (R(0, 1) + R(1, 0)) * dsdq) / ssquare;
236  dq.row(3) =
237  ((dR13_dq + dR31_dq) * s - (R(0, 2) + R(2, 0)) * dsdq) / ssquare;
238  break;
239  }
240  case 2: {
241  // val = M(2, 2) - M(1, 1) - M(3, 3)
242  auto dvaldq = -dR11_dq + dR22_dq - dR33_dq;
243  auto s = 2.0 * (sqrt(1.0 + val));
244  auto ssquare = s * s;
245  auto dsdq = dvaldq / sqrt(1.0 + val);
246  dq.row(0) =
247  ((dR13_dq - dR31_dq) * s - (R(0, 2) - R(2, 0)) * dsdq) / ssquare;
248  dq.row(1) =
249  ((dR12_dq + dR21_dq) * s - (R(0, 1) + R(1, 0)) * dsdq) / ssquare;
250  dq.row(2) = .25 * dsdq;
251  dq.row(3) =
252  ((dR23_dq + dR32_dq) * s - (R(1, 2) + R(2, 1)) * dsdq) / ssquare;
253  break;
254  }
255  default: {
256  // val = M(3, 3) - M(2, 2) - M(1, 1)
257  auto dvaldq = -dR11_dq - dR22_dq + dR33_dq;
258  auto s = 2.0 * (sqrt(1.0 + val));
259  auto ssquare = s * s;
260  auto dsdq = dvaldq / sqrt(1.0 + val);
261  dq.row(0) =
262  ((dR21_dq - dR12_dq) * s - (R(1, 0) - R(0, 1)) * dsdq) / ssquare;
263  dq.row(1) =
264  ((dR13_dq + dR31_dq) * s - (R(0, 2) + R(2, 0)) * dsdq) / ssquare;
265  dq.row(2) =
266  ((dR23_dq + dR32_dq) * s - (R(1, 2) + R(2, 1)) * dsdq) / ssquare;
267  dq.row(3) = .25 * dsdq;
268  break;
269  }
270  }
271  return dq;
272 }
273 
274 /*
275  * cross product related
276  */
277 template <typename Derived>
278 Eigen::Matrix<typename Derived::Scalar, 3, 3> vectorToSkewSymmetric(
279  const Eigen::MatrixBase<Derived>& p) {
280  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Eigen::MatrixBase<Derived>,
282  Eigen::Matrix<typename Derived::Scalar, 3, 3> ret;
283  ret << 0.0, -p(2), p(1), p(2), 0.0, -p(0), -p(1), p(0), 0.0;
284  return ret;
285 }
286 
287 template <typename DerivedA, typename DerivedB>
288 Eigen::Matrix<typename DerivedA::Scalar, 3, Eigen::Dynamic> dcrossProduct(
289  const Eigen::MatrixBase<DerivedA>& a, const Eigen::MatrixBase<DerivedB>& b,
292  Eigen::Matrix<typename DerivedA::Scalar, 3, Eigen::Dynamic> ret(3, da.cols());
293  ret.noalias() = da.colwise().cross(b);
294  ret.noalias() -= db.colwise().cross(a);
295  return ret;
296 }
297 
298 /*
299  * angular velocity conversion functions
300  */
301 template <typename DerivedQ, typename DerivedM, typename DerivedDM>
302 void angularvel2quatdotMatrix(const Eigen::MatrixBase<DerivedQ>& q,
303  Eigen::MatrixBase<DerivedM>& M,
304  Eigen::MatrixBase<DerivedDM>* dM = nullptr) {
305  // note: not normalizing to match MATLAB implementation
306  using Scalar = typename DerivedQ::Scalar;
308  M.row(0) << -q(1), -q(2), -q(3);
309  M.row(1) << q(0), q(3), -q(2);
310  M.row(2) << -q(3), q(0), q(1);
311  M.row(3) << q(2), -q(1), q(0);
312  M *= Scalar(0.5);
313 
314  if (dM) {
315  (*dM) << Scalar(0), Scalar(-0.5), Scalar(0), Scalar(0), Scalar(0.5),
316  Scalar(0), Scalar(0), Scalar(0), Scalar(0), Scalar(0), Scalar(0),
317  Scalar(-0.5), Scalar(0), Scalar(0), Scalar(0.5), Scalar(0), Scalar(0),
318  Scalar(0), Scalar(-0.5), Scalar(0), Scalar(0), Scalar(0), Scalar(0),
319  Scalar(0.5), Scalar(0.5), Scalar(0), Scalar(0), Scalar(0), Scalar(0),
320  Scalar(-0.5), Scalar(0), Scalar(0), Scalar(0), Scalar(0), Scalar(0),
321  Scalar(-0.5), Scalar(0), Scalar(0), Scalar(-0.5), Scalar(0), Scalar(0),
322  Scalar(0.5), Scalar(0), Scalar(0), Scalar(0.5), Scalar(0), Scalar(0),
323  Scalar(0);
324  }
325 }
326 
327 template <typename DerivedRPY, typename DerivedPhi, typename DerivedDPhi,
328  typename DerivedDDPhi>
330  const Eigen::MatrixBase<DerivedRPY>& rpy,
331  typename Eigen::MatrixBase<DerivedPhi>& phi,
332  typename Eigen::MatrixBase<DerivedDPhi>* dphi = nullptr,
333  typename Eigen::MatrixBase<DerivedDDPhi>* ddphi = nullptr) {
335 
336  typedef typename DerivedRPY::Scalar Scalar;
337  Scalar p = rpy(1);
338  Scalar y = rpy(2);
339 
340  using namespace std;
341  Scalar sy = sin(y);
342  Scalar cy = cos(y);
343  Scalar sp = sin(p);
344  Scalar cp = cos(p);
345  Scalar tp = sp / cp;
346 
347  phi << cy / cp, sy / cp, Scalar(0), -sy, cy, Scalar(0), cy * tp, tp * sy,
348  Scalar(1);
349  if (dphi) {
350  dphi->resize(phi.size(), drake::kRpySize);
351  Scalar sp2 = sp * sp;
352  Scalar cp2 = cp * cp;
353  (*dphi) << Scalar(0), (cy * sp) / cp2, -sy / cp, Scalar(0), Scalar(0), -cy,
354  Scalar(0), cy + (cy * sp2) / cp2, -(sp * sy) / cp, Scalar(0),
355  (sp * sy) / cp2, cy / cp, Scalar(0), Scalar(0), -sy, Scalar(0),
356  sy + (sp2 * sy) / cp2, (cy * sp) / cp, Scalar(0), Scalar(0), Scalar(0),
357  Scalar(0), Scalar(0), Scalar(0), Scalar(0), Scalar(0), Scalar(0);
358 
359  if (ddphi) {
360  ddphi->resize(dphi->size(), drake::kRpySize);
361  Scalar cp3 = cp2 * cp;
362  (*ddphi) << Scalar(0), Scalar(0), Scalar(0), Scalar(0), Scalar(0),
363  Scalar(0), Scalar(0), Scalar(0), Scalar(0), Scalar(0), Scalar(0),
364  Scalar(0), Scalar(0), Scalar(0), Scalar(0), Scalar(0), Scalar(0),
365  Scalar(0), Scalar(0), Scalar(0), Scalar(0), Scalar(0), Scalar(0),
366  Scalar(0), Scalar(0), Scalar(0), Scalar(0), Scalar(0),
367  -(cy * (cp2 - Scalar(2))) / cp3, (sp * sy) / (sp2 - Scalar(1)),
368  Scalar(0), Scalar(0), Scalar(0), Scalar(0),
369  (Scalar(2) * cy * sp) / cp3, sy / (sp2 - Scalar(1)), Scalar(0),
370  (Scalar(2) * sy - cp2 * sy) / cp3, (cy * sp) / cp2, Scalar(0),
371  Scalar(0), Scalar(0), Scalar(0), (Scalar(2) * sp * sy) / cp3,
372  cy / cp2, Scalar(0), Scalar(0), Scalar(0), Scalar(0), Scalar(0),
373  Scalar(0), Scalar(0), Scalar(0), Scalar(0), Scalar(0),
374  (sp * sy) / (sp2 - Scalar(1)), -cy / cp, Scalar(0), Scalar(0), sy,
375  Scalar(0), sy / (sp2 - Scalar(1)), -(cy * sp) / cp, Scalar(0),
376  (cy * sp) / cp2, -sy / cp, Scalar(0), Scalar(0), -cy, Scalar(0),
377  cy / cp2, -(sp * sy) / cp, Scalar(0), Scalar(0), Scalar(0), Scalar(0),
378  Scalar(0), Scalar(0), Scalar(0), Scalar(0), Scalar(0);
379  }
380  }
381 }
382 
383 template <typename DerivedRPY, typename DerivedE>
385  const Eigen::MatrixBase<DerivedRPY>& rpy, Eigen::MatrixBase<DerivedE>& E,
387  dE = nullptr) {
388  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Eigen::MatrixBase<DerivedRPY>,
390  EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Eigen::MatrixBase<DerivedE>,
393  typedef typename DerivedRPY::Scalar Scalar;
394  Scalar p = rpy(1);
395  Scalar y = rpy(2);
396  Scalar sp = sin(p);
397  Scalar cp = cos(p);
398  Scalar sy = sin(y);
399  Scalar cy = cos(y);
400 
401  E << cp * cy, -sy, 0.0, cp * sy, cy, 0.0, -sp, 0.0, 1.0;
402  if (dE) {
403  (*dE) << 0.0, -sp * cy, -cp * sy, 0.0, -sp * sy, cp * cy, 0.0, -cp, 0.0,
404  0.0, 0.0, -cy, 0.0, 0.0, -sy, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
405  0.0, 0.0, 0.0, 0.0;
406  }
407 }
408 
409 template <typename Derived>
410 Eigen::Matrix<typename Derived::Scalar, 3, 4> quatdot2angularvelMatrix(
411  const Eigen::MatrixBase<Derived>& q) {
412  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Eigen::MatrixBase<Derived>,
414  typedef typename Derived::Scalar Scalar;
415  auto qtilde = q.normalized();
416  Eigen::Matrix<Scalar, 3, 4> ret;
417  ret << -qtilde(1), qtilde(0), -qtilde(3), qtilde(2), -qtilde(2), qtilde(3),
418  qtilde(0), -qtilde(1), -qtilde(3), -qtilde(2), qtilde(1), qtilde(0);
419  ret *= Scalar(2);
420  return ret;
421 }
422 
423 template <typename DerivedRPY, typename DerivedRPYdot, typename DerivedOMEGA>
425  const Eigen::MatrixBase<DerivedRPY>& rpy,
426  const Eigen::MatrixBase<DerivedRPYdot>& rpydot,
427  Eigen::MatrixBase<DerivedOMEGA>& omega,
428  typename drake::math::Gradient<DerivedOMEGA, drake::kRpySize,
429  1>::type* domega = nullptr) {
430  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Eigen::MatrixBase<DerivedRPY>,
432  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Eigen::MatrixBase<DerivedRPYdot>,
434  EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Eigen::MatrixBase<DerivedOMEGA>,
435  drake::kRpySize, 1);
436 
437  Eigen::Matrix<typename DerivedOMEGA::Scalar, 3, 3> E;
438  if (domega) {
439  Eigen::Matrix<typename DerivedOMEGA::Scalar, 9, 3> dE;
440  rpydot2angularvelMatrix(rpy, E, &dE);
441  (*domega) << matGradMult(dE, rpydot), E;
442  } else {
443  rpydot2angularvelMatrix(rpy, E);
444  }
445  omega = E * rpydot;
446 }
447 
448 /*
449  * spatial transform functions
450  */
451 template <typename Derived>
453  typedef typename Eigen::Matrix<typename Derived::Scalar, drake::kTwistSize,
454  Derived::ColsAtCompileTime> type;
455 };
456 
457 template <typename DerivedM>
459  const Eigen::Transform<typename DerivedM::Scalar, 3, Eigen::Isometry>& T,
460  const Eigen::MatrixBase<DerivedM>& M) {
461  Eigen::Matrix<typename DerivedM::Scalar, drake::kTwistSize,
462  DerivedM::ColsAtCompileTime> ret(drake::kTwistSize, M.cols());
463  ret.template topRows<3>().noalias() = T.linear() * M.template topRows<3>();
464  ret.template bottomRows<3>().noalias() =
465  -ret.template topRows<3>().colwise().cross(T.translation());
466  ret.template bottomRows<3>().noalias() +=
467  T.linear() * M.template bottomRows<3>();
468  return ret;
469 }
470 
471 template <typename Scalar, typename DerivedX, typename DerivedDT,
472  typename DerivedDX>
474 dTransformSpatialMotion(const Eigen::Transform<Scalar, 3, Eigen::Isometry>& T,
475  const Eigen::MatrixBase<DerivedX>& X,
476  const Eigen::MatrixBase<DerivedDT>& dT,
477  const Eigen::MatrixBase<DerivedDX>& dX) {
478  DRAKE_ASSERT(dT.cols() == dX.cols());
479  typename DerivedDT::Index nq = dT.cols();
480 
481  const auto& R = T.linear();
482  const auto& p = T.translation();
483 
484  std::array<int, 3> rows = {{0, 1, 2}};
485  std::array<int, 3> R_cols = {{0, 1, 2}};
486  std::array<int, 1> p_cols = {{3}};
487 
488  auto dR = getSubMatrixGradient<Eigen::Dynamic>(dT, rows, R_cols, T.Rows);
489  auto dp = getSubMatrixGradient<Eigen::Dynamic>(dT, rows, p_cols, T.Rows);
490 
491  typename drake::math::Gradient<DerivedX, DerivedDX::ColsAtCompileTime,
492  1>::type ret(X.size(), nq);
493  std::array<int, 3> Xomega_rows = {{0, 1, 2}};
494  std::array<int, 3> Xv_rows = {{3, 4, 5}};
495  for (int col = 0; col < X.cols(); col++) {
496  auto Xomega_col = X.template block<3, 1>(0, col);
497  auto Xv_col = X.template block<3, 1>(3, col);
498 
499  auto RXomega_col = (R * Xomega_col).eval();
500 
501  std::array<int, 1> col_array = {{col}};
502  auto dXomega_col = getSubMatrixGradient<Eigen::Dynamic>(
503  dX, Xomega_rows, col_array, X.rows());
504  auto dXv_col =
505  getSubMatrixGradient<Eigen::Dynamic>(dX, Xv_rows, col_array, X.rows());
506 
507  auto domega_part_col =
508  (R * dXomega_col + matGradMult(dR, Xomega_col)).eval();
509  auto dv_part_col = (R * dXv_col + matGradMult(dR, Xv_col)).eval();
510  dv_part_col += dp.colwise().cross(RXomega_col);
511  dv_part_col -= domega_part_col.colwise().cross(p);
512 
513  setSubMatrixGradient<Eigen::Dynamic>(ret, domega_part_col, Xomega_rows,
514  col_array, X.rows());
515  setSubMatrixGradient<Eigen::Dynamic>(ret, dv_part_col, Xv_rows, col_array,
516  X.rows());
517  }
518  return ret;
519 }
520 
521 template <typename DerivedF>
523  const Eigen::Transform<typename DerivedF::Scalar, 3, Eigen::Isometry>& T,
524  const Eigen::MatrixBase<DerivedF>& F) {
525  Eigen::Matrix<typename DerivedF::Scalar, drake::kTwistSize,
526  DerivedF::ColsAtCompileTime> ret(drake::kTwistSize, F.cols());
527  ret.template bottomRows<3>().noalias() =
528  T.linear() * F.template bottomRows<3>().eval();
529  ret.template topRows<3>() =
530  -ret.template bottomRows<3>().colwise().cross(T.translation());
531  ret.template topRows<3>().noalias() += T.linear() * F.template topRows<3>();
532  return ret;
533 }
534 
535 template <typename Scalar, typename DerivedX, typename DerivedDT,
536  typename DerivedDX>
538 dTransformSpatialForce(const Eigen::Transform<Scalar, 3, Eigen::Isometry>& T,
539  const Eigen::MatrixBase<DerivedX>& X,
540  const Eigen::MatrixBase<DerivedDT>& dT,
541  const Eigen::MatrixBase<DerivedDX>& dX) {
542  DRAKE_ASSERT(dT.cols() == dX.cols());
543  typename DerivedDT::Index nq = dT.cols();
544 
545  const auto& R = T.linear();
546  const auto& p = T.translation();
547 
548  std::array<int, 3> rows = {{0, 1, 2}};
549  std::array<int, 3> R_cols = {{0, 1, 2}};
550  std::array<int, 1> p_cols = {{3}};
551 
552  auto dR = getSubMatrixGradient<Eigen::Dynamic>(dT, rows, R_cols, T.Rows);
553  auto dp = getSubMatrixGradient<Eigen::Dynamic>(dT, rows, p_cols, T.Rows);
554 
556  ret(X.size(), nq);
557  std::array<int, 3> Xomega_rows = {{0, 1, 2}};
558  std::array<int, 3> Xv_rows = {{3, 4, 5}};
559  for (int col = 0; col < X.cols(); col++) {
560  auto Xomega_col = X.template block<3, 1>(0, col);
561  auto Xv_col = X.template block<3, 1>(3, col);
562 
563  auto RXv_col = (R * Xv_col).eval();
564 
565  std::array<int, 1> col_array = {{col}};
566  auto dXomega_col = getSubMatrixGradient<Eigen::Dynamic>(
567  dX, Xomega_rows, col_array, X.rows());
568  auto dXv_col =
569  getSubMatrixGradient<Eigen::Dynamic>(dX, Xv_rows, col_array, X.rows());
570 
571  auto domega_part_col = (R * dXomega_col).eval();
572  domega_part_col += matGradMult(dR, Xomega_col);
573  auto dv_part_col = (R * dXv_col).eval();
574  dv_part_col += matGradMult(dR, Xv_col);
575  domega_part_col += dp.colwise().cross(RXv_col);
576  domega_part_col -= dv_part_col.colwise().cross(p);
577 
578  setSubMatrixGradient<Eigen::Dynamic>(ret, domega_part_col, Xomega_rows,
579  col_array, X.rows());
580  setSubMatrixGradient<Eigen::Dynamic>(ret, dv_part_col, Xv_rows, col_array,
581  X.rows());
582  }
583  return ret;
584 }
585 
586 template <typename DerivedI>
587 bool isRegularInertiaMatrix(const Eigen::MatrixBase<DerivedI>& I) {
588  using namespace Eigen;
589  using Scalar = typename DerivedI::Scalar;
590  bool ret = true;
591 
592  auto J = I.template topLeftCorner<3, 3>();
593  auto cross_part_1 = I.template topRightCorner<3, 3>();
594  auto cross_part_2 = I.template bottomLeftCorner<3, 3>();
595  const auto& m = I(3, 3);
596  ret = ret && (J - J.transpose()).isZero(); // J symmetric
597  ret = ret &&
598  (m * Matrix<Scalar, 3, 3>::Identity() -
599  I.template bottomRightCorner<3, 3>())
600  .isZero(); // mass part is a scalar matrix
601  ret = ret &&
602  (cross_part_1 - cross_part_2)
603  .isZero(); // cross parts transposes of each other
604  ret = ret &&
605  (cross_part_1 + cross_part_1.transpose())
606  .isZero(); // cross parts skew symmetric
607 
608  return ret;
609 }
610 
611 template <typename DerivedI>
613  const Eigen::Transform<typename DerivedI::Scalar, drake::kSpaceDimension,
614  Eigen::Isometry>& T_current_to_new,
615  const Eigen::MatrixBase<DerivedI>& I) {
616  using namespace Eigen;
617  using Scalar = typename DerivedI::Scalar;
618 
619  if (isRegularInertiaMatrix(I)) {
620  // this check is necessary to support the nonstandard inertia matrices
621  // resulting from added masses
622 
623  // TODO(tkoolen): SpatialInertiaMatrix class that keeps track of whether
624  // matrix is regular or not
625  const auto& R = T_current_to_new.linear();
626  const auto& p = T_current_to_new.translation();
627 
628  auto J = I.template topLeftCorner<3, 3>();
629  Matrix<Scalar, 3, 1> c;
630  c << I(2, 4), I(0, 5), I(1, 3);
631  const auto& m = I(3, 3);
632 
633  auto vectorToSkewSymmetricSquared = [](const Matrix<Scalar, 3, 1>& a) {
634  Matrix<Scalar, 3, 3> ret;
635  auto a0_2 = a(0) * a(0);
636  auto a1_2 = a(1) * a(1);
637  auto a2_2 = a(2) * a(2);
638 
639  ret(0, 0) = -a1_2 - a2_2;
640  ret(0, 1) = a(0) * a(1);
641  ret(0, 2) = a(0) * a(2);
642 
643  ret(1, 0) = ret(0, 1);
644  ret(1, 1) = -a0_2 - a2_2;
645  ret(1, 2) = a(1) * a(2);
646 
647  ret(2, 0) = ret(0, 2);
648  ret(2, 1) = ret(1, 2);
649  ret(2, 2) = -a0_2 - a1_2;
650  return ret;
651  };
652 
654  auto c_new = (R * c).eval();
655  auto J_new = I_new.template topLeftCorner<3, 3>();
656 
657  if (m > NumTraits<Scalar>::epsilon()) {
658  J_new = vectorToSkewSymmetricSquared(c_new);
659  c_new.noalias() += m * p;
660  J_new -= vectorToSkewSymmetricSquared(c_new);
661  J_new /= m;
662  } else {
663  J_new.setZero();
664  }
665  J_new.noalias() += R * J.template selfadjointView<Lower>() * R.transpose();
666 
667  I_new.template topRightCorner<3, 3>() = vectorToSkewSymmetric(c_new);
668  I_new.template bottomLeftCorner<3, 3>() =
669  -I_new.template topRightCorner<3, 3>();
670  I_new.template bottomRightCorner<3, 3>() =
671  I.template bottomRightCorner<3, 3>();
672 
673  return I_new;
674  } else {
675  auto I_half_transformed = transformSpatialForce(T_current_to_new, I);
676  return transformSpatialForce(T_current_to_new,
677  I_half_transformed.transpose());
678  }
679 }
680 
681 template <typename DerivedA, typename DerivedB>
683  const Eigen::MatrixBase<DerivedA>& a,
684  const Eigen::MatrixBase<DerivedB>& b) {
685  typename TransformSpatial<DerivedB>::type ret(drake::kTwistSize, b.cols());
686  ret.template topRows<3>() =
687  -b.template topRows<3>().colwise().cross(a.template topRows<3>());
688  ret.template bottomRows<3>() =
689  -b.template topRows<3>().colwise().cross(a.template bottomRows<3>());
690  ret.template bottomRows<3>() -=
691  b.template bottomRows<3>().colwise().cross(a.template topRows<3>());
692  return ret;
693 }
694 
695 template <typename DerivedA, typename DerivedB>
697  const Eigen::MatrixBase<DerivedA>& a,
698  const Eigen::MatrixBase<DerivedB>& b) {
699  typename TransformSpatial<DerivedB>::type ret(drake::kTwistSize, b.cols());
700  ret.template topRows<3>() =
701  -b.template topRows<3>().colwise().cross(a.template topRows<3>());
702  ret.template topRows<3>() -=
703  b.template bottomRows<3>().colwise().cross(a.template bottomRows<3>());
704  ret.template bottomRows<3>() =
705  -b.template bottomRows<3>().colwise().cross(a.template topRows<3>());
706  return ret;
707 }
708 
709 template <typename DerivedA, typename DerivedB>
711  const Eigen::MatrixBase<DerivedA>& a, const Eigen::MatrixBase<DerivedB>& b,
715  da.cols());
716  ret.row(0) = -da.row(2) * b[1] + da.row(1) * b[2] - a[2] * db.row(1) +
717  a[1] * db.row(2);
718  ret.row(1) =
719  da.row(2) * b[0] - da.row(0) * b[2] + a[2] * db.row(0) - a[0] * db.row(2);
720  ret.row(2) = -da.row(1) * b[0] + da.row(0) * b[1] - a[1] * db.row(0) +
721  a[0] * db.row(1);
722  ret.row(3) = -da.row(5) * b[1] + da.row(4) * b[2] - da.row(2) * b[4] +
723  da.row(1) * b[5] - a[5] * db.row(1) + a[4] * db.row(2) -
724  a[2] * db.row(4) + a[1] * db.row(5);
725  ret.row(4) = da.row(5) * b[0] - da.row(3) * b[2] + da.row(2) * b[3] -
726  da.row(0) * b[5] + a[5] * db.row(0) - a[3] * db.row(2) +
727  a[2] * db.row(3) - a[0] * db.row(5);
728  ret.row(5) = -da.row(4) * b[0] + da.row(3) * b[1] - da.row(1) * b[3] +
729  da.row(0) * b[4] - a[4] * db.row(0) + a[3] * db.row(1) -
730  a[1] * db.row(3) + a[0] * db.row(4);
731  return ret;
732 }
733 
734 template <typename DerivedA, typename DerivedB>
736  const Eigen::MatrixBase<DerivedA>& a, const Eigen::MatrixBase<DerivedB>& b,
740  da.cols());
741  ret.row(0) = da.row(2) * b[1] - da.row(1) * b[2] + da.row(5) * b[4] -
742  da.row(4) * b[5] + a[2] * db.row(1) - a[1] * db.row(2) +
743  a[5] * db.row(4) - a[4] * db.row(5);
744  ret.row(1) = -da.row(2) * b[0] + da.row(0) * b[2] - da.row(5) * b[3] +
745  da.row(3) * b[5] - a[2] * db.row(0) + a[0] * db.row(2) -
746  a[5] * db.row(3) + a[3] * db.row(5);
747  ret.row(2) = da.row(1) * b[0] - da.row(0) * b[1] + da.row(4) * b[3] -
748  da.row(3) * b[4] + a[1] * db.row(0) - a[0] * db.row(1) +
749  a[4] * db.row(3) - a[3] * db.row(4);
750  ret.row(3) =
751  da.row(2) * b[4] - da.row(1) * b[5] + a[2] * db.row(4) - a[1] * db.row(5);
752  ret.row(4) = -da.row(2) * b[3] + da.row(0) * b[5] - a[2] * db.row(3) +
753  a[0] * db.row(5);
754  ret.row(5) =
755  da.row(1) * b[3] - da.row(0) * b[4] + a[1] * db.row(3) - a[0] * db.row(4);
756  ret = -ret;
757  return ret;
758 }
759 
760 /*
761  * spatial transform gradient methods
762  */
763 template <typename DerivedQdotToV>
764 struct DHomogTrans {
765  typedef typename Eigen::Matrix<typename DerivedQdotToV::Scalar,
767  DerivedQdotToV::ColsAtCompileTime> type;
768 };
769 
770 template <typename DerivedS, typename DerivedQdotToV>
772  const Eigen::Transform<typename DerivedQdotToV::Scalar, 3, Eigen::Isometry>&
773  T,
774  const Eigen::MatrixBase<DerivedS>& S,
775  const Eigen::MatrixBase<DerivedQdotToV>& qdot_to_v) {
776  const int nq_at_compile_time = DerivedQdotToV::ColsAtCompileTime;
777  typename DerivedQdotToV::Index nq = qdot_to_v.cols();
778  auto qdot_to_twist = (S * qdot_to_v).eval();
779 
780  const int numel = HOMOGENEOUS_TRANSFORM_SIZE;
781  Eigen::Matrix<typename DerivedQdotToV::Scalar, numel, nq_at_compile_time> ret(
782  numel, nq);
783 
784  const auto& Rx = T.linear().col(0);
785  const auto& Ry = T.linear().col(1);
786  const auto& Rz = T.linear().col(2);
787 
788  const auto& qdot_to_omega_x = qdot_to_twist.row(0);
789  const auto& qdot_to_omega_y = qdot_to_twist.row(1);
790  const auto& qdot_to_omega_z = qdot_to_twist.row(2);
791 
792  ret.template middleRows<3>(0) = -Rz * qdot_to_omega_y + Ry * qdot_to_omega_z;
793  ret.row(3).setZero();
794 
795  ret.template middleRows<3>(4) = Rz * qdot_to_omega_x - Rx * qdot_to_omega_z;
796  ret.row(7).setZero();
797 
798  ret.template middleRows<3>(8) = -Ry * qdot_to_omega_x + Rx * qdot_to_omega_y;
799  ret.row(11).setZero();
800 
801  ret.template middleRows<3>(12) = T.linear() * qdot_to_twist.bottomRows(3);
802  ret.row(15).setZero();
803 
804  return ret;
805 }
806 
807 template <typename DerivedDT>
809  const Eigen::Transform<typename DerivedDT::Scalar, 3, Eigen::Isometry>& T,
810  const Eigen::MatrixBase<DerivedDT>& dT) {
811  typename DerivedDT::Index nq = dT.cols();
812 
813  const auto& R = T.linear();
814  const auto& p = T.translation();
815 
816  std::array<int, 3> rows = {{0, 1, 2}};
817  std::array<int, 3> R_cols = {{0, 1, 2}};
818  std::array<int, 1> p_cols = {{3}};
819 
820  auto dR = getSubMatrixGradient<Eigen::Dynamic>(dT, rows, R_cols, T.Rows);
821  auto dp = getSubMatrixGradient<Eigen::Dynamic>(dT, rows, p_cols, T.Rows);
822 
823  auto dinvT_R = transposeGrad(dR, R.rows());
824  auto dinvT_p = (-R.transpose() * dp - matGradMult(dinvT_R, p)).eval();
825 
826  const int numel = HOMOGENEOUS_TRANSFORM_SIZE;
827  Eigen::Matrix<typename DerivedDT::Scalar, numel, DerivedDT::ColsAtCompileTime>
828  ret(numel, nq);
829  setSubMatrixGradient<Eigen::Dynamic>(ret, dinvT_R, rows, R_cols, T.Rows);
830  setSubMatrixGradient<Eigen::Dynamic>(ret, dinvT_p, rows, p_cols, T.Rows);
831 
832  // zero out gradient of elements in last row:
833  const int last_row = 3;
834  for (int col = 0; col < T.HDim; col++) {
835  ret.row(last_row + col * T.Rows).setZero();
836  }
837 
838  return ret;
839 }
840 
841 template <typename Derived>
842 Eigen::Matrix<typename Derived::Scalar, 3, 1> flipExpmap(
843  const Eigen::MatrixBase<Derived>& expmap) {
844  using namespace Eigen;
845  typedef typename Derived::Scalar Scalar;
846  static_assert(
847  Derived::RowsAtCompileTime == 3 && Derived::ColsAtCompileTime == 1,
848  "Wrong size.");
849 
850  Scalar expmap_norm = expmap.norm();
851  bool is_degenerate = (expmap_norm < std::numeric_limits<double>::epsilon());
852  Eigen::Matrix<Scalar, 3, 1> ret = expmap;
853  if (!is_degenerate) ret -= expmap / expmap_norm * 2 * M_PI;
854 
855  return ret;
856 }
857 
858 template <typename Derived1, typename Derived2>
859 Eigen::Matrix<typename Derived1::Scalar, 3, 1> unwrapExpmap(
860  const Eigen::MatrixBase<Derived1>& expmap1,
861  const Eigen::MatrixBase<Derived2>& expmap2) {
862  using namespace Eigen;
863  static_assert(
864  Derived1::RowsAtCompileTime == 3 && Derived1::ColsAtCompileTime == 1,
865  "Wrong size.");
866  static_assert(
867  Derived2::RowsAtCompileTime == 3 && Derived2::ColsAtCompileTime == 1,
868  "Wrong size.");
869  static_assert(
870  std::is_same<typename Derived1::Scalar, typename Derived2::Scalar>::value,
871  "Scalar types don't match.");
872  typedef typename Derived1::Scalar Scalar;
873  typedef typename NumTraits<Scalar>::Real Real;
874 
875  auto expmap2_flip = flipExpmap(expmap2);
876  Real distance1 = (expmap1 - expmap2).squaredNorm();
877  Real distance2 = (expmap1 - expmap2_flip).squaredNorm();
878  if (distance1 > distance2) {
879  return expmap2_flip;
880  } else {
881  return expmap2;
882  }
883 }
Eigen::Matrix< typename Derived::Scalar, drake::kTwistSize, Derived::ColsAtCompileTime > type
Definition: drakeGeometryUtil.h:454
const int SPACE_DIMENSION
Definition: drakeGeometryUtil.h:28
const int RotmatSize
Definition: drakeGeometryUtil.h:30
THIS FILE IS DEPRECATED.
Definition: drakeGeometryUtil.h:452
std::vector< Number > x
Definition: IpoptSolver.cpp:169
This file contains abbreviated definitions for certain specializations of Eigen::Matrix that are comm...
DHomogTrans< DerivedDT >::type dHomogTransInv(const Eigen::Transform< typename DerivedDT::Scalar, 3, Eigen::Isometry > &T, const Eigen::MatrixBase< DerivedDT > &dT)
Definition: drakeGeometryUtil.h:808
DRAKEGEOMETRYUTIL_EXPORT Eigen::Vector4d uniformlyRandomAxisAngle(std::default_random_engine &generator)
Definition: drakeGeometryUtil.cpp:20
Provides a portable macro for use in generating compile-time warnings for use of code that is permitt...
void normalizeVec(const Eigen::MatrixBase< Derived > &x, typename Derived::PlainObject &x_norm, typename drake::math::Gradient< Derived, Derived::RowsAtCompileTime, 1 >::type *dx_norm=nullptr, typename drake::math::Gradient< Derived, Derived::RowsAtCompileTime, 2 >::type *ddx_norm=nullptr)
Definition: drakeGeometryUtil.h:45
Definition: constants.h:3
MatGradMult< DerivedDA, DerivedB >::type matGradMult(const Eigen::MatrixBase< DerivedDA > &dA, const Eigen::MatrixBase< DerivedB > &B)
Definition: drakeGradientUtil.h:143
drake::math::Gradient< DerivedX, DerivedDX::ColsAtCompileTime, 1 >::type dTransformSpatialMotion(const Eigen::Transform< Scalar, 3, Eigen::Isometry > &T, const Eigen::MatrixBase< DerivedX > &X, const Eigen::MatrixBase< DerivedDT > &dT, const Eigen::MatrixBase< DerivedDX > &dX)
Definition: drakeGeometryUtil.h:474
drake::math::Gradient< DerivedX, DerivedDX::ColsAtCompileTime >::type dTransformSpatialForce(const Eigen::Transform< Scalar, 3, Eigen::Isometry > &T, const Eigen::MatrixBase< DerivedX > &X, const Eigen::MatrixBase< DerivedDT > &dT, const Eigen::MatrixBase< DerivedDX > &dX)
Definition: drakeGeometryUtil.h:538
Eigen::Matrix< Scalar, kTwistSize, Eigen::Dynamic > TwistMatrix
A matrix with one twist per column, and dynamically many columns.
Definition: eigen_types.h:73
DRAKEGEOMETRYUTIL_EXPORT Eigen::Matrix3d uniformlyRandomRotmat(std::default_random_engine &generator)
Definition: drakeGeometryUtil.cpp:36
DRAKEGEOMETRYUTIL_EXPORT Eigen::Vector4d uniformlyRandomQuat(std::default_random_engine &generator)
Definition: drakeGeometryUtil.cpp:32
STL namespace.
Eigen::Matrix< typename DerivedA::Scalar, 3, Eigen::Dynamic > dcrossProduct(const Eigen::MatrixBase< DerivedA > &a, const Eigen::MatrixBase< DerivedB > &b, const typename drake::math::Gradient< DerivedA, Eigen::Dynamic >::type &da, const typename drake::math::Gradient< DerivedB, Eigen::Dynamic >::type &db)
Definition: drakeGeometryUtil.h:288
FunctionalForm cos(FunctionalForm const &x)
Definition: functional_form.cc:188
default_random_engine generator
Definition: testSplineGeneration.cpp:11
drake::math::Gradient< Eigen::Matrix< typename Derived::Scalar, 3, 3 >, drake::kQuaternionSize >::type dquat2rotmat(const Eigen::MatrixBase< Derived > &q)
Definition: drakeGeometryUtil.h:87
Definition: drakeGeometryUtil.h:764
Eigen::Matrix< FunctionalForm, 3, 2 > A
Definition: functional_form_test.cc:619
FunctionalForm sqrt(FunctionalForm const &x)
Definition: functional_form.cc:208
#define DRAKE_ASSERT(condition)
DRAKE_ASSERT(condition) is similar to the built-in assert(condition) from the C++ system header <cas...
Definition: drake_assert.h:35
void rpydot2angularvelMatrix(const Eigen::MatrixBase< DerivedRPY > &rpy, Eigen::MatrixBase< DerivedE > &E, typename drake::math::Gradient< DerivedE, drake::kRpySize, 1 >::type *dE=nullptr)
Definition: drakeGeometryUtil.h:384
void rpydot2angularvel(const Eigen::MatrixBase< DerivedRPY > &rpy, const Eigen::MatrixBase< DerivedRPYdot > &rpydot, Eigen::MatrixBase< DerivedOMEGA > &omega, typename drake::math::Gradient< DerivedOMEGA, drake::kRpySize, 1 >::type *domega=nullptr)
Definition: drakeGeometryUtil.h:424
constexpr int kTwistSize
https://en.wikipedia.org/wiki/Screw_theory#Twist
Definition: constants.h:12
Provides Drake&#39;s assertion implementation.
DRAKEGEOMETRYUTIL_EXPORT Eigen::Vector3d uniformlyRandomRPY(std::default_random_engine &generator)
Definition: drakeGeometryUtil.cpp:40
MatGradMultMat< DerivedA, DerivedB, DerivedDA >::type matGradMultMat(const Eigen::MatrixBase< DerivedA > &A, const Eigen::MatrixBase< DerivedB > &B, const Eigen::MatrixBase< DerivedDA > &dA, const Eigen::MatrixBase< DerivedDB > &dB)
Definition: drakeGradientUtil.h:106
DRAKEGEOMETRYUTIL_EXPORT double angleDiff(double phi1, double phi2)
Definition: drakeGeometryUtil.cpp:10
drake::SquareTwistMatrix< typename DerivedI::Scalar > transformSpatialInertia(const Eigen::Transform< typename DerivedI::Scalar, drake::kSpaceDimension, Eigen::Isometry > &T_current_to_new, const Eigen::MatrixBase< DerivedI > &I)
Definition: drakeGeometryUtil.h:612
static int nq
Definition: inverseKinSnoptBackend.cpp:60
drake::math::Gradient< Eigen::Matrix< typename DerivedR::Scalar, drake::kRpySize, 1 >, DerivedDR::ColsAtCompileTime >::type drotmat2rpy(const Eigen::MatrixBase< DerivedR > &R, const Eigen::MatrixBase< DerivedDR > &dR)
Definition: drakeGeometryUtil.h:114
drake::math::Gradient< Eigen::Matrix< typename DerivedR::Scalar, drake::kQuaternionSize, 1 >, DerivedDR::ColsAtCompileTime >::type drotmat2quat(const Eigen::MatrixBase< DerivedR > &R, const Eigen::MatrixBase< DerivedDR > &dR)
Definition: drakeGeometryUtil.h:164
const int QUAT_SIZE
Definition: drakeGeometryUtil.h:24
Eigen::Matrix< FunctionalForm, 2, 3 > B
Definition: functional_form_test.cc:620
DRAKEGEOMETRYUTIL_EXPORT int rotationRepresentationSize(int rotation_type)
Definition: drakeGeometryUtil.cpp:44
Eigen::Matrix< typename Derived::Scalar, 3, 3 > vectorToSkewSymmetric(const Eigen::MatrixBase< Derived > &p)
Definition: drakeGeometryUtil.h:278
const int HOMOGENEOUS_TRANSFORM_SIZE
Definition: drakeGeometryUtil.h:21
Eigen::Matrix< typename Derived::Scalar, 3, 1 > flipExpmap(const Eigen::MatrixBase< Derived > &expmap)
Definition: drakeGeometryUtil.h:842
drake::TwistMatrix< typename DerivedA::Scalar > dCrossSpatialMotion(const Eigen::MatrixBase< DerivedA > &a, const Eigen::MatrixBase< DerivedB > &b, const typename drake::math::Gradient< DerivedA, Eigen::Dynamic >::type &da, const typename drake::math::Gradient< DerivedB, Eigen::Dynamic >::type &db)
Definition: drakeGeometryUtil.h:710
Eigen::Matrix< typename DerivedQdotToV::Scalar, HOMOGENEOUS_TRANSFORM_SIZE, DerivedQdotToV::ColsAtCompileTime > type
Definition: drakeGeometryUtil.h:767
DHomogTrans< DerivedQdotToV >::type dHomogTrans(const Eigen::Transform< typename DerivedQdotToV::Scalar, 3, Eigen::Isometry > &T, const Eigen::MatrixBase< DerivedS > &S, const Eigen::MatrixBase< DerivedQdotToV > &qdot_to_v)
Definition: drakeGeometryUtil.h:771
constexpr int kSpaceDimension
Definition: constants.h:7
#define DRAKE_DEPRECATED(message)
Use DRAKE_DEPRECATED("message") to discourage use of particular classes, typedefs, variables, non-static data members, functions, arguments, enumerations, and template specializations.
Definition: drake_deprecated.h:33
Eigen::Matrix< typename Derived1::Scalar, 3, 1 > unwrapExpmap(const Eigen::MatrixBase< Derived1 > &expmap1, const Eigen::MatrixBase< Derived2 > &expmap2)
Definition: drakeGeometryUtil.h:859
Utilities for arithmetic on quaternions.
std::vector< snopt::doublereal > F
Definition: SnoptSolver.cpp:47
TransformSpatial< DerivedF >::type transformSpatialForce(const Eigen::Transform< typename DerivedF::Scalar, 3, Eigen::Isometry > &T, const Eigen::MatrixBase< DerivedF > &F)
Definition: drakeGeometryUtil.h:522
constexpr int kQuaternionSize
Definition: constants.h:5
const int RPY_SIZE
Definition: drakeGeometryUtil.h:26
Eigen::Matrix< typename Derived::Scalar,((Derived::SizeAtCompileTime==Eigen::Dynamic||Nq==Eigen::Dynamic)?Eigen::Dynamic:Gradient< Derived, Nq, DerivativeOrder-1 >::type::SizeAtCompileTime), Nq > type
Definition: gradient.h:20
Definition: gradient.h:13
constexpr int kRpySize
Definition: constants.h:9
void angularvel2rpydotMatrix(const Eigen::MatrixBase< DerivedRPY > &rpy, typename Eigen::MatrixBase< DerivedPhi > &phi, typename Eigen::MatrixBase< DerivedDPhi > *dphi=nullptr, typename Eigen::MatrixBase< DerivedDDPhi > *ddphi=nullptr)
Definition: drakeGeometryUtil.h:329
TransformSpatial< DerivedB >::type crossSpatialMotion(const Eigen::MatrixBase< DerivedA > &a, const Eigen::MatrixBase< DerivedB > &b)
Definition: drakeGeometryUtil.h:682
Eigen::Matrix< Scalar, kTwistSize, kTwistSize > SquareTwistMatrix
A six-by-six matrix.
Definition: eigen_types.h:77
TransformSpatial< DerivedM >::type transformSpatialMotion(const Eigen::Transform< typename DerivedM::Scalar, 3, Eigen::Isometry > &T, const Eigen::MatrixBase< DerivedM > &M)
Definition: drakeGeometryUtil.h:458
Eigen::Matrix< typename Derived::Scalar, 3, 4 > quatdot2angularvelMatrix(const Eigen::MatrixBase< Derived > &q)
Definition: drakeGeometryUtil.h:410
void angularvel2quatdotMatrix(const Eigen::MatrixBase< DerivedQ > &q, Eigen::MatrixBase< DerivedM > &M, Eigen::MatrixBase< DerivedDM > *dM=nullptr)
Definition: drakeGeometryUtil.h:302
TransformSpatial< DerivedB >::type crossSpatialForce(const Eigen::MatrixBase< DerivedA > &a, const Eigen::MatrixBase< DerivedB > &b)
Definition: drakeGeometryUtil.h:696
FunctionalForm sin(FunctionalForm const &x)
Definition: functional_form.cc:203
Derived::PlainObject transposeGrad(const Eigen::MatrixBase< Derived > &dX, typename Derived::Index rows_X)
Definition: drakeGradientUtil.h:89
drake::TwistMatrix< typename DerivedA::Scalar > dCrossSpatialForce(const Eigen::MatrixBase< DerivedA > &a, const Eigen::MatrixBase< DerivedB > &b, const typename drake::math::Gradient< DerivedA, Eigen::Dynamic >::type &da, const typename drake::math::Gradient< DerivedB, Eigen::Dynamic >::type &db)
Definition: drakeGeometryUtil.h:735
bool isRegularInertiaMatrix(const Eigen::MatrixBase< DerivedI > &I)
Definition: drakeGeometryUtil.h:587