Robowflex  v0.1
Making MoveIt Easy
joint.cpp
Go to the documentation of this file.
1 /* Author: Zachary Kingston */
2 
4 #include <robowflex_dart/space.h>
5 #include <robowflex_dart/world.h>
6 
7 #include <utility>
8 
9 using namespace robowflex::darts;
10 
11 ///
12 /// Joint
13 ///
14 
16  unsigned int skelIndex, //
17  unsigned int jointIndex, //
18  unsigned int sizeInSpace, //
19  unsigned int startIndex, //
20  unsigned int numDof)
21  : space_(space)
22  , rng_(space->rng_)
23  , skelIndex_(skelIndex)
24  , jointIndex_(jointIndex)
25  , startInSpace_(space_->getDimension())
26  , sizeInSpace_(sizeInSpace)
27  , startIndex_(startIndex)
28  , numDof_(numDof)
29 {
30  auto *joint = getJoint(space_->getWorld());
31  for (unsigned int i = 0; i < numDof_; ++i)
32  {
33  unsigned int j = startIndex_ + i;
34  if (j >= joint->getNumDofs())
35  throw std::runtime_error("Invalid joint");
36 
37  auto *dof = joint->getDof(j);
38  indices_.emplace_back(dof->getIndexInSkeleton());
39  dofs_.emplace_back(dof->getName());
40  }
41 }
42 
43 Joint::Joint(StateSpace *space, dart::dynamics::Joint *joint, unsigned int sizeInSpace,
44  unsigned int startIndex, unsigned int numDof)
45  : Joint(space, //
46  space->getWorld()->getSkeletonIndex(joint->getSkeleton()), //
47  joint->getJointIndexInSkeleton(), //
48  sizeInSpace, //
49  startIndex, //
50  (numDof) ? numDof : joint->getNumDofs())
51 {
52 }
53 
54 dart::dynamics::Joint *Joint::getJoint(WorldPtr world) const
55 {
56  const auto &sim = world->getSimConst();
57  return sim->getSkeleton(skelIndex_)->getJoint(jointIndex_);
58 }
59 
60 Eigen::Ref<Eigen::VectorXd> Joint::getSpaceVars(Eigen::Ref<Eigen::VectorXd> a)
61 {
62  return a.segment(startInSpace_, sizeInSpace_);
63 }
64 
65 Eigen::Ref<const Eigen::VectorXd> Joint::getSpaceVarsConst(const Eigen::Ref<const Eigen::VectorXd> &a)
66 {
67  return a.segment(startInSpace_, sizeInSpace_);
68 }
69 
71 {
72  return indices_;
73 }
74 
76 {
77  return dofs_;
78 }
79 
81 {
82  return skelIndex_;
83 }
84 
86 {
87  return jointIndex_;
88 }
89 
91 {
92  return numDof_;
93 }
94 
95 void Joint::setJointState(WorldPtr world, const Eigen::Ref<const Eigen::VectorXd> &a) const
96 {
97  auto *joint = getJoint(std::move(world));
98  joint->getSkeleton()->setPositions(indices_, a);
99 }
100 
101 void Joint::getJointState(WorldPtr world, Eigen::Ref<Eigen::VectorXd> a) const
102 {
103  auto *joint = getJoint(std::move(world));
104  a = joint->getSkeleton()->getPositions(indices_);
105 }
106 
107 void Joint::setUpperLimits(const Eigen::Ref<const Eigen::VectorXd> & /*v*/)
108 {
109  throw std::runtime_error("Cannot set bounds on this joint!");
110 }
111 
112 void Joint::setLowerLimits(const Eigen::Ref<const Eigen::VectorXd> & /*v*/)
113 {
114  throw std::runtime_error("Cannot set bounds on this joint!");
115 }
116 
117 Eigen::VectorXd Joint::getUpperLimits() const
118 {
119  return space_->getUpperBound().segment(startInSpace_, sizeInSpace_);
120 }
121 
122 Eigen::VectorXd Joint::getLowerLimits() const
123 {
124  return space_->getLowerBound().segment(startInSpace_, sizeInSpace_);
125 }
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
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
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
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
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
An OMPL state space for robowflex::darts::World. Can do motion planning for any of the robots or stru...
Definition: space.h:31
Eigen::VectorXd getLowerBound() const
Get a vector of the lower joint bounds for the space.
Definition: space.cpp:474
Eigen::VectorXd getUpperBound() const
Get a vector of the upper joint bounds for the space.
Definition: space.cpp:480
WorldPtr getWorld()
Get underlying world.
Definition: space.cpp:373
A shared pointer wrapper for robowflex::darts::World.
T emplace_back(T... args)
T move(T... args)
DART-based robot modeling and planning.
Definition: acm.h:16