Program Listing for File Lightning.h

Return to documentation for file (src/ompl/tools/lightning/Lightning.h)

/*********************************************************************
 * Software License Agreement (BSD License)
 *
 *  Copyright (c) 2014, JSK, The University of Tokyo.
 *  All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above
 *     copyright notice, this list of conditions and the following
 *     disclaimer in the documentation and/or other materials provided
 *     with the distribution.
 *   * Neither the name of the JSK, The University of Tokyo nor the names of its
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 *  POSSIBILITY OF SUCH DAMAGE.
 *********************************************************************/

/* Author: Dave Coleman
   Desc:   Implementation of the Lightning Framework for experienced-based planning

   Paper:  Berenson, Dmitry, Pieter Abbeel, and Ken Goldberg.
           "A robot path planning framework that learns from experience."
           Robotics and Automation (ICRA), 2012 IEEE International Conference on. IEEE, 2012.

   Notes:  The user of this class should invoke the loading and saving from file, otherwise experiences
           will be lost.
*/

#ifndef OMPL_TOOLS_LIGHTNING_LIGHTNING_
#define OMPL_TOOLS_LIGHTNING_LIGHTNING_

#include "ompl/tools/experience/ExperienceSetup.h"
#include "ompl/base/Planner.h"
#include "ompl/base/PlannerData.h"
#include "ompl/base/ProblemDefinition.h"
#include "ompl/base/SpaceInformation.h"
#include "ompl/base/ProblemDefinition.h"

#include "ompl/geometric/PathGeometric.h"
#include "ompl/geometric/PathSimplifier.h"
#include "ompl/geometric/planners/experience/LightningRetrieveRepair.h"

#include "ompl/tools/multiplan/ParallelPlan.h"
#include "ompl/tools/config/SelfConfig.h"

#include "ompl/util/Console.h"
#include "ompl/util/Exception.h"

#include "ompl/tools/lightning/DynamicTimeWarp.h"

namespace ompl
{
    namespace tools
    {
        // class LightningDB; // forward declaration
        OMPL_CLASS_FORWARD(LightningDB);
        OMPL_CLASS_FORWARD(ParallelPlan);

        OMPL_CLASS_FORWARD(Lightning);

        class Lightning : public ompl::tools::ExperienceSetup
        {
        public:
            explicit Lightning(const base::SpaceInformationPtr &si);

            explicit Lightning(const base::StateSpacePtr &space);

        private:
            void initialize();

        public:
            void printResultsInfo(std::ostream &out = std::cout) const override;

            void printLogs(std::ostream &out = std::cout) const override;

            ompl::geometric::LightningRetrieveRepair &getLightningRetrieveRepairPlanner() const
            {
                return static_cast<ompl::geometric::LightningRetrieveRepair &>(*rrPlanner_);
            }

            void setRepairPlanner(const base::PlannerPtr &planner) override
            {
                static_cast<og::LightningRetrieveRepair &>(*rrPlanner_).setRepairPlanner(planner);
            }

            void setPlannerAllocator(const base::PlannerAllocator &pa)
            {
                pa_ = pa;
                planner_.reset();
                // note: the rrPlanner_ never uses the allocator so does not need to be reset
                configured_ = false;
            }

            base::PlannerStatus solve(double time = 1.0) override;

            base::PlannerStatus solve(const base::PlannerTerminationCondition &ptc) override;

            bool save() override;

            bool saveIfChanged() override;

            void clear() override;

            void print(std::ostream &out = std::cout) const override;

            void setup() override;

            void getAllPlannerDatas(std::vector<ompl::base::PlannerDataPtr> &plannerDatas) const override;

            std::size_t getExperiencesCount() const override;

            void convertPlannerData(const ompl::base::PlannerDataPtr &plannerData,
                                    ompl::geometric::PathGeometric &path);

            const ompl::tools::DynamicTimeWarpPtr &getDynamicTimeWarp() const
            {
                return dtw_;
            }

        protected:
            bool reversePathIfNecessary(ompl::geometric::PathGeometric &path1, ompl::geometric::PathGeometric &path2);

            base::PlannerPtr rrPlanner_;

            ompl::tools::ParallelPlanPtr pp_;

            ompl::tools::LightningDBPtr experienceDB_;

            ompl::tools::DynamicTimeWarpPtr dtw_;

        };  // end of class Lightning

    }  // end of namespace

}  // end of namespace
#endif