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

A helper class to setup common OMPL structures for planning. More...

#include <planning.h>

+ Inheritance diagram for robowflex::darts::PlanBuilder:

Public Member Functions

Setup and Initialization.
 PlanBuilder (WorldPtr world)
 Constructor. More...
 
void initialize ()
 Initialize OMPL structures. Only call this once all constraints, groups, and other parameters have been set for the builder. More...
 
void setup ()
 Calls setup routines on OMPL structures. Call after all setup is done and builder is initialized. More...
 
MoveIt Planning Messages
void getWorkspaceBoundsFromMessage (const moveit_msgs::MotionPlanRequest &msg)
 Get workspace bounds from a planning request. More...
 
void getGroupFromMessage (const std::string &robot_name, const moveit_msgs::MotionPlanRequest &msg)
 Set group for planning from message. More...
 
void getStartFromMessage (const std::string &robot_name, const moveit_msgs::MotionPlanRequest &msg)
 Get the start state from the request message. More...
 
void getPathConstraintsFromMessage (const std::string &robot_name, const moveit_msgs::MotionPlanRequest &msg)
 Get the set of path constraints from the request message. More...
 
ompl::base::GoalPtr getGoalFromMessage (const std::string &robot_name, const moveit_msgs::MotionPlanRequest &msg)
 Get the goal constraints from the planning request message. More...
 
TSRPtr fromPositionConstraint (const std::string &robot_name, const moveit_msgs::PositionConstraint &msg) const
 Get a TSR from an position constraint. More...
 
TSRPtr fromOrientationConstraint (const std::string &robot_name, const moveit_msgs::OrientationConstraint &msg) const
 Get a TSR from an orientation constraint. More...
 
JointRegionGoalPtr fromJointConstraints (const std::vector< moveit_msgs::JointConstraint > &msgs) const
 Get a joint region goal from a message. More...
 
ompl::base::GoalPtr fromMessage (const std::string &robot_name, const moveit_msgs::MotionPlanRequest &msg)
 Use all of the planning request message to setup motion planning. More...
 
Other Settings
void addGroup (const std::string &robot, const std::string &name, std::size_t cyclic=0)
 Add a robot's planning group to the controlled DoF in the state space. More...
 
void addConstraint (const TSRPtr &tsr)
 Adds a TSR as a path constraint to the problem. More...
 
Start Configuration
void setStartConfigurationFromWorld ()
 Set the start configuration from the current state of the world. More...
 
void setStartConfiguration (const Eigen::Ref< const Eigen::VectorXd > &q)
 Set the start configuration from a configuration. More...
 
void setStartConfiguration (const std::vector< double > &q)
 Set the start configuration from a configuration. More...
 
void sampleStartConfiguration ()
 Sample a valid start configuration. More...
 
Goals
std::shared_ptr< ompl::base::GoalStates > getGoalConfigurationFromWorld ()
 Set the goal configuration from the current state of the world. More...
 
std::shared_ptr< ompl::base::GoalStates > getGoalConfiguration (const Eigen::Ref< const Eigen::VectorXd > &q)
 Set the goal configuration from a configuration. More...
 
std::shared_ptr< ompl::base::GoalStates > getGoalConfiguration (const std::vector< double > &q)
 Set the goal configuration from a configuration. More...
 
TSRGoalPtr getGoalTSR (const TSRPtr &tsr)
 Set a TSR as the goal for the planning problem (will create a TSRGoal) More...
 
TSRGoalPtr getGoalTSR (const std::vector< TSRPtr > &tsrs)
 Set a set of TSRs as the goal for the planning problem (will create a TSRGoal) More...
 
std::shared_ptr< ompl::base::GoalStates > sampleGoalConfiguration ()
 Sample a valid goal configuration. More...
 
void setGoal (const ompl::base::GoalPtr &goal)
 Set the goal for the problem. More...
 
Other Functions
ompl::base::State * sampleState () const
 Sample a valid state. More...
 
ompl::geometric::PathGeometric getSolutionPath (bool simplify=true, bool interpolate=true) const
 Get the solution path from a successful plan. More...
 
- Public Member Functions inherited from robowflex::darts::ConstraintExtractor
 ConstraintExtractor ()=default
 Constructor. More...
 
 ConstraintExtractor (const ompl::base::SpaceInformationPtr &si)
 Constructor. More...
 
const StateSpacegetSpace () const
 Gets the underlying state space from the space information. More...
 
void setSpaceInformation (const ompl::base::SpaceInformationPtr &si)
 Set space information used for constraint extraction. More...
 
