00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef EIGEN_UTILS_H_
00033 #define EIGEN_UTILS_H_
00034
00035 #include <Eigen/Dense>
00036 #include <Eigen/Geometry>
00037
00039 template<class Derived>
00040 inline Eigen::Matrix<typename Derived::Scalar, 3, 3> skew(const Eigen::MatrixBase<Derived> & vec)
00041 {
00042 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived, 3);
00043 return (Eigen::Matrix<typename Derived::Scalar, 3, 3>() << 0.0, -vec[2], vec[1], vec[2], 0.0, -vec[0], -vec[1], vec[0], 0.0).finished();
00044 }
00045
00047
00052 template<class Derived>
00053 inline Eigen::Matrix<typename Derived::Scalar, 4, 4> omegaMatJPL(const Eigen::MatrixBase<Derived> & vec)
00054 {
00055 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived, 3);
00056 return (
00057 Eigen::Matrix<typename Derived::Scalar, 4, 4>() <<
00058 0, vec[2], -vec[1], vec[0],
00059 -vec[2], 0, vec[0], vec[1],
00060 vec[1], -vec[0], 0, vec[2],
00061 -vec[0], -vec[1], -vec[2], 0
00062 ).finished();
00063 }
00064
00066
00071 template<class Derived>
00072 inline Eigen::Matrix<typename Derived::Scalar, 4, 4> omegaMatHamilton(const Eigen::MatrixBase<Derived> & vec)
00073 {
00074 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived, 3);
00075 return (
00076 Eigen::Matrix<typename Derived::Scalar, 4, 4>() <<
00077 0, -vec[2], vec[1], vec[0],
00078 vec[2], 0, -vec[0], vec[1],
00079 -vec[1], vec[0], 0, vec[2],
00080 -vec[0], -vec[1], -vec[2], 0
00081 ).finished();
00082 }
00083
00085 template<class Derived>
00086 Eigen::Quaternion<typename Derived::Scalar> quaternionFromSmallAngle(const Eigen::MatrixBase<Derived> & theta)
00087 {
00088 typedef typename Derived::Scalar Scalar;
00089 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived);
00090 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived, 3);
00091 const Scalar q_squared = theta.squaredNorm() / 4.0;
00092
00093 if ( q_squared < 1)
00094 {
00095 return Eigen::Quaternion<Scalar>(sqrt(1 - q_squared), theta[0] * 0.5, theta[1] * 0.5, theta[2] * 0.5);
00096 }
00097 else
00098 {
00099 const Scalar w = 1.0 / sqrt(1 + q_squared);
00100 const Scalar f = w*0.5;
00101 return Eigen::Quaternion<Scalar>(w, theta[0] * f, theta[1] * f, theta[2] * f);
00102 }
00103 }
00104
00106 template<class T>
00107 bool checkForNumeric(const T & vec, int size, const std::string & info)
00108 {
00109 for (int i = 0; i < size; i++)
00110 {
00111 if (isnan(vec[i]))
00112 {
00113 std::cerr << "=== ERROR === " << info << ": NAN at index " << i << std::endl;
00114 return false;
00115 }
00116 if (isinf(vec[i]))
00117 {
00118 std::cerr << "=== ERROR === " << info << ": INF at index " << i << std::endl;
00119 return false;
00120 }
00121 }
00122 return true;
00123 }
00124
00125 #endif