Robowflex  v0.1
Making MoveIt Easy
so2joint.cpp
Go to the documentation of this file.
1 /* Author: Zachary Kingston */
2 
4 
6 #include <robowflex_dart/space.h>
7 
9 using namespace robowflex::darts;
10 
11 ///
12 /// SO2Joint
13 ///
14 
16  dart::dynamics::Joint *joint, unsigned int index)
17  : Joint(space, joint, 1, index, 1)
18 {
19  space_->addDimension(-constants::pi, constants::pi);
20 }
21 
22 // L1
23 double SO2Joint::distance(const Eigen::Ref<const Eigen::VectorXd> &a,
24  const Eigen::Ref<const Eigen::VectorXd> &b) const
25 {
26  double d = std::fabs(a[0] - b[0]);
27  return (d > constants::pi) ? constants::two_pi - d : d;
28 }
29 
31 {
32  return constants::pi;
33 }
34 
35 void SO2Joint::interpolate(const Eigen::Ref<const Eigen::VectorXd> &a, //
36  const Eigen::Ref<const Eigen::VectorXd> &b, //
37  double t, //
38  Eigen::Ref<Eigen::VectorXd> c) const
39 {
40  double diff = b[0] - a[0];
41  if (std::fabs(diff) <= constants::pi)
42  c[0] = a[0] + diff * t;
43  else
44  {
45  if (diff > 0.0)
46  diff = constants::two_pi - diff;
47  else
48  diff = -constants::two_pi - diff;
49 
50  double &v = c[0];
51  v = a[0] - diff * t;
52 
53  if (v > constants::pi)
54  v -= constants::two_pi;
55  else if (v < -constants::pi)
56  v += constants::two_pi;
57  }
58 }
59 
60 void SO2Joint::enforceBounds(Eigen::Ref<Eigen::VectorXd> a) const
61 {
62  double &v = a[0];
64  if (v < -constants::pi)
65  v += constants::two_pi;
66  else if (v >= constants::pi)
67  v -= constants::two_pi;
68 }
69 
70 bool SO2Joint::satisfiesBounds(const Eigen::Ref<const Eigen::VectorXd> &a) const
71 {
72  const double &v = a[0];
73  return (v >= -constants::pi) and (v <= constants::pi);
74 }
75 
76 void SO2Joint::sample(Eigen::Ref<Eigen::VectorXd> a) const
77 {
78  a[0] = rng_.uniformReal(-constants::pi, constants::pi);
79 }
80 
81 void SO2Joint::sampleNear(Eigen::Ref<Eigen::VectorXd> a, //
82  const Eigen::Ref<const Eigen::VectorXd> &near, //
83  double r) const
84 {
85  a[0] = rng_.uniformReal(near[0] - r, near[0] + r);
86  enforceBounds(a);
87 }
Abstract controllable joint for robowflex::darts::StateSpace.
Definition: joints.h:38
StateSpace * space_
State space this joint is for.
Definition: joints.h:205
ompl::RNG & rng_
Random number generator.
Definition: joints.h:206
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
An OMPL state space for robowflex::darts::World. Can do motion planning for any of the robots or stru...
Definition: space.h:31
T fabs(T... args)
T fmod(T... args)
static const double two_pi
Definition: constants.h:24
static const double pi
Definition: constants.h:21
DART-based robot modeling and planning.
Definition: acm.h:16