ControlSampler.h
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2010, Rice University
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Rice University nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34 
35 /* Author: Ioan Sucan */
36 
37 #ifndef OMPL_CONTROL_CONTROL_SAMPLER_
38 #define OMPL_CONTROL_CONTROL_SAMPLER_
39 
40 #include "ompl/base/State.h"
41 #include "ompl/control/Control.h"
42 #include "ompl/util/RandomNumbers.h"
43 #include "ompl/util/ClassForward.h"
44 #include <vector>
45 #include <functional>
46 
47 namespace ompl
48 {
49  namespace control
50  {
51 
53  OMPL_CLASS_FORWARD(ControlSpace);
55 
57 
58  OMPL_CLASS_FORWARD(ControlSampler);
60 
70  {
71  public:
72  // non-copyable
73  ControlSampler(const ControlSampler&) = delete;
74  ControlSampler& operator=(const ControlSampler&) = delete;
75 
77  ControlSampler(const ControlSpace *space) : space_(space)
78  {
79  }
80 
81  virtual ~ControlSampler()
82  {
83  }
84 
88  virtual void sample(Control *control) = 0;
89 
98  virtual void sample(Control *control, const base::State *state);
99 
107  virtual void sampleNext(Control *control, const Control *previous);
108 
116  virtual void sampleNext(Control *control, const Control *previous, const base::State *state);
117 
119  virtual unsigned int sampleStepCount(unsigned int minSteps, unsigned int maxSteps);
120 
121  protected:
122 
125 
128  };
129 
132  {
133  public:
134 
137  {
138  }
139 
142  {
143  }
144 
148  virtual void addSampler(const ControlSamplerPtr &sampler);
149 
150 
151  virtual void sample(Control *control);
152  virtual void sample(Control *control, const base::State *state);
153  virtual void sampleNext(Control *control, const Control *previous);
154  virtual void sampleNext(Control *control, const Control *previous, const base::State *state);
155 
156  protected:
157 
159  std::vector<ControlSamplerPtr> samplers_;
160 
161  private:
162 
164  unsigned int samplerCount_;
165 
166  };
167 
169  typedef std::function<ControlSamplerPtr(const ControlSpace*)> ControlSamplerAllocator;
170  }
171 }
172 
173 
174 #endif
Abstract definition of a control sampler. Motion planners that need to sample controls will call func...
Definition of a compound control sampler. This is useful to construct samplers for compound controls...
Definition of an abstract control.
Definition: Control.h:48
virtual void sample(Control *control)=0
Sample a control. All other control sampling functions default to this one, unless a user-specified i...
virtual void addSampler(const ControlSamplerPtr &sampler)
Add a sampler as part of the new compound sampler. This sampler is used to sample part of the compoun...
A shared pointer wrapper for ompl::control::ControlSampler.
const ControlSpace * space_
The control space this sampler operates on.
std::function< ControlSamplerPtr(const ControlSpace *)> ControlSamplerAllocator
Definition of a function that can allocate a control sampler.
Random number generation. An instance of this class cannot be used by multiple threads at once (membe...
Definition: RandomNumbers.h:58
virtual ~CompoundControlSampler()
Destructor. This frees the added samplers as well.
std::vector< ControlSamplerPtr > samplers_
The instances of samplers used for compound sampler.
virtual unsigned int sampleStepCount(unsigned int minSteps, unsigned int maxSteps)
Sample a number of steps to execute a control for.
virtual void sample(Control *control)
Sample a control. All other control sampling functions default to this one, unless a user-specified i...
A control space representing the space of applicable controls.
Definition: ControlSpace.h:65
Definition of an abstract state.
Definition: State.h:50
RNG rng_
Instance of random number generator.
virtual void sampleNext(Control *control, const Control *previous)
Sample a control, given the previously applied control. The default implementation calls the first de...
virtual void sampleNext(Control *control, const Control *previous)
Sample a control, given the previously applied control. The default implementation calls the first de...
ControlSampler(const ControlSpace *space)
Constructor takes the state space to construct samples for as argument.
CompoundControlSampler(const ControlSpace *space)
Constructor.