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

API to use OMPL Planners within the new planner framework #466

Merged
merged 35 commits into from
Nov 30, 2018

Conversation

aditya-vk
Copy link
Contributor

This PR enables using the OMPL planners via AIKIDO for any of the ConfigurationToConfiguration problems. This should allow us to plan for exact/approximate solutions for configuration(s)/TSR problems.

There are a few TODOs in the PR, one of which would be part of another PR perhaps(?) since they are in relation to statespaces and contraints.


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

@aditya-vk aditya-vk added this to the Aikido 0.3.0 milestone Oct 27, 2018
@codecov
Copy link

codecov bot commented Oct 28, 2018

Codecov Report

Merging #466 into master will decrease coverage by 0.02%.
The diff coverage is 84.49%.

@@            Coverage Diff             @@
##           master     #466      +/-   ##
==========================================
- Coverage   77.61%   77.58%   -0.03%     
==========================================
  Files         260      262       +2     
  Lines        6588     6669      +81     
==========================================
+ Hits         5113     5174      +61     
- Misses       1475     1495      +20
Impacted Files Coverage Δ
...nclude/aikido/planner/ompl/GeometricStateSpace.hpp 100% <ø> (ø) ⬆️
src/planner/ompl/Planner.cpp 88.82% <100%> (+0.06%) ⬆️
src/planner/ompl/GeometricStateSpace.cpp 100% <100%> (ø) ⬆️
...r/ompl/OMPLConfigurationToConfigurationPlanner.hpp 100% <100%> (ø)
...l/OMPLConfigurationToConfigurationPlanner-impl.hpp 71.42% <71.42%> (ø)

public:
/// Constructor.
///
/// \param[in] planner The OMPL planner to use.
Copy link
Member

Choose a reason for hiding this comment

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

This planner is not in the constructor arguments. I guess you wanted to describe the template type of this class. Let's move this to the class docstring something like:

/// \tparam PlannerType The OMPL planner to use.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this line should be deleted now?

#include <ompl/base/ScopedState.h>
#include <ompl/base/SpaceInformation.h>
#include <ompl/base/goals/GoalRegion.h>
#include <ompl/geometric/PathSimplifier.h>
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Third party headers should come first and then the project headers (see this)


#include "aikido/planner/ompl/detail/OMPLConfigurationToConfigurationPlanner-impl.hpp"

#endif // AIKIDO_PLANNER_SNAPCONFIGURATIONTOCONFIGURATIONPLANNER_HPP_
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#endif // AIKIDO_PLANNER_SNAPCONFIGURATIONTOCONFIGURATIONPLANNER_HPP_
#endif // AIKIDO_PLANNER_OMPL_OMPLCONFIGURATIONTOCONFIGURATIONPLANNER_HPP_

// createTestableBounds(space),
// createProjectableBounds(space),
// timelimit,
// collisionResolution);
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Let's remove old code

std::move(dmetric),
std::move(sampler),
mBoundsConstraint,
std::move(mBoundsProjector));
Copy link
Member

Choose a reason for hiding this comment

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

We don't need to have mBoundsProjector as a member variable because it's been moved. It seems we could convert this as a local variable in this constructor implementation.

jslee02
jslee02 previously approved these changes Nov 5, 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!

Copy link
Contributor

@brianhou brianhou left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! I have one major question. The OMPLPlanner constructor takes an interpolator, dmetric, sampler, boundsConstraint, boundsProjector. However, it seems that we're inconsistent with which of those are stored as fields in the OMPLPlanner class, versus which of those are only used as local variables in the constructor to create the OMPL Planner.

