Bench-MR
A Motion Planning Benchmark for Wheeled Mobile Robots
OptimizationObjective.h
Go to the documentation of this file.
1#pragma once
2
3#include <ompl/base/OptimizationObjective.h>
4#include <ompl/base/objectives/PathLengthOptimizationObjective.h>
5#include <ompl/base/samplers/InformedStateSampler.h>
6#include <ompl/base/samplers/informed/PathLengthDirectInfSampler.h>
7
8#include <limits>
9
10namespace ob = ompl::base;
11
12class CustomPathLengthDirectInfSampler : public ob::InformedSampler {
13 public:
14 CustomPathLengthDirectInfSampler(const ob::ProblemDefinitionPtr &probDefn,
15 unsigned int maxNumberCalls);
16
18
19 bool sampleUniform(ob::State *statePtr, const ob::Cost &maxCost) override;
20
21 bool sampleUniform(ob::State *statePtr, const ob::Cost &minCost,
22 const ob::Cost &maxCost) override;
23
24 bool hasInformedMeasure() const override;
25
26 double getInformedMeasure(const ob::Cost &currentCost) const override;
27
28 ob::Cost heuristicSolnCost(const ob::State *statePtr) const override;
29
30 private:
31 typedef std::shared_ptr<const ompl::ProlateHyperspheroid>
32 ProlateHyperspheroidCPtr;
33
34 // Helper functions:
35 // High level
36 bool sampleUniform(ob::State *statePtr, const ob::Cost &maxCost,
37 unsigned int *iters);
38
39 bool sampleBoundsRejectPhs(ob::State *statePtr, unsigned int *iters);
40
41 bool samplePhsRejectBounds(ob::State *statePtr, unsigned int *iters);
42
43 // Low level
44 std::vector<double> getInformedSubstate(const ob::State *statePtr) const;
45
46 void createFullState(ob::State *statePtr,
47 const std::vector<double> &informedVector);
48
49 void updatePhsDefinitions(const ob::Cost &maxCost);
50
51 ompl::ProlateHyperspheroidPtr randomPhsPtr();
52
53 bool keepSample(const std::vector<double> &informedVector);
54
55 bool isInAnyPhs(const std::vector<double> &informedVector) const;
56
57 bool isInPhs(const ProlateHyperspheroidCPtr &phsCPtr,
58 const std::vector<double> &informedVector) const;
59
60 unsigned int numberOfPhsInclusions(
61 const std::vector<double> &informedVector) const;
62
63 // Variables
64 std::list<ompl::ProlateHyperspheroidPtr> listPhsPtrs_;
65
66 double summedMeasure_;
67
68 unsigned int informedIdx_;
69
70 ob::StateSpacePtr informedSubSpace_;
71
72 unsigned int uninformedIdx_;
73
74 ob::StateSpacePtr uninformedSubSpace_;
75
76 ob::StateSamplerPtr baseSampler_;
77
78 ob::StateSamplerPtr uninformedSubSampler_;
79
80 ompl::RNG rng_;
81};
82
84 : public ob::PathLengthOptimizationObjective {
85 public:
86 CustomPathLengthOptimizationObjective(ob::SpaceInformationPtr &space_info)
87 : ob::PathLengthOptimizationObjective(space_info) {}
88 ob::InformedSamplerPtr allocInformedStateSampler(
89 const ob::ProblemDefinitionPtr &probDefn,
90 unsigned int maxNumberCalls) const override {
91 OMPL_DEBUG(
92 "Using a custom informed state sampler to support CC/HC steer "
93 "functions.");
94 return ob::InformedSamplerPtr(
95 new CustomPathLengthDirectInfSampler(probDefn, maxNumberCalls));
96 }
97};
98
104class SmoothnessOptimizationObjective : public ob::OptimizationObjective {
105 public:
106 SmoothnessOptimizationObjective(ob::SpaceInformationPtr &space_info)
107 : ob::OptimizationObjective(space_info) {}
108
110 ob::Cost stateCost(const ob::State *s) const override;
111
114 ob::Cost motionCost(const ob::State *s1, const ob::State *s2) const override;
115};
116
129class CurvatureOptimizationObjective : public ob::OptimizationObjective {
130 public:
132 ob::SpaceInformationPtr &space_info,
133 double max_curvature = std::numeric_limits<double>::max())
134 : ob::OptimizationObjective(space_info), max_curvature_(max_curvature) {}
135
137 ob::Cost stateCost(const ob::State *s) const override;
138
141 ob::Cost motionCost(const ob::State *s1, const ob::State *s2) const override;
142
143 protected:
145};
ob::SE2StateSpace::StateType State
Definition: Primitives.h:12
An optimization objective for minimizing curvature of a path.
Definition: OptimizationObjective.h:129
ob::Cost stateCost(const ob::State *s) const override
Returns identity cost.
Definition: OptimizationObjective.cpp:632
double max_curvature_
Definition: OptimizationObjective.h:144
ob::Cost motionCost(const ob::State *s1, const ob::State *s2) const override
Motion cost for this objective is defined as the sum of normalied curvature along the path.
Definition: OptimizationObjective.cpp:636
CurvatureOptimizationObjective(ob::SpaceInformationPtr &space_info, double max_curvature=std::numeric_limits< double >::max())
Definition: OptimizationObjective.h:131
Definition: OptimizationObjective.h:12
CustomPathLengthDirectInfSampler(const ob::ProblemDefinitionPtr &probDefn, unsigned int maxNumberCalls)
Definition: OptimizationObjective.cpp:12
bool sampleUniform(ob::State *statePtr, const ob::Cost &maxCost) override
Definition: OptimizationObjective.cpp:213
bool hasInformedMeasure() const override
Definition: OptimizationObjective.cpp:263
double getInformedMeasure(const ob::Cost &currentCost) const override
Definition: OptimizationObjective.cpp:267
ob::Cost heuristicSolnCost(const ob::State *statePtr) const override
Definition: OptimizationObjective.cpp:296
Definition: OptimizationObjective.h:84
ob::InformedSamplerPtr allocInformedStateSampler(const ob::ProblemDefinitionPtr &probDefn, unsigned int maxNumberCalls) const override
Definition: OptimizationObjective.h:88
CustomPathLengthOptimizationObjective(ob::SpaceInformationPtr &space_info)
Definition: OptimizationObjective.h:86
An optimization objective for minimizing OMPL's smoothness.
Definition: OptimizationObjective.h:104
ob::Cost stateCost(const ob::State *s) const override
Returns identity cost.
Definition: OptimizationObjective.cpp:619
ob::Cost motionCost(const ob::State *s1, const ob::State *s2) const override
Motion cost for this objective is defined as the smoothness between the path between s1 and s2 .
Definition: OptimizationObjective.cpp:623
SmoothnessOptimizationObjective(ob::SpaceInformationPtr &space_info)
Definition: OptimizationObjective.h:106
double max(const std::vector< double > &values)
Definition: PathStatistics.hpp:79