trajopt
 All Classes Namespaces Files Functions Variables Typedefs Pages
configuration_space.hpp
1 #pragma once
2 #include "typedefs.hpp"
3 #include <openrave/openrave.h>
4 #include "macros.h"
5 namespace trajopt {
6 
7 
8 class TRAJOPT_API Configuration {
9 public:
10 
11  virtual void SetDOFValues(const DblVec& dofs) = 0;
12  virtual void GetDOFLimits(DblVec& lower, DblVec& upper) const = 0;
13  virtual DblVec GetDOFValues() = 0;
14  virtual int GetDOF() const = 0;
15  virtual OpenRAVE::EnvironmentBasePtr GetEnv() = 0;
16  virtual DblMatrix PositionJacobian(int link_ind, const OR::Vector& pt) const = 0;
17  virtual DblMatrix RotationJacobian(int link_ind) const = 0;
18  virtual bool DoesAffect(const KinBody::Link& link) = 0;
19  virtual vector<OpenRAVE::KinBodyPtr> GetBodies() = 0;
20  virtual std::vector<KinBody::LinkPtr> GetAffectedLinks() = 0;
21  virtual void GetAffectedLinks(std::vector<KinBody::LinkPtr>& links, bool only_with_geom, vector<int>& link_inds) = 0;
22  virtual DblVec RandomDOFValues() = 0;
23  virtual ~Configuration() {}
24  struct Saver {
25  virtual ~Saver(){}
26  };
27  typedef boost::shared_ptr<Saver> SaverPtr;
28  struct GenericSaver : public Saver {
29  DblVec dofvals;
30  Configuration* parent;
31  GenericSaver(Configuration* _parent) : dofvals(_parent->GetDOFValues()), parent(_parent) {}
32  ~GenericSaver() {
33  parent->SetDOFValues(dofvals);
34  }
35  }; // inefficient
36 
37  virtual SaverPtr Save() {
38  return SaverPtr(new GenericSaver(this));
39  }
40 
41 
42 };
43 typedef boost::shared_ptr<Configuration> ConfigurationPtr;
44 
48 class TRAJOPT_API RobotAndDOF : public Configuration {
49 public:
50  RobotAndDOF(OR::KinBodyPtr _robot, const IntVec& _joint_inds, int _affinedofs=0, const OR::Vector _rotationaxis=OR::Vector(0,0,1)) :
51  robot(_robot), joint_inds(_joint_inds), affinedofs(_affinedofs), rotationaxis(_rotationaxis) {}
52 
53  void SetDOFValues(const DblVec& dofs);
54  void GetDOFLimits(DblVec& lower, DblVec& upper) const;
55  DblVec GetDOFValues();
56  int GetDOF() const;
57  virtual OpenRAVE::EnvironmentBasePtr GetEnv() {return robot->GetEnv();};
58  IntVec GetJointIndices() const {return joint_inds;}
59  DblMatrix PositionJacobian(int link_ind, const OR::Vector& pt) const;
60  DblMatrix RotationJacobian(int link_ind) const;
61  OR::RobotBasePtr GetRobot() const {return boost::dynamic_pointer_cast<RobotBase>(robot);}
62  virtual vector<OpenRAVE::KinBodyPtr> GetBodies();
63  bool DoesAffect(const KinBody::Link& link);
64  std::vector<KinBody::LinkPtr> GetAffectedLinks();
65  void GetAffectedLinks(std::vector<KinBody::LinkPtr>& links, bool only_with_geom, vector<int>& link_inds);
66  DblVec RandomDOFValues();
67 
68  struct RobotSaver : public Saver {
69  OpenRAVE::KinBody::KinBodyStateSaver saver;
70  RobotSaver(OpenRAVE::KinBodyPtr robot) : saver(robot) {}
71  };
72  SaverPtr Save() {
73  return SaverPtr(new RobotSaver(robot));
74  }
75  void SetRobotActiveDOFs();
76 
77 private:
78  OpenRAVE::KinBodyPtr robot;
79  IntVec joint_inds;
80  int affinedofs;
81  OR::Vector rotationaxis;
82 };
83 typedef boost::shared_ptr<RobotAndDOF> RobotAndDOFPtr;
84 
85 }