Skip to content
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

Planning adapters #437

Merged
merged 19 commits into from
May 30, 2018
Merged

Planning adapters #437

merged 19 commits into from
May 30, 2018

Conversation

brianhou
Copy link
Contributor

@brianhou brianhou commented May 24, 2018

Re-implementation of #425.

Main changes:

  • This PR adds a MetaSkeleton argument to the constructor of all "DART planners" in planner::dart. All DART planners now also define getMetaSkeletonStateSpace and getMetaSkeleton to make adapters possible. These methods are currently re-implemented in each planner, but they could (should?) be moved into a dart::SingleProblemPlanner class that all DART planners inherit from.
  • This PR introduces the dart::DartPlannerAdapter class for converting planners that don't contain a MetaSkeleton (i.e. SnapConfigurationToConfigurationPlanner) into their corresponding DART planner (in this case, dart::ConfigurationToConfigurationPlanner). This correspondence isn't enforced anywhere, but maybe some fancy template code could do so?
  • The dart::PlannerAdapter class is essentially the same single-problem adapter from [WIP] Planning adapters #425, but only operates on DART planners that contain a MetaSkeleton. We can't adapt a planner that doesn't contain a MetaSkeleton into one that should.
  • Preliminary implementation of the adapter from ConfigurationToConfiguration to ConfigurationToTSR. It does a few const_casts, which we should look hard at to make sure that they're absolutely necessary.

The pipeline to use a SnapConfigurationToConfigurationPlanner as a dart::ConfigurationToTSRPlanner now takes an extra step:

auto snapDelegate = std::make_shared<SnapConfigurationToConfigurationPlanner>(metaSkeletonStateSpace, interpolator);
auto delegate = std::make_shared<DartPlannerAdapter<SnapConfigurationToConfigurationPlanner, dart::ConfigurationToConfigurationPlanner>>(snapDelegate, metaSkeleton);
auto planner = std::make_shared<ConfigurationToConfiguration_to_ConfigurationToTSR>(delegate);

The new intermediate step is necessary to adapt the non-DART SnapConfigurationToConfigurationPlanner into a DART ConfigurationToConfigurationPlanner.

Issues raised during this PR:

  • Should all Planners have an RNG? This is needed to create a bounds sampler for the IKSampleable, so it might be convenient to include this with all Planners in case an adapter needs it.

Before creating a pull request

  • Document new methods and classes
  • Format code with make format

Before merging a pull request

  • Set version target by selecting a milestone on the right side
  • Summarize this change in CHANGELOG.md
  • Add unit test(s) for this change

@brianhou brianhou added help wanted pr: work-in-progress Calls for preliminary review of the PR. Remove when PR is ready for complete review. labels May 24, 2018
@brianhou brianhou added this to the Aikido 0.3.0 milestone May 24, 2018
@brianhou brianhou requested review from jslee02 and sniyaz May 24, 2018 05:47
@brianhou brianhou mentioned this pull request May 24, 2018
5 tasks
@codecov
Copy link

codecov bot commented May 24, 2018

Codecov Report

Merging #437 into master will decrease coverage by 0.33%.
The diff coverage is 38.88%.

@@            Coverage Diff            @@
##           master    #437      +/-   ##
=========================================
- Coverage   80.03%   79.7%   -0.34%     
=========================================
  Files         235     243       +8     
  Lines        6002    6050      +48     
