LightningRetrieveRepair.cpp
49 ompl::geometric::LightningRetrieveRepair::LightningRetrieveRepair(const base::SpaceInformationPtr &si,
77 void ompl::geometric::LightningRetrieveRepair::setLightningDB(const ompl::tools::LightningDBPtr &experienceDB)
85 throw Exception("LightningRetrieveRepair: Repair planner instance does not match space information");
100 OMPL_DEBUG("LightningRetrieveRepair: No repairing planner specified. Using default: %s", repairPlanner_->getName().c_str() );
104 repairProblemDef_->setOptimizationObjective(pdef_->getOptimizationObjective()); // copy primary problem def
112 ompl::base::PlannerStatus ompl::geometric::LightningRetrieveRepair::solve(const base::PlannerTerminationCondition &ptc)
119 OMPL_INFORM("LightningRetrieveRepair: Experience database is empty so unable to run LightningRetrieveRepair algorithm.");
143 OMPL_INFORM("LightningRetrieveRepair: No similar path founds in nearest neighbor tree, unable to retrieve repair");
150 // TODO Rather than selecting 1 best path, you could also spawn n (n<=k) threads and repair the top n paths.
171 // All save trajectories should be at least 2 states long, and then we append the start and goal states
187 OMPL_INFORM("LightningRetrieveRepair: Path simplification took %f seconds and removed %d states",
196 bool ompl::geometric::LightningRetrieveRepair::findBestPath(const base::State *startState, const base::State *goalState, ompl::base::PlannerDataPtr &chosenPath)
198 OMPL_INFORM("LightningRetrieveRepair: Found %d similar paths. Filtering", nearestPaths_.size());
217 OMPL_ERROR("A path was recalled that somehow has less than 2 vertices, which shouldn't happen");
222 const ompl::base::State *pathGoalState = currentPath->getVertex(currentPath->numVertices()-1).getState();
224 double regularDistance = si_->distance(startState,pathStartState) + si_->distance(goalState,pathGoalState);
225 double reversedDistance = si_->distance(startState,pathGoalState) + si_->distance(goalState,pathStartState);
233 // We won't actually flip it until later to save memory operations and not alter our NN tree in the LightningDB
271 OMPL_INFORM("LightningRetrieveRepair: Path %d | %d verticies | %d invalid | score %d | reversed: %s | distance: %f",
278 OMPL_DEBUG("LightningRetrieveRepair: --> The shortest path (path 0) has a perfect score (0), ending filtering early.");
288 OMPL_DEBUG("LightningRetrieveRepair: --> This path is the best we've seen so far. Previous best: %d", bestPathScore);
298 OMPL_DEBUG("LightningRetrieveRepair: --> This path is as good as the best we've seen so far, but its path is shorter. Previous best score: %d from index %d",
305 OMPL_DEBUG("LightningRetrieveRepair: --> Not best. Best score: %d from index %d", bestPathScore, nearestPathsChosenID_);
316 OMPL_ERROR("LightningRetrieveRepair: Only %d verticies found in PlannerData loaded from file. This is a bug.", bestPath->numVertices());
320 // Reverse the path if necessary. We allocate memory for this so that we don't alter the database
323 OMPL_DEBUG("LightningRetrieveRepair: Reversing planner data verticies count %d", bestPath->numVertices());
325 for (std::size_t i = bestPath->numVertices(); i > 0; --i) // size_t can't go negative so subtract 1 instead
342 bool ompl::geometric::LightningRetrieveRepair::repairPath(const base::PlannerTerminationCondition &ptc,
367 OMPL_DEBUG("LightningRetrieveRepair: Repair path function interrupted because termination condition is true.");
378 OMPL_DEBUG("LightningRetrieveRepair: Searching for next valid state, because state %d to %d was not valid out %d total states",
385 OMPL_DEBUG("LightningRetrieveRepair: State %d was found to valid, we can now repair between states", subsearchID);
396 // We never found a valid state to plan to, instead we reached the goal state and it too wasn't valid. This is bad.
398 OMPL_ERROR("LightningRetrieveRepair: No state was found valid in the remainder of the path. Invalid goal state. This should not happen.");
410 OMPL_INFORM("LightningRetrieveRepair: Unable to repair path between state %d and %d", fromID, toID);
430 OMPL_DEBUG("LightningRetrieveRepair: Inserting new %d states into old path. Previous length: %d",
433 // Note: skip first and last states because they should be same as our start and goal state, same as `fromID` and `toID`
437 OMPL_DEBUG("LightningRetrieveRepair: Inserting newPathSegment state %d into old path at position %d",
442 OMPL_DEBUG("LightningRetrieveRepair: Inserted new states into old path. New length: %d", primaryPathStates.size());
444 // Set the toID to jump over the newly inserted states to the next unchecked state. Subtract 2 because we ignore start and goal
455 bool ompl::geometric::LightningRetrieveRepair::replan(const ompl::base::State *start, const ompl::base::State *goal,
483 OMPL_INFORM("LightningRetrieveRepair: No replan solution between disconnected states found after %f seconds", planTime);
488 if (repairProblemDef_->hasApproximateSolution() || repairProblemDef_->getSolutionDifference() > std::numeric_limits<double>::epsilon())
510 OMPL_INFORM("LightningRetrieveRepair: Path simplification took %f seconds and removed %d states",
516 repairPlannerDatas_.back()->decoupleFromPlanner(); // copy states so that when planner unloads/clears we don't lose them
542 const std::vector<ompl::base::PlannerDataPtr>& ompl::geometric::LightningRetrieveRepair::getLastRecalledNearestPaths() const
552 ompl::base::PlannerDataPtr ompl::geometric::LightningRetrieveRepair::getChosenRecallPath() const
557 void ompl::geometric::LightningRetrieveRepair::getRepairPlannerDatas(std::vector<base::PlannerDataPtr> &data) const
562 std::size_t ompl::geometric::LightningRetrieveRepair::checkMotionScore(const ompl::base::State *s1, const ompl::base::State *s2) const
bool approximateSolutions
Flag indicating whether the planner is able to compute approximate solutions.
Definition: Planner.h:212
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...
Definition: LightningRetrieveRepair.cpp:68
std::vector< base::PlannerDataPtr > nearestPaths_
Recall the nearest paths and store this in planner data for introspection later.
Definition: LightningRetrieveRepair.h:176
virtual void setup()
Perform extra configuration steps, if needed. This call will also issue a call to ompl::base::SpaceIn...
Definition: LightningRetrieveRepair.cpp:90
void setRepairPlanner(const base::PlannerPtr &planner)
Set the planner that will be used for repairing invalid paths recalled from experience.
Definition: LightningRetrieveRepair.cpp:82
The planner failed to find a solution.
Definition: PlannerStatus.h:62
base::PlannerDataPtr getChosenRecallPath() const
Get the chosen path used from database for repair.
Definition: LightningRetrieveRepair.cpp:552
const State * nextGoal(const PlannerTerminationCondition &ptc)
Return the next valid goal state or nullptr if no more valid goal states are available. Because sampling of goal states may also produce invalid goals, this function takes an argument that specifies whether a termination condition has been reached. If the termination condition evaluates to true the function terminates even if no valid goal has been found.
Definition: Planner.cpp:271
std::size_t getLastRecalledNearestPathChosen() const
Get debug information about the top recalled paths that were chosen for further filtering.
Definition: LightningRetrieveRepair.cpp:547
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 ...
Definition: LightningRetrieveRepair.cpp:562
LightningRetrieveRepair(const base::SpaceInformationPtr &si, const tools::LightningDBPtr &experienceDB)
Constructor.
Definition: LightningRetrieveRepair.cpp:49
Encapsulate a termination condition for a motion planner. Planners will call operator() to decide whe...
Definition: PlannerTerminationCondition.h:66
bool directed
Flag indicating whether the planner is able to account for the fact that the validity of a motion fro...
Definition: Planner.h:220
base::State * getState(unsigned int index)
Get the state located at index along the path.
Definition: PathGeometric.h:225
std::size_t getStateCount() const
Get the number of states (way-points) that make up this path.
Definition: PathGeometric.h:237
virtual void getPlannerData(base::PlannerData &data) const
Get information about the exploration data structure the planning from scratch motion planner used...
Definition: LightningRetrieveRepair.cpp:525
tools::LightningDBPtr experienceDB_
The database of motions to search through.
Definition: LightningRetrieveRepair.h:173
Base class for a vertex in the PlannerData structure. All derived classes must implement the clone an...
Definition: PlannerData.h:59
duration seconds(double sec)
Return the time duration representing a given number of seconds.
Definition: Time.h:78
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...
Definition: LightningRetrieveRepair.cpp:112
void getRepairPlannerDatas(std::vector< base::PlannerDataPtr > &data) const
Get information about the exploration data structure the repair motion planner used each call...
Definition: LightningRetrieveRepair.cpp:557
A shared pointer wrapper for ompl::base::Planner.
The goal is of a type that a planner does not recognize.
Definition: PlannerStatus.h:60
The planner did not find a solution for some other reason.
Definition: PlannerStatus.h:70
std::vector< base::State * > & getStates()
Get the states that make up the path (as a reference, so it can be modified, hence the function is no...
Definition: PathGeometric.h:219
geometric::PathSimplifierPtr psk_
The instance of the path simplifier.
Definition: LightningRetrieveRepair.h:191
bool repairPath(const base::PlannerTerminationCondition &ptc, geometric::PathGeometric &path)
Repairs a path to be valid in the current planning environment.
Definition: LightningRetrieveRepair.cpp:342
base::PlannerPtr repairPlanner_
A secondary planner for replanning.
Definition: LightningRetrieveRepair.h:182
A class to store the exit status of Planner::solve()
Definition: PlannerStatus.h:48
virtual bool addEdge(unsigned int v1, unsigned int v2, const PlannerDataEdge &edge=PlannerDataEdge(), Cost weight=Cost(1.0))
Adds a directed edge between the given vertex indexes. An optional edge structure and weight can be s...
Definition: PlannerData.cpp:435
This class contains routines that attempt to simplify geometric paths.
Definition: PathSimplifier.h:67
A shared pointer wrapper for ompl::base::SpaceInformation.
std::size_t nearestPathsChosenID_
the ID within nearestPaths_ of the path that was chosen for repair
Definition: LightningRetrieveRepair.h:179
std::vector< base::PlannerDataPtr > repairPlannerDatas_
Debug the repair planner by saving its planner data each time it is used.
Definition: LightningRetrieveRepair.h:188
const State * nextStart()
Return the next valid start state or nullptr if no more valid start states are available.
Definition: Planner.cpp:230
int nearestK_
Number of 'k' close solutions to choose from database for further filtering.
Definition: LightningRetrieveRepair.h:194
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...
Definition: LightningRetrieveRepair.cpp:196
Definition of a problem to be solved. This includes the start state(s) for the system and a goal spec...
Definition: ProblemDefinition.h:149
const std::vector< base::PlannerDataPtr > & getLastRecalledNearestPaths() const
Get debug information about the top recalled paths that were chosen for further filtering.
Definition: LightningRetrieveRepair.cpp:542
void restart()
Forget how many states were returned by nextStart() and nextGoal() and return all states again...
Definition: Planner.cpp:170
void setLightningDB(const tools::LightningDBPtr &experienceDB)
Pass a pointer of the database from the lightning framework.
Definition: LightningRetrieveRepair.cpp:77
base::ProblemDefinitionPtr repairProblemDef_
A secondary problem definition for the repair planner to use.
Definition: LightningRetrieveRepair.h:185
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...
Definition: LightningRetrieveRepair.cpp:455
A shared pointer wrapper for ompl::base::Path.