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 */,
51  const base::State * /* state */)
52 {
53  sample(control);
54 }
55 
56 unsigned int ompl::control::ControlSampler::sampleStepCount(unsigned int minSteps, unsigned int maxSteps)
57 {
58  return rng_.uniformInt(minSteps, maxSteps);
59 }
60 
62 {
63  samplers_.push_back(sampler);
64  samplerCount_ = samplers_.size();
65 }
66 
68 {
69  Control **comps = static_cast<CompoundControl *>(control)->components;
70  for (unsigned int i = 0; i < samplerCount_; ++i)
71  samplers_[i]->sample(comps[i]);
72 }
73 
75 {
76  Control **comps = static_cast<CompoundControl *>(control)->components;
77  for (unsigned int i = 0; i < samplerCount_; ++i)
78  samplers_[i]->sample(comps[i], state);
79 }
80 
82 {
83  Control **comps = static_cast<CompoundControl *>(control)->components;
84  const Control *const *prev = static_cast<const CompoundControl *>(previous)->components;
85  for (unsigned int i = 0; i < samplerCount_; ++i)
86  samplers_[i]->sampleNext(comps[i], prev[i]);
87 }
88 
90  const base::State *state)
91 {
92  Control **comps = static_cast<CompoundControl *>(control)->components;
93  const Control *const *prev = static_cast<const CompoundControl *>(previous)->components;
94  for (unsigned int i = 0; i < samplerCount_; ++i)
95  samplers_[i]->sampleNext(comps[i], prev[i], state);
96 }
Definition of an abstract control.
Definition: Control.h:111
Definition of an abstract state.
Definition: State.h:113
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...
Definition of a compound control.
Definition: Control.h:148
virtual unsigned int sampleStepCount(unsigned int minSteps, unsigned int maxSteps)
Sample a number of steps to execute a control for.
void sampleNext(Control *control, const Control *previous) override
Sample a control, given the previously applied control. The default implementation calls the first de...
A shared pointer wrapper for ompl::control::ControlSampler.
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 sampleNext(Control *control, const Control *previous)
Sample a control, given the previously applied control. The default implementation calls the first de...
void sample(Control *control) override
Sample a control. All other control sampling functions default to this one, unless a user-specified i...