=========================================
+ Hits         4804    4822      +18     
- Misses       1198    1228      +30
Impacted Files Coverage Δ
...do/constraint/dart/InverseKinematicsSampleable.hpp 100% <ø> (ø) ⬆️
...do/planner/dart/ConfigurationToEndEffectorPose.hpp 0% <ø> (ø) ⬆️
...lanner/SnapConfigurationToConfigurationPlanner.hpp 100% <ø> (ø) ⬆️
...do/planner/ConfigurationToConfigurationPlanner.hpp 100% <ø> (ø) ⬆️
...rc/constraint/dart/InverseKinematicsSampleable.cpp 84.94% <ø> (ø) ⬆️
include/aikido/planner/dart/ConfigurationToTSR.hpp 0% <ø> (ø) ⬆️
...orFieldConfigurationToEndEffectorOffsetPlanner.hpp 100% <ø> (ø) ⬆️
...r/dart/ConfigurationToEndEffectorOffsetPlanner.hpp 100% <ø> (ø) ⬆️
include/aikido/planner/SequenceMetaPlanner.hpp 0% <ø> (ø) ⬆️
...rc/planner/dart/ConfigurationToEndEffectorPose.cpp 0% <ø> (ø) ⬆️
... and 20 more

Copy link

@sniyaz sniyaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good! My main feedback is that it would be nice to have a base class for all of the DART planners, since we copy getMetaSkeletonStateSpace() and getMetaSkeleton() a lot. We could save this for a future PR too, depending on what others think.

