Robowflex  v0.1
Making MoveIt Easy
robowflex::darts::SO3Joint Class Reference

A SO(3) joint modeled with quaternions. More...

#include <joints.h>

+ Inheritance diagram for robowflex::darts::SO3Joint:

Public Member Functions

 SO3Joint (StateSpace *space, dart::dynamics::Joint *joint)
 Constructor. More...
 
Eigen::Quaterniond toQuat (const Eigen::Ref< const Eigen::VectorXd > &a) const
 Get the quaternion corresponding to the joint configuration. More...
 
void setQuat (Eigen::Ref< Eigen::VectorXd > a, const Eigen::Quaterniond &q) const
 Set the joint configuration to a quaternion. More...
 
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. More...
 
double getMaximumExtent () const override
 Get the maximum extent of this joint (maximum distance). More...
 
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. More...
 
void enforceBounds (Eigen::Ref< Eigen::VectorXd > a) const override
 Enforce bounds on a joint configuration. More...
 
bool satisfiesBounds (const Eigen::Ref< const Eigen::VectorXd > &a) const override
 Check if a joint configuration satisfies bounds. More...
 
void sample (Eigen::Ref< Eigen::VectorXd > a) const override
 Sample a configuration for this joint. More...
 
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. More...
 
void setJointState (WorldPtr world, const Eigen::Ref< const Eigen::VectorXd > &a) const override
 Set the state of the joint in world. More...
 
void getJointState (WorldPtr world, Eigen::Ref< Eigen::VectorXd > a) const override
 Get the state of the joint in world. More...
 
- Public Member Functions inherited from robowflex::darts::Joint
 Joint (StateSpace *space, unsigned int skelIndex, unsigned int jointIndex, unsigned int sizeInSpace, unsigned int startIndex, unsigned int numDof)
 Constructor. More...
 
 Joint (StateSpace *space, dart::dynamics::Joint *joint, unsigned int sizeInSpace, unsigned int startIndex=0, unsigned int numDof=0)
 Constructor. More...
 
Eigen::Ref< Eigen::VectorXd > getSpaceVars (Eigen::Ref< Eigen::VectorXd > a)
 Gets the joint configuration (subvector of variables for this joint) from a configuration. More...
 
Eigen::Ref< const Eigen::VectorXd > getSpaceVarsConst (const Eigen::Ref< const Eigen::VectorXd > &a)
 Gets the subvector of variables for this joint from a configuration. More...
 
const std::vector< std::size_t > & getIndices () const
 Get the indices in the skeleton for this joint. More...
 
const std::vector< std::string > & getDofs () const
 Get the names of the DoF in the skeleton for this joint. More...
 
std::size_t getSkeletonIndex () const
 Get the index of the skeleton for this joint in the world. More...
 
std::size_t getJointIndex () const
 Get the index of the joint in the skeleton. More...
 
std::size_t getDimension () const
 Get the dimension of this joint. More...
 
virtual void setUpperLimits (const Eigen::Ref< const Eigen::VectorXd > &v)
 Set the upper limits of a joint. More...
 
virtual void setLowerLimits (const Eigen::Ref< const Eigen::VectorXd > &v)
 Set the lower limits of a joint. More...
 
virtual Eigen::VectorXd getUpperLimits () const
 Get the upper limits of a joint. More...
 
virtual Eigen::VectorXd getLowerLimits () const
 Get the lower limits of a joint. More...
 
dart::dynamics::Joint * getJoint (WorldPtr world) const
 Get the Dart joint from a world. More...
 

Additional Inherited Members

- Protected Attributes inherited from robowflex::darts::Joint
StateSpacespace_
 State space this joint is for. More...
 
ompl::RNG & rng_
 Random number generator. More...
 
std::vector< std::size_tindices_
 Indices this joint corresponds to. More...
 
std::vector< std::stringdofs_
 Controlled DoF names. More...
 
unsigned int skelIndex_
 Index of skeleton. More...
 
unsigned int jointIndex_
 Index of joint. More...
 
unsigned int startInSpace_
 Start index in space configuration. More...
 
unsigned int sizeInSpace_
 Size of joint in space configuration. More...
 
unsigned int startIndex_
 Start index in joint. More...
 
