コード例 #1
0
void ompl::app::DynamicCarPlanning::postPropagate(const base::State* /*state*/, const control::Control* /*control*/, const double /*duration*/, base::State* result)
{
    // Normalize orientation value between 0 and 2*pi
    const base::SO2StateSpace* SO2 = getStateSpace()->as<base::CompoundStateSpace>()
        ->as<base::SE2StateSpace>(0)->as<base::SO2StateSpace>(1);
    auto* so2 = result->as<base::CompoundStateSpace::StateType>()
        ->as<base::SE2StateSpace::StateType>(0)->as<base::SO2StateSpace::StateType>(1);
    SO2->enforceBounds(so2);
}
コード例 #2
0
void ompl::app::DynamicCarPlanning::setDefaultBounds()
{
    base::RealVectorBounds bounds(2);
    bounds.low[0] = -1.;
    bounds.high[0] = 1.;
    bounds.low[1] = -boost::math::constants::pi<double>() * 30. / 180.;
    bounds.high[1] = boost::math::constants::pi<double>() * 30. / 180.;
    getStateSpace()->as<base::CompoundStateSpace>()->as<base::RealVectorStateSpace>(1)->setBounds(bounds);
    bounds.low[0] = -.5;
    bounds.high[0] = .5;
    bounds.low[1] = -boost::math::constants::pi<double>() * 2. / 180.;
    bounds.high[1] = boost::math::constants::pi<double>() * 2. / 180.;
    getControlSpace()->as<control::RealVectorControlSpace>()->setBounds(bounds);
}
コード例 #3
0
ompl::base::ScopedState<> ompl::app::DynamicCarPlanning::getDefaultStartState() const
{
    base::ScopedState<base::CompoundStateSpace> s(getStateSpace());
    base::SE2StateSpace::StateType& pose = *s->as<base::SE2StateSpace::StateType>(0);
    base::RealVectorStateSpace::StateType& vel = *s->as<base::RealVectorStateSpace::StateType>(1);

    aiVector3D c = getRobotCenter(0);
    pose.setX(c.x);
    pose.setY(c.y);
    pose.setYaw(0.);
    vel.values[0] = 0.;
    vel.values[1] = 0.;
    return s;
}
コード例 #4
0
void DensoSetup::initialize(RobotBasePtr probot)
{
    const ob::StateSpacePtr &sSpace = getStateSpace();
    sSpace->setup();

    ob::ScopedState<> start(sSpace);
    ob::ScopedState<> goal(sSpace);
    std::vector<double> startVec(sSpace->getDimension(), 0.);
    std::vector<double> goalVec(sSpace->getDimension(), 0.);
    
    unsigned int ndof = si_->getStateSpace()->as<DensoStateSpace>()->
	_probot->GetActiveDOF();
    for (unsigned int i = 0; i < ndof; i++)
	goalVec[i] = 1.0;

    if (_useRealScene)
    {
	startVec[0] = -1.576;
	startVec[1] = 1.374;
	startVec[2] = 0.0;
	startVec[3] = 0.0;
	startVec[4] = -1.36751533;
	startVec[5] = 1.615;
	goalVec[0] = 1.55;
	goalVec[1] = 1.35;
	goalVec[2] = 0.1;
	goalVec[3] = -000057;
	goalVec[4] = -1.40754;
	goalVec[5] = 1.6;
    }
    
    sSpace->copyFromReals(start.get(), startVec);
    sSpace->copyFromReals(goal.get(), goalVec);
    /* set start, goal, and threshold*/
    setStartAndGoalStates(start, goal, threshold);
    /* set propagation step size and min-max propagation steps*/
    si_->setPropagationStepSize(propagationStepSize);
    si_->setMinMaxControlDuration(propagationMinSteps, propagationMaxSteps);
    /* initialize a new KPIECE planner */
    setPlanner(ob::PlannerPtr(new oc::KPIECE1(si_)));
    /* set default parameters */
    getPlanner()->as<oc::KPIECE1>()->setMaxCloseSamplesCount(maxCloseSamplesCount);
    getPlanner()->as<oc::KPIECE1>()->setGoalBias(goalBias);
    /* set a state validity checker */
    setStateValidityChecker(ob::StateValidityCheckerPtr
			    (new DensoStateValidityChecker(si_)));
    si_->setStateValidityCheckingResolution(0.05); //5%
    /* set a state propagator */
    setStatePropagator(oc::StatePropagatorPtr(new DensoStatePropagator(si_)));
}
コード例 #5
0
ファイル: KoulesSetup.cpp プロジェクト: jvgomez/ompl
void KoulesSetup::initialize(unsigned int numKoules, const std::string& plannerName,
    const std::vector<double>& stateVec)
{
    const ob::StateSpacePtr& space = getStateSpace();
    space->setup();
    // setup start state
    ob::ScopedState<> start(space);
    if (stateVec.size() == space->getDimension())
        space->copyFromReals(start.get(), stateVec);
    else
    {
        // Pick koule positions evenly radially distributed, but at a linearly
        // increasing distance from the center. The ship's initial position is
        // at the center. Initial velocities are 0.
        std::vector<double> startVec(space->getDimension(), 0.);
        double r, theta = boost::math::constants::pi<double>(), delta = 2.*theta / numKoules;
        startVec[0] = .5 * sideLength;
        startVec[1] = .5 * sideLength;
        startVec[4] = .5 * delta;
        for (unsigned int i = 0; i < numKoules; ++i, theta += delta)
        {
            r = .1 + i * .1 / numKoules;
            startVec[4 * i + 5] = .5 * sideLength + r * cos(theta);
            startVec[4 * i + 6] = .5 * sideLength + r * sin(theta);
        }
        space->copyFromReals(start.get(), startVec);
    }
    setStartState(start);
    // set goal
    setGoal(std::make_shared<KoulesGoal>(si_));
    // set propagation step size
    si_->setPropagationStepSize(propagationStepSize);
    // set min/max propagation steps
    si_->setMinMaxControlDuration(propagationMinSteps, propagationMaxSteps);
    // set directed control sampler; when using the PDST planner, propagate as long as possible
    bool isPDST = plannerName == "pdst";
    const ompl::base::GoalPtr& goal = getGoal();
    si_->setDirectedControlSamplerAllocator(
        [&goal, isPDST](const ompl::control::SpaceInformation *si)
        {
            return KoulesDirectedControlSamplerAllocator(si,  goal, isPDST);
        });
    // set planner
    setPlanner(getConfiguredPlannerInstance(plannerName));
    // set validity checker
    setStateValidityChecker(std::make_shared<KoulesStateValidityChecker>(si_));
    // set state propagator
    setStatePropagator(std::make_shared<KoulesStatePropagator>(si_));
}
コード例 #6
0
ompl::base::ScopedState<> ompl::app::SE3MultiRigidBodyPlanning::getDefaultStartState(void) const
{
    base::ScopedState<> st(getStateSpace());
    base::CompoundStateSpace::StateType* c_st = st.get()->as<base::CompoundStateSpace::StateType>();
    for (unsigned int i = 0; i < n_; ++i)
    {
        aiVector3D s = getRobotCenter(i);
        base::SE3StateSpace::StateType* sub = c_st->as<base::SE3StateSpace::StateType>(i);
        sub->setX(s.x);
        sub->setY(s.y);
        sub->setZ(s.z);
        sub->rotation().setIdentity();
    }
    return st;
}
コード例 #7
0
trajectory::InterpolatedPtr planOMPL(
    const statespace::StateSpace::State* _start,
    const statespace::StateSpace::State* _goal,
    statespace::ConstStateSpacePtr _stateSpace,
    statespace::InterpolatorPtr _interpolator,
    distance::DistanceMetricPtr _dmetric,
    constraint::SampleablePtr _sampler,
    constraint::TestablePtr _validityConstraint,
    constraint::TestablePtr _boundsConstraint,
    constraint::ProjectablePtr _boundsProjector,
    double _maxPlanTime,
    double _maxDistanceBtwValidityChecks)
{
  // Create a SpaceInformation.  This function will ensure state space matching
  auto si = getSpaceInformation(
      _stateSpace,
      _interpolator,
      std::move(_dmetric),
      std::move(_sampler),
      std::move(_validityConstraint),
      std::move(_boundsConstraint),
      std::move(_boundsProjector),
      _maxDistanceBtwValidityChecks);

  // Start and states
  auto pdef = ompl_make_shared<::ompl::base::ProblemDefinition>(si);
  auto sspace
      = ompl_static_pointer_cast<GeometricStateSpace>(si->getStateSpace());
  auto start = sspace->allocState(_start);
  auto goal = sspace->allocState(_goal);

  // ProblemDefinition clones states and keeps them internally
  pdef->setStartAndGoalStates(start, goal);

  sspace->freeState(start);
  sspace->freeState(goal);

  auto planner = ompl_make_shared<PlannerType>(si);
  return planOMPL(
      planner,
      pdef,
      std::move(_stateSpace),
      std::move(_interpolator),
      _maxPlanTime);
}
コード例 #8
0
void SuperBotSetup::initialize(RobotBasePtr probot)
{
    const ob::StateSpacePtr &sSpace = getStateSpace();
    sSpace->setup();

    ob::ScopedState<> start(sSpace);
    ob::ScopedState<> goal(sSpace);
    std::vector<double> startVec(sSpace->getDimension(), 0.);
    std::vector<double> goalVec(sSpace->getDimension(), 0.);
    
    unsigned int ndof = si_->getStateSpace()->as<SuperBotStateSpace>()->_probot->GetActiveDOF();
    for (unsigned int i = 0; i < ndof; i++)
	goalVec[i] = 1.0;
    
    sSpace->copyFromReals(start.get(), startVec);
    sSpace->copyFromReals(goal.get(), goalVec);
    // set start, goal, and threshold
    setStartAndGoalStates(start, goal, threshold);
    
    // set propagation step size and min-max propagation steps
    si_->setPropagationStepSize(propagationStepSize);
    si_->setMinMaxControlDuration(propagationMinSteps, propagationMaxSteps);
    
    // initialize a new KPIECE planner
    setPlanner(ob::PlannerPtr(new oc::KPIECE1(si_)));
    
    // set default parameters
    getPlanner()->as<oc::KPIECE1>()->setMaxCloseSamplesCount(maxCloseSamplesCount);
    getPlanner()->as<oc::KPIECE1>()->setGoalBias(goalBias);
    
    // set a state validity checker
    setStateValidityChecker(ob::StateValidityCheckerPtr(new SuperBotStateValidityChecker(si_)));
    si_->setStateValidityCheckingResolution(0.05); //5%
    
    // set a state propagator
    setStatePropagator(oc::StatePropagatorPtr(new SuperBotStatePropagator(si_)));
}
コード例 #9
0
trajectory::InterpolatedPtr planOMPL(
    const statespace::StateSpace::State* _start,
    constraint::TestablePtr _goalTestable,
    constraint::SampleablePtr _goalSampler,
    statespace::ConstStateSpacePtr _stateSpace,
    statespace::InterpolatorPtr _interpolator,
    distance::DistanceMetricPtr _dmetric,
    constraint::SampleablePtr _sampler,
    constraint::TestablePtr _validityConstraint,
    constraint::TestablePtr _boundsConstraint,
    constraint::ProjectablePtr _boundsProjector,
    double _maxPlanTime,
    double _maxDistanceBtwValidityChecks)
{
  if (_goalTestable == nullptr)
  {
    throw std::invalid_argument("Testable goal is nullptr.");
  }

  if (_goalSampler == nullptr)
  {
    throw std::invalid_argument("Sampleable goal is nullptr.");
  }

  if (_goalTestable->getStateSpace() != _stateSpace)
  {
    throw std::invalid_argument("Testable goal does not match StateSpace");
  }

  if (_goalSampler->getStateSpace() != _stateSpace)
  {
    throw std::invalid_argument("Sampleable goal does not match StateSpace");
  }

  auto si = getSpaceInformation(
      _stateSpace,
      _interpolator,
      std::move(_dmetric),
      std::move(_sampler),
      std::move(_validityConstraint),
      std::move(_boundsConstraint),
      std::move(_boundsProjector),
      _maxDistanceBtwValidityChecks);

  // Set the start and goal
  auto pdef = ompl_make_shared<::ompl::base::ProblemDefinition>(si);
  auto sspace
      = ompl_static_pointer_cast<GeometricStateSpace>(si->getStateSpace());
  auto start = sspace->allocState(_start);
  pdef->addStartState(start); // copies
  sspace->freeState(start);

  auto goalRegion = ompl_make_shared<GoalRegion>(
      si, std::move(_goalTestable), _goalSampler->createSampleGenerator());
  pdef->setGoal(goalRegion);

  auto planner = ompl_make_shared<PlannerType>(si);
  return planOMPL(
      planner,
      pdef,
      std::move(_stateSpace),
      std::move(_interpolator),
      _maxPlanTime);
}