Robowflex  v0.1
Making MoveIt Easy
joints.h
Go to the documentation of this file.
1 /* Author: Zachary Kingston */
2 
3 #ifndef ROBOWFLEX_DART_JOINTS_
4 #define ROBOWFLEX_DART_JOINTS_
5 
6 #include <dart/dynamics/DegreeOfFreedom.hpp>
7 #include <dart/dynamics/RevoluteJoint.hpp>
8 #include <dart/dynamics/PrismaticJoint.hpp>
9 #include <dart/dynamics/FreeJoint.hpp>
10 #include <dart/dynamics/PlanarJoint.hpp>
11 
12 #include <ompl/util/RandomNumbers.h>
13 
15 
16 namespace robowflex
17 {
18  namespace darts
19  {
20  /** \cond IGNORE */
22  ROBOWFLEX_CLASS_FORWARD(StateSpace);
23  /** \endcond */
24 
25  /** \cond IGNORE */
27  /** \endcond */
28 
29  /** \class robowflex::darts::JointPtr
30  \brief A shared pointer wrapper for robowflex::darts::Joint. */
31 
32  /** \class robowflex::darts::JointConstPtr
33  \brief A const shared pointer wrapper for robowflex::darts::Joint. */
34 
35  /** \brief Abstract controllable joint for robowflex::darts::StateSpace.
36  */
37  class Joint
38  {
39  public:
40  /** \name Constructors.
41  \{ */
42 
43  /** \brief Constructor.
44  * \param[in] space State space this joint will be in.
45  * \param[in] skelIndex Index of the skeleton this joint is in.
46  * \param[in] jointIndex Index of joint in skeleton.
47  * \param[in] sizeInSpace Number of DoFs in the state space.
48  * \param[in] startIndex Starting index in a configuration vector.
49  * \param[in] numDof Number of DoFs this joint has in the skeleton.
50  */
51  Joint(StateSpace *space, unsigned int skelIndex, unsigned int jointIndex,
52  unsigned int sizeInSpace, unsigned int startIndex, unsigned int numDof);
53 
54  /** \brief Constructor.
55  * \param[in] space State space this joint will be in.
56  * \param[in] joint Joint in skeleton.
57  * \param[in] sizeInSpace Number of DoFs in the state space.
58  * \param[in] startIndex Starting index in a configuration vector.
59  * \param[in] numDof Number of DoFs this joint has in the skeleton.
60  */
61  Joint(StateSpace *space, dart::dynamics::Joint *joint, unsigned int sizeInSpace,
62  unsigned int startIndex = 0, unsigned int numDof = 0);
63 
64  /** \} */
65 
66  /** \name Configuration access.
67  \{ */
68 
69  /** \brief Gets the joint configuration (subvector of variables for this joint) from a
70  * configuration.
71  * \param[in] a Configuration of the full space.
72  * \return A vector of variables for this joint.
73  */
74  Eigen::Ref<Eigen::VectorXd> getSpaceVars(Eigen::Ref<Eigen::VectorXd> a);
75 
76  /** \brief Gets the subvector of variables for this joint from a configuration.
77  * \param[in] a Configuration of the full space.
78  * \return A vector of variables for this joint.
79  */
80  Eigen::Ref<const Eigen::VectorXd> getSpaceVarsConst(const Eigen::Ref<const Eigen::VectorXd> &a);
81 
82  /** \brief Get the indices in the skeleton for this joint.
83  * \return Indices of joint DoFs.
84  */
85  const std::vector<std::size_t> &getIndices() const;
86 
87  /** \brief Get the names of the DoF in the skeleton for this joint.
88  * \return Names of joint DoFs.
89  */
90  const std::vector<std::string> &getDofs() const;
91 
92  /** \brief Get the index of the skeleton for this joint in the world.
93  * \return Skeleton index.
94  */
96 
97  /** \brief Get the index of the joint in the skeleton.
98  * \return Joint index.
99  */
100  std::size_t getJointIndex() const;
101 
102  /** \brief Get the dimension of this joint.
103  * \return The dimension of the joint.
104  */
105  std::size_t getDimension() const;
106 
107  /** \} */
108 
109  /** \name Joint operations.
110  \{ */
111 
112  /** \brief Set the upper limits of a joint.
113  * \param[in] v Upper limits of the joint.
114  */
115  virtual void setUpperLimits(const Eigen::Ref<const Eigen::VectorXd> &v);
116 
117  /** \brief Set the lower limits of a joint.
118  * \param[in] v Lower limits of the joint.
119  */
120  virtual void setLowerLimits(const Eigen::Ref<const Eigen::VectorXd> &v);
121 
122  /** \brief Get the upper limits of a joint.
123  \return The upper limits of the joint.
124  */
125  virtual Eigen::VectorXd getUpperLimits() const;
126 
127  /** \brief Get the lower limits of a joint.
128  * \return The lower limits of the joint.
129  */
130  virtual Eigen::VectorXd getLowerLimits() const;
131 
132  /** \brief Compute the distance between two joint configurations.
133  * \param[in] a Joint configuration a.
134  * \param[in] b Joint configuration b.
135  * \return Distance between configurations.
136  */
137  virtual double distance(const Eigen::Ref<const Eigen::VectorXd> &a,
138  const Eigen::Ref<const Eigen::VectorXd> &b) const = 0;
139 
140  /** \brief Get the maximum extent of this joint (maximum distance).
141  * \return The maximum extent.
142  */
143  virtual double getMaximumExtent() const = 0;
144 
145  /** \brief Interpolate to a new configuration \a c which is \a t from \a a to \a b.
146  * \param[in] a Joint configuration a.
147  * \param[in] b Joint configuration b.
148  * \param[in] t Amount to interpolate.
149  * \param[out] c Interpolated configuration.
150  */
151  virtual void interpolate(const Eigen::Ref<const Eigen::VectorXd> &a, //
152  const Eigen::Ref<const Eigen::VectorXd> &b, //
153  double t, //
154  Eigen::Ref<Eigen::VectorXd> c) const = 0;
155 
156  /** \brief Enforce bounds on a joint configuration.
157  * \param[in,out] a Joint configuration to modify.
158  */
159  virtual void enforceBounds(Eigen::Ref<Eigen::VectorXd> a) const = 0;
160 
161  /** \brief Check if a joint configuration satisfies bounds.
162  * \param[in,out] a Joint configuration to check.
163  * \return True if configuration satisfies bounds, false otherwise.
164  */
165  virtual bool satisfiesBounds(const Eigen::Ref<const Eigen::VectorXd> &a) const = 0;
166 
167  /** \brief Sample a configuration for this joint.
168  * \param[out] a Joint configuration to sample.
169  */
170  virtual void sample(Eigen::Ref<Eigen::VectorXd> a) const = 0;
171 
172  /** \brief Sample a configuration for this joint near another configuration \a near.
173  * \param[out] a Joint configuration to sample.
174  * \param[in] near Joint configuration to sample near.
175  * \param[in] r Distance from near to sample within.
176  */
177  virtual void sampleNear(Eigen::Ref<Eigen::VectorXd> a, //
178  const Eigen::Ref<const Eigen::VectorXd> &near, //
179  double r) const = 0;
180  /** \} */
181 
182  /** \name World modification.
183  \{ */
184 
185  /** \brief Set the state of the joint in \a world.
186  * \param[out] world World to set joint state in.
187  * \param[in] a Joint configuration to set.
188  */
189  virtual void setJointState(WorldPtr world, const Eigen::Ref<const Eigen::VectorXd> &a) const;
190  /** \brief Get the state of the joint in \a world.
191  * \param[in] world World to get joint state from.
192  * \param[out] a Joint configuration to set.
193  */
194  virtual void getJointState(WorldPtr world, Eigen::Ref<Eigen::VectorXd> a) const;
195 
196  /** \brief Get the Dart joint from a world.
197  * \param[in] world World to get joint from.
198  * \return Joint.
199  */
200  dart::dynamics::Joint *getJoint(WorldPtr world) const;
201 
202  /** \} */
203 
204  protected:
205  StateSpace *space_; ///< State space this joint is for.
206  ompl::RNG &rng_; ///< Random number generator.
207 
208  std::vector<std::size_t> indices_; ///< Indices this joint corresponds to.
209  std::vector<std::string> dofs_; ///< Controlled DoF names.
210 
211  unsigned int skelIndex_; ///< Index of skeleton.
212  unsigned int jointIndex_; ///< Index of joint.
213 
214  unsigned int startInSpace_; ///< Start index in space configuration.
215  unsigned int sizeInSpace_; ///< Size of joint in space configuration.
216 
217  unsigned int startIndex_; ///< Start index in joint.
218  unsigned int numDof_; ///< Number of DoF this joint controls.
219  };
220 
221  /** \brief A real vector joint of \a n dimensions.
222  */
223  class RnJoint : public Joint
224  {
225  public:
226  /** \name Constructors.
227  \{ */
228 
229  /** \brief Constructor.
230  * \param[in] space State space.
231  * \param[in] joint 1-DoF joint to control.
232  * \param[in] low Lower bound.
233  * \param[in] high Upper bound.
234  */
235  RnJoint(StateSpace *space, //
236  dart::dynamics::Joint *joint, //
237  double low, double high);
238 
239  /** \brief Constructor.
240  * \param[in] space State space.
241  * \param[in] joint n-DoF joint to control.
242  * \param[in] n Number of DoF.
243  * \param[in] start Which DoF to start controlling.
244  * \param[in] low Lower bound.
245  * \param[in] high Upper bound.
246  */
247  RnJoint(StateSpace *space, //
248  dart::dynamics::Joint *joint, //
249  unsigned int n, unsigned int start, //
250  Eigen::VectorXd low, Eigen::VectorXd high);
251 
252  /** \} */
253 
254  void setUpperLimits(const Eigen::Ref<const Eigen::VectorXd> &v) override;
255  void setLowerLimits(const Eigen::Ref<const Eigen::VectorXd> &v) override;
256 
257  double distance(const Eigen::Ref<const Eigen::VectorXd> &a,
258  const Eigen::Ref<const Eigen::VectorXd> &b) const override;
259 
260  double getMaximumExtent() const override;
261 
262  void interpolate(const Eigen::Ref<const Eigen::VectorXd> &a, //
263  const Eigen::Ref<const Eigen::VectorXd> &b, //
264  double t, //
265  Eigen::Ref<Eigen::VectorXd> c) const override;
266 
267  void enforceBounds(Eigen::Ref<Eigen::VectorXd> a) const override;
268 
269  bool satisfiesBounds(const Eigen::Ref<const Eigen::VectorXd> &a) const override;
270 
271  void sample(Eigen::Ref<Eigen::VectorXd> a) const override;
272 
273  void sampleNear(Eigen::Ref<Eigen::VectorXd> a, //
274  const Eigen::Ref<const Eigen::VectorXd> &near, //
275  double r) const override;
276 
277  private:
278  Eigen::VectorXd low_; ///< Lower bounds.
279  Eigen::VectorXd high_; ///< Upper bounds.
280  };
281 
282  /** \brief A SO(2) joint. Bounds are from -pi to pi, and wraps.
283  */
284  class SO2Joint : public Joint
285  {
286  public:
287  /** \brief Constructor.
288  * \param[in] space State space.
289  * \param[in] joint Joint.
290  */
291  SO2Joint(StateSpace *space, dart::dynamics::Joint *joint, unsigned int index = 0);
292 
293  double distance(const Eigen::Ref<const Eigen::VectorXd> &a,
294  const Eigen::Ref<const Eigen::VectorXd> &b) const override;
295 
296  double getMaximumExtent() const override;
297 
298  void interpolate(const Eigen::Ref<const Eigen::VectorXd> &a, //
299  const Eigen::Ref<const Eigen::VectorXd> &b, //
300  double t, //
301  Eigen::Ref<Eigen::VectorXd> c) const override;
302 
303  void enforceBounds(Eigen::Ref<Eigen::VectorXd> a) const override;
304 
305  bool satisfiesBounds(const Eigen::Ref<const Eigen::VectorXd> &a) const override;
306 
307  void sample(Eigen::Ref<Eigen::VectorXd> a) const override;
308 
309  void sampleNear(Eigen::Ref<Eigen::VectorXd> a, //
310  const Eigen::Ref<const Eigen::VectorXd> &near, //
311  double r) const override;
312  };
313 
314  /** \brief A SO(3) joint modeled with quaternions.
315  */
316  class SO3Joint : public Joint
317  {
318  public:
319  /** \brief Constructor.
320  * \param[in] space State space.
321  * \param[in] joint Joint.
322  */
323  SO3Joint(StateSpace *space, dart::dynamics::Joint *joint);
324 
325  /** \brief Get the quaternion corresponding to the joint configuration.
326  * \param[in] a Joint configuration.
327  * \return Quaternion of configuration.
328  */
329  Eigen::Quaterniond toQuat(const Eigen::Ref<const Eigen::VectorXd> &a) const;
330 
331  /** \brief Set the joint configuration to a quaternion.
332  * \param[out] a Joint configuration.
333  * \param[in] q Quaternion to set.
334  */
335  void setQuat(Eigen::Ref<Eigen::VectorXd> a, const Eigen::Quaterniond &q) const;
336 
337  double distance(const Eigen::Ref<const Eigen::VectorXd> &a,
338  const Eigen::Ref<const Eigen::VectorXd> &b) const override;
339 
340  double getMaximumExtent() const override;
341 
342  void interpolate(const Eigen::Ref<const Eigen::VectorXd> &a, //
343  const Eigen::Ref<const Eigen::VectorXd> &b, //
344  double t, //
345  Eigen::Ref<Eigen::VectorXd> c) const override;
346 
347  void enforceBounds(Eigen::Ref<Eigen::VectorXd> a) const override;
348 
349  bool satisfiesBounds(const Eigen::Ref<const Eigen::VectorXd> &a) const override;
350 
351  void sample(Eigen::Ref<Eigen::VectorXd> a) const override;
352 
353  void sampleNear(Eigen::Ref<Eigen::VectorXd> a, //
354  const Eigen::Ref<const Eigen::VectorXd> &near, //
355  double r) const override;
356 
357  void setJointState(WorldPtr world, const Eigen::Ref<const Eigen::VectorXd> &a) const override;
358  void getJointState(WorldPtr world, Eigen::Ref<Eigen::VectorXd> a) const override;
359  };
360 
361  } // namespace darts
362 } // namespace robowflex
363 #endif
#define ROBOWFLEX_CLASS_FORWARD(C)
Macro that forward declares a class and defines two shared ptrs types:
Definition: class_forward.h:16
Abstract controllable joint for robowflex::darts::StateSpace.
Definition: joints.h:38
const std::vector< std::size_t > & getIndices() const
Get the indices in the skeleton for this joint.
Definition: joint.cpp:70
unsigned int skelIndex_
Index of skeleton.
Definition: joints.h:211
virtual void setLowerLimits(const Eigen::Ref< const Eigen::VectorXd > &v)
Set the lower limits of a joint.
Definition: joint.cpp:112
unsigned int jointIndex_
Index of joint.
Definition: joints.h:212
unsigned int startIndex_
Start index in joint.
Definition: joints.h:217
StateSpace * space_
State space this joint is for.
Definition: joints.h:205
virtual void setJointState(WorldPtr world, const Eigen::Ref< const Eigen::VectorXd > &a) const
Set the state of the joint in world.
Definition: joint.cpp:95
virtual Eigen::VectorXd getLowerLimits() const
Get the lower limits of a joint.
Definition: joint.cpp:122
std::vector< std::size_t > indices_
Indices this joint corresponds to.
Definition: joints.h:208
virtual void enforceBounds(Eigen::Ref< Eigen::VectorXd > a) const =0
Enforce bounds on a joint configuration.
virtual bool satisfiesBounds(const Eigen::Ref< const Eigen::VectorXd > &a) const =0
Check if a joint configuration satisfies bounds.
Eigen::Ref< Eigen::VectorXd > getSpaceVars(Eigen::Ref< Eigen::VectorXd > a)
Gets the joint configuration (subvector of variables for this joint) from a configuration.
Definition: joint.cpp:60
unsigned int numDof_
Number of DoF this joint controls.
Definition: joints.h:218
Joint(StateSpace *space, unsigned int skelIndex, unsigned int jointIndex, unsigned int sizeInSpace, unsigned int startIndex, unsigned int numDof)
Constructor.
Definition: joint.cpp:15
virtual void interpolate(const Eigen::Ref< const Eigen::VectorXd > &a, const Eigen::Ref< const Eigen::VectorXd > &b, double t, Eigen::Ref< Eigen::VectorXd > c) const =0
Interpolate to a new configuration c which is t from a to b.
std::size_t getJointIndex() const
Get the index of the joint in the skeleton.
Definition: joint.cpp:85
unsigned int startInSpace_
Start index in space configuration.
Definition: joints.h:214
dart::dynamics::Joint * getJoint(WorldPtr world) const
Get the Dart joint from a world.
Definition: joint.cpp:54
virtual void getJointState(WorldPtr world, Eigen::Ref< Eigen::VectorXd > a) const
Get the state of the joint in world.
Definition: joint.cpp:101
Eigen::Ref< const Eigen::VectorXd > getSpaceVarsConst(const Eigen::Ref< const Eigen::VectorXd > &a)
Gets the subvector of variables for this joint from a configuration.
Definition: joint.cpp:65
virtual double distance(const Eigen::Ref< const Eigen::VectorXd > &a, const Eigen::Ref< const Eigen::VectorXd > &b) const =0
Compute the distance between two joint configurations.
unsigned int sizeInSpace_
Size of joint in space configuration.
Definition: joints.h:215
std::vector< std::string > dofs_
Controlled DoF names.
Definition: joints.h:209
std::size_t getDimension() const
Get the dimension of this joint.
Definition: joint.cpp:90
const std::vector< std::string > & getDofs() const
Get the names of the DoF in the skeleton for this joint.
Definition: joint.cpp:75
ompl::RNG & rng_
Random number generator.
Definition: joints.h:206
virtual void sample(Eigen::Ref< Eigen::VectorXd > a) const =0
Sample a configuration for this joint.
virtual double getMaximumExtent() const =0
Get the maximum extent of this joint (maximum distance).
virtual void sampleNear(Eigen::Ref< Eigen::VectorXd > a, const Eigen::Ref< const Eigen::VectorXd > &near, double r) const =0
Sample a configuration for this joint near another configuration near.
virtual Eigen::VectorXd getUpperLimits() const
Get the upper limits of a joint.
Definition: joint.cpp:117
std::size_t getSkeletonIndex() const
Get the index of the skeleton for this joint in the world.
Definition: joint.cpp:80
virtual void setUpperLimits(const Eigen::Ref< const Eigen::VectorXd > &v)
Set the upper limits of a joint.
Definition: joint.cpp:107
A real vector joint of n dimensions.
Definition: joints.h:224
void sampleNear(Eigen::Ref< Eigen::VectorXd > a, const Eigen::Ref< const Eigen::VectorXd > &near, double r) const override
Sample a configuration for this joint near another configuration near.
Definition: rnjoint.cpp:83
double distance(const Eigen::Ref< const Eigen::VectorXd > &a, const Eigen::Ref< const Eigen::VectorXd > &b) const override
Compute the distance between two joint configurations.
Definition: rnjoint.cpp:37
RnJoint(StateSpace *space, dart::dynamics::Joint *joint, double low, double high)
Constructor.
Definition: rnjoint.cpp:12
double getMaximumExtent() const override
Get the maximum extent of this joint (maximum distance).
Definition: rnjoint.cpp:43
void sample(Eigen::Ref< Eigen::VectorXd > a) const override
Sample a configuration for this joint.
Definition: rnjoint.cpp:77
void enforceBounds(Eigen::Ref< Eigen::VectorXd > a) const override
Enforce bounds on a joint configuration.
Definition: rnjoint.cpp:56
Eigen::VectorXd high_
Upper bounds.
Definition: joints.h:279
bool satisfiesBounds(const Eigen::Ref< const Eigen::VectorXd > &a) const override
Check if a joint configuration satisfies bounds.
Definition: rnjoint.cpp:65
void setUpperLimits(const Eigen::Ref< const Eigen::VectorXd > &v) override
Set the upper limits of a joint.
Definition: rnjoint.cpp:93
void setLowerLimits(const Eigen::Ref< const Eigen::VectorXd > &v) override
Set the lower limits of a joint.
Definition: rnjoint.cpp:104
void interpolate(const Eigen::Ref< const Eigen::VectorXd > &a, const Eigen::Ref< const Eigen::VectorXd > &b, double t, Eigen::Ref< Eigen::VectorXd > c) const override
Interpolate to a new configuration c which is t from a to b.
Definition: rnjoint.cpp:48
Eigen::VectorXd low_
Lower bounds.
Definition: joints.h:278
A SO(2) joint. Bounds are from -pi to pi, and wraps.
Definition: joints.h:285
void sample(Eigen::Ref< Eigen::VectorXd > a) const override
Sample a configuration for this joint.
Definition: so2joint.cpp:76
void enforceBounds(Eigen::Ref< Eigen::VectorXd > a) const override
Enforce bounds on a joint configuration.
Definition: so2joint.cpp:60
void interpolate(const Eigen::Ref< const Eigen::VectorXd > &a, const Eigen::Ref< const Eigen::VectorXd > &b, double t, Eigen::Ref< Eigen::VectorXd > c) const override
Interpolate to a new configuration c which is t from a to b.
Definition: so2joint.cpp:35
void sampleNear(Eigen::Ref< Eigen::VectorXd > a, const Eigen::Ref< const Eigen::VectorXd > &near, double r) const override
Sample a configuration for this joint near another configuration near.
Definition: so2joint.cpp:81
double distance(const Eigen::Ref< const Eigen::VectorXd > &a, const Eigen::Ref< const Eigen::VectorXd > &b) const override
Compute the distance between two joint configurations.
Definition: so2joint.cpp:23
double getMaximumExtent() const override
Get the maximum extent of this joint (maximum distance).
Definition: so2joint.cpp:30
bool satisfiesBounds(const Eigen::Ref< const Eigen::VectorXd > &a) const override
Check if a joint configuration satisfies bounds.
Definition: so2joint.cpp:70
SO2Joint(StateSpace *space, dart::dynamics::Joint *joint, unsigned int index=0)
Constructor.
Definition: so2joint.cpp:15
A SO(3) joint modeled with quaternions.
Definition: joints.h:317
void interpolate(const Eigen::Ref< const Eigen::VectorXd > &a, const Eigen::Ref< const Eigen::VectorXd > &b, double t, Eigen::Ref< Eigen::VectorXd > c) const override
Interpolate to a new configuration c which is t from a to b.
Definition: so3joint.cpp:46
SO3Joint(StateSpace *space, dart::dynamics::Joint *joint)
Constructor.
Definition: so3joint.cpp:11
void setQuat(Eigen::Ref< Eigen::VectorXd > a, const Eigen::Quaterniond &q) const
Set the joint configuration to a quaternion.
Definition: so3joint.cpp:26
void enforceBounds(Eigen::Ref< Eigen::VectorXd > a) const override
Enforce bounds on a joint configuration.
Definition: so3joint.cpp:55
double getMaximumExtent() const override
Get the maximum extent of this joint (maximum distance).
Definition: so3joint.cpp:41
double distance(const Eigen::Ref< const Eigen::VectorXd > &a, const Eigen::Ref< const Eigen::VectorXd > &b) const override
Compute the distance between two joint configurations.
Definition: so3joint.cpp:35
void sample(Eigen::Ref< Eigen::VectorXd > a) const override
Sample a configuration for this joint.
Definition: so3joint.cpp:67
void setJointState(WorldPtr world, const Eigen::Ref< const Eigen::VectorXd > &a) const override
Set the state of the joint in world.
Definition: so3joint.cpp:97
void getJointState(WorldPtr world, Eigen::Ref< Eigen::VectorXd > a) const override
Get the state of the joint in world.
Definition: so3joint.cpp:109
Eigen::Quaterniond toQuat(const Eigen::Ref< const Eigen::VectorXd > &a) const
Get the quaternion corresponding to the joint configuration.
Definition: so3joint.cpp:21
void sampleNear(Eigen::Ref< Eigen::VectorXd > a, const Eigen::Ref< const Eigen::VectorXd > &near, double r) const override
Sample a configuration for this joint near another configuration near.
Definition: so3joint.cpp:77
bool satisfiesBounds(const Eigen::Ref< const Eigen::VectorXd > &a) const override
Check if a joint configuration satisfies bounds.
Definition: so3joint.cpp:61
An OMPL state space for robowflex::darts::World. Can do motion planning for any of the robots or stru...
Definition: space.h:31
A shared pointer wrapper for robowflex::darts::World.
Main namespace. Contains all library classes and functions.
Definition: scene.cpp:25