reachable_valid_pose_filter.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 /* Author: Ioan Sucan */
00036 
00037 #include <moveit/pick_place/reachable_valid_pose_filter.h>
00038 #include <moveit/kinematic_constraints/utils.h>
00039 #include <eigen_conversions/eigen_msg.h>
00040 #include <boost/bind.hpp>
00041 #include <ros/console.h>
00042 
00043 namespace pick_place
00044 {
00045 
00046 ReachableAndValidPoseFilter::ReachableAndValidPoseFilter(const planning_scene::PlanningSceneConstPtr &scene,
00047                                                          const collision_detection::AllowedCollisionMatrixConstPtr &collision_matrix,
00048                                                          const constraint_samplers::ConstraintSamplerManagerPtr &constraints_sampler_manager) :
00049   ManipulationStage("reachable & valid pose filter"),
00050   planning_scene_(scene),
00051   collision_matrix_(collision_matrix),
00052   constraints_sampler_manager_(constraints_sampler_manager)
00053 {
00054 }
00055 
00056 bool ReachableAndValidPoseFilter::isStateCollisionFree(const ManipulationPlan *manipulation_plan,
00057                                                        robot_state::JointStateGroup *joint_state_group,
00058                                                        const std::vector<double> &joint_group_variable_values) const
00059 {
00060   joint_state_group->setVariableValues(joint_group_variable_values);
00061   // apply approach posture for the end effector (we always apply it here since it could be the case the sampler changes this posture)
00062   joint_state_group->getRobotState()->setStateValues(manipulation_plan->approach_posture_);
00063 
00064   collision_detection::CollisionRequest req;
00065   collision_detection::CollisionResult res;
00066   req.verbose = verbose_;
00067   req.group_name = manipulation_plan->shared_data_->planning_group_;
00068   planning_scene_->checkCollision(req, res, *joint_state_group->getRobotState(), *collision_matrix_);
00069   if (res.collision == false)
00070     return planning_scene_->isStateFeasible(*joint_state_group->getRobotState());
00071   else
00072     return false;
00073 }
00074 
00075 bool ReachableAndValidPoseFilter::isEndEffectorFree(const ManipulationPlanPtr &plan, robot_state::RobotState &token_state) const
00076 {
00077   tf::poseMsgToEigen(plan->goal_pose_.pose, plan->transformed_goal_pose_);
00078   plan->transformed_goal_pose_ = planning_scene_->getFrameTransform(token_state, plan->goal_pose_.header.frame_id) * plan->transformed_goal_pose_;
00079   token_state.updateStateWithLinkAt(plan->shared_data_->ik_link_name_, plan->transformed_goal_pose_);
00080   collision_detection::CollisionRequest req;
00081   req.verbose = verbose_;
00082   collision_detection::CollisionResult res;
00083   req.group_name = plan->shared_data_->end_effector_group_;
00084   planning_scene_->checkCollision(req, res, token_state, *collision_matrix_);
00085   return res.collision == false;
00086 }
00087 
00088 bool ReachableAndValidPoseFilter::evaluate(const ManipulationPlanPtr &plan) const
00089 {
00090   // initialize with scene state
00091   robot_state::RobotStatePtr token_state(new robot_state::RobotState(planning_scene_->getCurrentState()));
00092   if (isEndEffectorFree(plan, *token_state))
00093   {
00094     // update the goal pose message if anything has changed; this is because the name of the frame in the input goal pose
00095     // can be that of objects in the collision world but most components are unaware of those transforms,
00096     // so we convert to a frame that is certainly known
00097     if (robot_state::Transforms::sameFrame(planning_scene_->getPlanningFrame(), plan->goal_pose_.header.frame_id))
00098     {
00099       tf::poseEigenToMsg(plan->transformed_goal_pose_, plan->goal_pose_.pose);
00100       plan->goal_pose_.header.frame_id = planning_scene_->getPlanningFrame();
00101     }
00102 
00103     // convert the pose we want to reach to a set of constraints
00104     plan->goal_constraints_ = kinematic_constraints::constructGoalConstraints(plan->shared_data_->ik_link_name_, plan->goal_pose_);
00105 
00106     const std::string &planning_group = plan->shared_data_->planning_group_;
00107 
00108     // construct a sampler for the specified constraints; this can end up calling just IK, but it is more general
00109     // and allows for robot-specific samplers, producing samples that also change the base position if needed, etc
00110     plan->goal_sampler_ = constraints_sampler_manager_->selectSampler(planning_scene_, planning_group, plan->goal_constraints_);
00111     if (plan->goal_sampler_)
00112     {
00113       plan->goal_sampler_->setStateValidityCallback(boost::bind(&ReachableAndValidPoseFilter::isStateCollisionFree, this, plan.get(), _1, _2));
00114       plan->goal_sampler_->setVerbose(verbose_);
00115       if (plan->goal_sampler_->sample(token_state->getJointStateGroup(planning_group), *token_state, plan->shared_data_->max_goal_sampling_attempts_))
00116       {
00117         plan->possible_goal_states_.push_back(token_state);
00118         return true;
00119       }
00120       else
00121         if (verbose_)
00122           ROS_INFO("Sampler failed to produce a state");
00123     }
00124     else
00125       ROS_ERROR_THROTTLE(1, "No sampler was constructed");
00126   }
00127   plan->error_code_.val = moveit_msgs::MoveItErrorCodes::GOAL_IN_COLLISION;
00128   return false;
00129 }
00130 
00131 }


manipulation
Author(s): Ioan Sucan , Sachin Chitta
autogenerated on Mon Oct 6 2014 02:33:06