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
00036
00037 #include <gtest/gtest.h>
00038 #include <urdf_parser/urdf_parser.h>
00039 #include <chomp_motion_planner/chomp_planner.h>
00040 #include <chomp_motion_planner/chomp_parameters.h>
00041 #include <moveit_msgs/GetMotionPlan.h>
00042 #include <kinematic_constraints/utils.h>
00043 #include <planning_models/conversions.h>
00044 #include <collision_distance_field/collision_detector_allocator_distance_field.h>
00045 #include <rdf_loader/rdf_loader.h>
00046
00047 class Pr2ChompPlannerTester : public testing::Test{
00048
00049 protected:
00050
00051 virtual void SetUp()
00052 {
00053
00054 rml_.reset(new rdf_loader::RDFLoader("robot_description"));
00055
00056 acm_.reset(new collision_detection::AllowedCollisionMatrix());
00057
00058 ros::NodeHandle nh;
00059
00060 XmlRpc::XmlRpcValue coll_ops;
00061 nh.getParam("robot_description_planning/default_collision_operations", coll_ops);
00062
00063 if (coll_ops.getType() != XmlRpc::XmlRpcValue::TypeArray)
00064 {
00065 ROS_WARN("default_collision_operations is not an array");
00066 return;
00067 }
00068
00069 if (coll_ops.size() == 0)
00070 {
00071 ROS_WARN("No collision operations in default collision operations");
00072 return;
00073 }
00074
00075 for (int i = 0 ; i < coll_ops.size() ; ++i)
00076 {
00077 if (!coll_ops[i].hasMember("object1") || !coll_ops[i].hasMember("object2") || !coll_ops[i].hasMember("operation"))
00078 {
00079 ROS_WARN("All collision operations must have two objects and an operation");
00080 continue;
00081 }
00082 acm_->setEntry(std::string(coll_ops[i]["object1"]), std::string(coll_ops[i]["object2"]), std::string(coll_ops[i]["operation"]) == "disable");
00083 }
00084 }
00085
00086 virtual void TearDown()
00087 {
00088
00089 }
00090
00091 protected:
00092
00093 boost::shared_ptr<rdf_loader::RDFLoader> rml_;
00094 collision_detection::AllowedCollisionMatrixPtr acm_;
00095
00096 };
00097
00098 TEST_F(Pr2ChompPlannerTester, SimplePlan)
00099 {
00100 planning_scene::PlanningScenePtr ps(new planning_scene::PlanningScene());
00101 ps->setActiveCollisionDetector(collision_detection::CollisionDetectorAllocatorDistanceField::create());
00102 ps->configure(rml_->getURDF(), rml_->getSRDF());
00103 ASSERT_TRUE(ps->isConfigured());
00104 ps->getAllowedCollisionMatrixNonConst() = *acm_;
00105
00106 chomp::ChompPlanner chomp_planner(ps->getRobotModel());
00107
00108 moveit_msgs::GetMotionPlan::Request mplan_req;
00109 moveit_msgs::GetMotionPlan::Response mplan_res;
00110 mplan_req.motion_plan_request.group_name = "right_arm";
00111 mplan_req.motion_plan_request.num_planning_attempts = 5;
00112 mplan_req.motion_plan_request.allowed_planning_time = ros::Duration(5.0);
00113 const std::vector<std::string>& joint_names = ps->getRobotModel()->getJointModelGroup("right_arm")->getJointModelNames();
00114 mplan_req.motion_plan_request.goal_constraints.resize(1);
00115 mplan_req.motion_plan_request.goal_constraints[0].joint_constraints.resize(joint_names.size());
00116 for(unsigned int i = 0; i < joint_names.size(); i++)
00117 {
00118 mplan_req.motion_plan_request.goal_constraints[0].joint_constraints[i].joint_name = joint_names[i];
00119 mplan_req.motion_plan_request.goal_constraints[0].joint_constraints[i].position = 0.0;
00120 mplan_req.motion_plan_request.goal_constraints[0].joint_constraints[i].tolerance_above = 0.001;
00121 mplan_req.motion_plan_request.goal_constraints[0].joint_constraints[i].tolerance_below = 0.001;
00122 mplan_req.motion_plan_request.goal_constraints[0].joint_constraints[i].weight = 1.0;
00123 }
00124 mplan_req.motion_plan_request.goal_constraints[0].joint_constraints[0].position = -2.0;
00125 mplan_req.motion_plan_request.goal_constraints[0].joint_constraints[3].position = -.2;
00126 mplan_req.motion_plan_request.goal_constraints[0].joint_constraints[5].position = -.2;
00127
00128 chomp::ChompParameters params;
00129 chomp_planner.solve(ps,
00130 mplan_req,
00131 params,
00132 mplan_res);
00133
00134 ASSERT_EQ(mplan_res.error_code.val, mplan_res.error_code.SUCCESS);
00135 EXPECT_GT(mplan_res.trajectory.joint_trajectory.points.size(), 0);
00136 }
00137
00138 int main(int argc, char **argv)
00139 {
00140 testing::InitGoogleTest(&argc, argv);
00141 ros::init(argc, argv, "test_chomp_planning");
00142
00143 return RUN_ALL_TESTS();
00144 }