grasp_evaluator_fast_tests.cpp
Go to the documentation of this file.
00001 #include <planning_scene_monitor/planning_scene_monitor.h>
00002 #include <kinematics_constraint_aware/kinematics_solver_constraint_aware.h>
00003 #include <kinematics_plugin_loader/kinematics_plugin_loader.h>
00004 #include <grasp_place_evaluation/grasp_evaluator_fast.h>
00005 
00006 #include <gtest/gtest.h>
00007 
00008 
00009 class MoveitManipulationTester : public ::testing::Test {
00010 
00011 protected:
00012 
00013 
00014   virtual void SetUp() {
00015 
00016     ros::NodeHandle nh;
00017 
00018     planning_scene_monitor_.reset(new planning_scene_monitor::PlanningSceneMonitor("robot_description"));
00019 
00020     planning_scene_diff_.reset(new planning_scene::PlanningScene(planning_scene_monitor_->getPlanningScene()));
00021 
00022     kinematics_plugin_loader_.reset(new kinematics_plugin_loader::KinematicsPluginLoader());
00023 
00024     kinematics_plugin_loader::KinematicsLoaderFn kinematics_allocator = kinematics_plugin_loader_->getLoaderFunction();
00025 
00026     const planning_models::RobotModel::JointModelGroup* right_arm_group
00027       = planning_scene_diff_->getRobotModel()->getJointModelGroup("right_arm");
00028 
00029     const planning_models::RobotModel::JointModelGroup* left_arm_group
00030       = planning_scene_diff_->getRobotModel()->getJointModelGroup("left_arm");
00031 
00032     std::map<std::string, kinematics::KinematicsBasePtr> solver_map;
00033     solver_map["right_arm"] = kinematics_allocator(right_arm_group);
00034     solver_map["left_arm"] = kinematics_allocator(left_arm_group);
00035 
00036     grasp_evaluator_fast_.reset(new grasp_place_evaluation::GraspEvaluatorFast(planning_scene_diff_->getRobotModel(),
00037                                                                                solver_map));
00038 
00039     moveit_msgs::CollisionObject obj;
00040     obj.header.frame_id = planning_scene_diff_->getPlanningFrame();
00041     obj.operation = moveit_msgs::CollisionObject::ADD;
00042     obj.id = "obj";
00043     obj.shapes.resize(1);
00044     obj.shapes[0].type = shape_msgs::Shape::CYLINDER;
00045     obj.shapes[0].dimensions.resize(2);
00046     obj.shapes[0].dimensions[0] = .02;
00047     obj.shapes[0].dimensions[1] = .1;
00048     obj.poses.resize(1);
00049     obj.poses[0].position.x = .65;
00050     obj.poses[0].position.y = -.15;
00051     obj.poses[0].position.z = 1.0;
00052     obj.poses[0].orientation.w = 1.0;
00053 
00054     planning_scene_diff_->processCollisionObjectMsg(obj);
00055   }
00056 
00057   virtual void TearDown() {
00058     grasp_evaluator_fast_.reset();
00059     planning_scene_diff_.reset();
00060     planning_scene_monitor_.reset();
00061     kinematics_plugin_loader_.reset();
00062   }
00063 
00064 protected:
00065 
00066   boost::shared_ptr<kinematics_plugin_loader::KinematicsPluginLoader> kinematics_plugin_loader_;
00067   boost::shared_ptr<planning_scene_monitor::PlanningSceneMonitor> planning_scene_monitor_;
00068   boost::shared_ptr<planning_scene::PlanningScene> planning_scene_diff_;
00069   boost::shared_ptr<grasp_place_evaluation::GraspEvaluatorFast> grasp_evaluator_fast_;
00070 };
00071 
00072 TEST_F(MoveitManipulationTester, GraspCollideAttachedObject) {
00073 
00074   ROS_INFO_STREAM("Test");
00075 
00076   moveit_msgs::CollisionObject obj;
00077   obj.header.frame_id = planning_scene_diff_->getPlanningFrame();
00078   obj.operation = moveit_msgs::CollisionObject::ADD;
00079   obj.id = "box";
00080   obj.shapes.resize(1);
00081   obj.shapes[0].type = shape_msgs::Shape::BOX;
00082   obj.shapes[0].dimensions.resize(3);
00083   obj.shapes[0].dimensions[0] = .1;
00084   obj.shapes[0].dimensions[1] = .1;
00085   obj.shapes[0].dimensions[2] = .1;
00086   obj.poses.resize(1);
00087   obj.poses[0].position.x = .65;
00088   obj.poses[0].position.y = -.15;
00089   obj.poses[0].position.z = 1.1;
00090   obj.poses[0].orientation.w = 1.0;
00091 
00092   planning_scene_diff_->processCollisionObjectMsg(obj);
00093 
00094   moveit_manipulation_msgs::PickupGoal goal;
00095   goal.arm_name = "right_arm";
00096   goal.collision_object_name = "obj";
00097 
00098   goal.target.collision_name = "obj";
00099   goal.target.reference_frame_id = planning_scene_diff_->getPlanningFrame();
00100 
00101   goal.lift.direction.vector.z=1;
00102   goal.lift.desired_distance = .1;
00103 
00104   std::vector<moveit_manipulation_msgs::Grasp> grasps;
00105   grasps.resize(1);
00106   grasps[0].grasp_pose.position.x = .50;
00107   grasps[0].grasp_pose.position.y = -.15;
00108   grasps[0].grasp_pose.position.z = 1.0;
00109   grasps[0].grasp_pose.orientation.w = 1.0;
00110   grasps[0].desired_approach_distance = .1;
00111   grasps[0].min_approach_distance = .1;
00112 
00113   grasp_place_evaluation::GraspExecutionInfoVector execution_info;
00114 
00115   grasp_evaluator_fast_->testGrasps(planning_scene_diff_,
00116                                     &planning_scene_diff_->getCurrentState(),
00117                                     goal,
00118                                     grasps,
00119                                     execution_info,
00120                                     true);
00121   ASSERT_EQ(execution_info.size(),1);
00122   //low enough that box should be in collision with the gripper
00123   EXPECT_EQ(execution_info[0].result_.result_code, moveit_manipulation_msgs::GraspResult::LIFT_IN_COLLISION);
00124 
00125   collision_detection::CollisionWorld::ObjectConstPtr obj_ptr = planning_scene_diff_->getWorld()->getObject("box");
00126 
00127   //out of the way altogether
00128   obj.poses[0].position.z = 2.0;
00129   Eigen::Affine3d np;
00130   planning_models::poseFromMsg(obj.poses[0], np);
00131   planning_scene_diff_->getWorldNonConst()->moveShapeInObject("box", obj_ptr->shapes_[0], np);
00132 
00133   grasp_evaluator_fast_->testGrasps(planning_scene_diff_,
00134                                     &planning_scene_diff_->getCurrentState(),
00135                                     goal,
00136                                     grasps,
00137                                     execution_info,
00138                                     true);
00139   ASSERT_EQ(execution_info.size(),1);
00140   //low enough that box should be in collision with the gripper
00141   EXPECT_EQ(execution_info[0].result_.result_code, moveit_manipulation_msgs::GraspResult::SUCCESS);
00142 
00143   //only in contact with attached object
00144   obj.poses[0].position.z = 1.15;
00145   planning_models::poseFromMsg(obj.poses[0], np);
00146   planning_scene_diff_->getWorldNonConst()->moveShapeInObject("box", obj_ptr->shapes_[0], np);
00147 
00148   grasp_evaluator_fast_->testGrasps(planning_scene_diff_,
00149                                     &planning_scene_diff_->getCurrentState(),
00150                                     goal,
00151                                     grasps,
00152                                     execution_info,
00153                                     true);
00154   ASSERT_EQ(execution_info.size(),1);
00155   EXPECT_EQ(execution_info[0].result_.result_code, moveit_manipulation_msgs::GraspResult::LIFT_IN_COLLISION);
00156 }
00157 
00158 TEST_F(MoveitManipulationTester, GraspInWorldFrameOK) {
00159 
00160   moveit_manipulation_msgs::PickupGoal goal;
00161   goal.arm_name = "right_arm";
00162   goal.collision_object_name = "obj";
00163 
00164   goal.target.collision_name = "obj";
00165   goal.target.reference_frame_id = planning_scene_diff_->getPlanningFrame();
00166 
00167   goal.lift.direction.vector.z=1;
00168   goal.lift.desired_distance = .1;
00169 
00170   std::vector<moveit_manipulation_msgs::Grasp> grasps;
00171   grasps.resize(1);
00172   grasps[0].grasp_pose.position.x = .50;
00173   grasps[0].grasp_pose.position.y = -.15;
00174   grasps[0].grasp_pose.position.z = 1.0;
00175   grasps[0].grasp_pose.orientation.w = 1.0;
00176   grasps[0].desired_approach_distance = .1;
00177   grasps[0].min_approach_distance = .1;
00178 
00179   grasp_place_evaluation::GraspExecutionInfoVector execution_info;
00180 
00181   grasp_evaluator_fast_->testGrasps(planning_scene_diff_,
00182                                     &planning_scene_diff_->getCurrentState(),
00183                                     goal,
00184                                     grasps,
00185                                     execution_info,
00186                                     true);
00187   ASSERT_EQ(execution_info.size(),1);
00188   EXPECT_EQ(execution_info[0].result_.result_code, moveit_manipulation_msgs::GraspResult::SUCCESS);
00189 }
00190 
00191 int main(int argc, char** argv)
00192 {
00193   testing::InitGoogleTest(&argc, argv);
00194   ros::init(argc, argv, "pr2_moveit_manipulation_tests");
00195   return RUN_ALL_TESTS();
00196 }


pr2_test_moveit_manipulation
Author(s): Gil Jones
autogenerated on Mon Oct 6 2014 11:16:08