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 <moveit/kinematic_constraints/kinematic_constraint.h>
00038 #include <gtest/gtest.h>
00039 #include <urdf_parser/urdf_parser.h>
00040 #include <fstream>
00041 #include <eigen_conversions/eigen_msg.h>
00042 #include <boost/filesystem/path.hpp>
00043 #include <moveit_resources/config.h>
00044
00045 class LoadPlanningModelsPr2 : public testing::Test
00046 {
00047 protected:
00048 virtual void SetUp()
00049 {
00050 boost::filesystem::path res_path(MOVEIT_TEST_RESOURCES_DIR);
00051
00052 srdf_model.reset(new srdf::Model());
00053 std::string xml_string;
00054 std::fstream xml_file((res_path / "pr2_description/urdf/robot.xml").string().c_str(), std::fstream::in);
00055 if (xml_file.is_open())
00056 {
00057 while (xml_file.good())
00058 {
00059 std::string line;
00060 std::getline(xml_file, line);
00061 xml_string += (line + "\n");
00062 }
00063 xml_file.close();
00064 urdf_model = urdf::parseURDF(xml_string);
00065 }
00066 else
00067 {
00068 FAIL() << "Failed to find robot.xml";
00069 }
00070 srdf_model->initFile(*urdf_model, (res_path / "pr2_description/srdf/robot.xml").string());
00071 kmodel.reset(new robot_model::RobotModel(urdf_model, srdf_model));
00072 };
00073
00074 virtual void TearDown()
00075 {
00076 }
00077
00078 protected:
00079 boost::shared_ptr<urdf::ModelInterface> urdf_model;
00080 boost::shared_ptr<srdf::Model> srdf_model;
00081 robot_model::RobotModelPtr kmodel;
00082 };
00083
00084 TEST_F(LoadPlanningModelsPr2, JointConstraintsSimple)
00085 {
00086 robot_state::RobotState ks(kmodel);
00087 ks.setToDefaultValues();
00088 robot_state::Transforms tf(kmodel->getModelFrame());
00089
00090 kinematic_constraints::JointConstraint jc(kmodel);
00091 moveit_msgs::JointConstraint jcm;
00092 jcm.joint_name = "head_pan_joint";
00093 jcm.position = 0.4;
00094 jcm.tolerance_above = 0.1;
00095 jcm.tolerance_below = 0.05;
00096
00097 EXPECT_TRUE(jc.configure(jcm));
00098
00099 EXPECT_NEAR(jc.getConstraintWeight(), 1.0, std::numeric_limits<double>::epsilon());
00100
00101
00102
00103 EXPECT_TRUE(jc.configure(jcm));
00104 kinematic_constraints::ConstraintEvaluationResult p1 = jc.decide(ks);
00105 EXPECT_FALSE(p1.satisfied);
00106 EXPECT_NEAR(p1.distance, jcm.position, 1e-6);
00107
00108
00109
00110 double jval = 0.41;
00111 ks.setJointPositions(jcm.joint_name, &jval);
00112 kinematic_constraints::ConstraintEvaluationResult p2 = jc.decide(ks);
00113 EXPECT_TRUE(p2.satisfied);
00114 EXPECT_NEAR(p2.distance, 0.01, 1e-6);
00115
00116
00117 jval = 0.35;
00118 ks.setJointPositions(jcm.joint_name, &jval);
00119 EXPECT_TRUE(jc.decide(ks).satisfied);
00120
00121
00122
00123 jval = 0.35 - std::numeric_limits<double>::epsilon();
00124
00125 ks.setJointPositions(jcm.joint_name, &jval);
00126 EXPECT_TRUE(jc.decide(ks).satisfied);
00127
00128
00129 jval = 0.35 - 3 * std::numeric_limits<double>::epsilon();
00130 ks.setJointPositions(jcm.joint_name, &jval);
00131 EXPECT_FALSE(jc.decide(ks).satisfied);
00132
00133
00134 jcm.tolerance_below = -0.05;
00135 EXPECT_FALSE(jc.configure(jcm));
00136
00137 jcm.tolerance_below = 0.05;
00138 EXPECT_TRUE(jc.configure(jcm));
00139
00140
00141 jval = 0.46;
00142 ks.setJointPositions(jcm.joint_name, &jval);
00143 EXPECT_TRUE(jc.decide(ks).satisfied);
00144
00145
00146 jval = 0.501;
00147 ks.setJointPositions(jcm.joint_name, &jval);
00148 EXPECT_FALSE(jc.decide(ks).satisfied);
00149
00150
00151 jval = 0.39;
00152 ks.setJointPositions(jcm.joint_name, &jval);
00153 EXPECT_TRUE(jc.decide(ks).satisfied);
00154
00155
00156 jval = 0.34;
00157 ks.setJointPositions(jcm.joint_name, &jval);
00158 EXPECT_FALSE(jc.decide(ks).satisfied);
00159
00160
00161 kinematic_constraints::JointConstraint jc2(kmodel);
00162 EXPECT_TRUE(jc2.configure(jcm));
00163 EXPECT_TRUE(jc2.enabled());
00164 EXPECT_TRUE(jc.equal(jc2, 1e-12));
00165
00166
00167 jcm.joint_name = "head_tilt_joint";
00168 EXPECT_TRUE(jc2.configure(jcm));
00169 EXPECT_FALSE(jc.equal(jc2, 1e-12));
00170
00171
00172 jcm.joint_name = "head_pan_joint";
00173 jcm.position = 0.3;
00174 EXPECT_TRUE(jc2.configure(jcm));
00175 EXPECT_FALSE(jc.equal(jc2, 1e-12));
00176
00177 EXPECT_FALSE(jc.equal(jc2, .1));
00178 EXPECT_TRUE(jc.equal(jc2, .101));
00179
00180
00181 jcm.joint_name = "";
00182 jcm.position = 0.4;
00183 EXPECT_FALSE(jc2.configure(jcm));
00184 EXPECT_FALSE(jc2.enabled());
00185 EXPECT_FALSE(jc.equal(jc2, 1e-12));
00186
00187
00188 jcm.joint_name = "base_footprint_joint";
00189 EXPECT_FALSE(jc2.configure(jcm));
00190
00191
00192 jcm.joint_name = "head_pan_joint";
00193 EXPECT_TRUE(jc2.configure(jcm));
00194 jc2.clear();
00195 EXPECT_FALSE(jc2.enabled());
00196 EXPECT_FALSE(jc.equal(jc2, 1e-12));
00197 }
00198
00199 TEST_F(LoadPlanningModelsPr2, JointConstraintsCont)
00200 {
00201 robot_state::RobotState ks(kmodel);
00202 ks.setToDefaultValues();
00203 ks.update();
00204 robot_state::Transforms tf(kmodel->getModelFrame());
00205
00206 kinematic_constraints::JointConstraint jc(kmodel);
00207 moveit_msgs::JointConstraint jcm;
00208
00209 jcm.joint_name = "l_wrist_roll_joint";
00210 jcm.position = 0.0;
00211 jcm.tolerance_above = 0.04;
00212 jcm.tolerance_below = 0.02;
00213 jcm.weight = 1.0;
00214
00215 EXPECT_TRUE(jc.configure(jcm));
00216
00217 std::map<std::string, double> jvals;
00218
00219
00220 EXPECT_TRUE(jc.decide(ks).satisfied);
00221
00222
00223 jvals[jcm.joint_name] = .03;
00224 ks.setVariablePositions(jvals);
00225 ks.update();
00226 EXPECT_TRUE(jc.decide(ks).satisfied);
00227
00228
00229 jvals[jcm.joint_name] = .05;
00230 ks.setVariablePositions(jvals);
00231 ks.update();
00232 EXPECT_FALSE(jc.decide(ks).satisfied);
00233
00234
00235 jvals[jcm.joint_name] = -.01;
00236 ks.setVariablePositions(jvals);
00237 EXPECT_TRUE(jc.decide(ks).satisfied);
00238
00239
00240 jvals[jcm.joint_name] = -.03;
00241 ks.setVariablePositions(jvals);
00242 EXPECT_FALSE(jc.decide(ks).satisfied);
00243
00244
00245 jcm.position = 3.14;
00246 EXPECT_TRUE(jc.configure(jcm));
00247
00248
00249 jvals[jcm.joint_name] = 3.17;
00250 ks.setVariablePositions(jvals);
00251 kinematic_constraints::ConstraintEvaluationResult p1 = jc.decide(ks);
00252 EXPECT_TRUE(p1.satisfied);
00253 EXPECT_NEAR(p1.distance, 0.03, 1e-6);
00254
00255
00256 jvals[jcm.joint_name] = -3.14;
00257 ks.setVariablePositions(jvals);
00258 kinematic_constraints::ConstraintEvaluationResult p2 = jc.decide(ks);
00259 EXPECT_TRUE(p2.satisfied);
00260 EXPECT_NEAR(p2.distance, 0.003185, 1e-4);
00261
00262
00263 jvals[jcm.joint_name] = 3.19;
00264 ks.setVariablePositions(jvals);
00265 EXPECT_FALSE(jc.decide(ks).satisfied);
00266
00267
00268
00269 jvals[jcm.joint_name] = -3.11;
00270 ks.setVariablePositions(jvals);
00271 EXPECT_TRUE(jc.decide(ks).satisfied);
00272
00273
00274 jvals[jcm.joint_name] = -3.09;
00275 ks.setVariablePositions(jvals);
00276 EXPECT_FALSE(jc.decide(ks).satisfied);
00277
00278
00279
00280 jvals[jcm.joint_name] = 3.13;
00281 ks.setVariablePositions(jvals);
00282 EXPECT_TRUE(jc.decide(ks).satisfied);
00283
00284
00285 jvals[jcm.joint_name] = 3.11;
00286 ks.setVariablePositions(jvals);
00287 EXPECT_FALSE(jc.decide(ks).satisfied);
00288
00289
00290 jcm.position = -3.14;
00291 EXPECT_TRUE(jc.configure(jcm));
00292
00293
00294 jvals[jcm.joint_name] = -3.11;
00295 ks.setVariablePositions(jvals);
00296 EXPECT_TRUE(jc.decide(ks).satisfied);
00297
00298
00299 jvals[jcm.joint_name] = -3.09;
00300 ks.setVariablePositions(jvals);
00301 EXPECT_FALSE(jc.decide(ks).satisfied);
00302
00303
00304 jvals[jcm.joint_name] = 3.13;
00305 ks.setVariablePositions(jvals);
00306 EXPECT_TRUE(jc.decide(ks).satisfied);
00307
00308
00309 jvals[jcm.joint_name] = 3.12;
00310 ks.setVariablePositions(jvals);
00311 EXPECT_TRUE(jc.decide(ks).satisfied);
00312
00313
00314 jcm.position = 6.28;
00315 EXPECT_TRUE(jc.configure(jcm));
00316
00317
00318 jvals[jcm.joint_name] = 0.0;
00319 ks.setVariablePositions(jvals);
00320 EXPECT_TRUE(jc.decide(ks).satisfied);
00321
00322
00323 moveit_msgs::JointConstraint jcm2 = jcm;
00324 jcm2.position = -6.28;
00325 kinematic_constraints::JointConstraint jc2(kmodel);
00326 EXPECT_TRUE(jc.configure(jcm2));
00327 jc.equal(jc2, .02);
00328 }
00329
00330 TEST_F(LoadPlanningModelsPr2, JointConstraintsMultiDOF)
00331 {
00332 robot_state::RobotState ks(kmodel);
00333 ks.setToDefaultValues();
00334
00335 kinematic_constraints::JointConstraint jc(kmodel);
00336 moveit_msgs::JointConstraint jcm;
00337 jcm.joint_name = "world_joint";
00338 jcm.position = 3.14;
00339 jcm.tolerance_above = 0.1;
00340 jcm.tolerance_below = 0.05;
00341 jcm.weight = 1.0;
00342
00343
00344 EXPECT_FALSE(jc.configure(jcm));
00345
00346
00347 jcm.joint_name = "world_joint/x";
00348 EXPECT_TRUE(jc.configure(jcm));
00349
00350 std::map<std::string, double> jvals;
00351 jvals[jcm.joint_name] = 3.2;
00352 ks.setVariablePositions(jvals);
00353 kinematic_constraints::ConstraintEvaluationResult p1 = jc.decide(ks);
00354 EXPECT_TRUE(p1.satisfied);
00355
00356 jvals[jcm.joint_name] = 3.25;
00357 ks.setVariablePositions(jvals);
00358 kinematic_constraints::ConstraintEvaluationResult p2 = jc.decide(ks);
00359 EXPECT_FALSE(p2.satisfied);
00360
00361 jvals[jcm.joint_name] = -3.14;
00362 ks.setVariablePositions(jvals);
00363 kinematic_constraints::ConstraintEvaluationResult p3 = jc.decide(ks);
00364 EXPECT_FALSE(p3.satisfied);
00365
00366
00367 jcm.joint_name = "world_joint/theta";
00368 EXPECT_TRUE(jc.configure(jcm));
00369
00370 jvals[jcm.joint_name] = -3.14;
00371 ks.setVariablePositions(jvals);
00372 kinematic_constraints::ConstraintEvaluationResult p4 = jc.decide(ks);
00373 EXPECT_TRUE(p4.satisfied);
00374
00375 jvals[jcm.joint_name] = 3.25;
00376 ks.setVariablePositions(jvals);
00377 kinematic_constraints::ConstraintEvaluationResult p5 = jc.decide(ks);
00378 EXPECT_FALSE(p5.satisfied);
00379 }
00380
00381 TEST_F(LoadPlanningModelsPr2, PositionConstraintsFixed)
00382 {
00383 robot_state::RobotState ks(kmodel);
00384 ks.setToDefaultValues();
00385 ks.update(true);
00386 robot_state::Transforms tf(kmodel->getModelFrame());
00387 kinematic_constraints::PositionConstraint pc(kmodel);
00388 moveit_msgs::PositionConstraint pcm;
00389
00390
00391 EXPECT_FALSE(pc.configure(pcm, tf));
00392
00393 pcm.link_name = "l_wrist_roll_link";
00394 pcm.target_point_offset.x = 0;
00395 pcm.target_point_offset.y = 0;
00396 pcm.target_point_offset.z = 0;
00397 pcm.constraint_region.primitives.resize(1);
00398 pcm.constraint_region.primitives[0].type = shape_msgs::SolidPrimitive::SPHERE;
00399
00400
00401 EXPECT_FALSE(pc.configure(pcm, tf));
00402
00403 pcm.constraint_region.primitives[0].dimensions.resize(1);
00404 pcm.constraint_region.primitives[0].dimensions[0] = 0.2;
00405
00406
00407 EXPECT_FALSE(pc.configure(pcm, tf));
00408
00409 pcm.constraint_region.primitive_poses.resize(1);
00410 pcm.constraint_region.primitive_poses[0].position.x = 0.55;
00411 pcm.constraint_region.primitive_poses[0].position.y = 0.2;
00412 pcm.constraint_region.primitive_poses[0].position.z = 1.25;
00413 pcm.constraint_region.primitive_poses[0].orientation.x = 0.0;
00414 pcm.constraint_region.primitive_poses[0].orientation.y = 0.0;
00415 pcm.constraint_region.primitive_poses[0].orientation.z = 0.0;
00416 pcm.constraint_region.primitive_poses[0].orientation.w = 1.0;
00417 pcm.weight = 1.0;
00418
00419
00420 EXPECT_FALSE(pc.configure(pcm, tf));
00421
00422 pcm.header.frame_id = kmodel->getModelFrame();
00423 EXPECT_TRUE(pc.configure(pcm, tf));
00424 EXPECT_FALSE(pc.mobileReferenceFrame());
00425
00426 EXPECT_TRUE(pc.decide(ks).satisfied);
00427
00428 std::map<std::string, double> jvals;
00429 jvals["torso_lift_joint"] = 0.4;
00430 ks.setVariablePositions(jvals);
00431 ks.update();
00432 EXPECT_FALSE(pc.decide(ks).satisfied);
00433 EXPECT_TRUE(pc.equal(pc, 1e-12));
00434
00435
00436 pcm.target_point_offset.x = 0;
00437 pcm.target_point_offset.y = 0;
00438 pcm.target_point_offset.z = .15;
00439
00440 EXPECT_TRUE(pc.configure(pcm, tf));
00441 EXPECT_TRUE(pc.hasLinkOffset());
00442 EXPECT_TRUE(pc.decide(ks).satisfied);
00443
00444 pc.clear();
00445 EXPECT_FALSE(pc.enabled());
00446
00447
00448 pcm.constraint_region.primitive_poses[0].orientation.x = 0.0;
00449 pcm.constraint_region.primitive_poses[0].orientation.y = 0.0;
00450 pcm.constraint_region.primitive_poses[0].orientation.z = 0.0;
00451 pcm.constraint_region.primitive_poses[0].orientation.w = 0.0;
00452
00453 EXPECT_TRUE(pc.configure(pcm, tf));
00454 EXPECT_TRUE(pc.decide(ks).satisfied);
00455 }
00456
00457 TEST_F(LoadPlanningModelsPr2, PositionConstraintsMobile)
00458 {
00459 robot_state::RobotState ks(kmodel);
00460 ks.setToDefaultValues();
00461 robot_state::Transforms tf(kmodel->getModelFrame());
00462 ks.update();
00463
00464 kinematic_constraints::PositionConstraint pc(kmodel);
00465 moveit_msgs::PositionConstraint pcm;
00466
00467 pcm.link_name = "l_wrist_roll_link";
00468 pcm.target_point_offset.x = 0;
00469 pcm.target_point_offset.y = 0;
00470 pcm.target_point_offset.z = 0;
00471
00472 pcm.constraint_region.primitives.resize(1);
00473 pcm.constraint_region.primitives[0].type = shape_msgs::SolidPrimitive::SPHERE;
00474 pcm.constraint_region.primitives[0].dimensions.resize(1);
00475 pcm.constraint_region.primitives[0].dimensions[shape_msgs::SolidPrimitive::BOX_X] = 0.38 * 2.0;
00476
00477 pcm.header.frame_id = "r_wrist_roll_link";
00478
00479 pcm.constraint_region.primitive_poses.resize(1);
00480 pcm.constraint_region.primitive_poses[0].position.x = 0.0;
00481 pcm.constraint_region.primitive_poses[0].position.y = 0.6;
00482 pcm.constraint_region.primitive_poses[0].position.z = 0.0;
00483 pcm.constraint_region.primitive_poses[0].orientation.x = 0.0;
00484 pcm.constraint_region.primitive_poses[0].orientation.y = 0.0;
00485 pcm.constraint_region.primitive_poses[0].orientation.z = 0.0;
00486 pcm.constraint_region.primitive_poses[0].orientation.w = 1.0;
00487 pcm.weight = 1.0;
00488
00489 EXPECT_FALSE(tf.isFixedFrame(pcm.link_name));
00490 EXPECT_TRUE(pc.configure(pcm, tf));
00491 EXPECT_TRUE(pc.mobileReferenceFrame());
00492
00493 EXPECT_TRUE(pc.decide(ks).satisfied);
00494
00495 pcm.constraint_region.primitives[0].type = shape_msgs::SolidPrimitive::BOX;
00496 pcm.constraint_region.primitives[0].dimensions.resize(3);
00497 pcm.constraint_region.primitives[0].dimensions[shape_msgs::SolidPrimitive::BOX_X] = 0.1;
00498 pcm.constraint_region.primitives[0].dimensions[shape_msgs::SolidPrimitive::BOX_Y] = 0.1;
00499 pcm.constraint_region.primitives[0].dimensions[shape_msgs::SolidPrimitive::BOX_Z] = 0.1;
00500 EXPECT_TRUE(pc.configure(pcm, tf));
00501
00502 std::map<std::string, double> jvals;
00503 jvals["l_shoulder_pan_joint"] = 0.4;
00504 ks.setVariablePositions(jvals);
00505 ks.update();
00506 EXPECT_TRUE(pc.decide(ks).satisfied);
00507 EXPECT_TRUE(pc.equal(pc, 1e-12));
00508
00509 jvals["l_shoulder_pan_joint"] = -0.4;
00510 ks.setVariablePositions(jvals);
00511 ks.update();
00512 EXPECT_FALSE(pc.decide(ks).satisfied);
00513
00514
00515 pcm.constraint_region.primitive_poses.resize(2);
00516 pcm.constraint_region.primitive_poses[1].position.x = 0.0;
00517 pcm.constraint_region.primitive_poses[1].position.y = 0.1;
00518 pcm.constraint_region.primitive_poses[1].position.z = 0.0;
00519 pcm.constraint_region.primitive_poses[1].orientation.x = 0.0;
00520 pcm.constraint_region.primitive_poses[1].orientation.y = 0.0;
00521 pcm.constraint_region.primitive_poses[1].orientation.z = 0.0;
00522 pcm.constraint_region.primitive_poses[1].orientation.w = 1.0;
00523
00524 pcm.constraint_region.primitives.resize(2);
00525 pcm.constraint_region.primitives[1].type = shape_msgs::SolidPrimitive::BOX;
00526 pcm.constraint_region.primitives[1].dimensions.resize(3);
00527 pcm.constraint_region.primitives[1].dimensions[shape_msgs::SolidPrimitive::BOX_X] = 0.1;
00528 pcm.constraint_region.primitives[1].dimensions[shape_msgs::SolidPrimitive::BOX_Y] = 0.1;
00529 pcm.constraint_region.primitives[1].dimensions[shape_msgs::SolidPrimitive::BOX_Z] = 0.1;
00530 EXPECT_TRUE(pc.configure(pcm, tf));
00531 EXPECT_TRUE(pc.decide(ks, false).satisfied);
00532 }
00533
00534 TEST_F(LoadPlanningModelsPr2, PositionConstraintsEquality)
00535 {
00536 robot_state::RobotState ks(kmodel);
00537 ks.setToDefaultValues();
00538 robot_state::Transforms tf(kmodel->getModelFrame());
00539
00540 kinematic_constraints::PositionConstraint pc(kmodel);
00541 kinematic_constraints::PositionConstraint pc2(kmodel);
00542 moveit_msgs::PositionConstraint pcm;
00543
00544 pcm.link_name = "l_wrist_roll_link";
00545 pcm.target_point_offset.x = 0;
00546 pcm.target_point_offset.y = 0;
00547 pcm.target_point_offset.z = 0;
00548
00549 pcm.constraint_region.primitives.resize(2);
00550 pcm.constraint_region.primitives[0].type = shape_msgs::SolidPrimitive::SPHERE;
00551 pcm.constraint_region.primitives[0].dimensions.resize(1);
00552 pcm.constraint_region.primitives[0].dimensions[0] = 0.38 * 2.0;
00553 pcm.constraint_region.primitives[1].type = shape_msgs::SolidPrimitive::BOX;
00554 pcm.constraint_region.primitives[1].dimensions.resize(3);
00555 pcm.constraint_region.primitives[1].dimensions[shape_msgs::SolidPrimitive::BOX_X] = 2.0;
00556 pcm.constraint_region.primitives[1].dimensions[shape_msgs::SolidPrimitive::BOX_Y] = 2.0;
00557 pcm.constraint_region.primitives[1].dimensions[shape_msgs::SolidPrimitive::BOX_Z] = 2.0;
00558
00559 pcm.header.frame_id = "r_wrist_roll_link";
00560 pcm.constraint_region.primitive_poses.resize(2);
00561 pcm.constraint_region.primitive_poses[0].position.x = 0.0;
00562 pcm.constraint_region.primitive_poses[0].position.y = 0.6;
00563 pcm.constraint_region.primitive_poses[0].position.z = 0.0;
00564 pcm.constraint_region.primitive_poses[0].orientation.w = 1.0;
00565 pcm.constraint_region.primitive_poses[1].position.x = 2.0;
00566 pcm.constraint_region.primitive_poses[1].position.y = 0.0;
00567 pcm.constraint_region.primitive_poses[1].position.z = 0.0;
00568 pcm.constraint_region.primitive_poses[1].orientation.w = 1.0;
00569 pcm.weight = 1.0;
00570
00571 EXPECT_TRUE(pc.configure(pcm, tf));
00572 EXPECT_TRUE(pc2.configure(pcm, tf));
00573
00574 EXPECT_TRUE(pc.equal(pc2, .001));
00575 EXPECT_TRUE(pc2.equal(pc, .001));
00576
00577
00578 moveit_msgs::PositionConstraint pcm2 = pcm;
00579 pcm2.constraint_region.primitives[0] = pcm.constraint_region.primitives[1];
00580 pcm2.constraint_region.primitives[1] = pcm.constraint_region.primitives[0];
00581
00582 pcm2.constraint_region.primitive_poses[0] = pcm.constraint_region.primitive_poses[1];
00583 pcm2.constraint_region.primitive_poses[1] = pcm.constraint_region.primitive_poses[0];
00584
00585 EXPECT_TRUE(pc2.configure(pcm2, tf));
00586 EXPECT_TRUE(pc.equal(pc2, .001));
00587 EXPECT_TRUE(pc2.equal(pc, .001));
00588
00589
00590 pcm2.constraint_region.primitive_poses[0].position.z = .01;
00591 EXPECT_TRUE(pc2.configure(pcm2, tf));
00592 EXPECT_FALSE(pc.equal(pc2, .001));
00593 EXPECT_FALSE(pc2.equal(pc, .001));
00594 EXPECT_TRUE(pc.equal(pc2, .1));
00595 EXPECT_TRUE(pc2.equal(pc, .1));
00596
00597
00598 pcm2.constraint_region.primitive_poses[0].position.z = 0.0;
00599 pcm2.constraint_region.primitives.resize(3);
00600 pcm2.constraint_region.primitive_poses.resize(3);
00601 pcm2.constraint_region.primitives[2] = pcm2.constraint_region.primitives[0];
00602 pcm2.constraint_region.primitive_poses[2] = pcm2.constraint_region.primitive_poses[0];
00603 EXPECT_TRUE(pc2.configure(pcm2, tf));
00604 EXPECT_TRUE(pc.equal(pc2, .001));
00605 EXPECT_TRUE(pc2.equal(pc, .001));
00606
00607
00608 pcm2.constraint_region.primitives[2].dimensions[0] = 3.0;
00609 EXPECT_TRUE(pc2.configure(pcm2, tf));
00610 EXPECT_FALSE(pc.equal(pc2, .001));
00611 EXPECT_FALSE(pc2.equal(pc, .001));
00612
00613
00614 pcm2.constraint_region.primitives[2].dimensions[0] = pcm2.constraint_region.primitives[0].dimensions[0];
00615 pcm2.constraint_region.primitives[2].type = shape_msgs::SolidPrimitive::SPHERE;
00616 EXPECT_TRUE(pc2.configure(pcm2, tf));
00617 EXPECT_FALSE(pc.equal(pc2, .001));
00618 }
00619
00620 TEST_F(LoadPlanningModelsPr2, OrientationConstraintsSimple)
00621 {
00622 robot_state::RobotState ks(kmodel);
00623 ks.setToDefaultValues();
00624 ks.update();
00625 robot_state::Transforms tf(kmodel->getModelFrame());
00626
00627 kinematic_constraints::OrientationConstraint oc(kmodel);
00628
00629 moveit_msgs::OrientationConstraint ocm;
00630
00631 EXPECT_FALSE(oc.configure(ocm, tf));
00632
00633 ocm.link_name = "r_wrist_roll_link";
00634
00635
00636 EXPECT_TRUE(oc.configure(ocm, tf));
00637
00638 ocm.header.frame_id = kmodel->getModelFrame();
00639 ocm.orientation.x = 0.0;
00640 ocm.orientation.y = 0.0;
00641 ocm.orientation.z = 0.0;
00642 ocm.orientation.w = 1.0;
00643 ocm.absolute_x_axis_tolerance = 0.1;
00644 ocm.absolute_y_axis_tolerance = 0.1;
00645 ocm.absolute_z_axis_tolerance = 0.1;
00646 ocm.weight = 1.0;
00647
00648 EXPECT_TRUE(oc.configure(ocm, tf));
00649 EXPECT_FALSE(oc.mobileReferenceFrame());
00650
00651 EXPECT_FALSE(oc.decide(ks).satisfied);
00652
00653 ocm.header.frame_id = ocm.link_name;
00654 EXPECT_TRUE(oc.configure(ocm, tf));
00655
00656 EXPECT_TRUE(oc.decide(ks).satisfied);
00657 EXPECT_TRUE(oc.equal(oc, 1e-12));
00658 EXPECT_TRUE(oc.mobileReferenceFrame());
00659
00660 ASSERT_TRUE(oc.getLinkModel());
00661
00662 geometry_msgs::Pose p;
00663
00664 tf::poseEigenToMsg(ks.getGlobalLinkTransform(oc.getLinkModel()->getName()), p);
00665
00666 ocm.orientation = p.orientation;
00667 ocm.header.frame_id = kmodel->getModelFrame();
00668 EXPECT_TRUE(oc.configure(ocm, tf));
00669 EXPECT_TRUE(oc.decide(ks).satisfied);
00670
00671 std::map<std::string, double> jvals;
00672 jvals["r_wrist_roll_joint"] = .05;
00673 ks.setVariablePositions(jvals);
00674 ks.update();
00675 EXPECT_TRUE(oc.decide(ks).satisfied);
00676
00677 jvals["r_wrist_roll_joint"] = .11;
00678 ks.setVariablePositions(jvals);
00679 ks.update();
00680 EXPECT_FALSE(oc.decide(ks).satisfied);
00681 }
00682
00683 TEST_F(LoadPlanningModelsPr2, VisibilityConstraintsSimple)
00684 {
00685 robot_state::RobotState ks(kmodel);
00686 ks.setToDefaultValues();
00687 ks.update();
00688 robot_state::Transforms tf(kmodel->getModelFrame());
00689
00690 kinematic_constraints::VisibilityConstraint vc(kmodel);
00691 moveit_msgs::VisibilityConstraint vcm;
00692
00693 EXPECT_FALSE(vc.configure(vcm, tf));
00694
00695 vcm.sensor_pose.header.frame_id = "base_footprint";
00696 vcm.sensor_pose.pose.position.z = -1.0;
00697 vcm.sensor_pose.pose.orientation.y = 1.0;
00698
00699 vcm.target_pose.header.frame_id = "base_footprint";
00700 vcm.target_pose.pose.position.z = -2.0;
00701 vcm.target_pose.pose.orientation.y = 0.0;
00702 vcm.target_pose.pose.orientation.w = 1.0;
00703
00704 vcm.target_radius = .2;
00705 vcm.cone_sides = 10;
00706 vcm.max_view_angle = 0.0;
00707 vcm.max_range_angle = 0.0;
00708 vcm.sensor_view_direction = moveit_msgs::VisibilityConstraint::SENSOR_Z;
00709 vcm.weight = 1.0;
00710
00711 EXPECT_TRUE(vc.configure(vcm, tf));
00712
00713 EXPECT_TRUE(vc.decide(ks, true).satisfied);
00714
00715 vcm.max_view_angle = .1;
00716
00717
00718 EXPECT_TRUE(vc.configure(vcm, tf));
00719 EXPECT_TRUE(vc.decide(ks, true).satisfied);
00720
00721
00722 vcm.target_pose.pose.orientation.y = 0.03;
00723 vcm.target_pose.pose.orientation.w = .9995;
00724 EXPECT_TRUE(vc.configure(vcm, tf));
00725 EXPECT_TRUE(vc.decide(ks, true).satisfied);
00726
00727
00728 vcm.target_pose.pose.orientation.y = 0.06;
00729 vcm.target_pose.pose.orientation.w = .9981;
00730 EXPECT_TRUE(vc.configure(vcm, tf));
00731 EXPECT_FALSE(vc.decide(ks, true).satisfied);
00732 }
00733
00734 TEST_F(LoadPlanningModelsPr2, VisibilityConstraintsPR2)
00735 {
00736 robot_state::RobotState ks(kmodel);
00737 ks.setToDefaultValues();
00738 ks.update();
00739 robot_state::Transforms tf(kmodel->getModelFrame());
00740
00741 kinematic_constraints::VisibilityConstraint vc(kmodel);
00742 moveit_msgs::VisibilityConstraint vcm;
00743
00744 vcm.sensor_pose.header.frame_id = "narrow_stereo_optical_frame";
00745 vcm.sensor_pose.pose.position.z = 0.05;
00746 vcm.sensor_pose.pose.orientation.w = 1.0;
00747
00748 vcm.target_pose.header.frame_id = "l_gripper_r_finger_tip_link";
00749 vcm.target_pose.pose.position.z = 0.03;
00750 vcm.target_pose.pose.orientation.w = 1.0;
00751
00752 vcm.cone_sides = 10;
00753 vcm.max_view_angle = 0.0;
00754 vcm.max_range_angle = 0.0;
00755 vcm.sensor_view_direction = moveit_msgs::VisibilityConstraint::SENSOR_Z;
00756 vcm.weight = 1.0;
00757
00758
00759 EXPECT_FALSE(vc.configure(vcm, tf));
00760
00761
00762 vcm.target_radius = .05;
00763 EXPECT_TRUE(vc.configure(vcm, tf));
00764 EXPECT_TRUE(vc.decide(ks, true).satisfied);
00765
00766
00767 std::map<std::string, double> state_values;
00768 state_values["l_shoulder_lift_joint"] = .5;
00769 state_values["r_shoulder_pan_joint"] = .5;
00770 state_values["r_elbow_flex_joint"] = -1.4;
00771 ks.setVariablePositions(state_values);
00772 ks.update();
00773 EXPECT_FALSE(vc.decide(ks, true).satisfied);
00774
00775
00776 state_values["r_shoulder_pan_joint"] = .4;
00777 ks.setVariablePositions(state_values);
00778 ks.update();
00779 EXPECT_TRUE(vc.decide(ks, true).satisfied);
00780
00781
00782 state_values["l_shoulder_lift_joint"] = 0;
00783 state_values["r_shoulder_pan_joint"] = .5;
00784 state_values["r_elbow_flex_joint"] = -.6;
00785 ks.setVariablePositions(state_values);
00786 ks.update();
00787 EXPECT_TRUE(vc.decide(ks, true).satisfied);
00788
00789
00790 vcm.sensor_view_direction = moveit_msgs::VisibilityConstraint::SENSOR_X;
00791 EXPECT_TRUE(vc.decide(ks, true).satisfied);
00792
00793 ks.setToDefaultValues();
00794 ks.update();
00795
00796 vcm.target_radius = .01;
00797 vcm.target_pose.pose.position.z = 0.00;
00798 vcm.target_pose.pose.position.x = 0.035;
00799 EXPECT_TRUE(vc.configure(vcm, tf));
00800 EXPECT_TRUE(vc.decide(ks, true).satisfied);
00801
00802
00803 vcm.target_radius = .05;
00804 EXPECT_TRUE(vc.configure(vcm, tf));
00805 EXPECT_FALSE(vc.decide(ks, true).satisfied);
00806 }
00807
00808 TEST_F(LoadPlanningModelsPr2, TestKinematicConstraintSet)
00809 {
00810 robot_state::RobotState ks(kmodel);
00811 ks.setToDefaultValues();
00812 robot_state::Transforms tf(kmodel->getModelFrame());
00813
00814 kinematic_constraints::KinematicConstraintSet kcs(kmodel);
00815 EXPECT_TRUE(kcs.empty());
00816
00817 moveit_msgs::JointConstraint jcm;
00818 jcm.joint_name = "head_pan_joint";
00819 jcm.position = 0.4;
00820 jcm.tolerance_above = 0.1;
00821 jcm.tolerance_below = 0.05;
00822 jcm.weight = 1.0;
00823
00824
00825 std::vector<moveit_msgs::JointConstraint> jcv;
00826 jcv.push_back(jcm);
00827 EXPECT_TRUE(kcs.add(jcv));
00828
00829
00830 EXPECT_FALSE(kcs.decide(ks).satisfied);
00831
00832
00833 std::map<std::string, double> jvals;
00834 jvals[jcm.joint_name] = 0.41;
00835 ks.setVariablePositions(jvals);
00836 ks.update();
00837 EXPECT_TRUE(kcs.decide(ks).satisfied);
00838
00839
00840 EXPECT_FALSE(kcs.empty());
00841 kcs.clear();
00842 EXPECT_TRUE(kcs.empty());
00843 jcv.push_back(jcm);
00844 jcv.back().joint_name = "head_tilt_joint";
00845 EXPECT_TRUE(kcs.add(jcv));
00846
00847
00848 EXPECT_FALSE(kcs.decide(ks).satisfied);
00849
00850
00851 jvals[jcv.back().joint_name] = 0.41;
00852 ks.setVariablePositions(jvals);
00853 EXPECT_TRUE(kcs.decide(ks).satisfied);
00854
00855
00856 jvals[jcv.back().joint_name] = 0.51;
00857 ks.setVariablePositions(jvals);
00858 EXPECT_FALSE(kcs.decide(ks).satisfied);
00859
00860
00861 kcs.clear();
00862 jcv.back().joint_name = "no_joint";
00863 EXPECT_FALSE(kcs.add(jcv));
00864
00865
00866 EXPECT_TRUE(kcs.decide(ks).satisfied);
00867
00868
00869 jvals["head_pan_joint"] = 0.51;
00870 ks.setVariablePositions(jvals);
00871 EXPECT_FALSE(kcs.decide(ks).satisfied);
00872 }
00873
00874 TEST_F(LoadPlanningModelsPr2, TestKinematicConstraintSetEquality)
00875 {
00876 robot_state::RobotState ks(kmodel);
00877 ks.setToDefaultValues();
00878 robot_state::Transforms tf(kmodel->getModelFrame());
00879
00880 kinematic_constraints::KinematicConstraintSet kcs(kmodel);
00881 kinematic_constraints::KinematicConstraintSet kcs2(kmodel);
00882
00883 moveit_msgs::JointConstraint jcm;
00884 jcm.joint_name = "head_pan_joint";
00885 jcm.position = 0.4;
00886 jcm.tolerance_above = 0.1;
00887 jcm.tolerance_below = 0.05;
00888 jcm.weight = 1.0;
00889
00890 moveit_msgs::PositionConstraint pcm;
00891 pcm.link_name = "l_wrist_roll_link";
00892 pcm.target_point_offset.x = 0;
00893 pcm.target_point_offset.y = 0;
00894 pcm.target_point_offset.z = 0;
00895 pcm.constraint_region.primitives.resize(1);
00896 pcm.constraint_region.primitives[0].type = shape_msgs::SolidPrimitive::SPHERE;
00897 pcm.constraint_region.primitives[0].dimensions.resize(1);
00898 pcm.constraint_region.primitives[0].dimensions[0] = 0.2;
00899
00900 pcm.constraint_region.primitive_poses.resize(1);
00901 pcm.constraint_region.primitive_poses[0].position.x = 0.55;
00902 pcm.constraint_region.primitive_poses[0].position.y = 0.2;
00903 pcm.constraint_region.primitive_poses[0].position.z = 1.25;
00904 pcm.constraint_region.primitive_poses[0].orientation.x = 0.0;
00905 pcm.constraint_region.primitive_poses[0].orientation.y = 0.0;
00906 pcm.constraint_region.primitive_poses[0].orientation.z = 0.0;
00907 pcm.constraint_region.primitive_poses[0].orientation.w = 1.0;
00908 pcm.weight = 1.0;
00909
00910 pcm.header.frame_id = kmodel->getModelFrame();
00911
00912
00913 std::vector<moveit_msgs::JointConstraint> jcv;
00914 jcv.push_back(jcm);
00915 EXPECT_TRUE(kcs.add(jcv));
00916
00917 std::vector<moveit_msgs::PositionConstraint> pcv;
00918 pcv.push_back(pcm);
00919 EXPECT_TRUE(kcs.add(pcv, tf));
00920
00921
00922 EXPECT_TRUE(kcs2.add(pcv, tf));
00923 EXPECT_TRUE(kcs2.add(jcv));
00924
00925
00926 EXPECT_TRUE(kcs.equal(kcs2, .001));
00927 EXPECT_TRUE(kcs2.equal(kcs, .001));
00928
00929
00930 jcv.push_back(jcm);
00931 EXPECT_TRUE(kcs2.add(jcv));
00932
00933 EXPECT_TRUE(kcs.equal(kcs2, .001));
00934 EXPECT_TRUE(kcs2.equal(kcs, .001));
00935
00936 jcm.joint_name = "head_pan_joint";
00937 jcm.position = 0.35;
00938 jcm.tolerance_above = 0.1;
00939 jcm.tolerance_below = 0.05;
00940 jcm.weight = 1.0;
00941
00942 jcv.push_back(jcm);
00943 EXPECT_TRUE(kcs2.add(jcv));
00944
00945 EXPECT_FALSE(kcs.equal(kcs2, .001));
00946 EXPECT_FALSE(kcs2.equal(kcs, .001));
00947
00948
00949 EXPECT_TRUE(kcs.equal(kcs2, .1));
00950 EXPECT_TRUE(kcs2.equal(kcs, .1));
00951 }
00952
00953 int main(int argc, char** argv)
00954 {
00955 testing::InitGoogleTest(&argc, argv);
00956 return RUN_ALL_TESTS();
00957 }