7 #include <ompl/base/ConstrainedSpaceInformation.h> 
    8 #include <ompl/base/spaces/constraint/ProjectedStateSpace.h> 
   10 #include <moveit_msgs/MotionPlanRequest.h> 
   32     is_constrained_ = std::dynamic_pointer_cast<ompl::base::ConstrainedSpaceInformation>(si) != 
nullptr;
 
   45     return toState(
const_cast<ompl::base::State *
>(state));
 
   50     return state->as<ompl::base::ConstrainedStateSpace::StateType>()->getState()->as<
StateSpace::StateType>();
 
   73                 space_info_->getStateSpace()->as<ompl::base::ConstrainedStateSpace>()->getSpace() :
 
   84   : ompl::base::GoalLazySamples(
 
   85         si, 
std::bind(&
TSRGoal::sample, this, 
std::placeholders::_1, 
std::placeholders::_2), false, 1e-3)
 
   87   , world_(world->clone())
 
   88   , tsr_(
std::make_shared<
TSRSet>(world_, tsrs))
 
   91   , sampler_(
std::make_shared<
StateSpace::StateSampler>(getSpace()))
 
  113   : 
TSRGoal(builder.info, builder.world, [&] {
 
  128     if (getStateCount() >= 
options.max_samples)
 
  131     bool success = 
false;
 
  132     while (not terminateSamplingThread_ and not success)
 
  137         auto &&x = Eigen::Map<Eigen::VectorXd>(as->values, si_->getStateDimension());
 
  139         if (
tsr_->numTSRs() == 1 or not 
options.use_gradient)
 
  140             success = 
tsr_->solveWorldState(x);
 
  143             success = 
tsr_->solveGradientWorldState(x);
 
  145         success &= si_->satisfiesBounds(state);
 
  146         si_->enforceBounds(state);
 
  155     auto &&x = Eigen::Map<const Eigen::VectorXd>(as->values, si_->getStateDimension());
 
  156     return tsr_->distanceWorldState(x);
 
  171                     state - Eigen::VectorXd::Constant(state.size(), tolerance),  
 
  172                     state + Eigen::VectorXd::Constant(state.size(), tolerance))
 
  177                                  const Eigen::Ref<const Eigen::VectorXd> &upper)
 
  178   : ompl::base::GoalSampleableRegion(builder.info)
 
  180   , lower_(si_->allocState())
 
  181   , upper_(si_->allocState())
 
  183     if (lower.size() != upper.size())
 
  186     if (builder.
space->getDimension() != lower.size())
 
  205     for (
int i = 0; i < l.size(); ++i)
 
  206         s[i] = 
rng_.uniformReal(l[i], u[i]);
 
  220     const auto &ss = std::dynamic_pointer_cast<StateSpace>(si_->getStateSpace());
 
  223     for (
int i = 0; i < l.size(); ++i)
 
  225         const auto &joint = ss->getJoint(i);
 
  226         const auto &sv = joint->getSpaceVarsConst(s);
 
  227         const auto &lv = joint->getSpaceVarsConst(l);
 
  228         const auto &uv = joint->getSpaceVarsConst(u);
 
  231             d += joint->distance(sv, lv);
 
  233             d += joint->distance(sv, uv);
 
  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;
 
  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;
 
  261                                       const moveit_msgs::MotionPlanRequest &msg)
 
  264     if (not msg.path_constraints.position_constraints.empty() or
 
  265         not msg.path_constraints.orientation_constraints.empty())
 
  268     addGroup(robot_name, msg.group_name, cyclic ? 2 : 0);
 
  272                                       const moveit_msgs::MotionPlanRequest &msg)
 
  275     for (
std::size_t i = 0; i < msg.start_state.joint_state.name.size(); ++i)
 
  277         std::string name = msg.start_state.joint_state.name[i];
 
  278         double value = msg.start_state.joint_state.position[i];
 
  280         robot->setJoint(name, value);
 
  290     Eigen::VectorXd lower(n);
 
  291     Eigen::VectorXd upper(n);
 
  293     for (
const auto &msg : msgs)
 
  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;
 
  300     return std::make_shared<JointRegionGoal>(*
this, lower, upper);
 
  304                                            const moveit_msgs::PositionConstraint &msg)
 const 
  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);
 
  311     if (not msg.constraint_region.meshes.empty())
 
  313         RBX_ERROR(
"Invalid Position Constraint");
 
  317     if (msg.constraint_region.primitives.size() != 1)
 
  319         RBX_ERROR(
"Invalid Position Constraint");
 
  329     auto &&primitive = msg.constraint_region.primitives[0];
 
  330     if (primitive.type == shape_msgs::SolidPrimitive::BOX)
 
  336     else if (primitive.type == shape_msgs::SolidPrimitive::SPHERE)
 
  343     return std::make_shared<TSR>(
world, spec);
 
  347                                               const moveit_msgs::OrientationConstraint &msg)
 const 
  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);
 
  360     return std::make_shared<TSR>(
world, spec);
 
  364                                                 const moveit_msgs::MotionPlanRequest &msg)
 
  366     for (
const auto &
constraint : msg.path_constraints.position_constraints)
 
  368     for (
const auto &
constraint : msg.path_constraints.orientation_constraints)
 
  373                                                     const moveit_msgs::MotionPlanRequest &msg)
 
  377     for (
const auto &
constraint : msg.goal_constraints[0].position_constraints)
 
  379     for (
const auto &
constraint : msg.goal_constraints[0].orientation_constraints)
 
  389                                              const moveit_msgs::MotionPlanRequest &msg)
 
  405     rspace->addGroup(skeleton, name, cyclic);
 
  415     start = Eigen::VectorXd::Zero(
rspace->getDimension());
 
  435         space->freeState(state);
 
  441     Eigen::VectorXd goal = Eigen::VectorXd::Zero(
rspace->getDimension());
 
  452     ompl::base::ScopedState<> goal_state(
space);
 
  455     auto goal = std::make_shared<ompl::base::GoalStates>(
info);
 
  456     goal->addState(goal_state);
 
  476     return std::make_shared<TSRGoal>(*
this, tsrs);
 
  485         space->freeState(state);
 
  513     ompl::base::ScopedState<> start_state(
space);
 
  515     ss->setStartState(start_state);
 
  525     world->clearIKModules();
 
  526     rspace->setMetricSpace(
false);
 
  528     rinfo = std::make_shared<ompl::base::SpaceInformation>(
rspace);
 
  533     auto pss = std::make_shared<ompl::base::ProjectedStateSpace>(
rspace, 
constraint);
 
  535     info = std::make_shared<ompl::base::ConstrainedSpaceInformation>(pss);
 
  537     ss = std::make_shared<ompl::geometric::SimpleSetup>(
info);
 
  540     pss->setDelta(
options.constraints.delta);
 
  541     pss->setLambda(
options.constraints.lambda);
 
  547     ss = std::make_shared<ompl::geometric::SimpleSetup>(
space);
 
  557         auto sampler = 
