ompl_solver.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2018, University of Edinburgh
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of nor the names of its contributors may be used to
14 // endorse or promote products derived from this software without specific
15 // prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 // POSSIBILITY OF SUCH DAMAGE.
28 //
29 
30 #ifndef EXOTICA_OMPL_SOLVER_OMPL_SOLVER_H_
31 #define EXOTICA_OMPL_SOLVER_OMPL_SOLVER_H_
32 
35 
36 typedef boost::function<ompl::base::PlannerPtr(const ompl::base::SpaceInformationPtr &si, const std::string &name)> ConfiguredPlannerAllocator;
37 
38 #if ROS_VERSION_MINIMUM(1, 12, 0) // if ROS version >= ROS_KINETIC
39 template <class T, class T1>
40 std::shared_ptr<T> ompl_cast(std::shared_ptr<T1> ptr)
41 {
42  return std::static_pointer_cast<T>(ptr);
43 }
44 template <class T>
45 using ompl_ptr = std::shared_ptr<T>;
46 #else
47 template <class T, class T1>
49 {
50  return boost::static_pointer_cast<T>(ptr);
51 }
52 template <class T>
54 #endif
55 
56 namespace exotica
57 {
58 template <class ProblemType>
59 class OMPLSolver : public MotionSolver
60 {
61 public:
62  OMPLSolver();
63  virtual ~OMPLSolver();
64 
65  void Solve(Eigen::MatrixXd &solution) override;
66  void SpecifyProblem(PlanningProblemPtr pointer) override;
67 
68  int GetRandomSeed() const;
69 
70  // StateSpace related methods exposed via solver
71  double GetMaximumExtent() const { return state_space_->getMaximumExtent(); }
72  double GetLongestValidSegmentLength() const { return state_space_->getLongestValidSegmentLength(); }
73  void SetLongestValidSegmentFraction(double segmentFraction) { state_space_->setLongestValidSegmentFraction(segmentFraction); }
74  void SetValidSegmentCountFactor(unsigned int factor) { state_space_->setValidSegmentCountFactor(factor); }
75  unsigned int GetValidSegmentCountFactor() const { return state_space_->getValidSegmentCountFactor(); }
76 
77 protected:
78  template <typename T>
79  static ompl::base::PlannerPtr AllocatePlanner(const ompl::base::SpaceInformationPtr &si, const std::string &new_name)
80  {
81  ompl::base::PlannerPtr planner(new T(si));
82  if (!new_name.empty())
83  planner->setName(new_name);
84  return planner;
85  }
86 
87  void SetGoalState(Eigen::VectorXdRefConst qT, const double eps = 0);
88  void PreSolve();
89  void PostSolve();
90  void GetPath(Eigen::MatrixXd &traj, ompl::base::PlannerTerminationCondition &ptc);
91  OMPLSolverInitializer init_;
92  std::shared_ptr<ProblemType> prob_;
93  ompl::geometric::SimpleSetupPtr ompl_simple_setup_;
94  ompl::base::StateSpacePtr state_space_;
96  std::string algorithm_;
97  bool multi_query_ = false;
98  std::vector<double> bounds_; // original bounds for locked state space
99 };
100 } // namespace exotica
101 
102 #endif // EXOTICA_OMPL_SOLVER_OMPL_SOLVER_H_
OMPLSolverInitializer init_
Definition: ompl_solver.h:91
std::shared_ptr< ProblemType > prob_
Definition: ompl_solver.h:92
ompl::base::StateSpacePtr state_space_
Definition: ompl_solver.h:94
void SetValidSegmentCountFactor(unsigned int factor)
Definition: ompl_solver.h:74
boost::function< ompl::base::PlannerPtr(const ompl::base::SpaceInformationPtr &si, const std::string &name)> ConfiguredPlannerAllocator
Definition: ompl_solver.h:36
int GetRandomSeed() const
Definition: ompl_solver.cpp:83
std::vector< double > bounds_
Definition: ompl_solver.h:98
double GetLongestValidSegmentLength() const
Definition: ompl_solver.h:72
ConfiguredPlannerAllocator planner_allocator_
Definition: ompl_solver.h:95
void SpecifyProblem(PlanningProblemPtr pointer) override
Definition: ompl_solver.cpp:44
boost::shared_ptr< T > ompl_cast(boost::shared_ptr< T1 > ptr)
Definition: ompl_solver.h:48
double GetMaximumExtent() const
Definition: ompl_solver.h:71
const Eigen::Ref< const Eigen::VectorXd > & VectorXdRefConst
ompl::geometric::SimpleSetupPtr ompl_simple_setup_
Definition: ompl_solver.h:93
void SetGoalState(Eigen::VectorXdRefConst qT, const double eps=0)
void SetLongestValidSegmentFraction(double segmentFraction)
Definition: ompl_solver.h:73
void GetPath(Eigen::MatrixXd &traj, ompl::base::PlannerTerminationCondition &ptc)
unsigned int GetValidSegmentCountFactor() const
Definition: ompl_solver.h:75
std::string algorithm_
Definition: ompl_solver.h:96
std::shared_ptr< PlanningProblem > PlanningProblemPtr
void Solve(Eigen::MatrixXd &solution) override
static ompl::base::PlannerPtr AllocatePlanner(const ompl::base::SpaceInformationPtr &si, const std::string &new_name)
Definition: ompl_solver.h:79


exotica_ompl_solver
Author(s): Yiming Yang
autogenerated on Sat Apr 10 2021 02:36:37