We also don't enforce the adaptors at all- I don't think anything prevents you from using the wrong adaptor (i.e. PlannerAdaptor on a planner that doesn't contain a MetaSkeleton). Maybe we could add a flag for whether something is a DART planner to enforce this? This should probably be in a future PR though.

namespace planner {
namespace dart {

/// Adapts a non-DART DelegatePlanner to solve the single problem that
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the name of this class should be a little more clear about what it does- maybe ConvertToDartPlannerAdapter?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have also the similar impression, but couldn't come up with a better name. 😓

Copy link
Contributor Author

@brianhou brianhou May 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Planner_to_DartPlanner? PlannerAdapter could be called DartPlanner_to_DartPlanner if you think that's better?

while (generator->canSample())
{
// Sample from TSR
{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, why is this in braces?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding the braces creates a temporary scope, so all of the local variables in that scope will be destructed when it ends. A std::lock_guard releases the mutex when it's destructed.

@jslee02
Copy link
Member

jslee02 commented May 25, 2018

All DART planners now also define getMetaSkeletonStateSpace and getMetaSkeleton to make adapters possible. These methods are currently re-implemented in each planner, but they could (should?) be moved into a dart::SingleProblemPlanner class that all DART planners inherit from.

👍

This correspondence isn't enforced anywhere, but maybe some fancy template code could do so?

This sounds good to me. We could save this for furture though. In that case, it'd be good to create an issue to track this.

Copy link
Member

@jslee02 jslee02 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good to me. One high level comment and minor comments that are made in the code.

I think we need dart::ConfigurationToConfiguration to distinguish it from non-DART config-to-config problem so that dart::ConfigurationToConfigurationPlanner's solvable problem type becomes dart::ConfigurationToConfiguration but not non-DART config-to-config.

::dart::dynamics::ConstBodyNodePtr endEffectorBodyNode,
const statespace::StateSpace::State* startState,
std::size_t maxSamples,
const statespace::dart::MetaSkeletonStateSpace::State* startState,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Grouping the goal related arguments would make sense so that the argument order becomes startState -> maxSamples -> goalTSR or startState -> goalTSR -> maxSamples.

// Note: SolvableProblem is defined in SingleProblemPlanner.

/// Return this planner's MetaSkeletonStateSpace.
statespace::dart::ConstMetaSkeletonStateSpacePtr getMetaSkeletonStateSpace();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This function should be const since it returns a pointer to a const object.

throw std::invalid_argument("MetaSkeleton has 0 degrees of freedom.");

auto skeleton = mMetaSkeleton->getDof(0)->getSkeleton();
for (size_t i = 1; i < mMetaSkeleton->getNumDofs(); ++i)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: std::size_t

for (std::size_t i = 0; i < mMetaSkeleton->getNumBodyNodes(); ++i)
{
if (mMetaSkeleton->getBodyNode(i)->getName()
== problem.getEndEffectorBodyNode()->getName())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the equality check should be done over the pointer instead of their names. A MetaSkeleton could have multiple body nodes of the same name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thought was that BodyNode that the ConfigurationToTSR problem was constructed with could be from a different Skeleton than the one that the delegate planner's MetaSkeleton refers to. This might happen if we try multiple planners in parallel and therefore have several Skeleton copies that are being used. In this case, I think the BodyNode pointers would not be the same, but the names would be.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense.

MetaSkeleton has a function that returns all the BodyNodes that has the queried name. How about we use that function and prints a warning if it's more than one?

InverseKinematicsSampleable ikSampleable(
mMetaSkeletonStateSpace,
mMetaSkeleton,
std::const_pointer_cast<TSR>(problem.getGoalTSR()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Could you make a note here saying this const-casting should be removed once InverseKinematicsSampleable is changed to take const constraints?

@@ -0,0 +1,35 @@
#include "aikido/planner/dart/DartPlannerAdapter.hpp"

using aikido::statespace::dart::MetaSkeletonStateSpace;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, -impl.hpp is also a header file so using using namespace ~ can pollute the namespaces. Please remove this.

@@ -2,7 +2,7 @@
#define AIKIDO_PLANNER_DART_CONFIGURATIONTOCONFIGURATIONPLANNER_HPP_

#include "aikido/planner/ConfigurationToConfiguration.hpp"
#include "aikido/planner/SingleProblemPlanner.hpp"
#include "aikido/planner/dart/DartSingleProblemPlanner.hpp"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename dart::DartSingleProblemPlanner to dart::SingleProblemPlanner? We already have the dart namespace, so I think repeating it is unnecessary 🙂

brianhou and others added 6 commits May 25, 2018 16:58
[skip ci]
Remove DartPlannerAdapter class in favor of supporting conversion from non-DART
planners to DART planners in PlannerAdapter class.
…github.com/personalrobotics/aikido into enhancement/brianhou/metaskeleton-planners

Conflicts:
	include/aikido/planner/dart/detail/DartPlannerAdapter-impl.hpp
jslee02
jslee02 previously approved these changes May 29, 2018
Copy link
Member

@jslee02 jslee02 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Just one nitpick.

// Create an IK solver with MetaSkeleton DOFs
auto matchingNodes = mMetaSkeleton->getBodyNodes(
problem.getEndEffectorBodyNode()->getName());
if (matchingNodes.size() == 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Checking emptiness is generally faster or equal to comparing the size. So let's change this to if (!matchingNodes.empty()).

jslee02
jslee02 previously approved these changes May 30, 2018
@sniyaz sniyaz merged commit f7ebc5b into master May 30, 2018
@sniyaz sniyaz deleted the enhancement/brianhou/metaskeleton-planners branch May 30, 2018 23:50
gilwoolee pushed a commit that referenced this pull request Jan 21, 2019
* Add MetaSkeleton to ConfigurationToEndEffectorOffsetPlanner.

* Add more DART planners.

Add ConfigurationToTSRPlanner.
Add DART version of ConfigurationToConfigurationPlanner.

* Add max samples to ConfigurationToTSR problem.

* Implement single-problem PlannerAdapter class.

* Implement single-problem DartPlannerAdapter class.

* Add initial implementation of ConfigurationToConfiguration_to_ConfigurationToTSR adapter.

* Format code.

* Update ConfigurationToEndEffectorPose to MetaSkeletonStateSpace.

* Write DartSingleProblemPlanner. Change ConfigurationToConfigurationPlanner.

* Update the other two DART planners to use DartSingleProblemPlanner.

* Rename dart::DartSingleProblemPlanner to dart::SingleProblemPlanner.

* Fix formatting.

[skip ci]

* Update PlannerAdapter.

Remove DartPlannerAdapter class in favor of supporting conversion from non-DART
planners to DART planners in PlannerAdapter class.

* Respond to nits from JS.

* Make SequenceMetaPlanner use CompositePlanner constructor.

* Respond to final nit from JS.

* Update CHANGELOG

* Add that line back in CHANGELOG.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted pr: work-in-progress Calls for preliminary review of the PR. Remove when PR is ready for complete review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants