Aikido
Planner-impl.hpp
Go to the documentation of this file.
1 #include <ompl/geometric/PathGeometric.h>
2 
8 
9 namespace aikido {
10 namespace planner {
11 namespace ompl {
12 
13 //==============================================================================
14 template <class PlannerType>
16  const statespace::StateSpace::State* _start,
17  const statespace::StateSpace::State* _goal,
19  statespace::InterpolatorPtr _interpolator,
22  constraint::TestablePtr _validityConstraint,
23  constraint::TestablePtr _boundsConstraint,
24  constraint::ProjectablePtr _boundsProjector,
25  double _maxPlanTime,
26  double _maxDistanceBtwValidityChecks)
27 {
28  // Create a SpaceInformation. This function will ensure state space matching
29  auto si = getSpaceInformation(
30  _stateSpace,
31  _interpolator,
32  std::move(_dmetric),
33  std::move(_sampler),
34  std::move(_validityConstraint),
35  std::move(_boundsConstraint),
36  std::move(_boundsProjector),
37  _maxDistanceBtwValidityChecks);
38 
39  // Start and states
40  auto pdef = ompl_make_shared<::ompl::base::ProblemDefinition>(si);
41  auto sspace
42  = ompl_static_pointer_cast<GeometricStateSpace>(si->getStateSpace());
43  auto start = sspace->allocState(_start);
44  auto goal = sspace->allocState(_goal);
45 
46  // ProblemDefinition clones states and keeps them internally
47  pdef->setStartAndGoalStates(start, goal);
48 
49  sspace->freeState(start);
50  sspace->freeState(goal);
51 
52  auto planner = ompl_make_shared<PlannerType>(si);
53  return planOMPL(
54  planner,
55  pdef,
56  std::move(_stateSpace),
57  std::move(_interpolator),
58  _maxPlanTime);
59 }
60 
61 //==============================================================================
62 template <class PlannerType>
64  const statespace::StateSpace::State* _start,
65  constraint::TestablePtr _goalTestable,
66  constraint::SampleablePtr _goalSampler,
68  statespace::InterpolatorPtr _interpolator,
71  constraint::TestablePtr _validityConstraint,
72  constraint::TestablePtr _boundsConstraint,
73  constraint::ProjectablePtr _boundsProjector,
74  double _maxPlanTime,
75  double _maxDistanceBtwValidityChecks)
76 {
77  if (_goalTestable == nullptr)
78  {
79  throw std::invalid_argument("Testable goal is nullptr.");
80  }
81 
82  if (_goalSampler == nullptr)
83  {
84  throw std::invalid_argument("Sampleable goal is nullptr.");
85  }
86 
87  if (_goalTestable->getStateSpace() != _stateSpace)
88  {
89  throw std::invalid_argument("Testable goal does not match StateSpace");
90  }
91 
92  if (_goalSampler->getStateSpace() != _stateSpace)
93  {
94  throw std::invalid_argument("Sampleable goal does not match StateSpace");
95  }
96 
97  auto si = getSpaceInformation(
98  _stateSpace,
99  _interpolator,
100  std::move(_dmetric),
101  std::move(_sampler),
102  std::move(_validityConstraint),
103  std::move(_boundsConstraint),
104  std::move(_boundsProjector),
105  _maxDistanceBtwValidityChecks);
106 
107  // Set the start and goal
108  auto pdef = ompl_make_shared<::ompl::base::ProblemDefinition>(si);
109  auto sspace
110  = ompl_static_pointer_cast<GeometricStateSpace>(si->getStateSpace());
111  auto start = sspace->allocState(_start);
112  pdef->addStartState(start); // copies
113  sspace->freeState(start);
114 
115  auto goalRegion = ompl_make_shared<GoalRegion>(
116  si, std::move(_goalTestable), _goalSampler->createSampleGenerator());
117  pdef->setGoal(goalRegion);
118 
119  auto planner = ompl_make_shared<PlannerType>(si);
120  return planOMPL(
121  planner,
122  pdef,
123  std::move(_stateSpace),
124  std::move(_interpolator),
125  _maxPlanTime);
126 }
127 
128 } // namespace ompl
129 } // namespace planner
130 } // namespace aikido
aikido
Format of serialized trajectory in YAML.
Definition: algorithm.hpp:4
aikido::constraint::ProjectablePtr
std::shared_ptr< Projectable > ProjectablePtr
Definition: Projectable.hpp:33
aikido::distance::DistanceMetricPtr
std::shared_ptr< DistanceMetric > DistanceMetricPtr
Definition: DistanceMetric.hpp:10
aikido::statespace::ConstStateSpacePtr
std::shared_ptr< const StateSpace > ConstStateSpacePtr
Definition: StateSpace.hpp:15
aikido::constraint::SampleablePtr
std::shared_ptr< Sampleable > SampleablePtr
Definition: Sampleable.hpp:16
aikido::trajectory::InterpolatedPtr
std::shared_ptr< Interpolated > InterpolatedPtr
Definition: Interpolated.hpp:11
Interpolated.hpp
aikido::statespace::InterpolatorPtr
std::shared_ptr< Interpolator > InterpolatorPtr
Definition: Interpolator.hpp:12
aikido::planner::ompl::planOMPL
trajectory::InterpolatedPtr planOMPL(const statespace::StateSpace::State *_start, const statespace::StateSpace::State *_goal, statespace::ConstStateSpacePtr _stateSpace, statespace::InterpolatorPtr _interpolator, distance::DistanceMetricPtr _dmetric, constraint::SampleablePtr _sampler, constraint::TestablePtr _validityConstraint, constraint::TestablePtr _boundsConstraint, constraint::ProjectablePtr _boundsProjector, double _maxPlanTime, double _maxDistanceBtwValidityChecks)
Use the template OMPL Planner type to plan a trajectory that moves from the start to the goal point.
Definition: Planner-impl.hpp:15
StateValidityChecker.hpp
aikido::planner::ompl::getSpaceInformation
::ompl::base::SpaceInformationPtr getSpaceInformation(statespace::ConstStateSpacePtr _stateSpace, statespace::InterpolatorPtr _interpolator, distance::DistanceMetricPtr _dmetric, constraint::SampleablePtr _sampler, constraint::TestablePtr _validityConstraint, constraint::TestablePtr _boundsConstraint, constraint::ProjectablePtr _boundsProjector, double _maxDistanceBtwValidityChecks)
Generate an OMPL SpaceInformation from aikido components.
BackwardCompatibility.hpp
GoalRegion.hpp
aikido::statespace::StateSpace::State
Definition: StateSpace.hpp:167
aikido::constraint::TestablePtr
std::shared_ptr< Testable > TestablePtr
Definition: Testable.hpp:13
GeometricStateSpace.hpp