Go to the documentation of this file. 1 #ifndef AIKIDO_PLANNER_OMPL_DETAIL_OMPLCONFIGURATIONTOCONFIGURATION_IMPL_HPP_
2 #define AIKIDO_PLANNER_OMPL_DETAIL_OMPLCONFIGURATIONTOCONFIGURATION_IMPL_HPP_
28 template <
class PlannerType>
38 double maxDistanceBetweenValidityChecks)
43 = std::make_shared<const aikido::statespace::GeodesicInterpolator>(
50 const auto metaskeletonStatespace
51 = std::dynamic_pointer_cast<const MetaSkeletonStateSpace>(
mStateSpace);
53 if (metaskeletonStatespace)
58 throw std::invalid_argument(
59 "[OMPLPlanner] Both of sampler and rng cannot be nullptr.");
65 if (!boundsConstraint)
75 if (!sampler || !boundsConstraint || !boundsProjector)
76 throw std::invalid_argument(
77 "[OMPLPlanner] Either statespace must be metaSkeletonStateSpace or "
78 "all of sampler, boundsContraint and boundsProjector must be "
83 auto sspace = ompl_make_shared<GeometricStateSpace>(
85 std::move(interpolator),
88 std::move(boundsConstraint),
89 std::move(boundsProjector),
90 maxDistanceBetweenValidityChecks);
93 auto si = ompl_make_shared<::ompl::base::SpaceInformation>(sspace);
96 mPlanner = ompl_make_shared<PlannerType>(si);
100 template <
class PlannerType>
103 const SolvableProblem& problem,
Result* result)
105 auto si = mPlanner->getSpaceInformation();
108 assert(ompl_dynamic_pointer_cast<GeometricStateSpace>(si->getStateSpace()));
110 = ompl_static_pointer_cast<GeometricStateSpace>(si->getStateSpace());
113 std::vector<constraint::ConstTestablePtr> constraints{
114 problem.getConstraint(), sspace->getBoundsConstraint()};
115 auto conjunctionConstraint
116 = std::make_shared<constraint::TestableIntersection>(
117 mStateSpace, std::move(constraints));
118 ::ompl::base::StateValidityCheckerPtr vchecker
119 = ompl_make_shared<StateValidityChecker>(si, conjunctionConstraint);
120 si->setStateValidityChecker(vchecker);
122 ::ompl::base::MotionValidatorPtr mvalidator
123 = ompl_make_shared<MotionValidator>(
124 si, sspace->getMaxDistanceBetweenValidityChecks());
125 si->setMotionValidator(mvalidator);
128 auto pdef = ompl_make_shared<::ompl::base::ProblemDefinition>(si);
131 auto start = sspace->allocState(problem.getStartState());
132 auto goal = sspace->allocState(problem.getGoalState());
133 pdef->setStartAndGoalStates(start, goal);
136 sspace->freeState(start);
137 sspace->freeState(goal);
140 mPlanner->setProblemDefinition(pdef);
145 auto solved = mPlanner->solve(::ompl::base::plannerNonTerminatingCondition());
149 auto returnTraj = std::make_shared<trajectory::Interpolated>(
150 mStateSpace, sspace->getInterpolator());
153 auto path = ompl_dynamic_pointer_cast<::ompl::geometric::PathGeometric>(
154 pdef->getSolutionPath());
157 throw std::invalid_argument(
158 "Path is not of type PathGeometric. Cannot convert to aikido "
162 for (std::size_t idx = 0; idx < path->getStateCount(); ++idx)
166 path->getState(idx)));
169 path->getState(idx));
170 returnTraj->addWaypoint(idx, st->mState);
178 result->
setMessage(
"Problem could not be solved.");
184 template <
class PlannerType>
195 #endif // AIKIDO_PLANNER_OMPL_DETAIL_OMPLCONFIGURATIONTOCONFIGURATION_IMPL_HPP_
Wraps an aikido::statespace::StateSpace::State in an OMPL StateType.
Definition: GeometricStateSpace.hpp:28
std::unique_ptr< DistanceMetric > createDistanceMetric(statespace::ConstStateSpacePtr _sspace)
Creates a DistanceMetric that is appropriate for the statespace.
std::unique_ptr< Sampleable > createSampleableBounds(std::shared_ptr< const statespace::dart::JointStateSpace > _stateSpace, std::unique_ptr< common::RNG > _rng)
Create a Sampleabe constraint that can be used to sample values for the joint that are guarenteed to ...
Format of serialized trajectory in YAML.
Definition: algorithm.hpp:4
std::shared_ptr< Projectable > ProjectablePtr
Definition: Projectable.hpp:33
std::shared_ptr< DistanceMetric > DistanceMetricPtr
Definition: DistanceMetric.hpp:10
void setMessage(const std::string &message)
Sets message.
std::shared_ptr< const StateSpace > ConstStateSpacePtr
Definition: StateSpace.hpp:15
Base planner class for ConfigurationToConfiguration planning problem.
Definition: ConfigurationToConfigurationPlanner.hpp:12
std::shared_ptr< Sampleable > SampleablePtr
Definition: Sampleable.hpp:16
std::shared_ptr< const Interpolator > ConstInterpolatorPtr
Definition: Interpolator.hpp:12
std::shared_ptr< Trajectory > TrajectoryPtr
Definition: Trajectory.hpp:13
::ompl::base::PlannerPtr mPlanner
Pointer to the underlying OMPL Planner.
Definition: OMPLConfigurationToConfigurationPlanner.hpp:83
::ompl::base::PlannerPtr getOMPLPlanner()
Returns the underlying OMPL planner used.
Definition: OMPLConfigurationToConfigurationPlanner-impl.hpp:186
Implementation of the C++11 "random engine" concept that uses virtual function calls to erase the typ...
Definition: RNG.hpp:24
virtual std::unique_ptr< RNG > clone() const =0
Create a copy of this RNG, including its internal state.
std::unique_ptr< Testable > createTestableBounds(std::shared_ptr< const statespace::dart::JointStateSpace > _stateSpace)
Create a Testable constraint that can be used to determine if the value of a joint is within the join...
std::shared_ptr< Planner > PlannerPtr
Definition: Planner.hpp:14
OMPLConfigurationToConfigurationPlanner(statespace::ConstStateSpacePtr stateSpace, common::RNG *rng=nullptr, statespace::ConstInterpolatorPtr interpolator=nullptr, distance::DistanceMetricPtr dmetric=nullptr, constraint::SampleablePtr sampler=nullptr, constraint::ConstTestablePtr boundsConstraint=nullptr, constraint::ProjectablePtr boundsProjector=nullptr, double maxDistanceBtwValidityChecks=0.1)
Constructor.
Definition: OMPLConfigurationToConfigurationPlanner-impl.hpp:30
trajectory::TrajectoryPtr plan(const SolvableProblem &problem, Result *result=nullptr) override
Plans a trajectory from start state to goal state by using an interpolator to interpolate between the...
Definition: OMPLConfigurationToConfigurationPlanner-impl.hpp:102
statespace::ConstStateSpacePtr mStateSpace
State space associated with this planner.
Definition: Planner.hpp:51
Base class for planning result of various planning problems.
Definition: Planner.hpp:58
std::unique_ptr< Projectable > createProjectableBounds(std::shared_ptr< const statespace::dart::JointStateSpace > _stateSpace)
Create a Projectable that can be used to project the value of a joint back within joint limits.
std::shared_ptr< const Testable > ConstTestablePtr
Definition: Testable.hpp:13