eigen_types.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * eigen_types.hpp
  3. *
  4. * Created on: March 6, 2009
  5. * Author: benoit bolsee
  6. */
  7. #ifndef EIGEN_TYPES_HPP_
  8. #define EIGEN_TYPES_HPP_
  9. #include <Eigen/Core>
  10. #include "kdl/frames.hpp"
  11. #include "kdl/tree.hpp"
  12. #include "kdl/chain.hpp"
  13. #include "kdl/jacobian.hpp"
  14. #include "kdl/jntarray.hpp"
  15. namespace iTaSC{
  16. using KDL::Twist;
  17. using KDL::Frame;
  18. using KDL::Joint;
  19. using KDL::Inertia;
  20. using KDL::SegmentMap;
  21. using KDL::Tree;
  22. using KDL::JntArray;
  23. using KDL::Jacobian;
  24. using KDL::Segment;
  25. using KDL::Rotation;
  26. using KDL::Vector;
  27. using KDL::Vector2;
  28. using KDL::Chain;
  29. extern const Frame F_identity;
  30. #define e_scalar double
  31. #define e_vector Eigen::Matrix<e_scalar, Eigen::Dynamic, 1>
  32. #define e_zero_vector Eigen::Matrix<e_scalar, Eigen::Dynamic, 1>::Zero
  33. #define e_matrix Eigen::Matrix<e_scalar, Eigen::Dynamic, Eigen::Dynamic>
  34. #define e_matrix6 Eigen::Matrix<e_scalar,6,6>
  35. #define e_identity_matrix Eigen::Matrix<e_scalar, Eigen::Dynamic, Eigen::Dynamic>::Identity
  36. #define e_scalar_vector Eigen::Matrix<e_scalar, Eigen::Dynamic, 1>::Constant
  37. #define e_zero_matrix Eigen::Matrix<e_scalar, Eigen::Dynamic, Eigen::Dynamic>::Zero
  38. #define e_random_matrix Eigen::Matrix<e_scalar, Eigen::Dynamic, Eigen::Dynamic>::Random
  39. #define e_vector6 Eigen::Matrix<e_scalar,6,1>
  40. #define e_vector3 Eigen::Matrix<e_scalar,3,1>
  41. class Range {
  42. public:
  43. int start;
  44. int count;
  45. Range(int _start, int _count) { start = _start; count=_count; }
  46. Range(const Range& other) { start=other.start; count=other.count; }
  47. };
  48. template<typename MatrixType> inline Eigen::Block<MatrixType> project(MatrixType& m, Range r)
  49. {
  50. return Eigen::Block<MatrixType>(m,r.start,0,r.count,1);
  51. }
  52. template<typename MatrixType> inline Eigen::Block<MatrixType> project(MatrixType& m, Range r, Range c)
  53. {
  54. return Eigen::Block<MatrixType>(m,r.start,c.start,r.count,c.count);
  55. }
  56. template<typename Derived> inline static int changeBase(Eigen::MatrixBase<Derived>& J, const Frame& T) {
  57. if (J.rows() != 6)
  58. return -1;
  59. for (int j = 0; j < J.cols(); ++j) {
  60. typename Derived::ColXpr Jj = J.col(j);
  61. Twist arg;
  62. for(unsigned int i=0;i<6;++i)
  63. arg(i)=Jj[i];
  64. Twist tmp(T*arg);
  65. for(unsigned int i=0;i<6;++i)
  66. Jj[i]=e_scalar(tmp(i));
  67. }
  68. return 0;
  69. }
  70. }
  71. #endif /* UBLAS_TYPES_HPP_ */