space->allocStateSampler();
 
  558         auto *state = 
space->allocState();
 
  561         bool constrained = 
false;
 
  564             sampler->sampleUniform(state);
 
  565             space->enforceBounds(state);
 
  567             valid = 
info->isValid(state);
 
  572         } 
while (not valid or not constrained);
 
  585         ss->setStateValidityChecker([&](
const ompl::base::State *state) -> 
bool {
 
  590             bool r = not 
world->inCollision();
 
  599     return [&](
const ompl::base::State *state) -> 
bool {
 
  604         bool r = not 
world->inCollision();
 
  612     return [&](
const ompl::base::State *state) -> 
bool {
 
  617         bool r = not 
world->inCollision();
 
  626         ss->simplifySolution();
 
  628     auto path = 
ss->getSolutionPath();
 
A shared pointer wrapper for robowflex::darts::JointRegionGoal.
 
A joint space goal volume.
 
JointRegionGoal(const PlanBuilder &builder, const Eigen::Ref< const Eigen::VectorXd > &state, double tolerance=0.)
 
unsigned int maxSampleCount() const override
 
ompl::base::State * upper_
 
void sampleGoal(ompl::base::State *state) const override
 
ompl::base::State * lower_
 
double distanceGoal(const ompl::base::State *state) const override
 
A helper class to setup common OMPL structures for planning.
 
void setGoal(const ompl::base::GoalPtr &goal)
Set the goal for the problem.
 
void setStartConfigurationFromWorld()
Set the start configuration from the current state of the world.
 
TSRPtr fromOrientationConstraint(const std::string &robot_name, const moveit_msgs::OrientationConstraint &msg) const
Get a TSR from an orientation constraint.
 
std::shared_ptr< ompl::base::GoalStates > sampleGoalConfiguration()
Sample a valid goal configuration.
 
void addConstraint(const TSRPtr &tsr)
Adds a TSR as a path constraint to the problem.
 
void setup()
Calls setup routines on OMPL structures. Call after all setup is done and builder is initialized.
 
void setStartConfiguration(const Eigen::Ref< const Eigen::VectorXd > &q)
Set the start configuration from a configuration.
 
Eigen::VectorXd start
Start configuration.
 
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 initializeConstrained()
Initialize when path constraints are present.
 
ompl::base::SpaceInformationPtr info
Actual Space Information.
 
ompl::base::StateValidityCheckerFn getSVCUnconstrained()
Get a state validity checker for the unconstrained space.
 
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)
 
ompl::geometric::PathGeometric getSolutionPath(bool simplify=true, bool interpolate=true) const
Get the solution path from a successful plan.
 
ompl::geometric::SimpleSetupPtr ss
Simple Setup.
 
StateSpacePtr rspace
Underlying Robot State Space.
 
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.
 
PlanBuilder(WorldPtr world)
Constructor.
 
void getWorkspaceBoundsFromMessage(const moveit_msgs::MotionPlanRequest &msg)
Get workspace bounds from a planning request.
 
void setStateValidityChecker()
Set the state validity checker on the simple setup.
 
void sampleStartConfiguration()
Sample a valid start configuration.
 
std::vector< TSRPtr > path_constraints
Path Constraints.
 
struct robowflex::darts::PlanBuilder::@1 options
Hyperparameter options.
 
void getStartFromMessage(const std::string &robot_name, const moveit_msgs::MotionPlanRequest &msg)
Get the start state from the request message.
 
std::shared_ptr< ompl::base::GoalStates > getGoalConfigurationFromWorld()
Set the goal configuration from the current state of the world.
 
WorldPtr world
World used for planning.
 
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.
 
TSRPtr fromPositionConstraint(const std::string &robot_name, const moveit_msgs::PositionConstraint &msg) const
Get a TSR from an position constraint.
 
ompl::base::StateSpacePtr space
Actual OMPL State Space (might be constrained).
 
void initializeUnconstrained()
Initialize when no path constraints are present.
 
ompl::base::State * sampleState() const
Sample a valid state.
 
ompl::base::StateValidityCheckerFn getSVCConstrained()
Get a state validity checker for the unconstrained space.
 
JointRegionGoalPtr fromJointConstraints(const std::vector< moveit_msgs::JointConstraint > &msgs) const
Get a joint region goal from a message.
 
ompl::base::GoalPtr getGoalFromMessage(const std::string &robot_name, const moveit_msgs::MotionPlanRequest &msg)
Get the goal constraints from the planning request message.
 
ompl::base::GoalPtr goal_
Desired goal.
 
ompl::base::SpaceInformationPtr rinfo
Underlying Space Information.
 
std::shared_ptr< ompl::base::GoalStates > getGoalConfiguration(const Eigen::Ref< const Eigen::VectorXd > &q)
Set the goal configuration from a configuration.
 
void getGroupFromMessage(const std::string &robot_name, const moveit_msgs::MotionPlanRequest &msg)
Set group for planning from message.
 
State type for the robowflex::darts::StateSpace.
 
Eigen::VectorXd data
Vector for configuration.
 
An OMPL state space for robowflex::darts::World. Can do motion planning for any of the robots or stru...
 
A shared pointer wrapper for robowflex::darts::TSRGoal.
 
A sampleable goal region for OMPL for a set of TSRs. Samples goals in a separate thread using a clone...
 
struct robowflex::darts::TSRGoal::@0 options
Public options.
 
ompl::base::StateSamplerPtr sampler_
State sampler.
 
double distanceGoal(const ompl::base::State *state) const override
Distance to the goal.
 
~TSRGoal()
Destructor. Stops sampling thread.
 
TSRSetPtr getTSRSet()
Get the TSR set of this goal region.
 
bool sample(const ompl::base::GoalLazySamples *gls, ompl::base::State *state)
Sampling routine. Generates IK samples from the TSR goal.
 
TSRGoal(const ompl::base::SpaceInformationPtr &si, const WorldPtr &world, const std::vector< TSRPtr > &tsrs)
Constructor.
 
TSRSetPtr tsr_
TSR set to sample from.
 
A shared pointer wrapper for robowflex::darts::TSR.
 
A shared pointer wrapper for robowflex::darts::TSRSet.
 
Manager for a set of TSR constraints. Attempts to reduce redundancy and combines errors and Jacobians...
 
The specification of a TSR.
 
void setBase(const std::string &structure, const std::string &frame)
Set the base frame.
 
void setZRotTolerance(double bound)
Set the Z orientation tolerance to (-bound, bound).
 
void setRotation(const Eigen::Quaterniond &orientation)
Set the rotation of the TSR.
 
void setPose(const RobotPose &other)
Set the pose of the TSR.
 
void setFrame(const std::string &structure, const std::string &target, const std::string &base=magic::ROOT_FRAME)
Set the base and target frame.
 
void setYPosTolerance(double bound)
Set the Y position tolerance to (-bound, bound).
 
void setNoPosTolerance()
Set no position tolerance at all.
 
void setYRotTolerance(double bound)
Set the Y orientation tolerance to (-bound, bound).
 
void setXPosTolerance(double bound)
Setting Position Tolerances.
 
void setZPosTolerance(double bound)
Set the Z position tolerance to (-bound, bound).
 
void setXRotTolerance(double bound)
Setting Orientation Tolerances.
 
Eigen::Vector3d getPosition() const
Getters and Informative Methods.
 
void setPosition(const Eigen::Ref< const Eigen::Vector3d > &position)
Setting TSR Pose.
 
void setNoRotTolerance()
Set no orientation tolerance at all.
 
A shared pointer wrapper for robowflex::darts::World.
 
T emplace_back(T... args)
 
#define RBX_ERROR(fmt,...)
Output a error logging message.
 
Functions for loading and animating robots in Blender.
 
Eigen::Vector3d vectorMsgToEigen(const geometry_msgs::Vector3 &msg)
Converts a vector message to an Eigen::Vector3d.
 
RobotPose poseMsgToEigen(const geometry_msgs::Pose &msg)
Converts a pose message to RobotPose.
 
Eigen::Quaterniond quaternionMsgToEigen(const geometry_msgs::Quaternion &msg)
Converts a quaternion message to Eigen::Quaterniond.
 
DART-based robot modeling and planning.