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 <sbpl_interface/sbpl_interface.h>
00040 #include <moveit_msgs/GetMotionPlan.h>
00041 #include <kinematic_constraints/utils.h>
00042 #include <planning_models/conversions.h>
00043 #include <collision_distance_field/collision_world_hybrid.h>
00044 #include <collision_distance_field_ros/collision_robot_hybrid_ros.h>
00045 #include <rdf_loader/rdf_loader.h>
00046
00047 class Pr2SBPLPlannerTester : 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
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231 TEST_F(Pr2SBPLPlannerTester, HardPlan3)
00232 {
00233 planning_scene::PlanningScenePtr ps(new planning_scene::PlanningScene());
00234 ps->setActiveCollisionDetector(collision_detection::CollisionDetectorAllocatorHybridROS::create());
00235 ps->configure(rml_->getURDF(), rml_->getSRDF());
00236 ASSERT_TRUE(ps->isConfigured());
00237 ps->getAllowedCollisionMatrixNonConst() = *acm_;
00238
00239 planning_models::RobotState *::JointStateGroup* start_jsg = ps->getCurrentState().getJointStateGroup("right_arm");
00240 std::vector<double> start_vals(7);
00241 start_vals[0] = -.785163;
00242 start_vals[1] = -.346628;
00243 start_vals[2] = -2.36346;
00244 start_vals[3] = -0.204096;
00245 start_vals[4] = -1.75754;
00246 start_vals[5] = -0.771607;
00247 start_vals[6] = 1.67731;
00248 start_jsg->setStateValues(start_vals);
00249
00250 sbpl_interface::SBPLInterface sbpl_planner(ps->getRobotModel());
00251
00252 moveit_msgs::GetMotionPlan::Request mplan_req;
00253 moveit_msgs::GetMotionPlan::Response mplan_res;
00254 mplan_req.motion_plan_request.group_name = "right_arm";
00255 mplan_req.motion_plan_request.num_planning_attempts = 5;
00256 mplan_req.motion_plan_request.allowed_planning_time = ros::Duration(5.0);
00257 const std::vector<std::string>& joint_names = ps->getRobotModel()->getJointModelGroup("right_arm")->getJointModelNames();
00258 mplan_req.motion_plan_request.goal_constraints.resize(1);
00259 mplan_req.motion_plan_request.goal_constraints[0].joint_constraints.resize(joint_names.size());
00260 for(unsigned int i = 0; i < joint_names.size(); i++)
00261 {
00262 mplan_req.motion_plan_request.goal_constraints[0].joint_constraints[i].joint_name = joint_names[i];
00263 mplan_req.motion_plan_request.goal_constraints[0].joint_constraints[i].position = 0.0;
00264 mplan_req.motion_plan_request.goal_constraints[0].joint_constraints[i].tolerance_above = 0.001;
00265 mplan_req.motion_plan_request.goal_constraints[0].joint_constraints[i].tolerance_below = 0.001;
00266 mplan_req.motion_plan_request.goal_constraints[0].joint_constraints[i].weight = 1.0;
00267 }
00268
00269 std::vector<double> goal_vals(7);
00270 goal_vals[0] = -1.78778;
00271 goal_vals[1] = 0.749619;
00272 goal_vals[2] = 0.594005;
00273 goal_vals[3] = -1.83274;
00274 goal_vals[4] = 1.5158;
00275 goal_vals[5] = -.500754;
00276 goal_vals[6] = -.108037;
00277
00278 mplan_req.motion_plan_request.goal_constraints[0].joint_constraints[0].position = goal_vals[0];
00279 mplan_req.motion_plan_request.goal_constraints[0].joint_constraints[1].position = goal_vals[1];
00280 mplan_req.motion_plan_request.goal_constraints[0].joint_constraints[2].position = goal_vals[2];
00281 mplan_req.motion_plan_request.goal_constraints[0].joint_constraints[3].position = goal_vals[3];
00282 mplan_req.motion_plan_request.goal_constraints[0].joint_constraints[4].position = goal_vals[4];
00283 mplan_req.motion_plan_request.goal_constraints[0].joint_constraints[5].position = goal_vals[5];
00284 mplan_req.motion_plan_request.goal_constraints[0].joint_constraints[6].position = goal_vals[6];
00285
00286 sbpl_planner.solve(ps,
00287 mplan_req,
00288 mplan_res);
00289
00290 ASSERT_EQ(mplan_res.error_code.val, mplan_res.error_code.SUCCESS);
00291 EXPECT_GT(mplan_res.trajectory.joint_trajectory.points.size(), 0);
00292 }
00293
00294 static const unsigned int NUM_TRIALS = 100;
00295
00296 TEST_F(Pr2SBPLPlannerTester, ManyPlan)
00297 {
00298 planning_scene::PlanningScenePtr ps(new planning_scene::PlanningScene());
00299 ps->setActiveCollisionDetector(collision_detection::CollisionDetectorAllocatorHybridROS::create());
00300 ps->configure(rml_->getURDF(), rml_->getSRDF());
00301 ASSERT_TRUE(ps->isConfigured());
00302 ps->getAllowedCollisionMatrixNonConst() = *acm_;
00303
00304 planning_models::RobotState *::JointStateGroup* start_jsg = ps->getCurrentState().getJointStateGroup("right_arm");
00305 planning_models::RobotState *goal_state(ps->getCurrentState());
00306 planning_models::RobotState *::JointStateGroup* goal_jsg = goal_state.getJointStateGroup("right_arm");
00307
00308 sbpl_interface::SBPLInterface sbpl_planner(ps->getRobotModel());
00309
00310 moveit_msgs::GetMotionPlan::Request mplan_req;
00311 mplan_req.motion_plan_request.group_name = "right_arm";
00312 mplan_req.motion_plan_request.num_planning_attempts = 5;
00313 mplan_req.motion_plan_request.allowed_planning_time = ros::Duration(5.0);
00314 const std::vector<std::string>& joint_names = ps->getRobotModel()->getJointModelGroup("right_arm")->getJointModelNames();
00315 mplan_req.motion_plan_request.goal_constraints.resize(1);
00316 mplan_req.motion_plan_request.goal_constraints[0].joint_constraints.resize(joint_names.size());
00317 for(unsigned int i = 0; i < joint_names.size(); i++)
00318 {
00319 mplan_req.motion_plan_request.goal_constraints[0].joint_constraints[i].joint_name = joint_names[i];
00320 mplan_req.motion_plan_request.goal_constraints[0].joint_constraints[i].position = 0.0;
00321 mplan_req.motion_plan_request.goal_constraints[0].joint_constraints[i].tolerance_above = 0.001;
00322 mplan_req.motion_plan_request.goal_constraints[0].joint_constraints[i].tolerance_below = 0.001;
00323 mplan_req.motion_plan_request.goal_constraints[0].joint_constraints[i].weight = 1.0;
00324 }
00325
00326 unsigned int comp_trials = 0;
00327 unsigned int succ_trials = 0;
00328 double max_planning_time = 0.0;
00329 double total_planning_time = 0.0;
00330 while(comp_trials < NUM_TRIALS) {
00331 while(1) {
00332 start_jsg->setToRandomValues();
00333 goal_jsg->setToRandomValues();
00334 std::vector<double> goal_vals;
00335 goal_jsg->getGroupStateValues(goal_vals);
00336 for(unsigned int i = 0; i < joint_names.size(); i++) {
00337 mplan_req.motion_plan_request.goal_constraints[0].joint_constraints[i].position = goal_vals[i];
00338 }
00339 std::vector<double> start_vals;
00340 start_jsg->getGroupStateValues(start_vals);
00341 for(unsigned int i = 0; i < start_vals.size(); i++) {
00342 std::cerr << "Start joint " << i << " val " << start_vals[i] << std::endl;
00343 }
00344 for(unsigned int i = 0; i < goal_vals.size(); i++) {
00345 std::cerr << "Goal joint " << i << " val " << goal_vals[i] << std::endl;
00346 }
00347 moveit_msgs::GetMotionPlan::Response mplan_res;
00348 if(sbpl_planner.solve(ps,
00349 mplan_req,
00350 mplan_res)) {
00351 comp_trials++;
00352 succ_trials++;
00353 if(sbpl_planner.getLastPlanningStatistics().total_planning_time_.toSec() > max_planning_time) {
00354 max_planning_time = sbpl_planner.getLastPlanningStatistics().total_planning_time_.toSec();
00355 }
00356 ASSERT_LT(sbpl_planner.getLastPlanningStatistics().total_planning_time_.toSec(), 5.0);
00357 total_planning_time += sbpl_planner.getLastPlanningStatistics().total_planning_time_.toSec();
00358 break;
00359 } else {
00360 if(mplan_res.error_code.val != moveit_msgs::MoveItErrorCodes::GOAL_IN_COLLISION &&
00361 mplan_res.error_code.val != moveit_msgs::MoveItErrorCodes::START_STATE_IN_COLLISION) {
00362 std::cerr << "Bad error code " << mplan_res.error_code.val << std::endl;
00363 comp_trials++;
00364 break;
00365 } else {
00366
00367 }
00368 }
00369 }
00370 }
00371
00372 std::cerr << "Average planning time " << total_planning_time/(comp_trials*1.0) << " max " << max_planning_time << std::endl;
00373 EXPECT_EQ(succ_trials, comp_trials);
00374
00375
00376
00377 }
00378
00379 int main(int argc, char **argv)
00380 {
00381 testing::InitGoogleTest(&argc, argv);
00382 ros::init(argc, argv, "test_sbpl_planning");
00383
00384 return RUN_ALL_TESTS();
00385 }