frameacc.hpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /*****************************************************************************
  2. * \file
  3. * This file contains the definition of classes for a
  4. * Rall Algebra of (subset of) the classes defined in frames,
  5. * i.e. classes that contain a set (value,derivative,2nd derivative)
  6. * and define operations on that set
  7. * this classes are usefull for automatic differentiation ( <-> symbolic diff ,
  8. * <-> numeric diff).
  9. * Defines VectorAcc, RotationAcc, FrameAcc, doubleAcc.
  10. * Look at the corresponding classes Vector Rotation Frame Twist and
  11. * Wrench for the semantics of the methods.
  12. *
  13. * It also contains the 2nd derivative <-> RFrames.h
  14. *
  15. * Erwin Aertbelien, Div. PMA, Dep. of Mech. Eng., K.U.Leuven
  16. *
  17. * \version
  18. * ORO_Geometry V0.2
  19. *
  20. * \par History
  21. * - $log$
  22. *
  23. * \par Release
  24. * $Name: $
  25. ****************************************************************************/
  26. #ifndef RRFRAMES_H
  27. #define RRFRAMES_H
  28. #include "utilities/rall2d.h"
  29. #include "frames.hpp"
  30. namespace KDL {
  31. class TwistAcc;
  32. typedef Rall2d<double,double,double> doubleAcc;
  33. class VectorAcc
  34. {
  35. public:
  36. Vector p; //!< position vector
  37. Vector v; //!< velocity vector
  38. Vector dv; //!< acceleration vector
  39. public:
  40. VectorAcc():p(),v(),dv() {}
  41. explicit VectorAcc(const Vector& _p):p(_p),v(Vector::Zero()),dv(Vector::Zero()) {}
  42. VectorAcc(const Vector& _p,const Vector& _v):p(_p),v(_v),dv(Vector::Zero()) {}
  43. VectorAcc(const Vector& _p,const Vector& _v,const Vector& _dv):
  44. p(_p),v(_v),dv(_dv) {}
  45. IMETHOD VectorAcc& operator = (const VectorAcc& arg);
  46. IMETHOD VectorAcc& operator = (const Vector& arg);
  47. IMETHOD VectorAcc& operator += (const VectorAcc& arg);
  48. IMETHOD VectorAcc& operator -= (const VectorAcc& arg);
  49. IMETHOD static VectorAcc Zero();
  50. IMETHOD void ReverseSign();
  51. IMETHOD doubleAcc Norm();
  52. IMETHOD friend VectorAcc operator + (const VectorAcc& r1,const VectorAcc& r2);
  53. IMETHOD friend VectorAcc operator - (const VectorAcc& r1,const VectorAcc& r2);
  54. IMETHOD friend VectorAcc operator + (const Vector& r1,const VectorAcc& r2);
  55. IMETHOD friend VectorAcc operator - (const Vector& r1,const VectorAcc& r2);
  56. IMETHOD friend VectorAcc operator + (const VectorAcc& r1,const Vector& r2);
  57. IMETHOD friend VectorAcc operator - (const VectorAcc& r1,const Vector& r2);
  58. IMETHOD friend VectorAcc operator * (const VectorAcc& r1,const VectorAcc& r2);
  59. IMETHOD friend VectorAcc operator * (const VectorAcc& r1,const Vector& r2);
  60. IMETHOD friend VectorAcc operator * (const Vector& r1,const VectorAcc& r2);
  61. IMETHOD friend VectorAcc operator * (const VectorAcc& r1,double r2);
  62. IMETHOD friend VectorAcc operator * (double r1,const VectorAcc& r2);
  63. IMETHOD friend VectorAcc operator * (const doubleAcc& r1,const VectorAcc& r2);
  64. IMETHOD friend VectorAcc operator * (const VectorAcc& r2,const doubleAcc& r1);
  65. IMETHOD friend VectorAcc operator*(const Rotation& R,const VectorAcc& x);
  66. IMETHOD friend VectorAcc operator / (const VectorAcc& r1,double r2);
  67. IMETHOD friend VectorAcc operator / (const VectorAcc& r2,const doubleAcc& r1);
  68. IMETHOD friend bool Equal(const VectorAcc& r1,const VectorAcc& r2,double eps);
  69. IMETHOD friend bool Equal(const Vector& r1,const VectorAcc& r2,double eps);
  70. IMETHOD friend bool Equal(const VectorAcc& r1,const Vector& r2,double eps);
  71. IMETHOD friend VectorAcc operator - (const VectorAcc& r);
  72. IMETHOD friend doubleAcc dot(const VectorAcc& lhs,const VectorAcc& rhs);
  73. IMETHOD friend doubleAcc dot(const VectorAcc& lhs,const Vector& rhs);
  74. IMETHOD friend doubleAcc dot(const Vector& lhs,const VectorAcc& rhs);
  75. };
  76. class RotationAcc
  77. {
  78. public:
  79. Rotation R; //!< rotation matrix
  80. Vector w; //!< angular velocity vector
  81. Vector dw; //!< angular acceration vector
  82. public:
  83. RotationAcc():R(),w() {}
  84. explicit RotationAcc(const Rotation& R_):R(R_),w(Vector::Zero()){}
  85. RotationAcc(const Rotation& R_,const Vector& _w,const Vector& _dw):
  86. R(R_),w(_w),dw(_dw) {}
  87. IMETHOD RotationAcc& operator = (const RotationAcc& arg);
  88. IMETHOD RotationAcc& operator = (const Rotation& arg);
  89. IMETHOD static RotationAcc Identity();
  90. IMETHOD RotationAcc Inverse() const;
  91. IMETHOD VectorAcc Inverse(const VectorAcc& arg) const;
  92. IMETHOD VectorAcc Inverse(const Vector& arg) const;
  93. IMETHOD VectorAcc operator*(const VectorAcc& arg) const;
  94. IMETHOD VectorAcc operator*(const Vector& arg) const;
  95. // Rotations
  96. // The SetRot.. functions set the value of *this to the appropriate rotation matrix.
  97. // The Rot... static functions give the value of the appropriate rotation matrix back.
  98. // The DoRot... functions apply a rotation R to *this,such that *this = *this * R.
  99. // IMETHOD void DoRotX(const doubleAcc& angle);
  100. // IMETHOD void DoRotY(const doubleAcc& angle);
  101. // IMETHOD void DoRotZ(const doubleAcc& angle);
  102. // IMETHOD static RRotation RotX(const doubleAcc& angle);
  103. // IMETHOD static RRotation RotY(const doubleAcc& angle);
  104. // IMETHOD static RRotation RotZ(const doubleAcc& angle);
  105. // IMETHOD void SetRot(const Vector& rotaxis,const doubleAcc& angle);
  106. // Along an arbitrary axes. The norm of rotvec is neglected.
  107. // IMETHOD static RotationAcc Rot(const Vector& rotvec,const doubleAcc& angle);
  108. // rotvec has arbitrary norm
  109. // rotation around a constant vector !
  110. // IMETHOD static RotationAcc Rot2(const Vector& rotvec,const doubleAcc& angle);
  111. // rotvec is normalized.
  112. // rotation around a constant vector !
  113. IMETHOD friend RotationAcc operator* (const RotationAcc& r1,const RotationAcc& r2);
  114. IMETHOD friend RotationAcc operator* (const Rotation& r1,const RotationAcc& r2);
  115. IMETHOD friend RotationAcc operator* (const RotationAcc& r1,const Rotation& r2);
  116. IMETHOD friend bool Equal(const RotationAcc& r1,const RotationAcc& r2,double eps);
  117. IMETHOD friend bool Equal(const Rotation& r1,const RotationAcc& r2,double eps);
  118. IMETHOD friend bool Equal(const RotationAcc& r1,const Rotation& r2,double eps);
  119. IMETHOD TwistAcc Inverse(const TwistAcc& arg) const;
  120. IMETHOD TwistAcc Inverse(const Twist& arg) const;
  121. IMETHOD TwistAcc operator * (const TwistAcc& arg) const;
  122. IMETHOD TwistAcc operator * (const Twist& arg) const;
  123. };
  124. class FrameAcc
  125. {
  126. public:
  127. RotationAcc M; //!< Rotation,angular velocity, and angular acceleration of frame.
  128. VectorAcc p; //!< Translation, velocity and acceleration of origin.
  129. public:
  130. FrameAcc(){}
  131. explicit FrameAcc(const Frame& T_):M(T_.M),p(T_.p) {}
  132. FrameAcc(const Frame& T_,const Twist& _t,const Twist& _dt):
  133. M(T_.M,_t.rot,_dt.rot),p(T_.p,_t.vel,_dt.vel) {}
  134. FrameAcc(const RotationAcc& _M,const VectorAcc& _p):M(_M),p(_p) {}
  135. IMETHOD FrameAcc& operator = (const FrameAcc& arg);
  136. IMETHOD FrameAcc& operator = (const Frame& arg);
  137. IMETHOD static FrameAcc Identity();
  138. IMETHOD FrameAcc Inverse() const;
  139. IMETHOD VectorAcc Inverse(const VectorAcc& arg) const;
  140. IMETHOD VectorAcc operator*(const VectorAcc& arg) const;
  141. IMETHOD VectorAcc operator*(const Vector& arg) const;
  142. IMETHOD VectorAcc Inverse(const Vector& arg) const;
  143. IMETHOD Frame GetFrame() const;
  144. IMETHOD Twist GetTwist() const;
  145. IMETHOD Twist GetAccTwist() const;
  146. IMETHOD friend FrameAcc operator * (const FrameAcc& f1,const FrameAcc& f2);
  147. IMETHOD friend FrameAcc operator * (const Frame& f1,const FrameAcc& f2);
  148. IMETHOD friend FrameAcc operator * (const FrameAcc& f1,const Frame& f2);
  149. IMETHOD friend bool Equal(const FrameAcc& r1,const FrameAcc& r2,double eps);
  150. IMETHOD friend bool Equal(const Frame& r1,const FrameAcc& r2,double eps);
  151. IMETHOD friend bool Equal(const FrameAcc& r1,const Frame& r2,double eps);
  152. IMETHOD TwistAcc Inverse(const TwistAcc& arg) const;
  153. IMETHOD TwistAcc Inverse(const Twist& arg) const;
  154. IMETHOD TwistAcc operator * (const TwistAcc& arg) const;
  155. IMETHOD TwistAcc operator * (const Twist& arg) const;
  156. };
  157. //very similar to Wrench class.
  158. class TwistAcc
  159. {
  160. public:
  161. VectorAcc vel; //!< translational velocity and its 1st and 2nd derivative
  162. VectorAcc rot; //!< rotational velocity and its 1st and 2nd derivative
  163. public:
  164. TwistAcc():vel(),rot() {};
  165. TwistAcc(const VectorAcc& _vel,const VectorAcc& _rot):vel(_vel),rot(_rot) {};
  166. IMETHOD TwistAcc& operator-=(const TwistAcc& arg);
  167. IMETHOD TwistAcc& operator+=(const TwistAcc& arg);
  168. IMETHOD friend TwistAcc operator*(const TwistAcc& lhs,double rhs);
  169. IMETHOD friend TwistAcc operator*(double lhs,const TwistAcc& rhs);
  170. IMETHOD friend TwistAcc operator/(const TwistAcc& lhs,double rhs);
  171. IMETHOD friend TwistAcc operator*(const TwistAcc& lhs,const doubleAcc& rhs);
  172. IMETHOD friend TwistAcc operator*(const doubleAcc& lhs,const TwistAcc& rhs);
  173. IMETHOD friend TwistAcc operator/(const TwistAcc& lhs,const doubleAcc& rhs);
  174. IMETHOD friend TwistAcc operator+(const TwistAcc& lhs,const TwistAcc& rhs);
  175. IMETHOD friend TwistAcc operator-(const TwistAcc& lhs,const TwistAcc& rhs);
  176. IMETHOD friend TwistAcc operator-(const TwistAcc& arg);
  177. IMETHOD friend void SetToZero(TwistAcc& v);
  178. static IMETHOD TwistAcc Zero();
  179. IMETHOD void ReverseSign();
  180. IMETHOD TwistAcc RefPoint(const VectorAcc& v_base_AB);
  181. // Changes the reference point of the RTwist.
  182. // The RVector v_base_AB is expressed in the same base as the RTwist
  183. // The RVector v_base_AB is a RVector from the old point to
  184. // the new point.
  185. // Complexity : 6M+6A
  186. IMETHOD friend bool Equal(const TwistAcc& a,const TwistAcc& b,double eps);
  187. IMETHOD friend bool Equal(const Twist& a,const TwistAcc& b,double eps);
  188. IMETHOD friend bool Equal(const TwistAcc& a,const Twist& b,double eps);
  189. IMETHOD Twist GetTwist() const;
  190. IMETHOD Twist GetTwistDot() const;
  191. friend class RotationAcc;
  192. friend class FrameAcc;
  193. };
  194. IMETHOD bool Equal(const VectorAcc&, const VectorAcc&, double = epsilon);
  195. IMETHOD bool Equal(const Vector&, const VectorAcc&, double = epsilon);
  196. IMETHOD bool Equal(const VectorAcc&, const Vector&, double = epsilon);
  197. IMETHOD bool Equal(const RotationAcc&, const RotationAcc&, double = epsilon);
  198. IMETHOD bool Equal(const Rotation&, const RotationAcc&, double = epsilon);
  199. IMETHOD bool Equal(const RotationAcc&, const Rotation&, double = epsilon);
  200. IMETHOD bool Equal(const FrameAcc&, const FrameAcc&, double = epsilon);
  201. IMETHOD bool Equal(const Frame&, const FrameAcc&, double = epsilon);
  202. IMETHOD bool Equal(const FrameAcc&, const Frame&, double = epsilon);
  203. IMETHOD bool Equal(const TwistAcc&, const TwistAcc&, double = epsilon);
  204. IMETHOD bool Equal(const Twist&, const TwistAcc&, double = epsilon);
  205. IMETHOD bool Equal(const TwistAcc&, const Twist&, double = epsilon);
  206. #ifdef KDL_INLINE
  207. #include "frameacc.inl"
  208. #endif
  209. }
  210. #endif