Robowflex  v0.1
Making MoveIt Easy
robowflex::PoolPlanner Class Reference

A thread pool of planners P to service requests in a multi-threaded environment simultaneously. More...

#include <planning.h>

+ Inheritance diagram for robowflex::PoolPlanner:

Public Member Functions

 PoolPlanner (const RobotPtr &robot, unsigned int n=std::thread::hardware_concurrency(), const std::string &name="")
 Constructor. Takes in a robot description and an optional namespace name. If name is specified, planner parameters are namespaced under the namespace of robot. More...
 
 PoolPlanner (PoolPlanner const &)=delete
 
void operator= (PoolPlanner const &)=delete
 
template<typename P , typename... Args>
bool initialize (Args &&... args)
 Initialize the planner pool. Forwards template arguments Args to the initializer of the templated planner P. Assumes that the constructor of the planner takes robot_ and name_. More...
 
std::shared_ptr< Pool::Job< planning_interface::MotionPlanResponse > > submit (const SceneConstPtr &scene, const planning_interface::MotionPlanRequest &request)
 Submit a motion planning request job to the queue. More...
 
planning_interface::MotionPlanResponse plan (const SceneConstPtr &scene, const planning_interface::MotionPlanRequest &request) override
 Plan a motion given a request and a scene. Forwards the planning request onto the thread pool to be executed. Blocks until complete and returns result. More...
 
std::vector< std::stringgetPlannerConfigs () const override
 Return all planner configurations offered by this planner. Any of the configurations returned can be set as the planner for a motion planning query sent to plan(). More...
 
- Public Member Functions inherited from robowflex::Planner
 Planner (const RobotPtr &robot, const std::string &name="")
 Constructor. Takes in a robot description and an optional namespace name. If name is specified, planner parameters are namespaced under the namespace of robot. More...
 
 Planner (Planner const &)=delete
 
void operator= (Planner const &)=delete
 
virtual std::map< std::string, ProgressPropertygetProgressProperties (const SceneConstPtr &scene, const planning_interface::MotionPlanRequest &request) const
 Retrieve the planner progress property map for this planner given a specific request. More...
 
const RobotPtr getRobot () const
 Return the robot for this planner. More...
 
const std::stringgetName () const
 Get the name of the planner. More...
 
virtual void preRun (const SceneConstPtr &scene, const planning_interface::MotionPlanRequest &request)
 This function is called before benchmarking. More...
 

Private Attributes

Pool pool_
 Thread pool. More...
 
std::queue< PlannerPtrplanners_
 Motion planners. More...
 
std::mutex mutex_
 Planner mutex. More...
 
std::condition_variable cv_
 Planner condition variable. More...
 

Additional Inherited Members

- Public Types inherited from robowflex::Planner
using ProgressProperty = std::function< std::string()>
 A function that returns the value of a planner property over the course of a run. More...
 
- Protected Attributes inherited from robowflex::Planner
RobotPtr robot_
 The robot to plan for. More...
 
IO::Handler handler_
 The parameter handler for the planner. More...
 
const std::string name_
 Namespace for the planner. More...
 

Detailed Description

A thread pool of planners P to service requests in a multi-threaded environment simultaneously.

Definition at line 101 of file robowflex_library/include/robowflex_library/planning.h.

Constructor & Destructor Documentation

◆ PoolPlanner() [1/2]

PoolPlanner::PoolPlanner ( const RobotPtr robot,
unsigned int  n = std::thread::hardware_concurrency(),
const std::string name = "" 
)

Constructor. Takes in a robot description and an optional namespace name. If name is specified, planner parameters are namespaced under the namespace of robot.

Parameters
[in]robotThe robot to plan for.
[in]nThe number of threads to use. By default uses maximum available on the machine.
[in]nameOptional namespace for planner.

PoolPlanner

Definition at line 57 of file robowflex_library/src/planning.cpp.

58  : Planner(robot, name), pool_(n)
59 {
60 }
Planner(const RobotPtr &robot, const std::string &name="")
Constructor. Takes in a robot description and an optional namespace name. If name is specified,...
Functions for loading and animating robots in Blender.

◆ PoolPlanner() [2/2]

robowflex::PoolPlanner::PoolPlanner ( PoolPlanner const &  )
delete

Member Function Documentation

◆ getPlannerConfigs()

std::vector< std::string > PoolPlanner::getPlannerConfigs ( ) const
overridevirtual

Return all planner configurations offered by this planner. Any of the configurations returned can be set as the planner for a motion planning query sent to plan().

Returns
A vector of strings of planner configuration names.

Implements robowflex::Planner.

Definition at line 91 of file robowflex_library/src/planning.cpp.

92 {
93  return planners_.front()->getPlannerConfigs();
94 }
std::queue< PlannerPtr > planners_
Motion planners.

◆ initialize()

template<typename P , typename... Args>
bool robowflex::PoolPlanner::initialize ( Args &&...  args)
inline

Initialize the planner pool. Forwards template arguments Args to the initializer of the templated planner P. Assumes that the constructor of the planner takes robot_ and name_.

Parameters
[in]argsArguments to initializer of planner P.
Template Parameters
PThe robowflex::Planner to pool.
ArgsArgument types to initializer of planner P.
Returns
True on success, false on failure.

Definition at line 127 of file robowflex_library/include/robowflex_library/planning.h.

128  {
129  for (unsigned int i = 0; i < pool_.getThreadCount(); ++i)
130  {
131  auto planner = std::make_shared<P>(robot_, name_);
132 
133  if (!planner->initialize(std::forward<Args>(args)...))
134  return false;
135 
136  planners_.emplace(std::move(planner));
137  }
138 
139  return true;
140  }
const std::string name_
Namespace for the planner.
unsigned int getThreadCount() const
Get the number of threads.
Definition: pool.cpp:40
T move(T... args)

◆ operator=()

void robowflex::PoolPlanner::operator= ( PoolPlanner const &  )
delete

◆ plan()

planning_interface::MotionPlanResponse PoolPlanner::plan ( const SceneConstPtr scene,
const planning_interface::MotionPlanRequest request 
)
overridevirtual

Plan a motion given a request and a scene. Forwards the planning request onto the thread pool to be executed. Blocks until complete and returns result.

Parameters
[in]sceneA planning scene for the same robot_ to compute the plan in.
[in]requestThe motion planning request to solve.
Returns
The motion planning response generated by the planner.

Implements robowflex::Planner.

Definition at line 84 of file robowflex_library/src/planning.cpp.

86 {
87  auto job = submit(scene, request);
88  return job->get();
89 }
std::shared_ptr< Pool::Job< planning_interface::MotionPlanResponse > > submit(const SceneConstPtr &scene, const planning_interface::MotionPlanRequest &request)
Submit a motion planning request job to the queue.
Functions for loading and animating scenes in Blender.

◆ submit()

Submit a motion planning request job to the queue.

Parameters
[in]scenePlanning scene to plane for.
[in]requestMotion plan request to service.
Returns
Job that will service the planning request. This job can be canceled.

Definition at line 63 of file robowflex_library/src/planning.cpp.

64 {
65  return pool_.submit(make_function([&] {
67  cv_.wait(lock, [&] { return !planners_.empty(); });
68 
69  auto planner = planners_.front();
70  planners_.pop();
71 
72  lock.unlock();
73 
74  auto result = planner->plan(scene, request);
75 
76  lock.lock();
77  planners_.emplace(planner);
78  cv_.notify_one();
79 
80  return result;
81  }));
82 }
std::condition_variable cv_
Planner condition variable.
std::shared_ptr< Job< RT > > submit(const std::function< RT(Args...)> &&function, Args &&... args) const
Submit a function with arguments to be processed by the thread pool. Submitted functions must be wrap...
Definition: pool.h:209
T lock(T... args)

Member Data Documentation

◆ cv_

std::condition_variable robowflex::PoolPlanner::cv_
private

Planner condition variable.

Definition at line 167 of file robowflex_library/include/robowflex_library/planning.h.

◆ mutex_

std::mutex robowflex::PoolPlanner::mutex_
private

◆ planners_

std::queue<PlannerPtr> robowflex::PoolPlanner::planners_
private

Motion planners.

Definition at line 165 of file robowflex_library/include/robowflex_library/planning.h.

◆ pool_

Pool robowflex::PoolPlanner::pool_
private

Thread pool.

Definition at line 163 of file robowflex_library/include/robowflex_library/planning.h.


The documentation for this class was generated from the following files: