sbpl_interface.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 *
00004 *  Copyright (c) 2012, Willow Garage, Inc.
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 Willow Garage 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 #include <sbpl_interface/sbpl_interface.h>
00036 #include <planning_models/conversions.h>
00037 //#include <valgrind/callgrind.h>
00038 
00039 
00040 namespace sbpl_interface {
00041 
00042 bool SBPLInterface::solve(const planning_scene::PlanningSceneConstPtr& planning_scene,
00043                           const moveit_msgs::GetMotionPlan::Request &req,
00044                           moveit_msgs::GetMotionPlan::Response &res,
00045                           const PlanningParameters& params) const
00046 {
00047   res.trajectory.joint_trajectory.points.clear();
00048   (const_cast<SBPLInterface*>(this))->last_planning_statistics_ = PlanningStatistics();
00049   planning_models::RobotState *start_state(planning_scene->getCurrentState());
00050   planning_models::robotStateMsgToRobotState(*planning_scene->getTransforms(), req.motion_plan_request.start_state, start_state);
00051 
00052   ros::WallTime wt = ros::WallTime::now();
00053   boost::shared_ptr<EnvironmentChain3D> env_chain(new EnvironmentChain3D(planning_scene));
00054   if(!env_chain->setupForMotionPlan(planning_scene,
00055                                     req,
00056                                     res,
00057                                     params)){
00058     //std::cerr << "Env chain setup failing" << std::endl;
00059     return false;
00060   }
00061   //std::cerr << "Creation with params " << params.use_bfs_ << " took " << (ros::WallTime::now()-wt).toSec() << std::endl;
00062   boost::this_thread::interruption_point();
00063 
00064   //DummyEnvironment* dummy_env = new DummyEnvironment();
00065   boost::shared_ptr<ARAPlanner> planner(new ARAPlanner(env_chain.get(), true));
00066   planner->set_initialsolution_eps(100.0);
00067   planner->set_search_mode(true);
00068   planner->force_planning_from_scratch();
00069   planner->set_start(env_chain->getPlanningData().start_hash_entry_->stateID);
00070   planner->set_goal(env_chain->getPlanningData().goal_hash_entry_->stateID);
00071   //std::cerr << "Creation took " << (ros::WallTime::now()-wt) << std::endl;
00072   std::vector<int> solution_state_ids;
00073   int solution_cost;
00074   wt = ros::WallTime::now();
00075   //CALLGRIND_START_INSTRUMENTATION;
00076   bool b_ret = planner->replan(10.0, &solution_state_ids, &solution_cost);
00077   //CALLGRIND_STOP_INSTRUMENTATION;
00078   double el = (ros::WallTime::now()-wt).toSec();
00079   std::cerr << "B ret is " << b_ret << " planning time " << el << std::endl;
00080   std::cerr << "Expansions " << env_chain->getPlanningStatistics().total_expansions_
00081             << " average time " << (env_chain->getPlanningStatistics().total_expansion_time_.toSec()/(env_chain->getPlanningStatistics().total_expansions_*1.0))
00082             << " hz " << 1.0/(env_chain->getPlanningStatistics().total_expansion_time_.toSec()/(env_chain->getPlanningStatistics().total_expansions_*1.0))
00083             << std::endl;
00084   std::cerr << "Total coll checks " << env_chain->getPlanningStatistics().coll_checks_ << " hz " << 1.0/(env_chain->getPlanningStatistics().total_coll_check_time_.toSec()/(env_chain->getPlanningStatistics().coll_checks_*1.0)) << std::endl;
00085   std::cerr << "Path length is " << solution_state_ids.size() << std::endl;
00086   if(!b_ret) {
00087     res.error_code.val = moveit_msgs::MoveItErrorCodes::PLANNING_FAILED;
00088     return false;
00089   }
00090   if(solution_state_ids.size() == 0) {
00091     std::cerr << "Success but no path" << std::endl;
00092     res.error_code.val = moveit_msgs::MoveItErrorCodes::INVALID_MOTION_PLAN;
00093     return false;
00094   }
00095   if(!env_chain->populateTrajectoryFromStateIDSequence(solution_state_ids,
00096                                                        res.trajectory.joint_trajectory)) {
00097     std::cerr << "Success but path bad" << std::endl;
00098     res.error_code.val = moveit_msgs::MoveItErrorCodes::INVALID_MOTION_PLAN;
00099     return false;
00100   }
00101   ros::WallTime pre_short = ros::WallTime::now();
00102   //std::cerr << "Num traj points before " << res.trajectory.joint_trajectory.points.size() << std::endl;
00103   trajectory_msgs::JointTrajectory traj = res.trajectory.joint_trajectory;
00104   env_chain->attemptShortcut(traj, res.trajectory.joint_trajectory);
00105   //std::cerr << "Num traj points after " << res.trajectory.joint_trajectory.points.size() << std::endl;
00106   //std::cerr << "Time " << (ros::WallTime::now()-pre_short).toSec() << std::endl;
00107   //env_chain->getPlaneBFSMarker(mark, env_chain->getGoalPose().translation().z());
00108   res.error_code.val = moveit_msgs::MoveItErrorCodes::SUCCESS;
00109   PlanningStatistics stats = env_chain->getPlanningStatistics();
00110   stats.total_planning_time_ = ros::WallDuration(el);
00111   (const_cast<SBPLInterface*>(this))->last_planning_statistics_ = stats;
00112   return true;
00113 }
00114 
00115 }


sbpl_interface
Author(s): Gil Jones
autogenerated on Mon Oct 6 2014 11:11:34