StateSpace::StateTypetoState (ompl::base::State *state) const
 Extract underlying state from a base state. More...
 
const StateSpace::StateTypetoStateConst (const ompl::base::State *state) const
 Extract underlying state from a base state. More...
 
StateSpace::StateTypefromConstrainedState (ompl::base::State *state) const
 Access the underlying state from a constrained OMPL state. More...
 
const StateSpace::StateTypefromConstrainedStateConst (const ompl::base::State *state) const
 Access the underlying state from a constrained OMPL state. More...
 
StateSpace::StateTypefromUnconstrainedState (ompl::base::State *state) const
 Access the underlying state from an unconstrained OMPL state. More...
 
const StateSpace::StateTypefromUnconstrainedStateConst (const ompl::base::State *state) const
 Access the underlying state from an unconstrained OMPL state. More...
 

Public Attributes

StateSpacePtr rspace {nullptr}
 Underlying Robot State Space. More...
 
ompl::base::StateSpacePtr space {nullptr}
 Actual OMPL State Space (might be constrained). More...
 
ompl::base::SpaceInformationPtr rinfo {nullptr}
 Underlying Space Information. More...
 
ompl::base::SpaceInformationPtr info {nullptr}
 Actual Space Information. More...
 
ompl::geometric::SimpleSetupPtr ss {nullptr}
 Simple Setup. More...
 
WorldPtr world
 World used for planning. More...
 
std::vector< TSRPtrpath_constraints
 Path Constraints. More...
 
TSRConstraintPtr constraint {nullptr}
 OMPL Constraint for Path Constraints. More...
 
Eigen::VectorXd start
 Start configuration. More...
 
struct {
   struct {
      double   delta {0.2}
 Manifold delta. More...
 
