All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
SyclopEST.cpp
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 *
00004 *  Copyright (c) 2011, Rice University
00005 *  All rights reserved.
00006 *
00007 *  Redistribution and use in source and binary forms, with or without
00008 *  modification, are permitted provided that the following conditions
00009 *  are met:
00010 *
00011 *   * Redistributions of source code must retain the above copyright
00012 *     notice, this list of conditions and the following disclaimer.
00013 *   * Redistributions in binary form must reproduce the above
00014 *     copyright notice, this list of conditions and the following
00015 *     disclaimer in the documentation and/or other materials provided
00016 *     with the distribution.
00017 *   * Neither the name of the Rice University nor the names of its
00018 *     contributors may be used to endorse or promote products derived
00019 *     from this software without specific prior written permission.
00020 *
00021 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 *  POSSIBILITY OF SUCH DAMAGE.
00033 *********************************************************************/
00034 
00035 /* Author: Matt Maly */
00036 
00037 #include "ompl/control/planners/syclop/SyclopEST.h"
00038 #include "ompl/base/GoalSampleableRegion.h"
00039 
00040 void ompl::control::SyclopEST::setup(void)
00041 {
00042     Syclop::setup();
00043     sampler_ = si_->allocStateSampler();
00044     controlSampler_ = siC_->allocControlSampler();
00045 }
00046 
00047 void ompl::control::SyclopEST::clear(void)
00048 {
00049     Syclop::clear();
00050     freeMemory();
00051     motions_.clear();
00052 }
00053 
00054 void ompl::control::SyclopEST::getPlannerData(base::PlannerData& data) const
00055 {
00056     Planner::getPlannerData(data);
00057     if (PlannerData *cpd = dynamic_cast<control::PlannerData*>(&data))
00058     {
00059         const double delta = siC_->getPropagationStepSize();
00060 
00061         for (std::vector<Motion*>::const_iterator i = motions_.begin(); i != motions_.end(); ++i)
00062         {
00063             const Motion* m = *i;
00064             if (m->parent)
00065                 cpd->recordEdge(m->parent->state, m->state, m->control, m->steps * delta);
00066             else
00067                 cpd->recordEdge(NULL, m->state, NULL, 0.);
00068         }
00069     }
00070     else
00071     {
00072         for (std::vector<Motion*>::const_iterator i = motions_.begin(); i != motions_.end(); ++i)
00073         {
00074             const Motion* m = *i;
00075             data.recordEdge(m->parent ? m->parent->state : NULL, m->state);
00076         }
00077     }
00078 }
00079 
00080 ompl::control::Syclop::Motion* ompl::control::SyclopEST::addRoot(const base::State* s)
00081 {
00082     Motion* motion = new Motion(siC_);
00083     si_->copyState(motion->state, s);
00084     siC_->nullControl(motion->control);
00085     motions_.push_back(motion);
00086     return motion;
00087 }
00088 
00089 void ompl::control::SyclopEST::selectAndExtend(Region& region, std::vector<Motion*>& newMotions)
00090 {
00091     Motion* treeMotion = region.motions[rng_.uniformInt(0, region.motions.size()-1)];
00092     Control* rctrl = siC_->allocControl();
00093     base::State* newState = si_->allocState();
00094 
00095     controlSampler_->sample(rctrl, treeMotion->state);
00096     unsigned int duration = controlSampler_->sampleStepCount(siC_->getMinControlDuration(), siC_->getMaxControlDuration());
00097     duration = siC_->propagateWhileValid(treeMotion->state, rctrl, duration, newState);
00098 
00099     if (duration >= siC_->getMinControlDuration())
00100     {
00101         Motion* motion = new Motion(siC_);
00102         si_->copyState(motion->state, newState);
00103         siC_->copyControl(motion->control, rctrl);
00104         motion->steps = duration;
00105         motion->parent = treeMotion;
00106         motions_.push_back(motion);
00107         newMotions.push_back(motion);
00108     }
00109 
00110     siC_->freeControl(rctrl);
00111     si_->freeState(newState);
00112 }
00113 
00114 void ompl::control::SyclopEST::freeMemory(void)
00115 {
00116     for (std::vector<Motion*>::iterator i = motions_.begin(); i != motions_.end(); ++i)
00117     {
00118         Motion* m = *i;
00119         if (m->state)
00120             si_->freeState(m->state);
00121         if (m->control)
00122             siC_->freeControl(m->control);
00123         delete m;
00124     }
00125 }
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends