Klamp't  0.8.1
GeneralizedRobot.h
1 #ifndef GENERALIZED_ROBOT_H
2 #define GENERALIZED_ROBOT_H
3 
4 #include "Robot.h"
5 #include "RigidObject.h"
6 #include "World.h"
7 #include <map>
8 
16 {
17  public:
20  int Add(Robot* robot,const char* name=NULL);
21  int Add(RigidObject* object,const char* name=NULL);
22  void Remove(int id);
23  void Remove(const char* name) { Remove(ID(name)); }
24  void Remove(Robot* robot) { Remove(ID(robot)); }
25  void Remove(RigidObject* object) { Remove(ID(object)); }
27  int ID(const char* name) const;
29  int ID(Robot* robot) const;
31  int ID(RigidObject* object) const;
33  int NumDof() const;
35  string DofName(int index) const;
37  int DofToID(int index) const;
39  pair<int,int> Dofs(int id) const;
41  pair<int,int> Dofs(const char* name) const { return Dofs(ID(name)); }
43  pair<int,int> Dofs(Robot* robot) const { return Dofs(ID(robot)); }
45  pair<int,int> Dofs(RigidObject* object) const { return Dofs(ID(object)); }
47  int Dof(int id,int link) const { return Dofs(id).first+link; }
49  int Dof(Robot* robot,int link) const { return Dof(ID(robot),link); }
51  int Dof(const char* name,int link) const { return Dof(ID(name),link); }
53  void SetConfig(const Config& q);
55  void SetVelocity(const Vector& v);
57  void GetConfig(Config& q) const;
59  void GetVelocity(Vector& v) const;
61  void UpdateGeometry();
63  void Split(const Config& q,vector<Config>& qsplit) const;
65  void SplitRefs(const Config& q,vector<Config>& qsplit) const;
67  void Join(const vector<Config>& qsplit,Config& q) const;
69  void Interpolate(const Config& a,const Config& b,Real u,Config& out) const;
71  void InterpolateVelocity(const Config& a,const Config& b,Real u,Vector& dq) const;
72  //Integrates a velocity vector dq from q to obtain the configuration out
73  void Integrate(const Config& q,const Vector& dq,Config& out) const;
75  Real Distance(const Config& a,const Config& b,Real floatingRotationWeight=1.0) const;
77  void GetJointLimits(Config& qmin,Config& qmax) const;
79  Vector3 GetCOM() const;
81  void GetMegaRobot(Robot& voltron) const;
82 
83  struct Element
84  {
85  string name;
86  Robot* robot;
87  RigidObject* object;
89  int indexStart,indexEnd;
90  };
91  map<int,Element> elements;
92 };
93 
94 
97 void ObjectToRobot(const RigidObject& object,Robot& robot);
98 
100 void ConfigToTransform(const Vector& q,RigidTransform& T);
101 
103 void TransformToConfig(const RigidTransform& T,Vector& q);
104 
105 
106 
107 #endif
Real Distance(const Config &a, const Config &b, Real floatingRotationWeight=1.0) const
Returns a distance metric between two configurations.
int Dof(const char *name, int link) const
Returns the DOF index associated with the element of the given name.
Definition: GeneralizedRobot.h:51
The main robot type used in RobotSim.
Definition: Robot.h:79
void GetJointLimits(Config &qmin, Config &qmax) const
Gets joint limits among all objects.
void Join(const vector< Config > &qsplit, Config &q) const
Joins a list of configurations of indivdual elements into a single joint configuration.
pair< int, int > Dofs(const char *name) const
Returns the DOF index range associated with the given named element.
Definition: GeneralizedRobot.h:41
int NumDof() const
Returns the total number of DOF.
The main world class containing multiple robots, objects, and static geometries (terrains). Lights and other viewport information may also be stored here.
Definition: World.h:20
void UpdateGeometry()
Updates the geometry of all the elements.
void GetVelocity(Vector &v) const
Gets the joint velocity of all the elements.
void GetMegaRobot(Robot &voltron) const
Gets the "mega robot" that merges all robots and objects together.
int ID(const char *name) const
Returns the array index of the given named element.
void SetVelocity(const Vector &v)
Sets a joint velocity of all the elements.
pair< int, int > Dofs(Robot *robot) const
Returns the DOF index range associated with the given robot.
Definition: GeneralizedRobot.h:43
A collection of robots and objects that can be treated like one "big robot".
Definition: GeneralizedRobot.h:15
void Interpolate(const Config &a, const Config &b, Real u, Config &out) const
Interpolates two configurations.
int indexStart
indices governed by this element are in range [indexStart,indexEnd)
Definition: GeneralizedRobot.h:89
pair< int, int > Dofs(RigidObject *object) const
Returns the DOF index range associated with the given object.
Definition: GeneralizedRobot.h:45
int Dof(Robot *robot, int link) const
Returns the DOF index associated with the element of the given id, offset by link.
Definition: GeneralizedRobot.h:49
Vector3 GetCOM() const
Gets the overall center of mass.
int Dof(int id, int link) const
Returns the DOF index associated with the element of the given id, offset by link.
Definition: GeneralizedRobot.h:47
string DofName(int index) const
Returns a name for the given DOF index.
void SetConfig(const Config &q)
Sets a joint configuration of all the elements.
void InterpolateVelocity(const Config &a, const Config &b, Real u, Vector &dq) const
Returns the velocity vector that will move from a to b at the parameter u.
int DofToID(int index) const
Returns the ID for the indicated DOF.
void SplitRefs(const Config &q, vector< Config > &qsplit) const
Same as split, but generates references to q in order to minimize copying.
void GetConfig(Config &q) const
Gets the joint configuration of all the elements.
pair< int, int > Dofs(int id) const
Returns the DOF index range associated with the given id.
A (static) rigid object that may be manipulated.
Definition: RigidObject.h:13
void Split(const Config &q, vector< Config > &qsplit) const
Splits the joint configuration to a list of configurations of individual elements.
Definition: GeneralizedRobot.h:83