All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
ompl::base::GoalLazySamples Class Reference

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 <GoalLazySamples.h>

Inheritance diagram for ompl::base::GoalLazySamples:

List of all members.

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 that produces samples from that region needs to be passed to this constructor. The sampling thread is automatically started if autoStart is true.
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 (void)
 Start the goal sampling thread.
void stopSampling (void)
 Stop the goal sampling thread.
bool isSampling (void) const
 Return true if the sampling thread is active.
virtual bool canSample (void) const
 Return true of maxSampleCount() > 0 or if the sampling thread is active, as in this case it is possible a sample can be produced.
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 (void) 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.
bool wasLastStateAdded (void) const
 Return true if the last state returned by the sampling function was added. Return false otherwise.
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 void clear (void)
 Clear all goal states.

Protected Member Functions

void goalSamplingThread (void)
 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.
bool lastStateAdded_
 Flag indicating whether the last state returned by the sampling function was added or not.
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.

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.


Constructor & Destructor Documentation

ompl::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 that produces samples from that region needs to be passed to this constructor. The sampling thread is automatically started if autoStart is true.

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: