Definition of a goal region that can be sampled, but the sampling process can be slow. This class allows sampling the happen in a separate thread, and the number of goals may increase, as the planner is running, in a thread-safe manner. More...
#include <ompl/base/goals/GoalLazySamples.h>

Public Types | |
using | NewStateCallbackFn = std::function< void(const base::State *)> |
When new samples are generated and added to the list of possible samples, a callback can be called. This type specifies the signature of that callback. More... | |
Public Member Functions | |
GoalLazySamples (const SpaceInformationPtr &si, GoalSamplingFn samplerFunc, bool autoStart=true, double minDist=std::numeric_limits< double >::epsilon()) | |
Create a goal region that can be sampled in a lazy fashion. A function (samplerFunc) that produces samples from that region needs to be passed to this constructor. The sampling thread is automatically started if autoStart is true. The sampling function is not called in parallel by OMPL. Hence, the function is not required to be thread safe, unless the user issues additional calls in parallel. The instance of GoalLazySamples remains thread safe however. More... | |
void | sampleGoal (State *st) const override |
Sample a state in the goal region. More... | |
double | distanceGoal (const State *st) const override |
Compute the distance to the goal (heuristic). This function is the one used in computing the distance to the goal in a call to isSatisfied() More... | |
void | addState (const State *st) override |
Add a goal state. More... | |
void | startSampling () |
Start the goal sampling thread. More... | |
void | stopSampling () |
Stop the goal sampling thread. More... | |
bool | isSampling () const |
Return true if the sampling thread is active. More... | |
void | setMinNewSampleDistance (double dist) |
Set the minimum distance that a new state returned by the sampling thread needs to be away from previously added states, so that it is added to the list of goal states. More... | |
double | getMinNewSampleDistance () const |
Get the minimum distance that a new state returned by the sampling thread needs to be away from previously added states, so that it is added to the list of goal states. More... | |
unsigned int | samplingAttemptsCount () const |
The number of times the sampling function was called and it returned true. More... | |
void | setNewStateCallback (const NewStateCallbackFn &callback) |
Set the callback function to be called when a new state is added to the list of possible samples. This function is not required to be thread safe, as calls are made one at a time. More... | |
bool | addStateIfDifferent (const State *st, double minDistance) |
Add a state st if it further away that minDistance from previously added states. Return true if the state was added. More... | |
bool | couldSample () const override |
Return true if GoalStates::couldSample() is true or if the sampling thread is active, as in this case it is possible a sample can be produced at some point. More... | |
bool | hasStates () const override |
Check if there are any states in this goal region. More... | |
const State * | getState (unsigned int index) const override |
Return a pointer to the indexth state in the state list. More... | |
std::size_t | getStateCount () const override |
Return the number of valid goal states. More... | |
void | clear () override |
Clear all goal states. More... | |
unsigned int | maxSampleCount () const override |
Return the maximum number of samples that can be asked for before repeating. More... | |
![]() | |
GoalStates (const SpaceInformationPtr &si) | |
Create a goal representation that is in fact a set of states More... | |
void | sampleGoal (State *st) const override |
Sample a state in the goal region. More... | |
unsigned int | maxSampleCount () const override |
Return the maximum number of samples that can be asked for before repeating. More... | |
double | distanceGoal (const State *st) const override |
Compute the distance to the goal (heuristic). This function is the one used in computing the distance to the goal in a call to isSatisfied() More... | |
void | print (std::ostream &out=std::cout) const override |
Print information about the goal data structure to a stream. More... | |
virtual void | addState (const State *st) |
Add a goal state. More... | |
void | addState (const ScopedState<> &st) |
Add a goal state (calls the previous definition of addState()) More... | |
virtual void | clear () |
Clear all goal states. More... | |
virtual bool | hasStates () const |
Check if there are any states in this goal region. More... | |
virtual const State * | getState (unsigned int index) const |
Return a pointer to the indexth state in the state list. More... | |
virtual std::size_t | getStateCount () const |
Return the number of valid goal states. More... | |
![]() | |
GoalSampleableRegion (const SpaceInformationPtr &si) | |
Create a goal region that can be sampled. More... | |
virtual void | sampleGoal (State *st) const =0 |
Sample a state in the goal region. More... | |
virtual unsigned int | maxSampleCount () const =0 |
Return the maximum number of samples that can be asked for before repeating. More... | |
bool | canSample () const |
Return true if maxSampleCount() > 0, since in this case samples can certainly be produced. More... | |
virtual bool | couldSample () const |
Return true if samples could be generated by this sampler at some point in the future. By default this is equivalent to canSample(), but for GoalLazySamples, this call also reflects the fact that a sampling thread is active and although no samples are produced yet, some may become available at some point in the future. More... | |
![]() | |
GoalRegion (const SpaceInformationPtr &si) | |
Create a goal region. More... | |
bool | isSatisfied (const State *st) const override |
Equivalent to calling isSatisfied(const State *, double *) with a nullptr second argument. More... | |
bool | isSatisfied (const State *st, double *distance) const override |
Decide whether a given state is part of the goal region. Returns true if the distance to goal is less than the threshold (using distanceGoal()) More... | |
virtual double | distanceGoal (const State *st) const =0 |
Compute the distance to the goal (heuristic). This function is the one used in computing the distance to the goal in a call to isSatisfied() More... | |
void | print (std::ostream &out=std::cout) const override |
Print information about the goal data structure to a stream. More... | |
void | setThreshold (double threshold) |
Set the distance to the goal that is allowed for a state to be considered in the goal region. More... | |
double | getThreshold () const |
Get the distance to the goal that is allowed for a state to be considered in the goal region. More... | |
![]() | |
Goal (const Goal &)=delete | |
Goal & | operator= (const Goal &)=delete |
Goal (SpaceInformationPtr si) | |
Constructor. The goal must always know the space information it is part of. More... | |
virtual | ~Goal ()=default |
Destructor. | |
template<class T > | |
T * | as () |
Cast this instance to a desired type. More... | |
template<class T > | |
const T * | as () const |
Cast this instance to a desired type. More... | |
GoalType | getType () const |
Return the goal type. More... | |
bool | hasType (GoalType type) const |
Check if this goal can be cast to a particular goal type. More... | |
const SpaceInformationPtr & | getSpaceInformation () const |
Get the space information this goal is for. More... | |
virtual bool | isSatisfied (const State *st) const =0 |
Return true if the state satisfies the goal constraints. More... | |
virtual bool | isSatisfied (const State *st, double *distance) const |
Return true if the state satisfies the goal constraints and compute the distance between the state given as argument and the goal (even if the goal is not satisfied). This distance can be an approximation. It can even be set to a constant, if such a computation is not possible. More... | |
virtual bool | isStartGoalPairValid (const State *, const State *) const |
Since there can be multiple starting states (and multiple goal states) it is possible certain pairs are not to be allowed. By default we however assume all such pairs are allowed. Note: if this function returns true, isSatisfied() need not be called. More... | |
virtual void | print (std::ostream &out=std::cout) const |
Print information about the goal. More... | |
Protected Member Functions | |
void | goalSamplingThread () |
The function that samples goals by calling samplerFunc_ in a separate thread. More... | |
Protected Attributes | |
std::mutex | lock_ |
Lock for updating the set of states. More... | |
GoalSamplingFn | samplerFunc_ |
Function that produces samples. More... | |
bool | terminateSamplingThread_ |
Flag used to notify the sampling thread to terminate sampling. More... | |
std::thread * | samplingThread_ |
Additional thread for sampling goal states. More... | |
unsigned int | samplingAttempts_ |
The number of times the sampling function was called and it returned true. More... | |
double | minDist_ |
Samples returned by the sampling thread are added to the list of states only if they are at least minDist_ away from already added samples. More... | |
NewStateCallbackFn | callback_ |
If defined, this function is called when a new state is added to the list of possible samples. More... | |
![]() | |
std::vector< State * > | states_ |
The goal states. Only ones that are valid are considered by the motion planner. More... | |
![]() | |
double | threshold_ |
The maximum distance that is allowed to the goal. By default, this is initialized to the minimum epsilon value a double can represent. More... | |
![]() | |
GoalType | type_ |
Goal type. More... | |
SpaceInformationPtr | si_ |
The space information for this goal. More... | |
Detailed Description
Definition of a goal region that can be sampled, but the sampling process can be slow. This class allows sampling the happen in a separate thread, and the number of goals may increase, as the planner is running, in a thread-safe manner.
- Todo:
- The Python bindings for GoalLazySamples class are still broken. The OMPL C++ code creates a new thread from which you should be able to call a python Goal sampling function. Acquiring the right threads and locks and messing around with the Python Global Interpreter Lock (GIL) is very tricky. See ompl/py-bindings/generate_bindings.py for an initial attempt to make this work.
Definition at line 71 of file GoalLazySamples.h.
Member Typedef Documentation
◆ NewStateCallbackFn
using ompl::base::GoalLazySamples::NewStateCallbackFn = std::function<void(const base::State *)> |
When new samples are generated and added to the list of possible samples, a callback can be called. This type specifies the signature of that callback.
Definition at line 77 of file GoalLazySamples.h.
Constructor & Destructor Documentation
◆ GoalLazySamples()
ompl::base::GoalLazySamples::GoalLazySamples | ( | const SpaceInformationPtr & | si, |
GoalSamplingFn | samplerFunc, | ||
bool | autoStart = true , |
||
double | minDist = std::numeric_limits<double>::epsilon() |
||
) |
Create a goal region that can be sampled in a lazy fashion. A function (samplerFunc) that produces samples from that region needs to be passed to this constructor. The sampling thread is automatically started if autoStart is true. The sampling function is not called in parallel by OMPL. Hence, the function is not required to be thread safe, unless the user issues additional calls in parallel. The instance of GoalLazySamples remains thread safe however.
The function samplerFunc returns a truth value. If the return value is true, further calls to the function can be made. If the return is false, no more calls should be made. The function takes two arguments: the instance of GoalLazySamples making the call and the state to fill with a goal state. For every state filled in by samplerFunc, addStateIfDifferent() is called. A state computed by the sampling thread is added if it is "sufficiently
different" from previously added states. A state is considered "sufficiently different" if it is at least minDist away from previously added states.
Definition at line 43 of file GoalLazySamples.cpp.
◆ ~GoalLazySamples()
|
override |
Definition at line 57 of file GoalLazySamples.cpp.
Member Function Documentation
◆ addState()
|
overridevirtual |
Add a goal state.
Reimplemented from ompl::base::GoalStates.
Definition at line 174 of file GoalLazySamples.cpp.
◆ addStateIfDifferent()
bool ompl::base::GoalLazySamples::addStateIfDifferent | ( | const State * | st, |
double | minDistance | ||
) |
Add a state st if it further away that minDistance from previously added states. Return true if the state was added.
Definition at line 204 of file GoalLazySamples.cpp.
◆ clear()
|
overridevirtual |
Clear all goal states.
Reimplemented from ompl::base::GoalStates.
Definition at line 151 of file GoalLazySamples.cpp.
◆ couldSample()
|
overridevirtual |
Return true if GoalStates::couldSample() is true or if the sampling thread is active, as in this case it is possible a sample can be produced at some point.
Reimplemented from ompl::base::GoalSampleableRegion.
Definition at line 146 of file GoalLazySamples.cpp.
◆ distanceGoal()
|
overridevirtual |
Compute the distance to the goal (heuristic). This function is the one used in computing the distance to the goal in a call to isSatisfied()
Implements ompl::base::GoalRegion.
Definition at line 157 of file GoalLazySamples.cpp.
◆ getMinNewSampleDistance()
|
inline |
Get the minimum distance that a new state returned by the sampling thread needs to be away from previously added states, so that it is added to the list of goal states.
Definition at line 131 of file GoalLazySamples.h.
◆ getState()
|
overridevirtual |
Return a pointer to the indexth state in the state list.
Reimplemented from ompl::base::GoalStates.
Definition at line 180 of file GoalLazySamples.cpp.
◆ getStateCount()
|
overridevirtual |
Return the number of valid goal states.
Reimplemented from ompl::base::GoalStates.
Definition at line 192 of file GoalLazySamples.cpp.
◆ goalSamplingThread()
|
protected |
The function that samples goals by calling samplerFunc_ in a separate thread.
Definition at line 94 of file GoalLazySamples.cpp.
◆ hasStates()
|
overridevirtual |
Check if there are any states in this goal region.
Reimplemented from ompl::base::GoalStates.
Definition at line 186 of file GoalLazySamples.cpp.
◆ isSampling()
bool ompl::base::GoalLazySamples::isSampling | ( | ) | const |
Return true if the sampling thread is active.
Definition at line 140 of file GoalLazySamples.cpp.
◆ maxSampleCount()
|
overridevirtual |
Return the maximum number of samples that can be asked for before repeating.
Implements ompl::base::GoalSampleableRegion.
Definition at line 198 of file GoalLazySamples.cpp.
◆ sampleGoal()
|
overridevirtual |
Sample a state in the goal region.
Implements ompl::base::GoalSampleableRegion.
Definition at line 163 of file GoalLazySamples.cpp.
◆ samplingAttemptsCount()
|
inline |
The number of times the sampling function was called and it returned true.
Definition at line 137 of file GoalLazySamples.h.
◆ setMinNewSampleDistance()
|
inline |
Set the minimum distance that a new state returned by the sampling thread needs to be away from previously added states, so that it is added to the list of goal states.
Definition at line 124 of file GoalLazySamples.h.
◆ setNewStateCallback()
void ompl::base::GoalLazySamples::setNewStateCallback | ( | const NewStateCallbackFn & | callback | ) |
Set the callback function to be called when a new state is added to the list of possible samples. This function is not required to be thread safe, as calls are made one at a time.
Definition at line 169 of file GoalLazySamples.cpp.
◆ startSampling()
void ompl::base::GoalLazySamples::startSampling | ( | ) |
Start the goal sampling thread.
Definition at line 62 of file GoalLazySamples.cpp.
◆ stopSampling()
void ompl::base::GoalLazySamples::stopSampling | ( | ) |
Stop the goal sampling thread.
Definition at line 73 of file GoalLazySamples.cpp.
Member Data Documentation
◆ callback_
|
protected |
If defined, this function is called when a new state is added to the list of possible samples.
Definition at line 187 of file GoalLazySamples.h.
◆ lock_
|
mutableprotected |
Lock for updating the set of states.
Definition at line 168 of file GoalLazySamples.h.
◆ minDist_
|
protected |
Samples returned by the sampling thread are added to the list of states only if they are at least minDist_ away from already added samples.
Definition at line 184 of file GoalLazySamples.h.
◆ samplerFunc_
|
protected |
Function that produces samples.
Definition at line 171 of file GoalLazySamples.h.
◆ samplingAttempts_
|
protected |
The number of times the sampling function was called and it returned true.
Definition at line 180 of file GoalLazySamples.h.
◆ samplingThread_
|
protected |
Additional thread for sampling goal states.
Definition at line 177 of file GoalLazySamples.h.
◆ terminateSamplingThread_
|
protected |
Flag used to notify the sampling thread to terminate sampling.
Definition at line 174 of file GoalLazySamples.h.
The documentation for this class was generated from the following files:
- ompl/base/goals/GoalLazySamples.h
- ompl/base/goals/src/GoalLazySamples.cpp