Scene.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Scene.hpp
  3. *
  4. * Created on: Jan 5, 2009
  5. * Author: rubensmits
  6. */
  7. #ifndef SCENE_HPP_
  8. #define SCENE_HPP_
  9. #include "eigen_types.hpp"
  10. #include "WorldObject.hpp"
  11. #include "ConstraintSet.hpp"
  12. #include "Solver.hpp"
  13. #include <map>
  14. namespace iTaSC {
  15. class SceneLock;
  16. class Scene {
  17. friend class SceneLock;
  18. public:
  19. enum SceneParam {
  20. MIN_TIMESTEP = 0,
  21. MAX_TIMESTEP,
  22. COUNT
  23. };
  24. Scene();
  25. virtual ~Scene();
  26. bool addObject(const std::string& name, Object* object, UncontrolledObject* base=&Object::world, const std::string& baseFrame="");
  27. bool addConstraintSet(const std::string& name, ConstraintSet* task,const std::string& object1,const std::string& object2,const std::string& ee1="",const std::string& ee2="");
  28. bool addSolver(Solver* _solver);
  29. bool addCache(Cache* _cache);
  30. bool initialize();
  31. bool update(double timestamp, double timestep, unsigned int numsubstep=1, bool reiterate=false, bool cache=true, bool interpolate=true);
  32. bool setParam(SceneParam paramId, double value);
  33. EIGEN_MAKE_ALIGNED_OPERATOR_NEW
  34. private:
  35. e_matrix m_A,m_B,m_Atemp,m_Wq,m_Jf,m_Jq,m_Ju,m_Cf,m_Cq,m_Jf_inv;
  36. e_matrix6 m_Vf,m_Uf;
  37. e_vector m_Wy,m_ydot,m_qdot,m_xdot;
  38. e_vector6 m_Sf,m_tempf;
  39. double m_minstep;
  40. double m_maxstep;
  41. unsigned int m_ncTotal,m_nqTotal,m_nuTotal,m_nsets;
  42. std::vector<bool> m_ytask;
  43. Solver* m_solver;
  44. Cache* m_cache;
  45. struct Object_struct{
  46. Object* object;
  47. UncontrolledObject* base;
  48. unsigned int baseFrameIndex;
  49. Range constraintrange;
  50. Range jointrange;
  51. Range coordinaterange; // Xu range of base when object is controlled
  52. // Xu range of object when object is uncontrolled
  53. Object_struct(Object* _object,UncontrolledObject* _base,unsigned int _baseFrameIndex,Range nq_range,Range nc_range,Range nu_range):
  54. object(_object),base(_base),baseFrameIndex(_baseFrameIndex),constraintrange(nc_range),jointrange(nq_range),coordinaterange(nu_range)
  55. {};
  56. };
  57. typedef std::map<std::string,Object_struct*> ObjectMap;
  58. struct ConstraintSet_struct{
  59. ConstraintSet* task;
  60. ObjectMap::iterator object1;
  61. ObjectMap::iterator object2;
  62. Range constraintrange;
  63. Range featurerange;
  64. unsigned int ee1index;
  65. unsigned int ee2index;
  66. ConstraintSet_struct(ConstraintSet* _task,
  67. ObjectMap::iterator _object1,unsigned int _ee1index,
  68. ObjectMap::iterator _object2,unsigned int _ee2index,
  69. Range nc_range,Range coord_range):
  70. task(_task),
  71. object1(_object1),object2(_object2),
  72. constraintrange(nc_range),featurerange(coord_range),
  73. ee1index(_ee1index), ee2index(_ee2index)
  74. {};
  75. };
  76. typedef std::map<std::string,ConstraintSet_struct*> ConstraintMap;
  77. ObjectMap objects;
  78. ConstraintMap constraints;
  79. static bool getConstraintPose(ConstraintSet* constraint, void *_param, KDL::Frame& _pose);
  80. };
  81. }
  82. #endif /* SCENE_HPP_ */