ompl_exo.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2018, University of Edinburgh
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of nor the names of its contributors may be used to
14 // endorse or promote products derived from this software without specific
15 // prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 // POSSIBILITY OF SUCH DAMAGE.
28 //
29 
30 #ifndef EXOTICA_OMPL_SOLVER_OMPL_EXO_H_
31 #define EXOTICA_OMPL_SOLVER_OMPL_EXO_H_
32 
34 
35 #include <ompl/base/SpaceInformation.h>
36 #include <ompl/base/StateSpace.h>
37 #include <ompl/base/StateValidityChecker.h>
38 #include <ompl/base/spaces/DubinsStateSpace.h>
39 #include <ompl/base/spaces/RealVectorStateSpace.h>
40 #include <ompl/base/spaces/SE2StateSpace.h>
41 #include <ompl/base/spaces/SE3StateSpace.h>
42 #include <ompl/geometric/SimpleSetup.h>
43 
44 #include <exotica_ompl_solver/ompl_solver_initializer.h>
45 
46 #if OMPL_VERSION_VALUE >= 1004000 // Version greater than 1.4.0
47 typedef Eigen::Ref<Eigen::VectorXd> OMPLProjection;
48 #else // All other versions
49 typedef ompl::base::EuclideanProjection &OMPLProjection;
50 #endif
51 
52 namespace exotica
53 {
54 class OMPLStateSpace : public ompl::base::CompoundStateSpace
55 {
56 public:
57  OMPLStateSpace(OMPLSolverInitializer init) : ompl::base::CompoundStateSpace(), init_(init)
58  {
59  }
60 
61  virtual void SetBounds(SamplingProblemPtr &prob) = 0;
62  virtual void ExoticaToOMPLState(const Eigen::VectorXd &q, ompl::base::State *state) const = 0;
63  virtual void OMPLToExoticaState(const ompl::base::State *state, Eigen::VectorXd &q) const = 0;
64 
65  virtual ompl::base::StateSamplerPtr allocDefaultStateSampler() const = 0;
66  virtual void StateDebug(const Eigen::VectorXd &q) const = 0;
67 
68 protected:
69  OMPLSolverInitializer init_;
70 };
71 
72 class OMPLStateValidityChecker : public ompl::base::StateValidityChecker
73 {
74 public:
75  OMPLStateValidityChecker(const ompl::base::SpaceInformationPtr &si, const SamplingProblemPtr &prob);
76 
77  bool isValid(const ompl::base::State *state) const override;
78 
79  bool isValid(const ompl::base::State *state, double &dist) const override;
80 
81 protected:
83 };
84 
86 {
87 public:
88  class StateType : public ompl::base::CompoundStateSpace::StateType
89  {
90  public:
91  StateType() : CompoundStateSpace::StateType()
92  {
93  }
94 
95  const ompl::base::RealVectorStateSpace::StateType &getRNSpace() const
96  {
97  return *as<ompl::base::RealVectorStateSpace::StateType>(0);
98  }
99 
100  ompl::base::RealVectorStateSpace::StateType &getRNSpace()
101  {
102  return *as<ompl::base::RealVectorStateSpace::StateType>(0);
103  }
104  };
105  OMPLRNStateSpace(OMPLSolverInitializer init);
106 
107  ompl::base::StateSamplerPtr allocDefaultStateSampler() const override;
108  void SetBounds(SamplingProblemPtr &prob) override;
109  void ExoticaToOMPLState(const Eigen::VectorXd &q, ompl::base::State *state) const override;
110  void OMPLToExoticaState(const ompl::base::State *state, Eigen::VectorXd &q) const override;
111  void StateDebug(const Eigen::VectorXd &q) const override;
112 };
113 
115 {
116 public:
117  class StateType : public ompl::base::CompoundStateSpace::StateType
118  {
119  public:
120  StateType() : CompoundStateSpace::StateType()
121  {
122  }
123 
124  const ompl::base::RealVectorStateSpace::StateType &RealVectorStateSpace() const
125  {
126  return *as<ompl::base::RealVectorStateSpace::StateType>(1);
127  }
128 
129  ompl::base::RealVectorStateSpace::StateType &RealVectorStateSpace()
130  {
131  return *as<ompl::base::RealVectorStateSpace::StateType>(1);
132  }
133 
134  const ompl::base::SE3StateSpace::StateType &SE3StateSpace() const
135  {
136  return *as<ompl::base::SE3StateSpace::StateType>(0);
137  }
138  ompl::base::SE3StateSpace::StateType &SE3StateSpace()
139  {
140  return *as<ompl::base::SE3StateSpace::StateType>(0);
141  }
142  };
143  OMPLSE3RNStateSpace(OMPLSolverInitializer init);
144 
145  ompl::base::StateSamplerPtr allocDefaultStateSampler() const override;
146  void SetBounds(SamplingProblemPtr &prob) override;
147  void ExoticaToOMPLState(const Eigen::VectorXd &q, ompl::base::State *state) const override;
148  void OMPLToExoticaState(const ompl::base::State *state, Eigen::VectorXd &q) const override;
149  void StateDebug(const Eigen::VectorXd &q) const override;
150 
151 private:
152  unsigned int dim_ = 6;
153 };
154 
156 {
157 public:
158  class StateType : public ompl::base::CompoundStateSpace::StateType
159  {
160  public:
161  StateType() : CompoundStateSpace::StateType()
162  {
163  }
164 
165  const ompl::base::RealVectorStateSpace::StateType &RealVectorStateSpace() const
166  {
167  return *as<ompl::base::RealVectorStateSpace::StateType>(1);
168  }
169 
170  ompl::base::RealVectorStateSpace::StateType &RealVectorStateSpace()
171  {
172  return *as<ompl::base::RealVectorStateSpace::StateType>(1);
173  }
174 
175  const ompl::base::SE2StateSpace::StateType &SE2StateSpace() const
176  {
177  return *as<ompl::base::SE2StateSpace::StateType>(0);
178  }
179  ompl::base::SE2StateSpace::StateType &SE2StateSpace()
180  {
181  return *as<ompl::base::SE2StateSpace::StateType>(0);
182  }
183  };
184  OMPLSE2RNStateSpace(OMPLSolverInitializer init);
185 
186  ompl::base::StateSamplerPtr allocDefaultStateSampler() const override;
187  void SetBounds(SamplingProblemPtr &prob) override;
188  void ExoticaToOMPLState(const Eigen::VectorXd &q, ompl::base::State *state) const override;
189  void OMPLToExoticaState(const ompl::base::State *state, Eigen::VectorXd &q) const override;
190  void StateDebug(const Eigen::VectorXd &q) const override;
191 
192 private:
193  unsigned int dim_ = 3;
194 };
195 
197 {
198 public:
199  class StateType : public ompl::base::CompoundStateSpace::StateType
200  {
201  public:
202  StateType() : CompoundStateSpace::StateType()
203  {
204  }
205 
206  const ompl::base::RealVectorStateSpace::StateType &RealVectorStateSpace() const
207  {
208  return *as<ompl::base::RealVectorStateSpace::StateType>(1);
209  }
210 
211  ompl::base::RealVectorStateSpace::StateType &RealVectorStateSpace()
212  {
213  return *as<ompl::base::RealVectorStateSpace::StateType>(1);
214  }
215 
216  const ompl::base::DubinsStateSpace::StateType &DubinsStateSpace() const
217  {
218  return *as<ompl::base::DubinsStateSpace::StateType>(0);
219  }
220  ompl::base::SE2StateSpace::StateType &DubinsStateSpace()
221  {
222  return *as<ompl::base::DubinsStateSpace::StateType>(0);
223  }
224  };
225  OMPLDubinsRNStateSpace(OMPLSolverInitializer init);
226 
227  ompl::base::StateSamplerPtr allocDefaultStateSampler() const override;
228  void SetBounds(SamplingProblemPtr &prob) override;
229  void ExoticaToOMPLState(const Eigen::VectorXd &q, ompl::base::State *state) const override;
230  void OMPLToExoticaState(const ompl::base::State *state, Eigen::VectorXd &q) const override;
231  void StateDebug(const Eigen::VectorXd &q) const override;
232 
233 private:
234  unsigned int dim_ = 3;
235 };
236 
237 class OMPLRNProjection : public ompl::base::ProjectionEvaluator
238 {
239 public:
240  OMPLRNProjection(const ompl::base::StateSpacePtr &space,
241  const std::vector<int> &vars)
242  : ompl::base::ProjectionEvaluator(space), variables_(vars)
243  {
244  }
245 
247  {
248  }
249 
250  unsigned int getDimension(void) const override
251  {
252  return variables_.size();
253  }
254 
255  void defaultCellSizes() override
256  {
257  cellSizes_.clear();
258  cellSizes_.resize(variables_.size(), 0.1);
259  }
260 
261  void project(const ompl::base::State *state,
262  OMPLProjection projection) const override
263  {
264  for (std::size_t i = 0; i < variables_.size(); ++i)
265  projection(i) =
266  state->as<exotica::OMPLRNStateSpace::StateType>()->getRNSpace().values[variables_[i]];
267  }
268 
269 private:
270  std::vector<int> variables_;
271 };
272 
273 class OMPLSE3RNProjection : public ompl::base::ProjectionEvaluator
274 {
275 public:
276  OMPLSE3RNProjection(const ompl::base::StateSpacePtr &space,
277  const std::vector<int> &vars)
278  : ompl::base::ProjectionEvaluator(space), variables_(vars)
279  {
280  }
281 
283  {
284  }
285 
286  unsigned int getDimension(void) const override
287  {
288  return variables_.size();
289  }
290 
291  void defaultCellSizes() override
292  {
293  cellSizes_.clear();
294  cellSizes_.resize(variables_.size(), 0.1);
295  }
296 
297  void project(const ompl::base::State *state,
298  OMPLProjection projection) const override
299  {
300  for (std::size_t i = 0; i < variables_.size(); ++i)
301  projection(i) =
302  state->as<exotica::OMPLSE3RNStateSpace::StateType>()->RealVectorStateSpace().values[variables_[i]];
303  }
304 
305 private:
306  std::vector<int> variables_;
307 };
308 
309 class OMPLSE2RNProjection : public ompl::base::ProjectionEvaluator
310 {
311 public:
312  OMPLSE2RNProjection(const ompl::base::StateSpacePtr &space,
313  const std::vector<int> &vars)
314  : ompl::base::ProjectionEvaluator(space), variables_(vars)
315  {
316  }
317 
319  {
320  }
321 
322  unsigned int getDimension(void) const override
323  {
324  return variables_.size();
325  }
326 
327  void defaultCellSizes() override
328  {
329  cellSizes_.clear();
330  cellSizes_.resize(variables_.size(), 0.1);
331  }
332 
333  void project(const ompl::base::State *state,
334  OMPLProjection projection) const override
335  {
336  for (std::size_t i = 0; i < variables_.size(); ++i)
337  projection(i) =
338  state->as<exotica::OMPLSE2RNStateSpace::StateType>()->RealVectorStateSpace().values[variables_[i]];
339  }
340 
341 private:
342  std::vector<int> variables_;
343 };
344 } // namespace exotica
345 
346 #endif // EXOTICA_OMPL_SOLVER_OMPL_EXO_H_
std::vector< int > variables_
Definition: ompl_exo.h:342
ompl::base::SE2StateSpace::StateType & SE2StateSpace()
Definition: ompl_exo.h:179
virtual void OMPLToExoticaState(const ompl::base::State *state, Eigen::VectorXd &q) const =0
const ompl::base::SE3StateSpace::StateType & SE3StateSpace() const
Definition: ompl_exo.h:134
void defaultCellSizes() override
Definition: ompl_exo.h:291
void project(const ompl::base::State *state, OMPLProjection projection) const override
Definition: ompl_exo.h:333
virtual void SetBounds(SamplingProblemPtr &prob)=0
virtual void StateDebug(const Eigen::VectorXd &q) const =0
virtual void ExoticaToOMPLState(const Eigen::VectorXd &q, ompl::base::State *state) const =0
std::vector< int > variables_
Definition: ompl_exo.h:306
const ompl::base::RealVectorStateSpace::StateType & RealVectorStateSpace() const
Definition: ompl_exo.h:124
ompl::base::SE3StateSpace::StateType & SE3StateSpace()
Definition: ompl_exo.h:138
std::vector< int > variables_
Definition: ompl_exo.h:270
const ompl::base::SE2StateSpace::StateType & SE2StateSpace() const
Definition: ompl_exo.h:175
ompl::base::RealVectorStateSpace::StateType & RealVectorStateSpace()
Definition: ompl_exo.h:129
unsigned int getDimension(void) const override
Definition: ompl_exo.h:250
OMPLSE3RNProjection(const ompl::base::StateSpacePtr &space, const std::vector< int > &vars)
Definition: ompl_exo.h:276
void defaultCellSizes() override
Definition: ompl_exo.h:327
ompl::base::RealVectorStateSpace::StateType & getRNSpace()
Definition: ompl_exo.h:100
const ompl::base::DubinsStateSpace::StateType & DubinsStateSpace() const
Definition: ompl_exo.h:216
OMPLStateSpace(OMPLSolverInitializer init)
Definition: ompl_exo.h:57
virtual ompl::base::StateSamplerPtr allocDefaultStateSampler() const =0
const ompl::base::RealVectorStateSpace::StateType & RealVectorStateSpace() const
Definition: ompl_exo.h:206
std::shared_ptr< exotica::SamplingProblem > SamplingProblemPtr
SamplingProblemPtr prob_
Definition: ompl_exo.h:82
OMPLSE2RNProjection(const ompl::base::StateSpacePtr &space, const std::vector< int > &vars)
Definition: ompl_exo.h:312
const ompl::base::RealVectorStateSpace::StateType & getRNSpace() const
Definition: ompl_exo.h:95
unsigned int getDimension(void) const override
Definition: ompl_exo.h:286
OMPLRNProjection(const ompl::base::StateSpacePtr &space, const std::vector< int > &vars)
Definition: ompl_exo.h:240
void project(const ompl::base::State *state, OMPLProjection projection) const override
Definition: ompl_exo.h:261
ompl::base::SE2StateSpace::StateType & DubinsStateSpace()
Definition: ompl_exo.h:220
const ompl::base::RealVectorStateSpace::StateType & RealVectorStateSpace() const
Definition: ompl_exo.h:165
OMPLSolverInitializer init_
Definition: ompl_exo.h:69
unsigned int getDimension(void) const override
Definition: ompl_exo.h:322
ompl::base::RealVectorStateSpace::StateType & RealVectorStateSpace()
Definition: ompl_exo.h:170
ompl::base::EuclideanProjection & OMPLProjection
Definition: ompl_exo.h:49
void defaultCellSizes() override
Definition: ompl_exo.h:255
ompl::base::RealVectorStateSpace::StateType & RealVectorStateSpace()
Definition: ompl_exo.h:211
void project(const ompl::base::State *state, OMPLProjection projection) const override
Definition: ompl_exo.h:297


exotica_ompl_solver
Author(s): Yiming Yang
autogenerated on Sat Apr 10 2021 02:36:37