6 #ifndef __pinocchio_spatial_explog_hpp__ 7 #define __pinocchio_spatial_explog_hpp__ 9 #include "pinocchio/fwd.hpp" 10 #include "pinocchio/utils/static-if.hpp" 11 #include "pinocchio/math/fwd.hpp" 12 #include "pinocchio/math/sincos.hpp" 13 #include "pinocchio/math/taylor-expansion.hpp" 14 #include "pinocchio/spatial/motion.hpp" 15 #include "pinocchio/spatial/skew.hpp" 16 #include "pinocchio/spatial/se3.hpp" 18 #include <Eigen/Geometry> 20 #include "pinocchio/spatial/log.hpp" 32 template<
typename Vector3Like>
33 typename Eigen::Matrix<typename Vector3Like::Scalar,3,3,PINOCCHIO_EIGEN_PLAIN_TYPE(Vector3Like)::Options>
34 exp3(
const Eigen::MatrixBase<Vector3Like> & v)
36 PINOCCHIO_ASSERT_MATRIX_SPECIFIC_SIZE (Vector3Like, v, 3, 1);
38 typedef typename Vector3Like::Scalar Scalar;
39 typedef typename PINOCCHIO_EIGEN_PLAIN_TYPE(Vector3Like) Vector3LikePlain;
40 typedef Eigen::Matrix<Scalar,3,3,Vector3LikePlain::Options> Matrix3;
42 const Scalar t2 = v.squaredNorm();
44 const Scalar t = math::sqrt(t2);
45 Scalar ct,st;
SINCOS(t,&st,&ct);
49 Scalar(1)/Scalar(2) - t2/24);
53 Matrix3 res(alpha_vxvx * v * v.transpose());
54 res.coeffRef(0,1) -= alpha_vx * v[2]; res.coeffRef(1,0) += alpha_vx * v[2];
55 res.coeffRef(0,2) += alpha_vx * v[1]; res.coeffRef(2,0) -= alpha_vx * v[1];
56 res.coeffRef(1,2) -= alpha_vx * v[0]; res.coeffRef(2,1) += alpha_vx * v[0];
61 res.diagonal().array() += ct;
73 template<
typename Matrix3Like>
74 Eigen::Matrix<typename Matrix3Like::Scalar,3,1,PINOCCHIO_EIGEN_PLAIN_TYPE(Matrix3Like)::Options>
75 log3(
const Eigen::MatrixBase<Matrix3Like> & R,
76 typename Matrix3Like::Scalar & theta)
78 typedef typename Matrix3Like::Scalar Scalar;
79 typedef Eigen::Matrix<Scalar,3,1,
80 PINOCCHIO_EIGEN_PLAIN_TYPE(Matrix3Like)::Options> Vector3;
94 template<
typename Matrix3Like>
95 Eigen::Matrix<typename Matrix3Like::Scalar,3,1,PINOCCHIO_EIGEN_PLAIN_TYPE(Matrix3Like)::Options>
96 log3(
const Eigen::MatrixBase<Matrix3Like> & R)
98 typename Matrix3Like::Scalar theta;
99 return log3(R.derived(),theta);
110 template<AssignmentOperatorType op,
typename Vector3Like,
typename Matrix3Like>
111 void Jexp3(
const Eigen::MatrixBase<Vector3Like> & r,
112 const Eigen::MatrixBase<Matrix3Like> & Jexp)
114 PINOCCHIO_ASSERT_MATRIX_SPECIFIC_SIZE (Vector3Like, r , 3, 1);
115 PINOCCHIO_ASSERT_MATRIX_SPECIFIC_SIZE (Matrix3Like, Jexp, 3, 3);
117 Matrix3Like & Jout = PINOCCHIO_EIGEN_CONST_CAST(Matrix3Like,Jexp);
118 typedef typename Matrix3Like::Scalar Scalar;
120 const Scalar n2 = r.squaredNorm();
121 const Scalar n = math::sqrt(n2);
122 const Scalar n_inv = Scalar(1)/n;
123 const Scalar n2_inv = n_inv * n_inv;
124 Scalar cn,sn;
SINCOS(n,&sn,&cn);
127 Scalar(1) - n2/Scalar(6),
130 - Scalar(1)/Scalar(2) - n2/Scalar(24),
133 Scalar(1)/Scalar(6) - n2/Scalar(120),
139 Jout.diagonal().setConstant(a);
140 Jout(0,1) = -b*r[2]; Jout(1,0) = -Jout(0,1);
141 Jout(0,2) = b*r[1]; Jout(2,0) = -Jout(0,2);
142 Jout(1,2) = -b*r[0]; Jout(2,1) = -Jout(1,2);
143 Jout.noalias() += c * r * r.transpose();
146 Jout.diagonal().array() += a;
147 Jout(0,1) += -b*r[2]; Jout(1,0) += b*r[2];
148 Jout(0,2) += b*r[1]; Jout(2,0) += -b*r[1];
149 Jout(1,2) += -b*r[0]; Jout(2,1) += b*r[0];
150 Jout.noalias() += c * r * r.transpose();
153 Jout.diagonal().array() -= a;
154 Jout(0,1) -= -b*r[2]; Jout(1,0) -= b*r[2];
155 Jout(0,2) -= b*r[1]; Jout(2,0) -= -b*r[1];
156 Jout(1,2) -= -b*r[0]; Jout(2,1) -= b*r[0];
157 Jout.noalias() -= c * r * r.transpose();
160 assert(
false &&
"Wrong Op requesed value");
173 template<
typename Vector3Like,
typename Matrix3Like>
174 void Jexp3(
const Eigen::MatrixBase<Vector3Like> & r,
175 const Eigen::MatrixBase<Matrix3Like> & Jexp)
177 Jexp3<SETTO>(r, Jexp);
192 template<
typename Scalar,
typename Vector3Like,
typename Matrix3Like>
194 const Eigen::MatrixBase<Vector3Like> & log,
195 const Eigen::MatrixBase<Matrix3Like> & Jlog)
198 PINOCCHIO_EIGEN_CONST_CAST(Matrix3Like,Jlog));
213 template<
typename Matrix3Like1,
typename Matrix3Like2>
214 void Jlog3(
const Eigen::MatrixBase<Matrix3Like1> & R,
215 const Eigen::MatrixBase<Matrix3Like2> & Jlog)
217 typedef typename Matrix3Like1::Scalar Scalar;
218 typedef Eigen::Matrix<Scalar,3,1,PINOCCHIO_EIGEN_PLAIN_TYPE(Matrix3Like1)::Options> Vector3;
221 Vector3 w(
log3(R,t));
222 Jlog3(t,w,PINOCCHIO_EIGEN_CONST_CAST(Matrix3Like2,Jlog));
234 template<
typename MotionDerived>
238 typedef typename MotionDerived::Scalar Scalar;
239 enum { Options = PINOCCHIO_EIGEN_PLAIN_TYPE(
typename MotionDerived::Vector3)::Options };
244 typename SE3::LinearType & trans = res.translation();
245 typename SE3::AngularType & rot = res.rotation();
247 const typename MotionDerived::ConstAngularType & w = nu.angular();
248 const typename MotionDerived::ConstLinearType & v = nu.linear();
250 Scalar alpha_wxv, alpha_v, alpha_w, diagonal_term;
251 const Scalar t2 = w.squaredNorm();
252 const Scalar t = math::sqrt(t2);
253 Scalar ct,st;
SINCOS(t,&st,&ct);
254 const Scalar inv_t2 = Scalar(1)/t2;
257 Scalar(1)/Scalar(2) - t2/24,
258 (Scalar(1) - ct)*inv_t2);
265 (Scalar(1)/Scalar(6) - t2/120),
266 (Scalar(1) - alpha_v)*inv_t2);
273 trans.noalias() = (alpha_v*v + (alpha_w*w.dot(v))*w + alpha_wxv*w.cross(v));
276 rot.noalias() = alpha_wxv * w * w.transpose();
277 rot.coeffRef(0,1) -= alpha_v * w[2]; rot.coeffRef(1,0) += alpha_v * w[2];
278 rot.coeffRef(0,2) += alpha_v * w[1]; rot.coeffRef(2,0) -= alpha_v * w[1];
279 rot.coeffRef(1,2) -= alpha_v * w[0]; rot.coeffRef(2,1) += alpha_v * w[0];
280 rot.diagonal().array() += diagonal_term;
293 template<
typename Vector6Like>
295 exp6(
const Eigen::MatrixBase<Vector6Like> & v)
297 PINOCCHIO_ASSERT_MATRIX_SPECIFIC_SIZE (Vector6Like, v, 6, 1);
311 template<
typename Scalar,
int Options>
329 template<
typename Matrix4Like>
331 log6(
const Eigen::MatrixBase<Matrix4Like> & M)
333 PINOCCHIO_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix4Like, M, 4, 4);
335 typedef typename Matrix4Like::Scalar Scalar;
336 enum {Options = Eigen::internal::traits<Matrix4Like>::Options};
348 template<AssignmentOperatorType op,
typename MotionDerived,
typename Matrix6Like>
350 const Eigen::MatrixBase<Matrix6Like> & Jexp)
352 PINOCCHIO_ASSERT_MATRIX_SPECIFIC_SIZE (Matrix6Like, Jexp, 6, 6);
354 typedef typename MotionDerived::Scalar Scalar;
355 typedef typename MotionDerived::Vector3 Vector3;
356 typedef Eigen::Matrix<Scalar, 3, 3, Vector3::Options> Matrix3;
357 Matrix6Like & Jout = PINOCCHIO_EIGEN_CONST_CAST(Matrix6Like,Jexp);
359 const typename MotionDerived::ConstLinearType & v = nu.linear();
360 const typename MotionDerived::ConstAngularType & w = nu.angular();
361 const Scalar t2 = w.squaredNorm();
362 const Scalar t = math::sqrt(t2);
364 const Scalar tinv = Scalar(1)/t,
366 Scalar st,ct;
SINCOS (t, &st, &ct);
367 const Scalar inv_2_2ct = Scalar(1)/(Scalar(2)*(Scalar(1)-ct));
371 Scalar(1)/Scalar(12) + t2/Scalar(720),
372 t2inv - st*tinv*inv_2_2ct);
375 Scalar(1)/Scalar(360),
376 -Scalar(2)*t2inv*t2inv + (Scalar(1) + st*tinv) * t2inv * inv_2_2ct);
382 Jexp3<SETTO>(w, Jout.template bottomRightCorner<3,3>());
383 Jout.template topLeftCorner<3,3>() = Jout.template bottomRightCorner<3,3>();
384 const Vector3 p = Jout.template topLeftCorner<3,3>().transpose() * v;
385 const Scalar wTp (w.dot (p));
387 (beta_dot_over_theta*wTp) *w*w.transpose()
388 - (t2*beta_dot_over_theta+Scalar(2)*beta)*p*w.transpose()
389 + wTp * beta * Matrix3::Identity()
390 + beta *w*p.transpose());
391 Jout.template topRightCorner<3,3>().noalias() =
392 - Jout.template topLeftCorner<3,3>() * J;
393 Jout.template bottomLeftCorner<3,3>().setZero();
399 Jexp3<SETTO>(w, Jtmp3);
400 Jout.template bottomRightCorner<3,3>() += Jtmp3;
401 Jout.template topLeftCorner<3,3>() += Jtmp3;
402 const Vector3 p = Jtmp3.transpose() * v;
403 const Scalar wTp (w.dot (p));
405 (beta_dot_over_theta*wTp) *w*w.transpose()
406 - (t2*beta_dot_over_theta+Scalar(2)*beta)*p*w.transpose()
407 + wTp * beta * Matrix3::Identity()
408 + beta *w*p.transpose());
409 Jout.template topRightCorner<3,3>().noalias() +=
416 Jexp3<SETTO>(w, Jtmp3);
417 Jout.template bottomRightCorner<3,3>() -= Jtmp3;
418 Jout.template topLeftCorner<3,3>() -= Jtmp3;
419 const Vector3 p = Jtmp3.transpose() * v;
420 const Scalar wTp (w.dot (p));
422 (beta_dot_over_theta*wTp) *w*w.transpose()
423 - (t2*beta_dot_over_theta+Scalar(2)*beta)*p*w.transpose()
424 + wTp * beta * Matrix3::Identity()
425 + beta *w*p.transpose());
426 Jout.template topRightCorner<3,3>().noalias() -=
431 assert(
false &&
"Wrong Op requesed value");
438 template<
typename MotionDerived,
typename Matrix6Like>
440 const Eigen::MatrixBase<Matrix6Like> & Jexp)
442 Jexp6<SETTO>(nu, Jexp);
465 template<
typename Scalar,
int Options,
typename Matrix6Like>
467 const Eigen::MatrixBase<Matrix6Like> & Jlog)
472 template<
typename Scalar,
int Options>
473 template<
typename OtherScalar>
476 const OtherScalar & alpha)
482 ReturnType res = A *
exp6(alpha*dv);
488 #include "pinocchio/spatial/explog-quaternion.hpp" 489 #include "pinocchio/spatial/log.hxx" 491 #endif //#ifndef __pinocchio_spatial_explog_hpp__
void Jexp3(const Eigen::MatrixBase< Vector3Like > &r, const Eigen::MatrixBase< Matrix3Like > &Jexp)
Derivative of .
Eigen::Matrix< typename Matrix3Like::Scalar, 3, 1, Matrix3Like ::Options > log3(const Eigen::MatrixBase< Matrix3Like > &R, typename Matrix3Like::Scalar &theta)
Same as log3.
void Jlog3(const Scalar &theta, const Eigen::MatrixBase< Vector3Like > &log, const Eigen::MatrixBase< Matrix3Like > &Jlog)
Derivative of log3.
Eigen::Matrix< typename Vector3Like::Scalar, 3, 3, Vector3Like ::Options > exp3(const Eigen::MatrixBase< Vector3Like > &v)
Exp: so3 -> SO3.
void Jlog6(const SE3Tpl< Scalar, Options > &M, const Eigen::MatrixBase< Matrix6Like > &Jlog)
Derivative of log6 where and .
MotionTpl< Scalar, Options > log6(const SE3Tpl< Scalar, Options > &M)
Log: SE3 -> se3.
void Jexp6(const MotionDense< MotionDerived > &nu, const Eigen::MatrixBase< Matrix6Like > &Jexp)
Derivative of exp6 Computed as the inverse of Jlog6.
void SINCOS(const S1 &a, S2 *sa, S3 *ca)
Computes sin/cos values of a given input scalar.
Main pinocchio namespace.
void alphaSkew(const Scalar alpha, const Eigen::MatrixBase< Vector3 > &v, const Eigen::MatrixBase< Matrix3 > &M)
Computes the skew representation of a given 3d vector multiplied by a given scalar. i.e. the antisymmetric matrix representation of the cross product operator ( )
SE3Tpl< typename MotionDerived::Scalar, typename MotionDerived::Vector3 ::Options > exp6(const MotionDense< MotionDerived > &nu)
Exp: se3 -> SE3.
SE3GroupAction< D >::ReturnType actInv(const D &d) const
by = aXb.actInv(ay)
static SE3Tpl Interpolate(const SE3Tpl &A, const SE3Tpl &B, const OtherScalar &alpha)
Linear interpolation on the SE3 manifold.