Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include <sbpl_interface/sbpl_interface.h>
00036 #include <planning_models/conversions.h>
00037
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
00059 return false;
00060 }
00061
00062 boost::this_thread::interruption_point();
00063
00064
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
00072 std::vector<int> solution_state_ids;
00073 int solution_cost;
00074 wt = ros::WallTime::now();
00075
00076 bool b_ret = planner->replan(10.0, &solution_state_ids, &solution_cost);
00077
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
00103 trajectory_msgs::JointTrajectory traj = res.trajectory.joint_trajectory;
00104 env_chain->attemptShortcut(traj, res.trajectory.joint_trajectory);
00105
00106
00107
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 }