-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor DART StateSpaces #278
Conversation
This decouples the state space from the underlying DART Joint that was used to generate the state space. Joint properties (e.g. position limits) are maintained in a separate JointStateSpace::Properties field, which is not tied to the original DART Joint. This also changes the interfaces for the JointStateSpace::getState and JointStateSpace::setState methods to take in a DART Joint.
Since MetaSkeletonStateSpaces won't have an internal MetaSkeleton, having a MetaSkeletonStateSpaceSaver doesn't make sense.
This decouples the state space from the underlying DART MetaSkeleton that was used to generate the state space. Properties are maintained in a separate MetaSkeletonStateSpace::Properties field. This changes the interfaces for the MetaSkeletonStateSpace::getState and MetaSkeletonStateSpace::setState methods to take in a DART MetaSkeleton. This also changes the interfaces for many of the constraints and executors to take in an additional DART MetaSkeleton argument. The VectorFieldPlanner code is in a separate commit so it can be easily reverted when the improved VectorFieldPlanner is implemented.
One of the VectorFieldPlanner tests is currently failing, but I figured it's not worth debugging since the improved VectorFieldPlanner will be ready soon. This is in a separate commit so it can be easily reverted when the improved implementation is ready.
Codecov Report
@@ Coverage Diff @@
## master #278 +/- ##
==========================================
- Coverage 79.75% 79.42% -0.33%
==========================================
Files 201 202 +1
Lines 5768 5841 +73
==========================================
+ Hits 4600 4639 +39
- Misses 1168 1202 +34
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great. Nice work @brianhou! I generally think this is ready-to-merge once you address the merge conflicts with devel
, which seem to be caused by the recent merge of #286.
Two random musings:
- It's annoying that we often pass around a
MetaSkeletonStateSpace
and a concreteMetaSkeleton
as a pair, e.g. to implement constraints. If this continues to be an issue, it may be worthwhile to wrap this in a helper class that is effectively anstd::pair
that has an API similar to the old implementation ofMetaSkeletonStateSpace
. - At some point we'll likely want to parallelize constraint evaluations. That will require cloning a constraint onto a different
MetaSkeleton
, e.g. creating twoPoseConstraint
s that refer to the differentMetaSkeleton
s that both instantiate the sameMetaSkeletonStateSpace
. This will be tricky to implement for constraints that wrap other constraints - but I have some ideas here.
/// \return Degree of freedom | ||
const dart::dynamics::DegreeOfFreedom* dof() const; | ||
/// \return Degree of freedom name | ||
const std::string dof() const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
is not meaningful here. Also, I suggest naming this "DOF name" - since it is now a string
rather than a DegreeOfFreedom
object itself.
const Eigen::VectorXd getVelocityLowerLimits() const; | ||
|
||
/// Return the vector of velocity upper limits. | ||
const Eigen::VectorXd getVelocityUpperLimits() const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of these const
return values are not meaningful. Consider returning by const &
instead.
std::size_t getNumDofs() const; | ||
|
||
/// Return the names of DOFs in the joint. | ||
std::vector<std::string> getDofNames() const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return by const &
?
const std::string getName() const; | ||
|
||
/// Return the type of the joint. | ||
const std::string getType() const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return by const &
?
explicit Properties(::dart::dynamics::Joint* _joint); | ||
|
||
/// Return the name of the joint. | ||
const std::string getName() const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return by const &
?
/// Mapping from Joint index and Joint DOF index to MetaSkeleton DOF index | ||
std::unordered_map<std::size_t, | ||
std::unordered_map<std::size_t, std::size_t>> | ||
mIndexMap; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a suggestion: If the docstring is correct, maybe this should be a:
std::unordered_map<std::pair<std::size_t, std::size_t>, std::size_t>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was because pairs don't come with a hash function and I was being sloppy... I'll fix it.
for (std::size_t idof = 0; idof < joint->getNumDofs(); ++idof) | ||
{ | ||
const auto dof = joint->getDof(idof); | ||
const auto dofName = dof->getName(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: const auto&
?
std::size_t MetaSkeletonStateSpace::Properties::getDofIndex( | ||
const std::string& dofName) const | ||
{ | ||
std::vector<std::size_t> indices; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Call indices.reserve(mDofNames.size())
here.
using CartesianProduct::State; | ||
using CartesianProduct::ScopedState; | ||
|
||
/// Constructs a state space for a DART \c MetaSkeleton. | ||
/// | ||
/// \param _metaskeleton target \c MetaSkeleton | ||
MetaSkeletonStateSpace(::dart::dynamics::MetaSkeletonPtr _metaskeleton); | ||
MetaSkeletonStateSpace(::dart::dynamics::MetaSkeleton* _metaskeleton); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mark this as explicit
. It should have been before, too! 😱
/// \return \c MetaSkeleton associated with this state space | ||
::dart::dynamics::MetaSkeletonPtr getMetaSkeleton() const; | ||
/// \return MetaSkeleton properties associated with this state space | ||
const Properties getProperties() const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: const
is not meaningful.
Return const & rather than const.
…eSpaces." This reverts commit 934ee62.
Conflicts: src/planner/vectorfield/VectorFieldPlanner.cpp tests/constraint/test_CollisionFree.cpp tests/planner/ompl/OMPLTestHelpers.hpp
I've updated this PR with the new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per this change, all the DART state spaces take DART objects (meta-skeleton and joints) only to retrieve data from the DART objects but not to change them. So it would be good to take DART objects as const variable. I've made this change in this branch so feel free to merge if it looks good to you.
Also, DART state space assumes the passing-in DART object pointer is not nullptr
. I think we should either throw an exception for nullptr
or take it as a const reference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a few small comments but other than that it looks good. :)
@@ -31,8 +31,8 @@ namespace vectorfield { | |||
bool computeJointVelocityFromTwist( | |||
Eigen::VectorXd& jointVelocity, | |||
const Eigen::Vector6d& desiredTwist, | |||
aikido::statespace::dart::MetaSkeletonStateSpacePtr stateSpace, | |||
dart::dynamics::BodyNodePtr bodyNode, | |||
const dart::dynamics::MetaSkeletonPtr stateSpace, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to change the name to metaSkeleton
.
|
||
protected: | ||
::dart::dynamics::Joint* mJoint; | ||
Properties mProperties; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make it const
?
, mCollisionDetector(std::move(_collisionDetector)) | ||
, mCollisionOptions(std::move(_collisionOptions)) | ||
{ | ||
if (!mStatespace) | ||
throw std::invalid_argument("_statespace is nullptr."); | ||
if (!mMetaSkeletonStateSpace) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: check whether _metaSkeletonStateSpace
and _metaskeleton
are compatible.
{ | ||
if (!mMetaSkeletonStateSpace) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: check compatibility between _metaSkeletonStateSpace
and _metaskeleton
.
{ | ||
if (!mMetaSkeletonStateSpace) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check compatibility between statespace
and metaskeleton
.
@@ -13,6 +13,7 @@ namespace vectorfield { | |||
//============================================================================== | |||
MoveEndEffectorOffsetVectorField::MoveEndEffectorOffsetVectorField( | |||
aikido::statespace::dart::MetaSkeletonStateSpacePtr stateSpace, | |||
dart::dynamics::MetaSkeletonPtr metaskeleton, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check for compatibility between statespace and metaskeleton.
@@ -192,6 +195,7 @@ std::unique_ptr<aikido::trajectory::Spline> planToEndEffectorOffset( | |||
//============================================================================== | |||
std::unique_ptr<aikido::trajectory::Spline> planToEndEffectorPose( | |||
const aikido::statespace::dart::MetaSkeletonStateSpacePtr& stateSpace, | |||
dart::dynamics::MetaSkeletonPtr metaskeleton, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check for compatibility.
* Update changelog; Move #278 to 0.3.0 * Pass DART joint as const variable to state spaces * Use BallJoint::convertToPositions()
@jslee02 Merging master (with the |
* Refactor JointStateSpace to remove Joint. This decouples the state space from the underlying DART Joint that was used to generate the state space. Joint properties (e.g. position limits) are maintained in a separate JointStateSpace::Properties field, which is not tied to the original DART Joint. This also changes the interfaces for the JointStateSpace::getState and JointStateSpace::setState methods to take in a DART Joint. * Rename MetaSkeletonStateSpaceSaver to MetaSkeletonStateSaver. Since MetaSkeletonStateSpaces won't have an internal MetaSkeleton, having a MetaSkeletonStateSpaceSaver doesn't make sense. * Refactor MetaSkeletonStateSpace. This decouples the state space from the underlying DART MetaSkeleton that was used to generate the state space. Properties are maintained in a separate MetaSkeletonStateSpace::Properties field. This changes the interfaces for the MetaSkeletonStateSpace::getState and MetaSkeletonStateSpace::setState methods to take in a DART MetaSkeleton. This also changes the interfaces for many of the constraints and executors to take in an additional DART MetaSkeleton argument. The VectorFieldPlanner code is in a separate commit so it can be easily reverted when the improved VectorFieldPlanner is implemented. * Refactor VectorFieldPlanner to work with new MetaSkeletonStateSpaces. One of the VectorFieldPlanner tests is currently failing, but I figured it's not worth debugging since the improved VectorFieldPlanner will be ready soon. This is in a separate commit so it can be easily reverted when the improved implementation is ready. * Minor formatting fixes. * Add hash function for std::pair. * Address Mike's review comments. Return const & rather than const. * Address more of Mike's review comments. * Revert "Refactor VectorFieldPlanner to work with new MetaSkeletonStateSpaces." This reverts commit 934ee62. * Refactor new VectorFieldPlanner to work with new MetaSkeletonStateSpaces. * Update CHANGELOG.md * Pass DART objects as const to state spaces (#297) * Update changelog; Move #278 to 0.3.0 * Pass DART joint as const variable to state spaces * Use BallJoint::convertToPositions() * Address Gilwoo's review comments. * Update TrajectoryMarker per DART state space refactor * Fix code style
This PR refactors AIKIDO's DART state spaces to decouple the state space from the underlying DART
Joint
orMetaSkeleton
, as suggested by @mkoval and @psigen in #249.This will be a hugely backwards-incompatible API change. Any code that uses
MetaSkeletonStateSpace::getMetaSkeleton
,JointStateSpace::getJoint
, orMetaSkeletonStateSpaceSaver
will need to be fixed.Quick summary of changes:
JointStateSpace::getJoint
has been removed andJointStateSpace::getProperties
has been added.MetaSkeletonStateSpace::getMetaSkeleton
has been removed andMetaSkeletonStateSpace::getProperties
has been added.MetaSkeletonStateSpace::Properties
also holds information about how to map (joint index
,joint dof index
) tometaskeleton dof index
, rather than re-computing each time we need to convert between states and positions.MetaSkeletonStateSpaceSaver
has been renamed toMetaSkeletonStateSaver
. I think this makes more sense, since it was most importantly used to save the currentMetaSkeleton
position (which would no longer be in aMetaSkeletonStateSpace
).constraint::CollisionFree
,constraint::InverseKinematicsSampleable
) now take in an additionalMetaSkeleton
argument. This is necessary so they have a concrete skeleton that they can test with.SplineTrajectory
and ROSJointTrajectory
are somewhat different. The joint names in theJointTrajectory
now come from the DOF names, rather than the Joint names. I thought this was simpler, but could be convinced to figure out how to use Joint names instead if this is the wrong thing to do. (It seems that each joint in a ROSJointTrajectory
can only take on one value, so maybe it's closer to what we mean by DOF?)Note: one of the
VectorFieldPlanner
tests is currently failing, but I figured it's not really worth debugging since the improvedVectorFieldPlanner
will be ready soon and will need to be ported to the newMetaSkeletonStateSpace
anyway.Before creating a pull request
make format
Before merging a pull request
CHANGELOG.md