unsigned int numDof_
 Number of DoF this joint controls. More...
 

Detailed Description

A SO(3) joint modeled with quaternions.

Definition at line 316 of file joints.h.

Constructor & Destructor Documentation

◆ SO3Joint()

SO3Joint::SO3Joint ( StateSpace space,
dart::dynamics::Joint *  joint 
)

Constructor.

Parameters
[in]spaceState space.
[in]jointJoint.

Definition at line 11 of file so3joint.cpp.

13  : Joint(space, joint, 4)
14 {
15  space_->addDimension(-1., 1.); // q w
16  space_->addDimension(-1., 1.); // q x
17  space_->addDimension(-1., 1.); // q y
18  space_->addDimension(-1., 1.); // q z
19 }
StateSpace * space_
State space this joint is for.
Definition: joints.h:205
Joint(StateSpace *space, unsigned int skelIndex, unsigned int jointIndex, unsigned int sizeInSpace, unsigned int startIndex, unsigned int numDof)
Constructor.
Definition: joint.cpp:15

Member Function Documentation

◆ distance()

double SO3Joint::distance ( const Eigen::Ref< const Eigen::VectorXd > &  a,
const Eigen::Ref< const Eigen::VectorXd > &  b 
) const
overridevirtual

Compute the distance between two joint configurations.

Parameters
[in]aJoint configuration a.
[in]bJoint configuration b.
Returns
Distance between configurations.

Implements robowflex::darts::Joint.

Definition at line 35 of file so3joint.cpp.

37 {
38  return toQuat(a).angularDistance(toQuat(b));
39 }
Eigen::Quaterniond toQuat(const Eigen::Ref< const Eigen::VectorXd > &a) const
Get the quaternion corresponding to the joint configuration.
Definition: so3joint.cpp:21

◆ enforceBounds()

void SO3Joint::enforceBounds ( Eigen::Ref< Eigen::VectorXd >  a) const
overridevirtual

Enforce bounds on a joint configuration.

Parameters
[in,out]aJoint configuration to modify.

Implements robowflex::darts::Joint.

Definition at line 55 of file so3joint.cpp.

56 {
57  auto q = toQuat(a).normalized();
58  setQuat(a, q);
59 }
void setQuat(Eigen::Ref< Eigen::VectorXd > a, const Eigen::Quaterniond &q) const
Set the joint configuration to a quaternion.
Definition: so3joint.cpp:26

◆ getJointState()

void SO3Joint::getJointState ( WorldPtr  world,
Eigen::Ref< Eigen::VectorXd >  a 
) const
overridevirtual

Get the state of the joint in world.

Parameters
[in]worldWorld to get joint state from.
[out]aJoint configuration to set.

Reimplemented from robowflex::darts::Joint.

Definition at line 109 of file so3joint.cpp.

110 {
111  auto *joint = getJoint(world);
112 
113  Eigen::Isometry3d tf = joint->getRelativeTransform();
114  Eigen::Quaterniond q(tf.linear());
115 
116  setQuat(a, q);
117 }
dart::dynamics::Joint * getJoint(WorldPtr world) const
Get the Dart joint from a world.
Definition: joint.cpp:54

◆ getMaximumExtent()

double SO3Joint::getMaximumExtent ( ) const
overridevirtual

Get the maximum extent of this joint (maximum distance).

Returns
The maximum extent.

Implements robowflex::darts::Joint.

Definition at line 41 of file so3joint.cpp.

42 {
43  return constants::half_pi;
44 }
static const double half_pi
Definition: constants.h:22

◆ interpolate()

void SO3Joint::interpolate ( const Eigen::Ref< const Eigen::VectorXd > &  a,
const Eigen::Ref< const Eigen::VectorXd > &  b,
double  t,
Eigen::Ref< Eigen::VectorXd >  c 
) const
overridevirtual

Interpolate to a new configuration c which is t from a to b.

Parameters
[in]aJoint configuration a.
[in]bJoint configuration b.
[in]tAmount to interpolate.
[out]cInterpolated configuration.

Implements robowflex::darts::Joint.

Definition at line 46 of file so3joint.cpp.

