LightningRetrieveRepair.h
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2014, University of Colorado, Boulder
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the Univ of CO, Boulder nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Dave Coleman */
36 
37 #ifndef OMPL_GEOMETRIC_PLANNERS_EXPERIENCE_LIGHTNING_RETRIEVE_REPAIR_
38 #define OMPL_GEOMETRIC_PLANNERS_EXPERIENCE_LIGHTNING_RETRIEVE_REPAIR_
39 
40 #include "ompl/geometric/planners/PlannerIncludes.h"
41 #include "ompl/geometric/PathGeometric.h"
42 #include "ompl/geometric/PathSimplifier.h"
43 #include "ompl/datastructures/NearestNeighbors.h"
44 
45 namespace ompl
46 {
47  namespace tools
48  {
49  OMPL_CLASS_FORWARD(LightningDB);
50  }
51 
52  namespace geometric
53  {
54 
56 
57  OMPL_CLASS_FORWARD(LightningRetrieveRepair);
59 
78  {
79  public:
80 
82  LightningRetrieveRepair(const base::SpaceInformationPtr &si, const tools::LightningDBPtr &experienceDB);
83 
84  virtual ~LightningRetrieveRepair();
85 
87  virtual void getPlannerData(base::PlannerData &data) const;
88 
93  const std::vector<base::PlannerDataPtr>& getLastRecalledNearestPaths() const;
94 
99  std::size_t getLastRecalledNearestPathChosen() const;
100 
106 
108  void getRepairPlannerDatas(std::vector<base::PlannerDataPtr> &data) const;
109 
111 
112  virtual void clear();
113 
115  void setLightningDB(const tools::LightningDBPtr &experienceDB);
116 
118  void setRepairPlanner(const base::PlannerPtr &planner);
119 
120  virtual void setup();
121 
129 
137  bool replan(const base::State *start, const base::State *goal, geometric::PathGeometric &newPathSegment,
139 
144  {
145  return nearestK_;
146  }
147 
151  void setNumNearestSolutions(int nearestK)
152  {
153  nearestK_ = nearestK;
154  }
155 
156  protected:
157 
164  std::size_t checkMotionScore(const base::State *s1, const base::State *s2) const;
165 
170  bool findBestPath(const base::State *startState, const base::State *goalState, base::PlannerDataPtr& chosenPath);
171 
173  tools::LightningDBPtr experienceDB_;
174 
176  std::vector<base::PlannerDataPtr> nearestPaths_;
177 
180 
183 
186 
188  std::vector<base::PlannerDataPtr> repairPlannerDatas_;
189 
192 
195  };
196 
197  }
198 }
199 
200 #endif
Save and load entire paths from file.
Definition: LightningDB.h:73
Object containing planner generated vertex and edge data. It is assumed that all vertices are unique...
Definition: PlannerData.h:163
virtual void clear()
Clear all internal datastructures. Planner settings are not affected. Subsequent calls to solve() wil...
std::vector< base::PlannerDataPtr > nearestPaths_
Recall the nearest paths and store this in planner data for introspection later.
virtual void setup()
Perform extra configuration steps, if needed. This call will also issue a call to ompl::base::SpaceIn...
A shared pointer wrapper for ompl::base::ProblemDefinition.
void setRepairPlanner(const base::PlannerPtr &planner)
Set the planner that will be used for repairing invalid paths recalled from experience.
base::PlannerDataPtr getChosenRecallPath() const
Get the chosen path used from database for repair.
std::size_t getLastRecalledNearestPathChosen() const
Get debug information about the top recalled paths that were chosen for further filtering.
std::size_t checkMotionScore(const base::State *s1, const base::State *s2) const
Count the number of states along the discretized path that are in collision Note: This is kind of an ...
LightningRetrieveRepair(const base::SpaceInformationPtr &si, const tools::LightningDBPtr &experienceDB)
Constructor.
void setNumNearestSolutions(int nearestK)
Setter for number of 'k' close solutions to choose from database for further filtering.
Encapsulate a termination condition for a motion planner. Planners will call operator() to decide whe...
int getNumNearestSolutions() const
Getter for number of 'k' close solutions to choose from database for further filtering.
virtual void getPlannerData(base::PlannerData &data) const
Get information about the exploration data structure the planning from scratch motion planner used...
tools::LightningDBPtr experienceDB_
The database of motions to search through.
virtual base::PlannerStatus solve(const base::PlannerTerminationCondition &ptc)
Function that can solve the motion planning problem. This function can be called multiple times on th...
void getRepairPlannerDatas(std::vector< base::PlannerDataPtr > &data) const
Get information about the exploration data structure the repair motion planner used each call...
A shared pointer wrapper for ompl::base::Planner.
Base class for a planner.
Definition: Planner.h:230
geometric::PathSimplifierPtr psk_
The instance of the path simplifier.
bool repairPath(const base::PlannerTerminationCondition &ptc, geometric::PathGeometric &path)
Repairs a path to be valid in the current planning environment.
base::PlannerPtr repairPlanner_
A secondary planner for replanning.
A class to store the exit status of Planner::solve()
Definition: PlannerStatus.h:48
A shared pointer wrapper for ompl::base::SpaceInformation.
std::size_t nearestPathsChosenID_
the ID within nearestPaths_ of the path that was chosen for repair
The Lightning Framework's Retrieve-Repair component.
Definition of an abstract state.
Definition: State.h:50
A shared pointer wrapper for ompl::geometric::PathSimplifier.
std::vector< base::PlannerDataPtr > repairPlannerDatas_
Debug the repair planner by saving its planner data each time it is used.
int nearestK_
Number of 'k' close solutions to choose from database for further filtering.
bool findBestPath(const base::State *startState, const base::State *goalState, base::PlannerDataPtr &chosenPath)
Filters the top n paths in nearestPaths_ to the top 1, based on state validity with current environme...
const std::vector< base::PlannerDataPtr > & getLastRecalledNearestPaths() const
Get debug information about the top recalled paths that were chosen for further filtering.
Definition of a geometric path.
Definition: PathGeometric.h:60
void setLightningDB(const tools::LightningDBPtr &experienceDB)
Pass a pointer of the database from the lightning framework.
base::ProblemDefinitionPtr repairProblemDef_
A secondary problem definition for the repair planner to use.
A shared pointer wrapper for ompl::base::PlannerData.
bool replan(const base::State *start, const base::State *goal, geometric::PathGeometric &newPathSegment, const base::PlannerTerminationCondition &ptc)
Use our secondary planner to find a valid path between start and goal, and return that path...