ConstraintSet.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * ConstraintSet.hpp
  3. *
  4. * Created on: Jan 5, 2009
  5. * Author: rubensmits
  6. */
  7. #ifndef CONSTRAINTSET_HPP_
  8. #define CONSTRAINTSET_HPP_
  9. #include "kdl/frames.hpp"
  10. #include "eigen_types.hpp"
  11. #include "Cache.hpp"
  12. #include <vector>
  13. namespace iTaSC {
  14. enum ConstraintAction {
  15. ACT_NONE= 0,
  16. ACT_VALUE= 1,
  17. ACT_VELOCITY= 2,
  18. ACT_TOLERANCE= 4,
  19. ACT_FEEDBACK= 8,
  20. ACT_ALPHA= 16
  21. };
  22. struct ConstraintSingleValue {
  23. unsigned int id; // identifier of constraint value, depends on constraint
  24. unsigned int action;// action performed, compbination of ACT_..., set on return
  25. const double y; // actual constraint value
  26. const double ydot; // actual constraint velocity
  27. double yd; // current desired constraint value, changed on return
  28. double yddot; // current desired constraint velocity, changed on return
  29. ConstraintSingleValue(): id(0), action(0), y(0.0), ydot(0.0) {}
  30. };
  31. struct ConstraintValues {
  32. unsigned int id; // identifier of group of constraint values, depend on constraint
  33. unsigned short number; // number of constraints in list
  34. unsigned short action; // action performed, ACT_..., set on return
  35. double alpha; // constraint activation coefficient, should be [0..1]
  36. double tolerance; // current desired tolerance on constraint, same unit than yd, changed on return
  37. double feedback; // current desired feedback on error, in 1/sec, changed on return
  38. struct ConstraintSingleValue* values;
  39. ConstraintValues(): id(0), number(0), action(0), values(NULL) {}
  40. };
  41. class ConstraintSet;
  42. typedef bool (*ConstraintCallback)(const Timestamp& timestamp, struct ConstraintValues* const _values, unsigned int _nvalues, void* _param);
  43. class ConstraintSet {
  44. protected:
  45. unsigned int m_nc;
  46. e_scalar m_maxDeltaChi;
  47. e_matrix m_Cf;
  48. e_vector m_Wy,m_y,m_ydot;
  49. e_vector6 m_chi,m_chidot,m_S,m_temp,m_tdelta;
  50. e_matrix6 m_Jf,m_U,m_V,m_B,m_Jf_inv;
  51. KDL::Frame m_internalPose,m_externalPose;
  52. ConstraintCallback m_constraintCallback;
  53. void* m_constraintParam;
  54. void* m_poseParam;
  55. bool m_toggle;
  56. bool m_substep;
  57. double m_threshold;
  58. unsigned int m_maxIter;
  59. friend class Scene;
  60. virtual void modelUpdate(KDL::Frame& _external_pose,const Timestamp& timestamp);
  61. virtual void updateKinematics(const Timestamp& timestamp)=0;
  62. virtual void pushCache(const Timestamp& timestamp)=0;
  63. virtual void updateJacobian()=0;
  64. virtual void updateControlOutput(const Timestamp& timestamp)=0;
  65. virtual void initCache(Cache *_cache) = 0;
  66. virtual bool initialise(KDL::Frame& init_pose);
  67. virtual void reset(unsigned int nc,double accuracy,unsigned int maximum_iterations);
  68. virtual bool closeLoop();
  69. virtual double getMaxTimestep(double& timestep);
  70. public:
  71. ConstraintSet(unsigned int nc,double accuracy,unsigned int maximum_iterations);
  72. ConstraintSet();
  73. virtual ~ConstraintSet();
  74. EIGEN_MAKE_ALIGNED_OPERATOR_NEW
  75. virtual bool registerCallback(ConstraintCallback _function, void* _param)
  76. {
  77. m_constraintCallback = _function;
  78. m_constraintParam = _param;
  79. return true;
  80. }
  81. virtual const e_vector& getControlOutput()const{return m_ydot;};
  82. virtual const ConstraintValues* getControlParameters(unsigned int* _nvalues) = 0;
  83. virtual bool setControlParameters(ConstraintValues* _values, unsigned int _nvalues, double timestep=0.0) = 0;
  84. bool setControlParameter(int id, ConstraintAction action, double value, double timestep=0.0);
  85. virtual const e_matrix6& getJf() const{return m_Jf;};
  86. virtual const KDL::Frame& getPose() const{return m_internalPose;};
  87. virtual const e_matrix& getCf() const{return m_Cf;};
  88. virtual const e_vector& getWy() const {return m_Wy;};
  89. virtual void setWy(const e_vector& Wy_in){m_Wy = Wy_in;};
  90. virtual void setJointVelocity(const e_vector chidot_in){m_chidot = chidot_in;};
  91. virtual unsigned int getNrOfConstraints(){return m_nc;};
  92. void substep(bool _substep) {m_substep=_substep;}
  93. bool substep() {return m_substep;}
  94. };
  95. }
  96. #endif /* CONSTRAINTSET_HPP_ */