ControlledObject.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /** \file itasc/ControlledObject.cpp
  2. * \ingroup itasc
  3. */
  4. /*
  5. * ControlledObject.cpp
  6. *
  7. * Created on: Jan 5, 2009
  8. * Author: rubensmits
  9. */
  10. #include "ControlledObject.hpp"
  11. namespace iTaSC {
  12. ControlledObject::ControlledObject():
  13. Object(Controlled),m_nq(0),m_nc(0),m_nee(0)
  14. {
  15. // max joint variable = 0.52 radian or 0.52 meter in one timestep
  16. m_maxDeltaQ = e_scalar(0.52);
  17. }
  18. void ControlledObject::initialize(unsigned int _nq,unsigned int _nc, unsigned int _nee)
  19. {
  20. assert(_nee >= 1);
  21. m_nq = _nq;
  22. m_nc = _nc;
  23. m_nee = _nee;
  24. if (m_nq > 0) {
  25. m_Wq = e_identity_matrix(m_nq,m_nq);
  26. m_qdot = e_zero_vector(m_nq);
  27. }
  28. if (m_nc > 0) {
  29. m_Wy = e_scalar_vector(m_nc,1.0);
  30. m_ydot = e_zero_vector(m_nc);
  31. }
  32. if (m_nc > 0 && m_nq > 0)
  33. m_Cq = e_zero_matrix(m_nc,m_nq);
  34. // clear all Jacobian if any
  35. m_JqArray.clear();
  36. // reserve one more to have a zero matrix handy
  37. if (m_nq > 0)
  38. m_JqArray.resize(m_nee+1, e_zero_matrix(6,m_nq));
  39. }
  40. ControlledObject::~ControlledObject() {}
  41. const e_matrix& ControlledObject::getJq(unsigned int ee) const
  42. {
  43. assert(m_nq > 0);
  44. return m_JqArray[(ee>m_nee)?m_nee:ee];
  45. }
  46. double ControlledObject::getMaxTimestep(double& timestep)
  47. {
  48. e_scalar maxQdot = m_qdot.array().abs().maxCoeff();
  49. if (timestep*maxQdot > m_maxDeltaQ) {
  50. timestep = m_maxDeltaQ/maxQdot;
  51. }
  52. return timestep;
  53. }
  54. }