All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
ControlSampler.cpp
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 #include "ompl/control/ControlSampler.h"
38 #include "ompl/control/ControlSpace.h"
39 
40 void ompl::control::ControlSampler::sample(Control *control, const base::State * /* state */)
41 {
42  sample(control);
43 }
44 
45 void ompl::control::ControlSampler::sampleNext(Control *control, const Control * /* previous */)
46 {
47  sample(control);
48 }
49 
50 void ompl::control::ControlSampler::sampleNext(Control *control, const Control * /* previous */, const base::State * /* state */)
51 {
52  sample(control);
53 }
54 
55 unsigned int ompl::control::ControlSampler::sampleStepCount(unsigned int minSteps, unsigned int maxSteps)
56 {
57  return rng_.uniformInt(minSteps, maxSteps);
58 }
59 
61 {
62  samplers_.push_back(sampler);
63  samplerCount_ = samplers_.size();
64 }
65 
67 {
68  Control **comps = static_cast<CompoundControl*>(control)->components;
69  for (unsigned int i = 0 ; i < samplerCount_ ; ++i)
70  samplers_[i]->sample(comps[i]);
71 }
72 
74 {
75  Control **comps = static_cast<CompoundControl*>(control)->components;
76  for (unsigned int i = 0 ; i < samplerCount_ ; ++i)
77  samplers_[i]->sample(comps[i], state);
78 }
79 
81 {
82  Control **comps = static_cast<CompoundControl*>(control)->components;
83  const Control * const *prev = static_cast<const CompoundControl*>(previous)->components;
84  for (unsigned int i = 0 ; i < samplerCount_ ; ++i)
85  samplers_[i]->sampleNext(comps[i], prev[i]);
86 }
87 
89 {
90  Control **comps = static_cast<CompoundControl*>(control)->components;
91  const Control * const *prev = static_cast<const CompoundControl*>(previous)->components;
92  for (unsigned int i = 0 ; i < samplerCount_ ; ++i)
93  samplers_[i]->sampleNext(comps[i], prev[i], state);
94 }
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 boost shared pointer wrapper for ompl::control::ControlSampler.
Definition of a compound control.
Definition: Control.h:93
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...
Definition of an abstract state.
Definition: State.h:50
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...