CopyPose.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * CopyPose.h
  3. *
  4. * Created on: Mar 17, 2009
  5. * Author: benoit bolsee
  6. */
  7. #ifndef COPYPOSE_H_
  8. #define COPYPOSE_H_
  9. #include "ConstraintSet.hpp"
  10. namespace iTaSC{
  11. using namespace KDL;
  12. class CopyPose: public iTaSC::ConstraintSet
  13. {
  14. protected:
  15. virtual void updateKinematics(const Timestamp& timestamp);
  16. virtual void pushCache(const Timestamp& timestamp);
  17. virtual void updateJacobian();
  18. virtual bool initialise(Frame& init_pose);
  19. virtual void initCache(Cache *_cache);
  20. virtual void updateControlOutput(const Timestamp& timestamp);
  21. virtual void modelUpdate(Frame& _external_pose,const Timestamp& timestamp);
  22. virtual double getMaxTimestep(double& timestep);
  23. public:
  24. enum ID { // constraint ID in callback and setControlParameter
  25. ID_POSITION=0,
  26. ID_POSITIONX=1,
  27. ID_POSITIONY=2,
  28. ID_POSITIONZ=3,
  29. ID_ROTATION=4,
  30. ID_ROTATIONX=5,
  31. ID_ROTATIONY=6,
  32. ID_ROTATIONZ=7,
  33. };
  34. enum CTL { // control ID in constructor to specify which output is constrainted
  35. CTL_NONE=0x00,
  36. CTL_POSITIONX=0x01, // the bit order is important: it matches the y output order
  37. CTL_POSITIONY=0x02,
  38. CTL_POSITIONZ=0x04,
  39. CTL_POSITION=0x07,
  40. CTL_ROTATIONX=0x08,
  41. CTL_ROTATIONY=0x10,
  42. CTL_ROTATIONZ=0x20,
  43. CTL_ROTATION=0x38,
  44. CTL_ALL=0x3F,
  45. };
  46. // use a combination of CTL_.. in control_output to specify which
  47. CopyPose(unsigned int control_output=CTL_ALL, unsigned int dynamic_output=CTL_NONE, double armlength=1.0, double accuracy=1e-6, unsigned int maximum_iterations=100);
  48. virtual ~CopyPose();
  49. virtual bool setControlParameters(struct ConstraintValues* _values, unsigned int _nvalues, double timestep);
  50. virtual const ConstraintValues* getControlParameters(unsigned int* _nvalues);
  51. private:
  52. struct ConstraintSingleValue m_posData[3]; // index = controlled output in X,Y,Z order
  53. struct ConstraintSingleValue m_rotData[3];
  54. struct ConstraintValues m_values[2]; // index = group of controlled output, in position, rotation order
  55. Cache* m_cache;
  56. int m_poseCCh;
  57. CacheTS m_poseCTs;
  58. unsigned int m_poseCacheSize;
  59. unsigned int m_outputDynamic; // combination of CTL_... determine which variables are dynamically controlled by the application
  60. unsigned int m_outputControl; // combination of CTL_... determine which output are constrained
  61. unsigned int m_nvalues; // number of elements used in m_values[]
  62. double m_maxerror;
  63. struct ControlState {
  64. int firsty; // first y index
  65. int ny; // number of y in output
  66. double alpha;
  67. double K;
  68. double tolerance;
  69. struct ControlValue {
  70. double yddot;
  71. double yd;
  72. double nextyd;
  73. double nextyddot;
  74. } output[3]; // inded numbex = same as m_rotData
  75. } m_rot, m_pos;
  76. void pushPose(CacheTS timestamp);
  77. bool popPose(CacheTS timestamp);
  78. int nBitsOn(unsigned int v)
  79. { int n=0; while(v) { if (v&1) n++; v>>=1; } return n; }
  80. double* restoreValues(double* item, ConstraintValues* _values, ControlState* _state, unsigned int mask);
  81. double* pushValues(double* item, ControlState* _state, unsigned int mask);
  82. void updateState(ConstraintValues* _values, ControlState* _state, unsigned int mask, double timestep);
  83. void updateValues(Vector& vel, ConstraintValues* _values, ControlState* _state, unsigned int mask);
  84. void updateOutput(Vector& vel, ControlState* _state, unsigned int mask);
  85. void interpolateOutput(ControlState* _state, unsigned int mask, const Timestamp& timestamp);
  86. };
  87. }
  88. #endif /* COPYROTATION_H_ */