Robowflex  v0.1
Making MoveIt Easy
rnjoint.cpp
Go to the documentation of this file.
1 /* Author: Zachary Kingston */
2 
4 #include <robowflex_dart/space.h>
5 
6 using namespace robowflex::darts;
7 
8 ///
9 /// RnJoint
10 ///
11 
13  dart::dynamics::Joint *joint, //
14  double low, double high)
15  : RnJoint(space, joint, //
16  1, 0, //
17  Eigen::VectorXd::Constant(1, low), //
18  Eigen::VectorXd::Constant(1, high))
19 {
20 }
21 
23  dart::dynamics::Joint *joint, //
24  unsigned int n, unsigned int start, //
25  Eigen::VectorXd low, Eigen::VectorXd high)
26  : Joint(space, joint, n, start, n), low_(low), high_(high)
27 {
28  if (low_.size() != numDof_ or high_.size() != numDof_)
29  {
30  }
31 
32  for (unsigned int i = 0; i < numDof_; ++i)
33  space_->addDimension(low[i], high[i]);
34 }
35 
36 // L1
37 double RnJoint::distance(const Eigen::Ref<const Eigen::VectorXd> &a,
38  const Eigen::Ref<const Eigen::VectorXd> &b) const
39 {
40  return (a - b).lpNorm<1>();
41 }
42 
44 {
45  return distance(low_, high_);
46 }
47 
48 void RnJoint::interpolate(const Eigen::Ref<const Eigen::VectorXd> &a, //
49  const Eigen::Ref<const Eigen::VectorXd> &b, //
50  double t, //
51  Eigen::Ref<Eigen::VectorXd> c) const
52 {
53  c = a + t * (b - a);
54 }
55 
56 void RnJoint::enforceBounds(Eigen::Ref<Eigen::VectorXd> a) const
57 {
58  for (unsigned int i = 0; i < numDof_; ++i)
59  {
60  double &v = a[i];
61  v = (v < low_[i]) ? low_[i] : ((v > high_[i]) ? high_[i] : v);
62  }
63 }
64 
65 bool RnJoint::satisfiesBounds(const Eigen::Ref<const Eigen::VectorXd> &a) const
66 {
67  for (unsigned int i = 0; i < numDof_; ++i)
68  {
69  const double &v = a[i];
70  if ((v < low_[i]) or (v > high_[i]))
71  return false;
72  }
73 
74  return true;
75 }
76 
77 void RnJoint::sample(Eigen::Ref<Eigen::VectorXd> a) const
78 {
79  for (unsigned int i = 0; i < numDof_; ++i)
80  a[i] = rng_.uniformReal(low_[i], high_[i]);
81 }
82 
83 void RnJoint::sampleNear(Eigen::Ref<Eigen::VectorXd> a, //
84  const Eigen::Ref<const Eigen::VectorXd> &near, //
85  double r) const
86 {
87  for (unsigned int i = 0; i < numDof_; ++i)
88  a[i] = rng_.uniformReal(near[i] - r, near[i] + r);
89 
90  enforceBounds(a);
91 }
92 
93 void RnJoint::setUpperLimits(const Eigen::Ref<const Eigen::VectorXd> &v)
94 {
95  if (v.size() != high_.size())
96  throw std::runtime_error("Incorrect size for limits!");
97 
98  high_ = v;
99 
100  for (std::size_t i = 0; i < sizeInSpace_; ++i)
101  space_->bounds_.setHigh(startInSpace_ + i, high_[i]);
102 }
103 
104 void RnJoint::setLowerLimits(const Eigen::Ref<const Eigen::VectorXd> &v)
105 {
106  if (v.size() != low_.size())
107  throw std::runtime_error("Incorrect size for limits!");
108 
109  low_ = v;
110 
111  for (std::size_t i = 0; i < sizeInSpace_; ++i)
112  space_->bounds_.setLow(startInSpace_ + i, low_[i]);
113 }
Abstract controllable joint for robowflex::darts::StateSpace.
Definition: joints.h:38
StateSpace * space_
State space this joint is for.
Definition: joints.h:205
unsigned int numDof_
Number of DoF this joint controls.
Definition: joints.h:218
unsigned int startInSpace_
Start index in space configuration.
Definition: joints.h:214
unsigned int sizeInSpace_
Size of joint in space configuration.
Definition: joints.h:215
ompl::RNG & rng_
Random number generator.
Definition: joints.h:206
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
An OMPL state space for robowflex::darts::World. Can do motion planning for any of the robots or stru...
Definition: space.h:31
DART-based robot modeling and planning.
Definition: acm.h:16