50 {
51  auto slerp = toQuat(a).slerp(t, toQuat(b));
52  setQuat(c, slerp);
53 }

◆ sample()

void SO3Joint::sample ( Eigen::Ref< Eigen::VectorXd >  a) const
overridevirtual

Sample a configuration for this joint.

Parameters
[out]aJoint configuration to sample.

Implements robowflex::darts::Joint.

Definition at line 67 of file so3joint.cpp.

68 {
69  double q[4];
70  rng_.quaternion(q);
71  a[0] = q[3];
72  a[1] = q[0];
73  a[2] = q[1];
74  a[3] = q[2];
75 }
ompl::RNG & rng_
Random number generator.
Definition: joints.h:206

◆ sampleNear()

void SO3Joint::sampleNear ( Eigen::Ref< Eigen::VectorXd >  a,
const Eigen::Ref< const Eigen::VectorXd > &  near,
double  r 
) const
overridevirtual

Sample a configuration for this joint near another configuration near.

Parameters
[out]aJoint configuration to sample.
[in]nearJoint configuration to sample near.
[in]rDistance from near to sample within.

Implements robowflex::darts::Joint.

Definition at line 77 of file so3joint.cpp.

80 {
81  if (r >= constants::quarter_pi)
82  sample(a);
83 
84  else
85  {
86  double d = rng_.uniform01();
87  auto qnear = toQuat(near);
88  Eigen::Quaterniond q( //
89  Eigen::AngleAxisd(2. * std::pow(d, constants::third) * r, //
90  Eigen::Vector3d{rng_.gaussian01(), rng_.gaussian01(), rng_.gaussian01()}) //
91  );
92  auto qs = qnear * q;
93  setQuat(a, qs);
94  }
95 }
void sample(Eigen::Ref< Eigen::VectorXd > a) const override
Sample a configuration for this joint.
Definition: so3joint.cpp:67
static const double quarter_pi
Definition: constants.h:23
static const double third
Definition: constants.h:15
T pow(T... args)

◆ satisfiesBounds()

bool SO3Joint::satisfiesBounds ( const Eigen::Ref< const Eigen::VectorXd > &  a) const
overridevirtual

Check if a joint configuration satisfies bounds.

Parameters
[in,out]aJoint configuration to check.
Returns
True if configuration satisfies bounds, false otherwise.

Implements robowflex::darts::Joint.

Definition at line 61 of file so3joint.cpp.

62 {
63  double n = a.norm();
64  return (n - 1.) < constants::eps;
65 }
static const double eps
Definition: constants.h:16

◆ setJointState()

void SO3Joint::setJointState ( WorldPtr  world,
const Eigen::Ref< const Eigen::VectorXd > &  a 
) const
overridevirtual

Set the state of the joint in world.

Parameters
[out]worldWorld to set joint state in.
[in]aJoint configuration to set.

Reimplemented from robowflex::darts::Joint.

Definition at line 97 of file so3joint.cpp.

98 {
99  auto *joint = getJoint(world);
100  auto *j = static_cast<dart::dynamics::FreeJoint *>(joint);
101 
102  Eigen::Isometry3d tf;
103  tf.translation() = j->getPositions();
104  tf.linear() = toQuat(a).toRotationMatrix();
105 
106  j->setRelativeTransform(tf);
107 }

◆ setQuat()

void SO3Joint::setQuat ( Eigen::Ref< Eigen::VectorXd >  a,
const Eigen::Quaterniond &  q 
) const

Set the joint configuration to a quaternion.

Parameters
[out]aJoint configuration.
[in]qQuaternion to set.

Definition at line 26 of file so3joint.cpp.

27 {
28  a[0] = q.w();
29  a[1] = q.x();
30  a[2] = q.y();
31  a[3] = q.z();
32 }

◆ toQuat()

Eigen::Quaterniond SO3Joint::toQuat ( const Eigen::Ref< const Eigen::VectorXd > &  a) const

Get the quaternion corresponding to the joint configuration.

Parameters
[in]aJoint configuration.
Returns
Quaternion of configuration.

Definition at line 21 of file so3joint.cpp.

22 {
23  return Eigen::Quaterniond(a[0], a[1], a[2], a[3]);
24 }

The documentation for this class was generated from the following files: