47 #ifndef _MIRA_YAWPITCHROLL_H_ 48 #define _MIRA_YAWPITCHROLL_H_ 51 #include <boost/tuple/tuple.hpp> 84 template<
typename Derived>
91 EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Derived,3,3)
98 const Scalar epsilon = Eigen::NumTraits<Scalar>::dummy_precision();
101 const Index odd = ((a0+1)%3 == a1) ? 0 : 1;
103 const Index j = (a0 + 1 + odd)%3;
104 const Index k = (a0 + 2 - odd)%3;
108 Scalar s = Vector2(mat.
coeff(j,i) , mat.
coeff(k,i)).norm();
109 res[1] = std::atan2(s, mat.
coeff(i,i));
112 res[0] = std::atan2(mat.
coeff(j,i), mat.
coeff(k,i));
113 res[2] = std::atan2(mat.
coeff(i,j),-mat.
coeff(i,k));
118 res[2] = (mat.
coeff(i,i)>0?1:-1)*std::atan2(-mat.
coeff(k,j), mat.
coeff(j,j));
123 Scalar c = Vector2(mat.
coeff(i,i) , mat.
coeff(i,j)).norm();
124 res[1] = std::atan2(-mat.
coeff(i,k), c);
127 res[0] = std::atan2(mat.
coeff(j,k), mat.
coeff(k,k));
128 res[2] = std::atan2(mat.
coeff(i,j), mat.
coeff(i,i));
133 res[2] = (mat.
coeff(i,k)>0?1:-1)*std::atan2(-mat.
coeff(k,j), mat.
coeff(j,j));
172 ypr.template get<1>(),
173 ypr.template get<2>());
203 float yaw,
float pitch,
float roll,
209 T cy = (T)cos(yaw*(T)0.5);
210 T sy = (T)sin(yaw*(T)0.5);
211 T cp = (T)cos(pitch*(T)0.5);
212 T sp = (T)sin(pitch*(T)0.5);
213 T cr = (T)cos(roll*(T)0.5);
214 T sr = (T)sin(roll*(T)0.5);
225 J.template block<4,3>(3,3) <<
226 (T)0.5*( ssc -ccs), (T)0.5*( scs -csc), (T)0.5*( css -scc),
227 (T)0.5*(-csc -scs), (T)0.5*(-ssc -ccs), (T)0.5*( ccc +sss),
228 (T)0.5*( scc -css), (T)0.5*( ccc -sss), (T)0.5*( ccs -ssc),
229 (T)0.5*( ccc +sss), (T)0.5*(-css -scc), (T)0.5*(-csc -scs);
231 oCovariance = J * eulerCovariance * J.transpose();
259 float yaw,
float pitch,
float roll)
303 return boost::tuples::make_tuple(euler(0,0), euler(1,0), euler(2,0));
352 T a = (T)1.0 - (T)2.0 * (q.
x() * q.
x() + q.
y() * q.
y());
353 T b = (T)2.0 * (q.
y() * q.
z() + q.
w() * q.
x());
354 T c = sqrt(a*a + b*b);
363 T t1 = (T) ((T) q.
y() * (T) q.
y());
365 T t3 = (T) q.
z() * (T) q.
z();
366 T t5 = 1 - t2 - 2 * t3;
368 T t10 = (T) ((T) q.
w() * (T) q.
z() + (T) q.
x() * (T) q.
y());
369 T t13 = 1 / (t7 + 4 * t10 * t10);
370 T t31 = (T) q.
x() * (T) q.
x();
371 T t34 = 1 - 2 * t31 - 2 * t1;
373 T t38 = (T) q.
y() * (T) q.
z() + (T) q.
w() * (T) q.
x();
374 T t39 = (T) (t38 * t38);
376 T t42 = sqrt(t35 + t40);
377 T t47 = -(T) q.
x() * (T) q.
z() + (T) q.
w() * (T) q.
y();
378 T t48 = 2 * t47 * t38;
380 T t56 = 1 / (t35 + t40 + 4 * t47 * t47);
381 T t90 = 1 - 2 * t31 - t2;
383 T t95 = 1 / (t92 + 4 * t38 * t38);
385 J.template block<3,4>(3,3) <<
386 2 * q.
z() * t5 * t13,
387 2 * q.
y() * t5 * t13,
388 (2 * q.
x() * t5 + 8 * t10 * q.
y()) * t13,
389 (2 * q.
w() * t5 + 8 * t10 * q.
z()) * t13,
391 (2 * (T) q.
y() * t42 - 4 * (T) t48 * (T) q.
x() * t49) * t56,
392 (-2 * (T) q.
z() * t42 - (T) t47 * (-8 * t34 * (T) q.
x() + 8 * (T) t38 * (T) q.
w()) * t49) * t56,
393 (2 * (T) q.
w() * t42 - (T) t47 * (-8 * t34 * (T) q.
y() + 8 * (T) t38 * (T) q.
z()) * t49) * t56,
394 (-2 * (T) q.
x() * t42 - 4 * (T) t48 * (T) q.
y() * t49) * t56,
396 2 * (T) q.
x() * t90 * t95,
397 (2 * (T) q.
w() * t90 + 8 * t38 * (T) q.
x()) * t95,
398 (2 * (T) q.
z() * t90 + 8 * t38 * (T) q.
y()) * t95,
399 2 * (T) q.
y() * t90 * t95;
440 T t1 = q.
x() * q.
x();
441 T t3 = q.
y() * q.
y();
442 T t5 = (T)0.10e1 - (T)0.20e1 * t1 - (T)0.20e1 * t3;
444 T t9 = q.
y() * q.
z() + q.
w() * q.
x();
446 T t11 = (T)0.400e1 * t10;
447 T t13 = sqrt(t6 + t11);
448 T t16 = q.
x() * q.
z();
449 T t18 = q.
w() * q.
y();
450 T t20 = (T)-0.20e1 * t16 + (T)0.20e1 * t18;
451 T t22 = (T)0.1e1 / t13;
454 T t45 = (T)0.1e1 / (t6 + t11 + (T)0.4e1 * t33 * t33);
455 T t67 = (T)0.2e1 * t1;
456 T t68 = (T) (q.
z() * q.
z());
457 T t70 = (T)0.1e1 - t67 - (T) (2 * t68);
459 T t77 = (T)-0.20e1 * q.
x() * q.
y() + (T)0.20e1 * q.
w() * q.
z();
461 T t80 = (T)0.1e1 / (t72 + t78);
462 T t96 = (T)0.1e1 - t67 - (T)0.2e1 * t3;
470 if(q.
x()*q.
z() - q.
w() * q.
y() > 0){
476 J.template block<3,4>(3,3) <<
479 (T) ((0.20e1 * q.
y() * t13 - 0.4000000000e1 * t20 * t9 * q.
x() * t22) / (t6 + t11 + t27)),
480 (T) ((-0.2e1 * q.
z() * t13 - t33 * (-0.80e1 * q.
x() * t5 + 0.800e1 * t9 * q.
w()) * t22) * t45),
481 (T) ((0.2e1 * q.
w() * t13 - t33 * (-0.80e1 * t5 * q.
y() + 0.800e1 * t9 * q.
z()) * t22) * t45),
482 (T) ((-0.2e1 * q.
x() * t13 - 0.8000000000e1 * t33 * t9 * q.
y() * t22) * t45),
484 (T) (0.20e1 * q.
z() * t70 * t80),
485 (T) ((-0.20e1 * q.
y() * t70 + 0.4e1 * t77 * q.
x()) * t80),
486 -(T) (0.20e1 * q.
x() * t70 / (t72 * t70 + t78)),
487 (T) (0.2e1 * q.
y() * t96 / (t98 + 0.4e1 * t9 * t9));
505 J.template block<3,4>(3,3) <<
508 (T) ((0.20e1 * q.
y() * t13 - 0.4000000000e1 * t20 * t9 * q.
x() * t22) / (t6 + t11 + t27)),
509 (T) ((-0.2e1 * q.
z() * t13 - t33 * (-0.80e1 * q.
x() * t5 + 0.800e1 * t9 * q.
w()) * t22) * t45),
510 (T) ((0.2e1 * q.
w() * t13 - t33 * (-0.80e1 * t5 * q.
y() + 0.800e1 * t9 * q.
z()) * t22) * t45),
511 (T) ((-0.2e1 * q.
x() * t13 - 0.8000000000e1 * t33 * t9 * q.
y() * t22) * t45),
513 -(T) (0.20e1 * q.
z() * t70 * t80),
514 -(T) ((-0.20e1 * q.
y() * t70 + 0.4e1 * t77 * q.
x()) * t80),
515 (T) (0.20e1 * q.
x() * t70 / (t72 * t70 + t78)),
516 -(T) (0.2e1 * q.
y() * t96 / (t98 + 0.4e1 * t9 * t9));
531 return J * covariance * J.transpose();
556 float s1 = sin(roll);
557 float c1 = cos(roll);
562 float s2 = sin(pitch);
563 float c2 = cos(pitch);
585 ypr.template get<1>(),
586 ypr.template get<2>());
607 return boost::tuples::make_tuple(euler(0,0), euler(1,0), euler(2,0));
636 Mat3 Rx, Ry, Rz, dRx_droll, dRy_dpitch, dRz_dyaw;
638 float s1 = sin(roll);
639 float c1 = cos(roll);
644 dRx_droll << 0, 0, 0,
648 float s2 = sin(pitch);
649 float c2 = cos(pitch);
654 dRy_dpitch << -s2, 0, c2,
664 dRz_dyaw << -s3,-c3, 0,
669 oR_dyaw = Rx*Ry*dRz_dyaw;
670 oR_dpitch = Rx*dRy_dpitch*Rz;
671 oR_droll = dRx_droll*Ry*Rz;
void derivMatricesFromYawPitchRoll(T yaw, T pitch, T roll, Eigen::Matrix< T, 3, 3 > &oR_dyaw, Eigen::Matrix< T, 3, 3 > &oR_dpitch, Eigen::Matrix< T, 3, 3 > &oR_droll)
Returns the 3 derivates of the above rotation matrix, i.e.
Definition: YawPitchRoll.h:630
Eigen::Matrix< T, 6, 6 > quaternionCovToYawPitchRollCov(const Eigen::Matrix< T, 7, 7 > &covariance, const Eigen::Quaternion< T > &q)
Converts a 7x7 dimensional quaternion covariance (3D + Quaternion) back to a 6x6 dimensional euler co...
Definition: YawPitchRoll.h:318
Include file for all eigen related things.
boost::tuples::tuple< T, T, T > quaternionToYawPitchRoll(const Eigen::Quaternion< T > &q)
Converts a quaternion back to yaw, pitch, roll angles.
Definition: YawPitchRoll.h:299
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
void quaternionCovFromYawPitchRollCov(const Eigen::Matrix< T, 6, 6 > &eulerCovariance, float yaw, float pitch, float roll, Eigen::Quaternion< T > &oOrientation, Eigen::Matrix< T, 7, 7 > &oCovariance)
Converts 6x6 dimensional covariance matrix (3D + yaw, pitch and roll) angles to a 7x7 dimensional qua...
Definition: YawPitchRoll.h:201
Definition: YawPitchRoll.h:684
Matrix3 toRotationMatrix(void) const
const Scalar coeff(int index) const
boost::tuples::tuple< T, T, T > matrixToYawPitchRoll(const Eigen::Matrix< T, 3, 3 > &r)
Converts a rotation matrix back to yaw, pitch, roll angles.
Definition: YawPitchRoll.h:604
Eigen::Matrix< T, 3, 3 > matrixFromYawPitchRoll(T yaw, T pitch, T roll)
Converts yaw, pitch and roll angles to a rotation matrix.
Definition: YawPitchRoll.h:551
Eigen::Matrix< typename Eigen::MatrixBase< Derived >::Scalar, 3, 1 > eulerAngles(const Eigen::MatrixBase< Derived > &mat, typename Eigen::MatrixBase< Derived >::Index a0, typename Eigen::MatrixBase< Derived >::Index a1, typename Eigen::MatrixBase< Derived >::Index a2)
Returns the Euler-angles of the rotation matrix mat using the convention defined by the triplet (a0...
Definition: YawPitchRoll.h:86
Eigen::Quaternion< T > quaternionFromYawPitchRoll(T yaw, T pitch, T roll)
Converts yaw, pitch and roll angles to a quaternion.
Definition: YawPitchRoll.h:156