      double   lambda {5.0}
 Manifold lambda. More...
 
   }   constraints
 Constrained planning options. More...
 
options
 Hyperparameter options. More...
 

Protected Member Functions

void initializeConstrained ()
 Initialize when path constraints are present. More...
 
void initializeUnconstrained ()
 Initialize when no path constraints are present. More...
 
void setStateValidityChecker ()
 Set the state validity checker on the simple setup. More...
 
ompl::base::StateValidityCheckerFn getSVCUnconstrained ()
 Get a state validity checker for the unconstrained space. More...
 
ompl::base::StateValidityCheckerFn getSVCConstrained ()
 Get a state validity checker for the unconstrained space. More...
 

Protected Attributes

ompl::base::GoalPtr goal_ {nullptr}
 Desired goal. More...
 

Detailed Description

A helper class to setup common OMPL structures for planning.

Definition at line 221 of file robowflex_dart/include/robowflex_dart/planning.h.

Constructor & Destructor Documentation

◆ PlanBuilder()

PlanBuilder::PlanBuilder ( WorldPtr  world)

Constructor.

Parameters
[in]worldWorld to use for planning.

PlanBuilder

Definition at line 243 of file robowflex_dart/src/planning.cpp.

243  : rspace(std::make_shared<StateSpace>(world)), world(world)
244 {
245 }
StateSpacePtr rspace
Underlying Robot State Space.

Member Function Documentation

◆ addConstraint()

void PlanBuilder::addConstraint ( const TSRPtr tsr)

Adds a TSR as a path constraint to the problem.

Parameters
[in]tsrPath constraint.

Definition at line 408 of file robowflex_dart/src/planning.cpp.

409 {
410  path_constraints.emplace_back(tsr);
411 }
std::vector< TSRPtr > path_constraints
Path Constraints.

◆ addGroup()

void PlanBuilder::addGroup ( const std::string robot,
const std::string name,
std::size_t  cyclic = 0 
)

Add a robot's planning group to the controlled DoF in the state space.

Parameters
[in]robotName of the robot.
[in]nameName of the group in the robot to add.
[in]cyclicIf > 0, if the group contains cyclic joints (SO(2), SO(3)) these will be modeled as Rn.

Definition at line 403 of file robowflex_dart/src/planning.cpp.

404 {
405  rspace->addGroup(skeleton, name, cyclic);
406 }

◆ fromJointConstraints()

JointRegionGoalPtr PlanBuilder::fromJointConstraints ( const std::vector< moveit_msgs::JointConstraint > &  msgs) const

Get a joint region goal from a message.

Parameters
[in]msgsJoint constraint messages to create region goal.
Returns
The joint region goal.

Definition at line 287 of file robowflex_dart/src/planning.cpp.

288 {
289  std::size_t n = rspace->getDimension();
290  Eigen::VectorXd lower(n);
291  Eigen::VectorXd upper(n);
292 
293  for (const auto &msg : msgs)
294  {
295  const auto &joint = rspace->getJoint(msg.joint_name);
296  joint->getSpaceVars(lower)[0] = msg.position - msg.tolerance_below;
297  joint->getSpaceVars(upper)[0] = msg.position + msg.tolerance_above;
298  }
299 
300  return std::make_shared<JointRegionGoal>(*this, lower, upper);
301 }

◆ fromMessage()

ompl::base::GoalPtr PlanBuilder::fromMessage ( const std::string robot_name,
const moveit_msgs::MotionPlanRequest msg 
)

Use all of the planning request message to setup motion planning.

Parameters
[in]robot_nameRobot name to use message on.
[in]msgPlanning request message.

Definition at line 388 of file robowflex_dart/src/planning.cpp.

390 {
392  getGroupFromMessage(robot_name, msg);
393  getStartFromMessage(robot_name, msg);
394  getPathConstraintsFromMessage(robot_name, msg);
395  initialize();
396 
397  auto goal = getGoalFromMessage(robot_name, msg);
398  setGoal(goal);
399 
400  return goal;
401 }
void setGoal(const ompl::base::GoalPtr &goal)
Set the goal for the problem.
void getPathConstraintsFromMessage(const std::string &robot_name, const moveit_msgs::MotionPlanRequest &msg)
Get the set of path constraints from the request message.
void initialize()
Initialize OMPL structures. Only call this once all constraints, groups, and other parameters have be...
void getWorkspaceBoundsFromMessage(const moveit_msgs::MotionPlanRequest &msg)
Get workspace bounds from a planning request.
void getStartFromMessage(const std::string &robot_name, const moveit_msgs::MotionPlanRequest &msg)
Get the start state from the request message.
ompl::base::GoalPtr getGoalFromMessage(const std::string &robot_name, const moveit_msgs::MotionPlanRequest &msg)
Get the goal constraints from the planning request message.
void getGroupFromMessage(const std::string &robot_name, const moveit_msgs::MotionPlanRequest &msg)
Set group for planning from message.

◆ fromOrientationConstraint()

TSRPtr PlanBuilder::fromOrientationConstraint ( const std::string robot_name,
const moveit_msgs::OrientationConstraint &  msg 
) const

Get a TSR from an orientation constraint.

Parameters
[in]robot_nameRobot name to use message on.
[in]msgOrientation constraint.

Definition at line 346 of file robowflex_dart/src/planning.cpp.

348 {
349  TSR::Specification spec;
350  spec.setFrame(robot_name, msg.link_name);
351  if (not msg.header.frame_id.empty() and msg.header.frame_id != "world")
352  spec.setBase(robot_name, msg.header.frame_id);
353 
354  spec.setRotation(TF::quaternionMsgToEigen(msg.orientation));
355  spec.setNoPosTolerance();
356  spec.setXRotTolerance(msg.absolute_x_axis_tolerance);
357  spec.setYRotTolerance(msg.absolute_y_axis_tolerance);
358  spec.setZRotTolerance(msg.absolute_z_axis_tolerance);
359 
360  return std::make_shared<TSR>(world, spec);
361 }
The specification of a TSR.
Definition: tsr.h:70
void setBase(const std::string &structure, const std::string &frame)
Set the base frame.
Definition: tsr.cpp:42
void setZRotTolerance(double bound)
Set the Z orientation tolerance to (-bound, bound).
Definition: tsr.cpp:183
void setRotation(const Eigen::Quaterniond &orientation)
Set the rotation of the TSR.
Definition: tsr.cpp:74
void setFrame(const std::string &structure, const std::string &target, const std::string &base=magic::ROOT_FRAME)
Set the base and target frame.
Definition: tsr.cpp:48
void setNoPosTolerance()
Set no position tolerance at all.
Definition: tsr.cpp:233
void setYRotTolerance(double bound)
Set the Y orientation tolerance to (-bound, bound).
Definition: tsr.cpp:178
void setXRotTolerance(double bound)
Setting Orientation Tolerances.
Definition: tsr.cpp:173
Eigen::Quaterniond quaternionMsgToEigen(const geometry_msgs::Quaternion &msg)
Converts a quaternion message to Eigen::Quaterniond.
Definition: tf.cpp:135

◆ fromPositionConstraint()

TSRPtr PlanBuilder::fromPositionConstraint ( const std::string robot_name,
const moveit_msgs::PositionConstraint &  msg 
) const

Get a TSR from an position constraint.

Parameters
[in]robot_nameRobot name to use message on.
[in]msgPosition constraint.

Definition at line 303 of file robowflex_dart/src/planning.cpp.

305 {
306  TSR::Specification spec;
307  spec.setFrame(robot_name, msg.link_name);
308  if (not msg.header.frame_id.empty() and msg.header.frame_id != "world")
309  spec.setBase(robot_name, msg.header.frame_id);
310 
311  if (not msg.constraint_region.meshes.empty())
312  {
313  RBX_ERROR("Invalid Position Constraint");
314  return nullptr;
315  }
316 
317  if (msg.constraint_region.primitives.size() != 1)
318  {
319  RBX_ERROR("Invalid Position Constraint");
320  return nullptr;
321  }
322 
323  spec.setNoRotTolerance();
324 
325  // get pose
326  spec.setPose(TF::poseMsgToEigen(msg.constraint_region.primitive_poses[0]));
327  spec.setPosition(spec.getPosition() + TF::vectorMsgToEigen(msg.target_point_offset));
328 
329  auto &&primitive = msg.constraint_region.primitives[0];
330  if (primitive.type == shape_msgs::SolidPrimitive::BOX)
331  {
332  spec.setXPosTolerance(primitive.dimensions[0]);
333  spec.setYPosTolerance(primitive.dimensions[1]);
334  spec.setZPosTolerance(primitive.dimensions[2]);
335  }
336  else if (primitive.type == shape_msgs::SolidPrimitive::SPHERE)
337  {
338  spec.setXPosTolerance(primitive.dimensions[0]);
339  spec.setYPosTolerance(primitive.dimensions[0]);
340  spec.setZPosTolerance(primitive.dimensions[0]);
341  }
342 
343  return std::make_shared<TSR>(world, spec);
344 }
void setPose(const RobotPose &other)
Set the pose of the TSR.
Definition: tsr.cpp:93
void setYPosTolerance(double bound)
Set the Y position tolerance to (-bound, bound).
Definition: tsr.cpp:133
void setXPosTolerance(double bound)
Setting Position Tolerances.
Definition: tsr.cpp:128
void setZPosTolerance(double bound)
Set the Z position tolerance to (-bound, bound).
Definition: tsr.cpp:138
Eigen::Vector3d getPosition() const
Getters and Informative Methods.
Definition: tsr.cpp:311
void setPosition(const Eigen::Ref< const Eigen::Vector3d > &position)
Setting TSR Pose.
Definition: tsr.cpp:64
void setNoRotTolerance()
Set no orientation tolerance at all.
Definition: tsr.cpp:255
#define RBX_ERROR(fmt,...)
Output a error logging message.
Definition: log.h:102
Eigen::Vector3d vectorMsgToEigen(const geometry_msgs::Vector3 &msg)
Converts a vector message to an Eigen::Vector3d.
Definition: tf.cpp:94
RobotPose poseMsgToEigen(const geometry_msgs::Pose &msg)
Converts a pose message to RobotPose.
Definition: tf.cpp:114

◆ getGoalConfiguration() [1/2]

std::shared_ptr< ompl::base::GoalStates > PlanBuilder::getGoalConfiguration ( const Eigen::Ref< const Eigen::VectorXd > &  q)

Set the goal configuration from a configuration.

Parameters
[in]qConfiguration.

Definition at line 447 of file robowflex_dart/src/planning.cpp.

448 {
449  if (not space)
450  throw std::runtime_error("Builder must be initialized before creating goal!");
451 
452  ompl::base::ScopedState<> goal_state(space);
453  toState(goal_state.get())->data = q;
454 
455  auto goal = std::make_shared<ompl::base::GoalStates>(info);
456  goal->addState(goal_state);
457 
458  return goal;
459 }
StateSpace::StateType * toState(ompl::base::State *state) const
Extract underlying state from a base state.
ompl::base::SpaceInformationPtr info
Actual Space Information.
ompl::base::StateSpacePtr space
Actual OMPL State Space (might be constrained).
Eigen::VectorXd data
Vector for configuration.
Definition: space.h:76

◆ getGoalConfiguration() [2/2]

std::shared_ptr< ompl::base::GoalStates > PlanBuilder::getGoalConfiguration ( const std::vector< double > &  q)

Set the goal configuration from a configuration.

Parameters
[in]qConfiguration.

Definition at line 461 of file robowflex_dart/src/planning.cpp.

462 {
463  return getGoalConfiguration(Eigen::Map<const Eigen::VectorXd>(q.data(), rspace->getDimension()));
464 }
std::shared_ptr< ompl::base::GoalStates > getGoalConfiguration(const Eigen::Ref< const Eigen::VectorXd > &q)
Set the goal configuration from a configuration.
T data(T... args)

◆ getGoalConfigurationFromWorld()

std::shared_ptr< ompl::base::GoalStates > PlanBuilder::getGoalConfigurationFromWorld ( )

Set the goal configuration from the current state of the world.

Definition at line 439 of file robowflex_dart/src/planning.cpp.

440 {
441  Eigen::VectorXd goal = Eigen::VectorXd::Zero(rspace->getDimension());
442  rspace->getWorldState(world, goal);
443  return getGoalConfiguration(goal);
444 }

◆ getGoalFromMessage()

ompl::base::GoalPtr PlanBuilder::getGoalFromMessage ( const std::string robot_name,
const moveit_msgs::MotionPlanRequest msg 
)

Get the goal constraints from the planning request message.

Parameters
[in]robot_nameRobot name to use message on.
[in]msgPlanning request message.

Definition at line 372 of file robowflex_dart/src/planning.cpp.

374 {
375  // TODO get other goals as well
376  std::vector<TSRPtr> tsrs;
377  for (const auto &constraint : msg.goal_constraints[0].position_constraints)
379  for (const auto &constraint : msg.goal_constraints[0].orientation_constraints)
381 
382  if (tsrs.empty())
383  return fromJointConstraints(msg.goal_constraints[0].joint_constraints);
384 
385  return getGoalTSR(tsrs);
386 }
TSRPtr fromOrientationConstraint(const std::string &robot_name, const moveit_msgs::OrientationConstraint &msg) const
Get a TSR from an orientation constraint.
TSRConstraintPtr constraint
OMPL Constraint for Path Constraints.
TSRGoalPtr getGoalTSR(const TSRPtr &tsr)
Set a TSR as the goal for the planning problem (will create a TSRGoal)
TSRPtr fromPositionConstraint(const std::string &robot_name, const moveit_msgs::PositionConstraint &msg) const
Get a TSR from an position constraint.
JointRegionGoalPtr fromJointConstraints(const std::vector< moveit_msgs::JointConstraint > &msgs) const
Get a joint region goal from a message.
T emplace_back(T... args)
T empty(T... args)

◆ getGoalTSR() [1/2]

TSRGoalPtr PlanBuilder::getGoalTSR ( const std::vector< TSRPtr > &  tsrs)

Set a set of TSRs as the goal for the planning problem (will create a TSRGoal)

Parameters
[in]tsrsTSRs for the goal.

Definition at line 471 of file robowflex_dart/src/planning.cpp.

472 {
473  if (not info)
474  throw std::runtime_error("Builder must be initialized before creating goal!");
475 
476  return std::make_shared<TSRGoal>(*this, tsrs);
477 }

◆ getGoalTSR() [2/2]

TSRGoalPtr PlanBuilder::getGoalTSR ( const TSRPtr tsr)

Set a TSR as the goal for the planning problem (will create a TSRGoal)

Parameters
[in]tsrTSR for the goal.

Definition at line 466 of file robowflex_dart/src/planning.cpp.

467 {
468  return getGoalTSR(std::vector<TSRPtr>{tsr});
469 }

◆ getGroupFromMessage()

void PlanBuilder::getGroupFromMessage ( const std::string robot_name,
const moveit_msgs::MotionPlanRequest msg 
)

Set group for planning from message.

Parameters
[in]robot_nameRobot name to use message on.
[in]msgPlanning request message.

Definition at line 260 of file robowflex_dart/src/planning.cpp.

262 {
263  bool cyclic = false;
264  if (not msg.path_constraints.position_constraints.empty() or
265  not msg.path_constraints.orientation_constraints.empty())
266  cyclic = true;
267 
268  addGroup(robot_name, msg.group_name, cyclic ? 2 : 0);
269 }
void addGroup(const std::string &robot, const std::string &name, std::size_t cyclic=0)
Add a robot's planning group to the controlled DoF in the state space.

◆ getPathConstraintsFromMessage()

void PlanBuilder::getPathConstraintsFromMessage ( const std::string robot_name,
const moveit_msgs::MotionPlanRequest msg 
)

Get the set of path constraints from the request message.

Parameters
[in]robot_nameRobot name to use message on.
[in]msgPlanning request message.

Definition at line 363 of file robowflex_dart/src/planning.cpp.

365 {
366  for (const auto &constraint : msg.path_constraints.position_constraints)
368  for (const auto &constraint : msg.path_constraints.orientation_constraints)
370 }
void addConstraint(const TSRPtr &tsr)
Adds a TSR as a path constraint to the problem.

◆ getSolutionPath()

ompl::geometric::PathGeometric PlanBuilder::getSolutionPath ( bool  simplify = true,
bool  interpolate = true 
) const

Get the solution path from a successful plan.

Parameters
[in]simplifySimplify the solution.
[in]interpolateInterpolate the solution.

Definition at line 623 of file robowflex_dart/src/planning.cpp.

624 {
625  if (simplify)
626  ss->simplifySolution();
627 
628  auto path = ss->getSolutionPath();
629  if (interpolate)
630  path.interpolate();
631 
632  return path;
633 }
ompl::geometric::SimpleSetupPtr ss
Simple Setup.

◆ getStartFromMessage()

void PlanBuilder::getStartFromMessage ( const std::string robot_name,
const moveit_msgs::MotionPlanRequest msg 
)

Get the start state from the request message.

Parameters
[in]robot_nameRobot name to use message on.
[in]msgPlanning request message.

Definition at line 271 of file robowflex_dart/src/planning.cpp.

273 {
274  auto robot = world->getRobot(robot_name);
275  for (std::size_t i = 0; i < msg.start_state.joint_state.name.size(); ++i)
276  {
277  std::string name = msg.start_state.joint_state.name[i];
278  double value = msg.start_state.joint_state.position[i];
279 
280  robot->setJoint(name, value);
281  }
282 
284 }
void setStartConfigurationFromWorld()
Set the start configuration from the current state of the world.
Functions for loading and animating robots in Blender.

◆ getSVCConstrained()

ompl::base::StateValidityCheckerFn PlanBuilder::getSVCConstrained ( )
protected

Get a state validity checker for the unconstrained space.

Returns
The state validity checker.

Definition at line 610 of file robowflex_dart/src/planning.cpp.

611 {
612  return [&](const ompl::base::State *state) -> bool {
613  const auto &as = fromConstrainedStateConst(state);
614 
615  world->lock();
616  rspace->setWorldState(world, as);
617  bool r = not world->inCollision();
618  world->unlock();
619  return r;
620  };
621 }
const StateSpace::StateType * fromConstrainedStateConst(const ompl::base::State *state) const
Access the underlying state from a constrained OMPL state.

◆ getSVCUnconstrained()

ompl::base::StateValidityCheckerFn PlanBuilder::getSVCUnconstrained ( )
protected

Get a state validity checker for the unconstrained space.

Returns
The state validity checker.

Definition at line 597 of file robowflex_dart/src/planning.cpp.

598 {
599  return [&](const ompl::base::State *state) -> bool {
600  const auto &as = fromUnconstrainedStateConst(state);
601 
602  world->lock();
603  rspace->setWorldState(world, as);
604  bool r = not world->inCollision();
605  world->unlock();
606  return r;
607  };
608 }
const StateSpace::StateType * fromUnconstrainedStateConst(const ompl::base::State *state) const
Access the underlying state from an unconstrained OMPL state.

◆ getWorkspaceBoundsFromMessage()

void PlanBuilder::getWorkspaceBoundsFromMessage ( const moveit_msgs::MotionPlanRequest msg)

Get workspace bounds from a planning request.

Parameters
[in]msgPlanning request message.

Definition at line 247 of file robowflex_dart/src/planning.cpp.

248 {
249  const auto &mic = msg.workspace_parameters.min_corner;
250  world->getWorkspaceLow()[0] = mic.x;
251  world->getWorkspaceLow()[1] = mic.y;
252  world->getWorkspaceLow()[2] = mic.z;
253 
254  const auto &mac = msg.workspace_parameters.max_corner;
255  world->getWorkspaceHigh()[0] = mac.x;
256  world->getWorkspaceHigh()[1] = mac.y;
257  world->getWorkspaceHigh()[2] = mac.z;
258 }

◆ initialize()

void PlanBuilder::initialize ( )

Initialize OMPL structures. Only call this once all constraints, groups, and other parameters have been set for the builder.

Definition at line 501 of file robowflex_dart/src/planning.cpp.

502 {
503  if (path_constraints.empty())
505  else
507 
509 }
void setSpaceInformation(const ompl::base::SpaceInformationPtr &si)
Set space information used for constraint extraction.
void initializeConstrained()
Initialize when path constraints are present.
void initializeUnconstrained()
Initialize when no path constraints are present.

◆ initializeConstrained()

void PlanBuilder::initializeConstrained ( )
protected

Initialize when path constraints are present.

Definition at line 523 of file robowflex_dart/src/planning.cpp.

524 {
525  world->clearIKModules();
526  rspace->setMetricSpace(false);
527 
528  rinfo = std::make_shared<ompl::base::SpaceInformation>(rspace);
529  rinfo->setStateValidityChecker(getSVCUnconstrained());
530 
531  constraint = std::make_shared<TSRConstraint>(rspace, path_constraints);
532 
533  auto pss = std::make_shared<ompl::base::ProjectedStateSpace>(rspace, constraint);
534  space = pss;
535  info = std::make_shared<ompl::base::ConstrainedSpaceInformation>(pss);
536 
537  ss = std::make_shared<ompl::geometric::SimpleSetup>(info);
539 
540  pss->setDelta(options.constraints.delta);
541  pss->setLambda(options.constraints.lambda);
542 }
ompl::base::StateValidityCheckerFn getSVCUnconstrained()
Get a state validity checker for the unconstrained space.
void setStateValidityChecker()
Set the state validity checker on the simple setup.
struct robowflex::darts::PlanBuilder::@1 options
Hyperparameter options.
ompl::base::SpaceInformationPtr rinfo
Underlying Space Information.

◆ initializeUnconstrained()

void PlanBuilder::initializeUnconstrained ( )
protected

Initialize when no path constraints are present.

Definition at line 544 of file robowflex_dart/src/planning.cpp.

545 {
546  space = rspace;
547  ss = std::make_shared<ompl::geometric::SimpleSetup>(space);
549 
550  rinfo = info = ss->getSpaceInformation();
551 }

◆ sampleGoalConfiguration()

std::shared_ptr< ompl::base::GoalStates > PlanBuilder::sampleGoalConfiguration ( )

Sample a valid goal configuration.

Definition at line 479 of file robowflex_dart/src/planning.cpp.

480 {
481  if (space)
482  {
483  auto *state = sampleState();
484  auto goal = getGoalConfiguration(toState(state)->data);
485  space->freeState(state);
486 
487  return goal;
488  }
489 
490  return nullptr;
491 }
ompl::base::State * sampleState() const
Sample a valid state.

◆ sampleStartConfiguration()

void PlanBuilder::sampleStartConfiguration ( )

Sample a valid start configuration.

Definition at line 429 of file robowflex_dart/src/planning.cpp.

430 {
431  if (space)
432  {
433  auto *state = sampleState();
434  setStartConfiguration(toState(state)->data);
435  space->freeState(state);
436  }
437 }
void setStartConfiguration(const Eigen::Ref< const Eigen::VectorXd > &q)
Set the start configuration from a configuration.

◆ sampleState()

ompl::base::State * PlanBuilder::sampleState ( ) const

Sample a valid state.

Returns
a Valid state.

Definition at line 553 of file robowflex_dart/src/planning.cpp.

554 {
555  if (space)
556  {
557  auto sampler = space->allocStateSampler();
558  auto *state = space->allocState();
559 
560  bool valid = false;
561  bool constrained = false;
562  do
563  {
564  sampler->sampleUniform(state);
565  space->enforceBounds(state);
566 
567  valid = info->isValid(state);
568  if (constraint)
569  constrained = constraint->isSatisfied(state);
570  else
571  constrained = true;
572  } while (not valid or not constrained);
573 
574  return state;
575  }
576 
577  return nullptr;
578 }

◆ setGoal()

void PlanBuilder::setGoal ( const ompl::base::GoalPtr &  goal)

Set the goal for the problem.

Parameters
[in]goalGoal to use.

Definition at line 493 of file robowflex_dart/src/planning.cpp.

494 {
495  goal_ = goal;
496 
497  if (ss)
498  ss->setGoal(goal_);
499 }

◆ setStartConfiguration() [1/2]

void PlanBuilder::setStartConfiguration ( const Eigen::Ref< const Eigen::VectorXd > &  q)

Set the start configuration from a configuration.

Parameters
[in]qConfiguration.

Definition at line 419 of file robowflex_dart/src/planning.cpp.

420 {
421  start = q;
422 }

◆ setStartConfiguration() [2/2]

void PlanBuilder::setStartConfiguration ( const std::vector< double > &  q)

Set the start configuration from a configuration.

Parameters
[in]qConfiguration.

Definition at line 424 of file robowflex_dart/src/planning.cpp.

425 {
426  setStartConfiguration(Eigen::Map<const Eigen::VectorXd>(q.data(), rspace->getDimension()));
427 }

◆ setStartConfigurationFromWorld()

void PlanBuilder::setStartConfigurationFromWorld ( )

Set the start configuration from the current state of the world.

Definition at line 413 of file robowflex_dart/src/planning.cpp.

414 {
415  start = Eigen::VectorXd::Zero(rspace->getDimension());
416  rspace->getWorldState(world, start);
417 }

◆ setStateValidityChecker()

void PlanBuilder::setStateValidityChecker ( )
protected

Set the state validity checker on the simple setup.

Definition at line 580 of file robowflex_dart/src/planning.cpp.

581 {
582  if (ss)
583  {
584  // ss->setStateValidityChecker(std::make_shared<WorldValidityChecker>(info, 1));
585  ss->setStateValidityChecker([&](const ompl::base::State *state) -> bool {
586  const auto &as = toStateConst(state);
587 
588  world->lock();
589  rspace->setWorldState(world, as);
590  bool r = not world->inCollision();
591  world->unlock();
592  return r;
593  });
594  }
595 }
const StateSpace::StateType * toStateConst(const ompl::base::State *state) const
Extract underlying state from a base state.

◆ setup()

void PlanBuilder::setup ( )

Calls setup routines on OMPL structures. Call after all setup is done and builder is initialized.

Definition at line 511 of file robowflex_dart/src/planning.cpp.

512 {
513  ompl::base::ScopedState<> start_state(space);
514  toState(start_state.get())->data = start;
515  ss->setStartState(start_state);
516  if (not goal_)
517  throw std::runtime_error("No goal setup in PlanBuilder!");
518  ss->setGoal(goal_);
519 
520  ss->setup();
521 }

Member Data Documentation

◆ constraint

TSRConstraintPtr robowflex::darts::PlanBuilder::constraint {nullptr}

OMPL Constraint for Path Constraints.

Definition at line 415 of file robowflex_dart/include/robowflex_dart/planning.h.

◆ 

struct { ... } robowflex::darts::PlanBuilder::constraints

Constrained planning options.

◆ delta

double robowflex::darts::PlanBuilder::delta {0.2}

Manifold delta.

Definition at line 427 of file robowflex_dart/include/robowflex_dart/planning.h.

◆ goal_

ompl::base::GoalPtr robowflex::darts::PlanBuilder::goal_ {nullptr}
protected

Desired goal.

Definition at line 433 of file robowflex_dart/include/robowflex_dart/planning.h.

◆ info

ompl::base::SpaceInformationPtr robowflex::darts::PlanBuilder::info {nullptr}

Actual Space Information.

Definition at line 410 of file robowflex_dart/include/robowflex_dart/planning.h.

◆ lambda

double robowflex::darts::PlanBuilder::lambda {5.0}

Manifold lambda.

Definition at line 428 of file robowflex_dart/include/robowflex_dart/planning.h.

◆ 

struct { ... } robowflex::darts::PlanBuilder::options

Hyperparameter options.

◆ path_constraints

std::vector<TSRPtr> robowflex::darts::PlanBuilder::path_constraints

Path Constraints.

Definition at line 414 of file robowflex_dart/include/robowflex_dart/planning.h.

◆ rinfo

ompl::base::SpaceInformationPtr robowflex::darts::PlanBuilder::rinfo {nullptr}

Underlying Space Information.

Definition at line 409 of file robowflex_dart/include/robowflex_dart/planning.h.

◆ rspace

StateSpacePtr robowflex::darts::PlanBuilder::rspace {nullptr}

Underlying Robot State Space.

Definition at line 407 of file robowflex_dart/include/robowflex_dart/planning.h.

◆ space

ompl::base::StateSpacePtr robowflex::darts::PlanBuilder::space {nullptr}

Actual OMPL State Space (might be constrained).

Definition at line 408 of file robowflex_dart/include/robowflex_dart/planning.h.

◆ ss

ompl::geometric::SimpleSetupPtr robowflex::darts::PlanBuilder::ss {nullptr}

Simple Setup.

Definition at line 411 of file robowflex_dart/include/robowflex_dart/planning.h.

◆ start

Eigen::VectorXd robowflex::darts::PlanBuilder::start

Start configuration.

Definition at line 417 of file robowflex_dart/include/robowflex_dart/planning.h.

◆ world

WorldPtr robowflex::darts::PlanBuilder::world

World used for planning.

Definition at line 412 of file robowflex_dart/include/robowflex_dart/planning.h.


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