trajopt
 All Classes Namespaces Files Functions Variables Typedefs Pages
incremental_rb.hpp
1 #pragma once
2 #include "trajopt/common.hpp"
3 #include "utils/eigen_conversions.hpp"
4 #include <iostream>
5 
6 namespace trajopt {
7 struct IncrementalRB: public Configuration {
8  OpenRAVE::KinBodyPtr m_body;
9  OpenRAVE::Vector m_r;
10  OpenRAVE::Vector m_q;
11 
12  IncrementalRB(OpenRAVE::KinBodyPtr body) :
13  m_body(body), m_r(0, 0, 0), m_q(1,0,0,0) {
14  }
15  virtual void SetDOFValues(const DblVec& dofs) {
16  OR::Transform T;
17  T.trans = OR::Vector(dofs[0], dofs[1], dofs[2]);
18  m_r = OR::Vector(dofs[3],dofs[4], dofs[5]);
19  T.rot = OpenRAVE::geometry::quatMultiply(OpenRAVE::geometry::quatFromAxisAngle(m_r), m_q);
20  m_body->SetTransform(T);
21  }
22  virtual void GetDOFLimits(DblVec& lower, DblVec& upper) const {
23  lower = DblVec(6, -INFINITY);
24  upper = DblVec(6, INFINITY);
25  };
26  virtual DblVec GetDOFValues() {
27  throw;
28  DblVec out(6);
29  OpenRAVE::Transform T = m_body->GetTransform();
30  out[0] = T.trans.x;
31  out[1] = T.trans.y;
32  out[2] = T.trans.z;
33  out[3] = m_r[0];
34  out[4] = m_r[1];
35  out[5] = m_r[2];
36  return out;
37  }
38  ;
39  virtual int GetDOF() const {
40  return 6;
41  }
42  virtual OpenRAVE::EnvironmentBasePtr GetEnv() {
43  return m_body->GetEnv();
44  }
45  virtual DblMatrix PositionJacobian(int link_ind, const OR::Vector& pt) const {
46  MatrixXd out(3, 6);
47  out.leftCols(3) = Matrix3d::Identity();
48  assert(link_ind == 0);
49  KinBody::LinkPtr link = m_body->GetLinks()[link_ind];
50  OpenRAVE::Vector dr = pt - link->GetTransform().trans;
51  double matdata[9] = { 0, dr[2], -dr[1], -dr[2], 0, dr[0], dr[1], -dr[0], 0 };
52  out.rightCols(3) = Eigen::Map<MatrixXd>(matdata, 3, 3);
53  return out;
54  }
55  virtual DblMatrix RotationJacobian(int link_ind) const {
56  PRINT_AND_THROW("not implemented");
57  }
58  virtual bool DoesAffect(const KinBody::Link& link) {
59  const vector<KinBody::LinkPtr>& links = m_body->GetLinks();
60  for (int i=0; i < links.size(); ++i) {
61  if (links[i].get() == &link) return true;
62  }
63  return false;
64  }
65  virtual std::vector<KinBody::LinkPtr> GetAffectedLinks() {
66  return m_body->GetLinks();
67  }
68  virtual void GetAffectedLinks(std::vector<KinBody::LinkPtr>& links,
69  bool only_with_geom, vector<int>& link_inds) {
70  links = GetAffectedLinks();
71  link_inds.resize(links.size());
72  for (int i = 0; i < links.size(); ++i)
73  link_inds.push_back(links[i]->GetIndex());
74  }
75  virtual DblVec RandomDOFValues() {
76  return toDblVec(VectorXd::Random(6));
77  }
78  virtual vector<OpenRAVE::KinBodyPtr> GetBodies() {
79  return singleton(m_body);
80  }
81 };
82 typedef boost::shared_ptr<IncrementalRB> IncrementalRBPtr;
83 
84 }