My understanding is that this is because we need mInterpolator (to reconstruct an AIKIDO Interpolated) and mBoundsConstraint (to create the TestableIntersection with the problem's constraint). However, it seems that one way to resolve this is to modify GeometricStateSpace and add getters for all of the above. That way, we don't need any of them stored as fields: we can just get them directly from the state information. What do you think?

public:
/// Constructor.
///
/// \param[in] planner The OMPL planner to use.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this line should be deleted now?

/// Plans a trajectory from start state to goal state by using an interpolator
/// to interpolate between them.
///
/// The planner returns success if the resulting trajectory satisfies
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is accurate: this function always returns the trajectory, which is null if planning fails.

::ompl::base::PlannerPtr getOMPLPlanner();

/// Sets interpolator used to produce the output trajectory.
void setInterpolator(statespace::ConstInterpolatorPtr interpolator);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: missing documentation for interpolator.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this function being used? What's the use case for wanting to change the interpolator after construction, without changing the other fields?

statespace::ConstInterpolatorPtr mInterpolator;

private:
// TODO (avk): Should we make the problem take std::vector<TestablePtr>?
Copy link
Contributor

Choose a reason for hiding this comment

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

Why would we want a vector of Testables?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was also a little uncomfortable with needing to have an mBoundsConstraint to reconstruct the contraint during planning and was wondering if we could have a vector of testables passed in the problem instead of a single testable.

#define AIKIDO_PLANNER_OMPL_DETAIL_OMPLCONFIGURATIONTOCONFIGURATION_IMPL_HPP_

#include "aikido/planner/ompl/OMPLConfigurationToConfigurationPlanner.hpp"

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we try to avoid empty lines in the includes?

const auto metaskeletonStatespace
= std::dynamic_pointer_cast<const MetaSkeletonStateSpace>(mStateSpace);

if (!metaskeletonStatespace
Copy link
Contributor

Choose a reason for hiding this comment

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

I found this logic somewhat confusing because it wasn't clear to me when all of the conditions would be satisfied. I think this might be clearer:

if (metaSkeletonStateSpace)
{
  if (!sampler) ...
  if (!mBoundsConstraint) ...
  if (!boundsProjector) ...
}
else
{
  if (!sampler || !boundsConstraint || !boundsProjector)
  {
    throw ...
  }
}

auto sspace = ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sigh

// Geometric State space
auto sspace = ompl_make_shared<GeometricStateSpace>(
mStateSpace,
std::make_shared<aikido::statespace::GeodesicInterpolator>(mStateSpace),
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this use mInterpolator? (Again, still not clear why that's a field and not just a local variable.)

// Plan
mPlanner->setProblemDefinition(pdef);
mPlanner->setup();
auto solved = mPlanner->solve(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't 1 be timelimit or something?

{
// Only states belonging geometric statespaces are supported.
assert(
dynamic_cast<aikido::planner::ompl::GeometricStateSpace::StateType*>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible for a PathGeometric to have non-GeometricStateSpace::StateType? If so, is it possible for a PathGeometric to have a mixture of StateTypes (i.e. does this dynamic_cast need to happen every time)?

std::move(boundsProjection),
0.1);
auto traj = planner->plan(problem);
EXPECT_TRUE(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

What?

@aditya-vk
Copy link
Contributor Author

Really good idea about modifying GeometricStateSpace 👍

Copy link
Contributor

@brianhou brianhou left a comment

Choose a reason for hiding this comment

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

Almost there! I have a few minor nits we should address, but I think we can merge once those are in. Thanks for the great changes!

aikido::statespace::ConstInterpolatorPtr getInterpolator() const;

/// Return the bounds constraint for the statespace. Used to specify
/// constraints
Copy link
Contributor

Choose a reason for hiding this comment

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

This is wrapped weirdly.

/// Return the bounds constraint for the statespace. Used to specify
/// constraints
/// to the OMPL planner.
aikido::constraint::TestablePtr getBoundsConstraint() const;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason for this not to be ConstTestablePtr to match the statespace and interpolator?

/// \param[in] stateSpace State space that this planner associated with.
/// \param[in] rng Random number generator to create the state sampler.
/// \param[in] interpolator Interpolator used to interpolate between two
/// states. GeodesicInterpolator is used by default.
/// \param[in] dmetric A valid distance metric defined on the StateSpace.
/// Distance metric relevant to the statespace is used by default.
/// \param[in] sampler A Sampleable that can sample states from the
/// StateSpace. Warning: Many OMPL planners internally assume this sampler
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did we remove this warning? I think it'd be a good idea to keep (and perhaps denote with a \note to make it show up nicely in the docs).

/// otherwise. The reason for the failure is stored in the \c result output
/// parameter.
/// If successful, the planner returns a valid trajectory. If not, it
/// returns a \c nullptr. The corresponding message is stored in result.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think a combination of the old and new versions is the most descriptive/accurate. How about something like:

If successful, the planner returns a trajectory that satisfies the constraint. If not, it returns a \c nullptr and the reason for the failure is stored in the \c result.

double GeometricStateSpace::getMaxDistanceBetweenValidityChecks() const
{
return mMaxDistanceBetweenValidityChecks;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we usually have a newline before the closing braces for the namespaces. Also, // namespace XXX?

brianhou and others added 3 commits November 29, 2018 14:13
Co-Authored-By: aditya-vk <adityavk711@gmail.com>
Co-Authored-By: aditya-vk <adityavk711@gmail.com>
brianhou
brianhou previously approved these changes Nov 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 great to me. Just one nitpick.

for (std::size_t idx = 0; idx < path->getStateCount(); ++idx)
{
const auto* st
= static_cast<aikido::planner::ompl::GeometricStateSpace::StateType*>(
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Let's add an assertion for checking the type using dynamic_cast.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. For now, I don't much of a preference on this, since we are only working with geometric planners/statespaces. But I guess when we later extend our support, we might be dealing with other state types.

Thanks!

@aditya-vk aditya-vk merged commit f136924 into master Nov 30, 2018
@aditya-vk aditya-vk deleted the ompl/update branch November 30, 2018 04:28
gilwoolee pushed a commit that referenced this pull request Jan 21, 2019
* dirty init for OMPL + AIKIDO under new API

* new ompl api header

* ompl planner implementation

* use the new ompl api and test

* update ompl planner implementation; bugfix for replanning

* test planner specific params

* pass rng

* clean up tests, clear() after solving problem

* remove vscode files

* make format

* address JS's comments

* address minor comments from brian

* testing the new feature

Co-Authored-By: aditya-vk <adityavk711@gmail.com>

* WIP: Added a bunch of TODOs to address

* add getter methods

* use the member varaibles from statespace

* follow the new geometric statespace constructor

* use new API

* add new param to constructors in tests

* cleanup and add doscstrings

* unsigned int vs size_t

* cleanup of geometric statespace

* add some tests in geomteric statespace

* correct for changes in geomteric statespace class

* termination condition changed

* address travis error

* Format code

* typo fix

Co-Authored-By: aditya-vk <adityavk711@gmail.com>

* typo fix

Co-Authored-By: aditya-vk <adityavk711@gmail.com>

* address comments

* style change

* update changelog

* added an assertion before the static cast
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants