Robowflex  v0.1
Making MoveIt Easy
robowflex::darts::DARTPlanner Class Reference

Wrapper for easy access to DART planning tools via standard Robowflex interface. More...

#include <planner.h>

+ Inheritance diagram for robowflex::darts::DARTPlanner:

Public Member Functions

 DARTPlanner (const robowflex::RobotPtr &robot, const std::string &name="DARTPlanner")
 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...
 
void preRun (const robowflex::SceneConstPtr &scene, const planning_interface::MotionPlanRequest &request) override
 This function is called before benchmarking. Here, it is used to setup the DART scene before the solve method. More...
 
planning_interface::MotionPlanResponse plan (const robowflex::SceneConstPtr &scene, const planning_interface::MotionPlanRequest &request) override
 Plan a motion given a request and a scene. 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...
 

Public Attributes

PlanBuilderPtr builder
 DART Motion Plan Builder. More...
 

Private Types

using PlannerAllocator = std::function< ompl::base::PlannerPtr()>
 A funciton that returns an allocated planner. More...
 

Private Member Functions

template<typename T , typename... Args>
PlannerAllocator makePlanner (Args &&... args)
 Macro for creating and setting up an OMPL planner. More...
 
void setupPlanners ()
 Setup planner allocators. More...
 

Private Attributes

std::map< std::string, PlannerAllocatorplanner_allocators_
 Named planner allocators. More...
 
SceneConstPtr scene_
 Current planning request scene. More...
 
StructurePtr dart_scene_
 DART version of current planning request scene. More...
 
RobotPtr dart_robot_
 DART version of the robot. More...
 
WorldPtr world_
 DART world containing robot and scene. More...
 
ompl::base::GoalPtr goal_
 Current motion planning goal. 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

Wrapper for easy access to DART planning tools via standard Robowflex interface.

Definition at line 25 of file planner.h.

Member Typedef Documentation

◆ PlannerAllocator

using robowflex::darts::DARTPlanner::PlannerAllocator = std::function<ompl::base::PlannerPtr()>
private

A funciton that returns an allocated planner.

Definition at line 64 of file planner.h.

Constructor & Destructor Documentation

◆ DARTPlanner()

DARTPlanner::DARTPlanner ( const robowflex::RobotPtr robot,
const std::string name = "DARTPlanner" 
)

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]nameOptional namespace for planner.

Definition at line 34 of file planner.cpp.

35  : robowflex::Planner(robot, name)
36  , dart_robot_(std::make_shared<Robot>(robot))
37  , world_(std::make_shared<World>())
38 {
39  world_->addRobot(dart_robot_);
40  setupPlanners();
41  builder = std::make_shared<PlanBuilder>(world_);
42 }
An abstract interface to a motion planning algorithm.
void setupPlanners()
Setup planner allocators.
Definition: planner.cpp:44
RobotPtr dart_robot_
DART version of the robot.
Definition: planner.h:93
PlanBuilderPtr builder
DART Motion Plan Builder.
Definition: planner.h:59
WorldPtr world_
DART world containing robot and scene.
Definition: planner.h:94
Functions for loading and animating robots in Blender.

Member Function Documentation

◆ getPlannerConfigs()

std::vector< std::string > DARTPlanner::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 157 of file planner.cpp.

158 {
159  std::vector<std::string> configs;
160  for (const auto &pair : planner_allocators_)
161  configs.emplace_back(pair.first);
162 
163  return configs;
164 }
std::map< std::string, PlannerAllocator > planner_allocators_
Named planner allocators.
Definition: planner.h:90
T emplace_back(T... args)

◆ makePlanner()

template<typename T , typename... Args>
PlannerAllocator robowflex::darts::DARTPlanner::makePlanner ( Args &&...  args)
inlineprivate

Macro for creating and setting up an OMPL planner.

Parameters
[in]argsArguments to pass to the planner.
Template Parameters

Definition at line 72 of file planner.h.

73  {
74  return [&]() -> ompl::base::PlannerPtr {
75  if (builder)
76  {
77  auto p = std::make_shared<T>(builder->info, std::forward<Args>(args)...);
78  p->setup();
79  return p;
80  }
81 
82  return nullptr;
83  };
84  }

◆ plan()

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

Plan a motion given a request and a scene.

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 102 of file planner.cpp.

104 {
105  // if scene and preRun scene mismatch, recompute
106  if (scene != scene_)
107  preRun(scene, request);
108 
109  // start sampling if necessary
110  auto gls = std::dynamic_pointer_cast<ompl::base::GoalLazySamples>(goal_);
111  if (gls)
112  gls->startSampling();
113 
114  // solve the plan, time the request
115  auto start = std::chrono::steady_clock::now();
116  ompl::base::PlannerStatus solved = builder->ss->solve(request.allowed_planning_time);
118 
119  auto time = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
120 
121  // kill sampling
122  if (gls)
123  gls->stopSampling();
124 
125  // extract request
127  response.planning_time_ = 1e6 * (double)time;
128  if (solved == ompl::base::PlannerStatus::EXACT_SOLUTION)
129  response.error_code_.val = moveit_msgs::MoveItErrorCodes::SUCCESS;
130  else
131  response.error_code_.val = moveit_msgs::MoveItErrorCodes::FAILURE;
132 
133  // extract trajectory
134  auto path = builder->getSolutionPath();
135 
136  response.trajectory_ =
137  std::make_shared<robot_trajectory::RobotTrajectory>(robot_->getModel(), request.group_name);
138 
139  for (const auto &s : path.getStates())
140  {
141  // set world state
142  builder->rspace->setWorldState(world_, s);
143 
144  // copy over world state to moveit state
145  auto ms = robot_->allocState();
146  dart_robot_->setMoveItStateFromState(*ms);
147 
148  response.trajectory_->addSuffixWayPoint(ms, 0);
149  }
150 
151  // compute time parameterization
153 
154  return response;
155 }
bool computeTimeParameterization(double max_velocity=1., double max_acceleration=1.)
Computes the time parameterization of a path according to a desired max velocity or acceleration.
Definition: trajectory.cpp:91
void preRun(const robowflex::SceneConstPtr &scene, const planning_interface::MotionPlanRequest &request) override
This function is called before benchmarking. Here, it is used to setup the DART scene before the solv...
Definition: planner.cpp:78
ompl::base::GoalPtr goal_
Current motion planning goal.
Definition: planner.h:95
SceneConstPtr scene_
Current planning request scene.
Definition: planner.h:91
T end(T... args)
Functions for loading and animating scenes in Blender.
moveit_msgs::MoveItErrorCodes error_code_
robot_trajectory::RobotTrajectoryPtr trajectory_
T time(T... args)

◆ preRun()

void DARTPlanner::preRun ( const robowflex::SceneConstPtr scene,
const planning_interface::MotionPlanRequest request 
)
overridevirtual

This function is called before benchmarking. Here, it is used to setup the DART scene before the solve method.

Parameters
[in]sceneScene to plan for.
[in]requestPlanning request.

Reimplemented from robowflex::Planner.

Definition at line 78 of file planner.cpp.

80 {
81  // remove old scene, if one exists
82  if (dart_scene_)
83  world_->removeStructure(dart_scene_);
84 
85  // convert scene representation
86  scene_ = scene;
87  dart_scene_ = std::make_shared<Structure>("scene", scene);
88  world_->addStructure(dart_scene_);
89 
90  // setup planning request and get desired goal
91  goal_ = builder->fromMessage(robot_->getName(), request);
92 
93  // find and setup planner
94  auto it = planner_allocators_.find(request.planner_id);
95  if (it == planner_allocators_.end())
96  throw std::runtime_error("Invalid planner ID");
97 
98  builder->ss->setPlanner(it->second());
99  builder->setup();
100 }
StructurePtr dart_scene_
DART version of current planning request scene.
Definition: planner.h:92

◆ setupPlanners()

void DARTPlanner::setupPlanners ( )
private

Setup planner allocators.

Definition at line 44 of file planner.cpp.

45 {
46  // rrts
47  planner_allocators_.emplace("rrt::RRT", makePlanner<ompl::geometric::RRT>());
48  planner_allocators_.emplace("rrt::RRTConnect", makePlanner<ompl::geometric::RRTConnect>());
49  planner_allocators_.emplace("rrt::RRTConnectIntermediate",
50  makePlanner<ompl::geometric::RRTConnect>(true));
51  planner_allocators_.emplace("rrt::RRT*", makePlanner<ompl::geometric::RRTstar>());
52  planner_allocators_.emplace("rrt::LazyRRT", makePlanner<ompl::geometric::LazyRRT>());
53 
54  // ests
55  planner_allocators_.emplace("est::EST", makePlanner<ompl::geometric::EST>());
56  planner_allocators_.emplace("est::BiEST", makePlanner<ompl::geometric::BiEST>());
57  planner_allocators_.emplace("est::ProjEST", makePlanner<ompl::geometric::ProjEST>());
58 
59  // prms
60  planner_allocators_.emplace("prm::PRM", makePlanner<ompl::geometric::PRM>());
61  planner_allocators_.emplace("prm::PRM*", makePlanner<ompl::geometric::PRMstar>());
62  planner_allocators_.emplace("prm::LazyPRM", makePlanner<ompl::geometric::LazyPRM>());
63  planner_allocators_.emplace("prm::LazyPRM*", makePlanner<ompl::geometric::LazyPRMstar>());
64  planner_allocators_.emplace("spars::SPARS", makePlanner<ompl::geometric::SPARS>());
65  planner_allocators_.emplace("spars::SPARS2", makePlanner<ompl::geometric::SPARStwo>());
66 
67  // fmts
68  planner_allocators_.emplace("fmt::FMT", makePlanner<ompl::geometric::FMT>());
69  planner_allocators_.emplace("fmt::BFMT", makePlanner<ompl::geometric::BFMT>());
70 
71  // pdst / kpiece
72  planner_allocators_.emplace("pdst::PDST", makePlanner<ompl::geometric::PDST>());
73  planner_allocators_.emplace("kpiece::KPIECE", makePlanner<ompl::geometric::KPIECE1>());
74  planner_allocators_.emplace("kpiece::BKPIECE", makePlanner<ompl::geometric::BKPIECE1>());
75  planner_allocators_.emplace("kpiece::LBKPIECE", makePlanner<ompl::geometric::LBKPIECE1>());
76 }

Member Data Documentation

◆ builder

PlanBuilderPtr robowflex::darts::DARTPlanner::builder

DART Motion Plan Builder.

Definition at line 59 of file planner.h.

◆ dart_robot_

RobotPtr robowflex::darts::DARTPlanner::dart_robot_
private

DART version of the robot.

Definition at line 93 of file planner.h.

◆ dart_scene_

StructurePtr robowflex::darts::DARTPlanner::dart_scene_
private

DART version of current planning request scene.

Definition at line 92 of file planner.h.

◆ goal_

ompl::base::GoalPtr robowflex::darts::DARTPlanner::goal_
private

Current motion planning goal.

Definition at line 95 of file planner.h.

◆ planner_allocators_

std::map<std::string, PlannerAllocator> robowflex::darts::DARTPlanner::planner_allocators_
private

Named planner allocators.

Definition at line 90 of file planner.h.

◆ scene_

SceneConstPtr robowflex::darts::DARTPlanner::scene_
private

Current planning request scene.

Definition at line 91 of file planner.h.

◆ world_

WorldPtr robowflex::darts::DARTPlanner::world_
private

DART world containing robot and scene.

Definition at line 94 of file planner.h.


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