SyclopEST.cpp
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2011, 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: Matt Maly */
36 
37 #include "ompl/control/planners/syclop/SyclopEST.h"
38 #include "ompl/base/goals/GoalSampleableRegion.h"
39 
41 {
42  Syclop::setup();
43  sampler_ = si_->allocStateSampler();
44  controlSampler_ = siC_->allocControlSampler();
45  lastGoalMotion_ = nullptr;
46 }
47 
49 {
50  Syclop::clear();
51  freeMemory();
52  motions_.clear();
53  lastGoalMotion_ = nullptr;
54 }
55 
57 {
58  Planner::getPlannerData(data);
59 
60  double delta = siC_->getPropagationStepSize();
61 
62  if (lastGoalMotion_ != nullptr)
63  data.addGoalVertex(lastGoalMotion_->state);
64 
65  for (auto motion : motions_)
66  {
67  if (motion->parent != nullptr)
68  {
69  if (data.hasControls())
70  data.addEdge(base::PlannerDataVertex(motion->parent->state), base::PlannerDataVertex(motion->state),
71  control::PlannerDataEdgeControl(motion->control, motion->steps * delta));
72  else
73  data.addEdge(base::PlannerDataVertex(motion->parent->state), base::PlannerDataVertex(motion->state));
74  }
75  else
76  data.addStartVertex(base::PlannerDataVertex(motion->state));
77  }
78 }
79 
81 {
82  auto *motion = new Motion(siC_);
83  si_->copyState(motion->state, s);
84  siC_->nullControl(motion->control);
85  motions_.push_back(motion);
86  return motion;
87 }
88 
89 void ompl::control::SyclopEST::selectAndExtend(Region &region, std::vector<Motion *> &newMotions)
90 {
91  Motion *treeMotion = region.motions[rng_.uniformInt(0, region.motions.size() - 1)];
92  Control *rctrl = siC_->allocControl();
93  base::State *newState = si_->allocState();
94 
95  controlSampler_->sample(rctrl, treeMotion->state);
96  unsigned int duration =
97  controlSampler_->sampleStepCount(siC_->getMinControlDuration(), siC_->getMaxControlDuration());
98  duration = siC_->propagateWhileValid(treeMotion->state, rctrl, duration, newState);
99 
100  if (duration >= siC_->getMinControlDuration())
101  {
102  auto *motion = new Motion(siC_);
103  si_->copyState(motion->state, newState);
104  siC_->copyControl(motion->control, rctrl);
105  motion->steps = duration;
106  motion->parent = treeMotion;
107  motions_.push_back(motion);
108  newMotions.push_back(motion);
109 
110  lastGoalMotion_ = motion;
111  }
112 
113  siC_->freeControl(rctrl);
114  si_->freeState(newState);
115 }
116 
118 {
119  for (auto m : motions_)
120  {
121  if (m->state != nullptr)
122  si_->freeState(m->state);
123  if (m->control != nullptr)
124  siC_->freeControl(m->control);
125  delete m;
126  }
127 }
Definition of an abstract control.
Definition: Control.h:111
void getPlannerData(base::PlannerData &data) const override
Get information about the current run of the motion planner. Repeated calls to this function will upd...
Definition: SyclopEST.cpp:56
Representation of an edge in PlannerData for planning with controls. This structure encodes a specifi...
Definition: PlannerData.h:124
void freeMemory()
Free the memory allocated by this planner.
Definition: SyclopEST.cpp:117
Definition of an abstract state.
Definition: State.h:113
void clear() override
Clear all internal datastructures. Planner settings are not affected. Subsequent calls to solve() wil...
Definition: SyclopEST.cpp:48
Object containing planner generated vertex and edge data. It is assumed that all vertices are unique,...
Definition: PlannerData.h:238
void clear() override
Clear all internal datastructures. Planner settings are not affected. Subsequent calls to solve() wil...
Definition: Syclop.cpp:64
void setup() override
Perform extra configuration steps, if needed. This call will also issue a call to ompl::base::SpaceIn...
Definition: Syclop.cpp:49
Representation of a motion.
Definition: Syclop.h:352
Motion * lastGoalMotion_
The most recent goal motion. Used for PlannerData computation.
Definition: SyclopEST.h:176
const SpaceInformation * siC_
Handle to the control::SpaceInformation object.
Definition: Syclop.h:480
void setup() override
Perform extra configuration steps, if needed. This call will also issue a call to ompl::base::SpaceIn...
Definition: SyclopEST.cpp:40
SpaceInformationPtr si_
The space information for which planning is done.
Definition: Planner.h:474
unsigned int addStartVertex(const PlannerDataVertex &v)
Adds the given vertex to the graph data, and marks it as a start vertex. The vertex index is returned...
ControlSamplerPtr allocControlSampler() const
Allocate a control sampler.
virtual bool addEdge(unsigned int v1, unsigned int v2, const PlannerDataEdge &edge=PlannerDataEdge(), Cost weight=Cost(1.0))
Adds a directed edge between the given vertex indexes. An optional edge structure and weight can be s...
unsigned int addGoalVertex(const PlannerDataVertex &v)
Adds the given vertex to the graph data, and marks it as a start vertex. The vertex index is returned...
Syclop::Motion * addRoot(const base::State *s) override
Add State s as a new root in the low-level tree, and return the Motion corresponding to s.
Definition: SyclopEST.cpp:80
Base class for a vertex in the PlannerData structure. All derived classes must implement the clone an...
Definition: PlannerData.h:122
virtual bool hasControls() const
Indicate whether any information about controls (ompl::control::Control) is stored in this instance.