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 | |
typedef boost::function< void(const base::State *) | NewStateCallbackFn ) |
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. | |
Public Member Functions | |
GoalLazySamples (const SpaceInformationPtr &si, const 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. | |
virtual void | sampleGoal (State *st) const |
Sample a state in the goal region. | |
virtual double | distanceGoal (const State *st) const |
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() | |
virtual void | addState (const State *st) |
Add a goal state. | |
void | startSampling () |
Start the goal sampling thread. | |
void | stopSampling () |
Stop the goal sampling thread. | |
bool | isSampling () const |
Return true if the sampling thread is active. | |
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. | |
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. | |
unsigned int | samplingAttemptsCount () const |
The number of times the sampling function was called and it returned true. | |
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. | |
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. | |
virtual bool | couldSample () const |
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. | |
virtual bool | hasStates () const |
Check if there are any states in this goal region. | |
virtual const State * | getState (unsigned int index) const |
Return a pointer to the indexth state in the state list. | |
virtual std::size_t | getStateCount () const |
Return the number of valid goal states. | |
virtual void | clear () |
Clear all goal states. | |
Protected Member Functions | |
void | goalSamplingThread () |
The function that samples goals by calling samplerFunc_ in a separate thread. | |
Protected Attributes | |
boost::mutex | lock_ |
Lock for updating the set of states. | |
GoalSamplingFn | samplerFunc_ |
Function that produces samples. | |
bool | terminateSamplingThread_ |
Flag used to notify the sampling thread to terminate sampling. | |
boost::thread * | samplingThread_ |
Additional thread for sampling goal states. | |
unsigned int | samplingAttempts_ |
The number of times the sampling function was called and it returned true. | |
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. | |
NewStateCallbackFn | callback_ |
If defined, this function is called when a new state is added to the list of possible samples. |
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 72 of file GoalLazySamples.h.
Constructor & Destructor Documentation
base::GoalLazySamples::GoalLazySamples | ( | const SpaceInformationPtr & | si, |
const 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 41 of file GoalLazySamples.cpp.
The documentation for this class was generated from the following files:
- ompl/base/goals/GoalLazySamples.h
- ompl/base/goals/src/GoalLazySamples.cpp