46#include <geometric_shapes/shape_operations.h>
47#include <visualization_msgs/msg/marker_array.hpp>
49#include <gmock/gmock.h>
50#include <gtest/gtest.h>
51#include <urdf_parser/urdf_parser.h>
76 node_ = rclcpp::Node::make_shared(
"test_constraint_samplers");
81 {
"r_wrist_roll_link" }, .01);
85 {
"l_wrist_roll_link" }, .01);
90 std::map<std::string, moveit::core::SolverAllocatorFn> allocators;
108 planning_scene::PlanningScenePtr
ps_;
124 moveit_msgs::msg::JointConstraint jcm1;
126 jcm1.position = 0.42;
127 jcm1.tolerance_above = 0.01;
128 jcm1.tolerance_below = 0.05;
132 std::vector<kinematic_constraints::JointConstraint> js;
140 jcm1.joint_name =
"r_shoulder_pan_joint";
146 EXPECT_TRUE(jcs.
sample(ks, ks, 1));
148 for (
int t = 0; t < 100; ++t)
150 EXPECT_TRUE(jcs.
sample(ks, ks_const, 1));
160 moveit_msgs::msg::JointConstraint jcm2;
161 jcm2.joint_name =
"r_shoulder_pan_joint";
162 jcm2.position = 0.54;
163 jcm2.tolerance_above = 0.01;
164 jcm2.tolerance_below = 0.01;
171 EXPECT_FALSE(jcs.
sample(ks, ks_const, 1));
176 EXPECT_FALSE(jcs2.
sample(ks, ks_const, 1));
186 jcm1.tolerance_above = .05;
187 jcm1.tolerance_below = .05;
189 jcm2.tolerance_above = .1;
190 jcm2.tolerance_below = .1;
199 for (
int t = 0; t < 100; ++t)
201 EXPECT_TRUE(jcs.
sample(ks, ks_const, 1));
208 jcm1.position = -3.1;
209 jcm1.tolerance_above = .05;
210 jcm1.tolerance_below = .05;
220 jcm1.tolerance_above = .05;
221 jcm1.tolerance_below = .05;
223 jcm2.tolerance_above = .05;
224 jcm2.tolerance_below = .05;
232 for (
int t = 0; t < 100; ++t)
234 EXPECT_TRUE(jcs.
sample(ks, ks_const, 1));
235 std::map<std::string, double> var_values;
236 EXPECT_NEAR(ks.
getVariablePosition(
"r_shoulder_pan_joint"), .4, std::numeric_limits<double>::epsilon());
249 for (
int t = 0; t < 100; ++t)
251 EXPECT_TRUE(jcs.
sample(ks, ks_const, 1));
262 moveit_msgs::msg::PositionConstraint pcm;
264 pcm.link_name =
"l_wrist_roll_link";
265 pcm.target_point_offset.x = 0;
266 pcm.target_point_offset.y = 0;
267 pcm.target_point_offset.z = 0;
268 pcm.constraint_region.primitives.resize(1);
269 pcm.constraint_region.primitives[0].type = shape_msgs::msg::SolidPrimitive::SPHERE;
270 pcm.constraint_region.primitives[0].dimensions.resize(1);
271 pcm.constraint_region.primitives[0].dimensions[0] = 0.001;
273 pcm.constraint_region.primitive_poses.resize(1);
274 pcm.constraint_region.primitive_poses[0].position.x = 0.55;
275 pcm.constraint_region.primitive_poses[0].position.y = 0.2;
276 pcm.constraint_region.primitive_poses[0].position.z = 1.25;
277 pcm.constraint_region.primitive_poses[0].orientation.x = 0.0;
278 pcm.constraint_region.primitive_poses[0].orientation.y = 0.0;
279 pcm.constraint_region.primitive_poses[0].orientation.z = 0.0;
280 pcm.constraint_region.primitive_poses[0].orientation.w = 1.0;
286 EXPECT_FALSE(ik_bad.
isValid());
294 pcm.header.frame_id = robot_model_->getModelFrame();
301 EXPECT_FALSE(ik_bad_2.
isValid());
304 pcm.link_name =
"l_shoulder_pan_link";
310 pcm.link_name =
"l_wrist_roll_link";
313 EXPECT_FALSE(ik_base.
isValid());
332 moveit_msgs::msg::OrientationConstraint ocm;
334 ocm.link_name =
"r_wrist_roll_link";
335 ocm.header.frame_id = ocm.link_name;
336 ocm.orientation.x = 0.5;
337 ocm.orientation.y = 0.5;
338 ocm.orientation.z = 0.5;
339 ocm.orientation.w = 0.5;
340 ocm.absolute_x_axis_tolerance = 0.01;
341 ocm.absolute_y_axis_tolerance = 0.01;
342 ocm.absolute_z_axis_tolerance = 0.01;
344 ocm.parameterization = moveit_msgs::msg::OrientationConstraint::XYZ_EULER_ANGLES;
351 ocm.header.frame_id = robot_model_->getModelFrame();
356 for (
int t = 0; t < 100; ++t)
359 EXPECT_TRUE(iks.
sample(ks, ks_const, 100));
364 ocm.parameterization = moveit_msgs::msg::OrientationConstraint::ROTATION_VECTOR;
368 for (
int t = 0; t < 100; ++t)
371 EXPECT_TRUE(iks.
sample(ks, ks_const, 100));
388 moveit_msgs::msg::PositionConstraint pcm;
390 pcm.link_name =
"l_wrist_roll_link";
391 pcm.target_point_offset.x = 0;
392 pcm.target_point_offset.y = 0;
393 pcm.target_point_offset.z = 0;
394 pcm.constraint_region.primitives.resize(1);
395 pcm.constraint_region.primitives[0].type = shape_msgs::msg::SolidPrimitive::SPHERE;
396 pcm.constraint_region.primitives[0].dimensions.resize(1);
397 pcm.constraint_region.primitives[0].dimensions[0] = 0.001;
399 pcm.header.frame_id = robot_model_->getModelFrame();
401 pcm.constraint_region.primitive_poses.resize(1);
402 pcm.constraint_region.primitive_poses[0].position.x = 0.55;
403 pcm.constraint_region.primitive_poses[0].position.y = 0.2;
404 pcm.constraint_region.primitive_poses[0].position.z = 1.25;
405 pcm.constraint_region.primitive_poses[0].orientation.x = 0.0;
406 pcm.constraint_region.primitive_poses[0].orientation.y = 0.0;
407 pcm.constraint_region.primitive_poses[0].orientation.z = 0.0;
408 pcm.constraint_region.primitive_poses[0].orientation.w = 1.0;
414 moveit_msgs::msg::OrientationConstraint ocm;
416 ocm.link_name =
"l_wrist_roll_link";
417 ocm.header.frame_id = robot_model_->getModelFrame();
418 ocm.orientation.x = 0.0;
419 ocm.orientation.y = 0.0;
420 ocm.orientation.z = 0.0;
421 ocm.orientation.w = 1.0;
422 ocm.absolute_x_axis_tolerance = 0.2;
423 ocm.absolute_y_axis_tolerance = 0.1;
424 ocm.absolute_z_axis_tolerance = 0.4;
431 for (
int t = 0; t < 100; ++t)
433 EXPECT_TRUE(iks1.
sample(ks, ks_const, 100));
440 for (
int t = 0; t < 100; ++t)
442 EXPECT_TRUE(iks2.
sample(ks, ks_const, 100));
448 for (
int t = 0; t < 100; ++t)
450 EXPECT_TRUE(iks3.
sample(ks, ks_const, 100));
469 std::map<std::string, double> state_values;
471 moveit_msgs::msg::JointConstraint torso_constraint;
472 torso_constraint.joint_name =
"torso_lift_joint";
474 torso_constraint.tolerance_above = 0.01;
475 torso_constraint.tolerance_below = 0.01;
476 torso_constraint.weight = 1.0;
477 EXPECT_TRUE(jc1.
configure(torso_constraint));
480 moveit_msgs::msg::JointConstraint jcm2;
481 jcm2.joint_name =
"r_elbow_flex_joint";
483 jcm2.tolerance_above = 0.01;
484 jcm2.tolerance_below = 0.01;
488 moveit_msgs::msg::PositionConstraint pcm;
490 pcm.link_name =
"l_wrist_roll_link";
491 pcm.target_point_offset.x = 0;
492 pcm.target_point_offset.y = 0;
493 pcm.target_point_offset.z = 0;
494 pcm.constraint_region.primitives.resize(1);
495 pcm.constraint_region.primitives[0].type = shape_msgs::msg::SolidPrimitive::SPHERE;
496 pcm.constraint_region.primitives[0].dimensions.resize(1);
497 pcm.constraint_region.primitives[0].dimensions[0] = 0.001;
499 pcm.constraint_region.primitive_poses.resize(1);
500 pcm.constraint_region.primitive_poses[0].position.x = 0.55;
501 pcm.constraint_region.primitive_poses[0].position.y = 0.2;
502 pcm.constraint_region.primitive_poses[0].position.z = 1.25;
503 pcm.constraint_region.primitive_poses[0].orientation.x = 0.0;
504 pcm.constraint_region.primitive_poses[0].orientation.y = 0.0;
505 pcm.constraint_region.primitive_poses[0].orientation.z = 0.0;
506 pcm.constraint_region.primitive_poses[0].orientation.w = 1.0;
509 pcm.header.frame_id = robot_model_->getModelFrame();
511 moveit_msgs::msg::OrientationConstraint ocm;
513 ocm.link_name =
"l_wrist_roll_link";
514 ocm.header.frame_id = robot_model_->getModelFrame();
515 ocm.orientation.x = 0.0;
516 ocm.orientation.y = 0.0;
517 ocm.orientation.z = 0.0;
518 ocm.orientation.w = 1.0;
519 ocm.absolute_x_axis_tolerance = 0.2;
520 ocm.absolute_y_axis_tolerance = 0.1;
521 ocm.absolute_z_axis_tolerance = 0.4;
524 std::vector<kinematic_constraints::JointConstraint> js;
527 constraint_samplers::JointConstraintSamplerPtr jcsp(
529 EXPECT_TRUE(jcsp->configure(js));
531 std::vector<kinematic_constraints::JointConstraint> js2;
534 constraint_samplers::JointConstraintSamplerPtr jcsp2 =
535 std::make_shared<constraint_samplers::JointConstraintSampler>(ps_,
"arms");
536 EXPECT_TRUE(jcsp2->configure(js2));
544 constraint_samplers::IKConstraintSamplerPtr iksp =
545 std::make_shared<constraint_samplers::IKConstraintSampler>(ps_,
"left_arm");
547 EXPECT_TRUE(iksp->isValid());
549 std::vector<constraint_samplers::ConstraintSamplerPtr> cspv;
550 cspv.push_back(jcsp2);
551 cspv.push_back(iksp);
552 cspv.push_back(jcsp);
567 for (
int t = 0; t < 100; ++t)
569 EXPECT_TRUE(ucs.
sample(ks, ks_const, 100));
579 pcm.link_name =
"r_wrist_roll_link";
580 ocm.link_name =
"r_wrist_roll_link";
589 constraint_samplers::IKConstraintSamplerPtr iksp2 =
590 std::make_shared<constraint_samplers::IKConstraintSampler>(ps_,
"right_arm");
592 EXPECT_TRUE(iksp2->isValid());
596 cspv.push_back(iksp2);
597 cspv.push_back(iksp);
603 ASSERT_TRUE(ikcs_test);
607 pcm.link_name =
"l_wrist_roll_link";
608 ocm.link_name =
"l_wrist_roll_link";
609 pcm.header.frame_id =
"r_wrist_roll_link";
610 ocm.header.frame_id =
"r_wrist_roll_link";
616 cspv.push_back(iksp2);
617 cspv.push_back(iksp);
622 EXPECT_TRUE(ikcs_test);
637 moveit_msgs::msg::PositionConstraint pcm;
638 pcm.link_name =
"l_wrist_roll_link";
639 pcm.target_point_offset.x = 0;
640 pcm.target_point_offset.y = 0;
641 pcm.target_point_offset.z = 0;
642 pcm.constraint_region.primitives.resize(1);
643 pcm.constraint_region.primitives[0].type = shape_msgs::msg::SolidPrimitive::SPHERE;
644 pcm.constraint_region.primitives[0].dimensions.resize(1);
645 pcm.constraint_region.primitives[0].dimensions[0] = 0.001;
647 pcm.header.frame_id = robot_model_->getModelFrame();
649 pcm.constraint_region.primitive_poses.resize(1);
650 pcm.constraint_region.primitive_poses[0].position.x = 0.55;
651 pcm.constraint_region.primitive_poses[0].position.y = 0.2;
652 pcm.constraint_region.primitive_poses[0].position.z = 1.25;
653 pcm.constraint_region.primitive_poses[0].orientation.x = 0.0;
654 pcm.constraint_region.primitive_poses[0].orientation.y = 0.0;
655 pcm.constraint_region.primitive_poses[0].orientation.z = 0.0;
656 pcm.constraint_region.primitive_poses[0].orientation.w = 1.0;
659 moveit_msgs::msg::OrientationConstraint ocm;
661 ocm.link_name =
"l_wrist_roll_link";
662 ocm.header.frame_id = robot_model_->getModelFrame();
663 ocm.orientation.x = 0.0;
664 ocm.orientation.y = 0.0;
665 ocm.orientation.z = 0.0;
666 ocm.orientation.w = 1.0;
667 ocm.absolute_x_axis_tolerance = 0.2;
668 ocm.absolute_y_axis_tolerance = 0.1;
669 ocm.absolute_z_axis_tolerance = 0.4;
673 moveit_msgs::msg::Constraints c;
674 c.position_constraints.push_back(pcm);
675 c.orientation_constraints.push_back(ocm);
677 constraint_samplers::ConstraintSamplerPtr s =
679 EXPECT_TRUE(s !=
nullptr);
685 static const int NT = 100;
687 for (
int t = 0; t < NT; ++t)
689 EXPECT_TRUE(s->sample(ks, ks_const, 100));
692 if (s->sample(ks, ks_const, 1))
695 RCLCPP_INFO(rclcpp::get_logger(
"test_constraint_samplers"),
696 "Success rate for IK Constraint Sampler with position & orientation constraints for one arm: %lf",
697 static_cast<double>(succ) /
static_cast<double>(NT));
700 ocm.absolute_x_axis_tolerance = 0.1;
702 c.orientation_constraints.push_back(ocm);
705 EXPECT_TRUE(s !=
nullptr);
719 moveit_msgs::msg::Constraints con;
720 con.joint_constraints.resize(1);
722 con.joint_constraints[0].joint_name =
"l_shoulder_pan_joint";
723 con.joint_constraints[0].position = 0.54;
724 con.joint_constraints[0].tolerance_above = 0.01;
725 con.joint_constraints[0].tolerance_below = 0.01;
726 con.joint_constraints[0].weight = 1.0;
728 constraint_samplers::ConstraintSamplerPtr s =
730 EXPECT_FALSE(
static_cast<bool>(s));
732 EXPECT_TRUE(
static_cast<bool>(s));
734 con.joint_constraints.resize(7);
736 con.joint_constraints[1].joint_name =
"l_shoulder_lift_joint";
737 con.joint_constraints[1].position = 0.54;
738 con.joint_constraints[1].tolerance_above = 0.01;
739 con.joint_constraints[1].tolerance_below = 0.01;
740 con.joint_constraints[1].weight = 1.0;
742 con.joint_constraints[2].joint_name =
"l_upper_arm_roll_joint";
743 con.joint_constraints[2].position = 0.54;
744 con.joint_constraints[2].tolerance_above = 0.01;
745 con.joint_constraints[2].tolerance_below = 0.01;
746 con.joint_constraints[2].weight = 1.0;
748 con.joint_constraints[3].joint_name =
"l_elbow_flex_joint";
749 con.joint_constraints[3].position = -0.54;
750 con.joint_constraints[3].tolerance_above = 0.01;
751 con.joint_constraints[3].tolerance_below = 0.01;
752 con.joint_constraints[3].weight = 1.0;
754 con.joint_constraints[4].joint_name =
"l_forearm_roll_joint";
755 con.joint_constraints[4].position = 0.54;
756 con.joint_constraints[4].tolerance_above = 0.01;
757 con.joint_constraints[4].tolerance_below = 0.01;
758 con.joint_constraints[4].weight = 1.0;
760 con.joint_constraints[5].joint_name =
"l_wrist_flex_joint";
761 con.joint_constraints[5].position = -0.54;
762 con.joint_constraints[5].tolerance_above = 0.05;
763 con.joint_constraints[5].tolerance_below = 0.05;
764 con.joint_constraints[5].weight = 1.0;
767 con.joint_constraints[6].joint_name =
"l_wrist_flex_joint";
768 con.joint_constraints[6].position = -0.56;
769 con.joint_constraints[6].tolerance_above = 0.01;
770 con.joint_constraints[6].tolerance_below = 0.01;
771 con.joint_constraints[6].weight = 1.0;
774 EXPECT_TRUE(
static_cast<bool>(s));
776 con.position_constraints.resize(1);
779 con.position_constraints[0].link_name =
"r_wrist_roll_link";
780 con.position_constraints[0].target_point_offset.x = 0;
781 con.position_constraints[0].target_point_offset.y = 0;
782 con.position_constraints[0].target_point_offset.z = 0;
783 con.position_constraints[0].constraint_region.primitives.resize(1);
784 con.position_constraints[0].constraint_region.primitives[0].type = shape_msgs::msg::SolidPrimitive::SPHERE;
785 con.position_constraints[0].constraint_region.primitives[0].dimensions.resize(1);
786 con.position_constraints[0].constraint_region.primitives[0].dimensions[0] = 0.001;
788 con.position_constraints[0].header.frame_id = robot_model_->getModelFrame();
790 con.position_constraints[0].constraint_region.primitive_poses.resize(1);
791 con.position_constraints[0].constraint_region.primitive_poses[0].position.x = 0.55;
792 con.position_constraints[0].constraint_region.primitive_poses[0].position.y = 0.2;
793 con.position_constraints[0].constraint_region.primitive_poses[0].position.z = 1.25;
794 con.position_constraints[0].constraint_region.primitive_poses[0].orientation.x = 0.0;
795 con.position_constraints[0].constraint_region.primitive_poses[0].orientation.y = 0.0;
796 con.position_constraints[0].constraint_region.primitive_poses[0].orientation.z = 0.0;
797 con.position_constraints[0].constraint_region.primitive_poses[0].orientation.w = 1.0;
798 con.position_constraints[0].weight = 1.0;
802 EXPECT_TRUE(
static_cast<bool>(s));
807 con.position_constraints[0].link_name =
"l_wrist_roll_link";
809 EXPECT_TRUE(
static_cast<bool>(s));
820 con.orientation_constraints.resize(1);
823 con.orientation_constraints[0].link_name =
"r_wrist_roll_link";
824 con.orientation_constraints[0].header.frame_id = robot_model_->getModelFrame();
825 con.orientation_constraints[0].orientation.x = 0.0;
826 con.orientation_constraints[0].orientation.y = 0.0;
827 con.orientation_constraints[0].orientation.z = 0.0;
828 con.orientation_constraints[0].orientation.w = 1.0;
829 con.orientation_constraints[0].absolute_x_axis_tolerance = 0.2;
830 con.orientation_constraints[0].absolute_y_axis_tolerance = 0.1;
831 con.orientation_constraints[0].absolute_z_axis_tolerance = 0.4;
832 con.orientation_constraints[0].weight = 1.0;
836 EXPECT_TRUE(
static_cast<bool>(s));
847 con.orientation_constraints[0].link_name =
"l_wrist_roll_link";
851 EXPECT_TRUE(
static_cast<bool>(s));
859 con.position_constraints[0].link_name =
"r_wrist_roll_link";
861 ASSERT_TRUE(
static_cast<bool>(s));
869 con.joint_constraints.resize(8);
870 con.joint_constraints[7].joint_name =
"l_wrist_roll_joint";
871 con.joint_constraints[7].position = 0.54;
872 con.joint_constraints[7].tolerance_above = 0.01;
873 con.joint_constraints[7].tolerance_below = 0.01;
874 con.joint_constraints[7].weight = 1.0;
877 EXPECT_TRUE(
static_cast<bool>(s));
891 moveit_msgs::msg::Constraints con;
892 con.joint_constraints.resize(1);
894 con.joint_constraints[0].joint_name =
"torso_lift_joint";
896 con.joint_constraints[0].tolerance_above = 0.01;
897 con.joint_constraints[0].tolerance_below = 0.01;
898 con.joint_constraints[0].weight = 1.0;
901 EXPECT_TRUE(jc.
configure(con.joint_constraints[0]));
903 con.position_constraints.resize(1);
905 con.position_constraints[0].link_name =
"l_wrist_roll_link";
906 con.position_constraints[0].target_point_offset.x = 0;
907 con.position_constraints[0].target_point_offset.y = 0;
908 con.position_constraints[0].target_point_offset.z = 0;
909 con.position_constraints[0].constraint_region.primitives.resize(1);
910 con.position_constraints[0].constraint_region.primitives[0].type = shape_msgs::msg::SolidPrimitive::SPHERE;
911 con.position_constraints[0].constraint_region.primitives[0].dimensions.resize(1);
912 con.position_constraints[0].constraint_region.primitives[0].dimensions[0] = 0.001;
914 con.position_constraints[0].constraint_region.primitive_poses.resize(1);
915 con.position_constraints[0].constraint_region.primitive_poses[0].position.x = 0.55;
916 con.position_constraints[0].constraint_region.primitive_poses[0].position.y = 0.2;
917 con.position_constraints[0].constraint_region.primitive_poses[0].position.z = 1.25;
918 con.position_constraints[0].constraint_region.primitive_poses[0].orientation.x = 0.0;
919 con.position_constraints[0].constraint_region.primitive_poses[0].orientation.y = 0.0;
920 con.position_constraints[0].constraint_region.primitive_poses[0].orientation.z = 0.0;
921 con.position_constraints[0].constraint_region.primitive_poses[0].orientation.w = 1.0;
922 con.position_constraints[0].weight = 1.0;
924 con.position_constraints[0].header.frame_id = robot_model_->getModelFrame();
926 con.orientation_constraints.resize(1);
927 con.orientation_constraints[0].link_name =
"l_wrist_roll_link";
928 con.orientation_constraints[0].header.frame_id = robot_model_->getModelFrame();
929 con.orientation_constraints[0].orientation.x = 0.0;
930 con.orientation_constraints[0].orientation.y = 0.0;
931 con.orientation_constraints[0].orientation.z = 0.0;
932 con.orientation_constraints[0].orientation.w = 1.0;
933 con.orientation_constraints[0].absolute_x_axis_tolerance = 0.2;
934 con.orientation_constraints[0].absolute_y_axis_tolerance = 0.1;
935 con.orientation_constraints[0].absolute_z_axis_tolerance = 0.4;
936 con.orientation_constraints[0].weight = 1.0;
938 constraint_samplers::ConstraintSamplerPtr s =
947 ASSERT_TRUE(ikcs_test);
949 for (
int t = 0; t < 1; ++t)
951 EXPECT_TRUE(s->sample(ks, ks_const, 100));
968 moveit_msgs::msg::JointConstraint jcm1;
969 jcm1.joint_name =
"head_pan_joint";
970 jcm1.position = 0.42;
971 jcm1.tolerance_above = 0.01;
972 jcm1.tolerance_below = 0.05;
977 moveit_msgs::msg::JointConstraint jcm2;
978 jcm2.joint_name =
"l_shoulder_pan_joint";
980 jcm2.tolerance_above = 0.1;
981 jcm2.tolerance_below = 0.05;
986 moveit_msgs::msg::JointConstraint jcm3;
987 jcm3.joint_name =
"r_wrist_roll_joint";
989 jcm3.tolerance_above = 0.14;
990 jcm3.tolerance_below = 0.005;
995 moveit_msgs::msg::JointConstraint jcm4;
996 jcm4.joint_name =
"torso_lift_joint";
998 jcm4.tolerance_above = 0.09;
999 jcm4.tolerance_below = 0.01;
1003 std::vector<kinematic_constraints::JointConstraint> js;
1014 for (
int t = 0; t < 100; ++t)
1016 EXPECT_TRUE(jcs.
sample(ks, ks_const, 1));
1022 moveit_msgs::msg::Constraints c;
1025 constraint_samplers::ConstraintSamplerPtr s0 =
1027 EXPECT_TRUE(s0 ==
nullptr);
1030 c.joint_constraints.push_back(jcm1);
1031 c.joint_constraints.push_back(jcm2);
1032 c.joint_constraints.push_back(jcm3);
1033 c.joint_constraints.push_back(jcm4);
1035 constraint_samplers::ConstraintSamplerPtr s =
1037 EXPECT_TRUE(s !=
nullptr);
1040 for (
int t = 0; t < 1000; ++t)
1042 EXPECT_TRUE(s->sample(ks, ks_const, 1));
1050 moveit_msgs::msg::Constraints c;
1052 moveit_msgs::msg::PositionConstraint pcm;
1053 pcm.link_name =
"l_wrist_roll_link";
1054 pcm.target_point_offset.x = 0;
1055 pcm.target_point_offset.y = 0;
1056 pcm.target_point_offset.z = 0;
1058 pcm.constraint_region.primitives.resize(1);
1059 pcm.constraint_region.primitives[0].type = shape_msgs::msg::SolidPrimitive::SPHERE;
1060 pcm.constraint_region.primitives[0].dimensions.resize(1);
1061 pcm.constraint_region.primitives[0].dimensions[0] = 0.001;
1063 pcm.header.frame_id = robot_model_->getModelFrame();
1065 pcm.constraint_region.primitive_poses.resize(1);
1066 pcm.constraint_region.primitive_poses[0].position.x = 0.55;
1067 pcm.constraint_region.primitive_poses[0].position.y = 0.2;
1068 pcm.constraint_region.primitive_poses[0].position.z = 1.25;
1069 pcm.constraint_region.primitive_poses[0].orientation.x = 0.0;
1070 pcm.constraint_region.primitive_poses[0].orientation.y = 0.0;
1071 pcm.constraint_region.primitive_poses[0].orientation.z = 0.0;
1072 pcm.constraint_region.primitive_poses[0].orientation.w = 1.0;
1074 c.position_constraints.push_back(pcm);
1076 moveit_msgs::msg::OrientationConstraint ocm;
1077 ocm.link_name =
"l_wrist_roll_link";
1078 ocm.header.frame_id = robot_model_->getModelFrame();
1079 ocm.orientation.x = 0.0;
1080 ocm.orientation.y = 0.0;
1081 ocm.orientation.z = 0.0;
1082 ocm.orientation.w = 1.0;
1083 ocm.absolute_x_axis_tolerance = 0.2;
1084 ocm.absolute_y_axis_tolerance = 0.1;
1085 ocm.absolute_z_axis_tolerance = 0.4;
1087 c.orientation_constraints.push_back(ocm);
1089 ocm.link_name =
"r_wrist_roll_link";
1090 ocm.header.frame_id = robot_model_->getModelFrame();
1091 ocm.orientation.x = 0.0;
1092 ocm.orientation.y = 0.0;
1093 ocm.orientation.z = 0.0;
1094 ocm.orientation.w = 1.0;
1095 ocm.absolute_x_axis_tolerance = 0.01;
1096 ocm.absolute_y_axis_tolerance = 0.01;
1097 ocm.absolute_z_axis_tolerance = 0.01;
1099 c.orientation_constraints.push_back(ocm);
1102 constraint_samplers::ConstraintSamplerPtr s =
1104 EXPECT_TRUE(
static_cast<bool>(s));
1119 static const int NT = 100;
1121 for (
int t = 0; t < NT; ++t)
1123 EXPECT_TRUE(s->sample(ks, ks_const, 1000));
1125 if (s->sample(ks, ks_const, 1))
1128 RCLCPP_INFO(rclcpp::get_logger(
"pr2_arm_kinematics_plugin"),
1129 "Success rate for IK Constraint Sampler with position & orientation constraints for both arms: %lf",
1130 static_cast<double>(succ) /
static_cast<double>(NT));
1137 moveit_msgs::msg::JointConstraint jcm;
1138 jcm.position = 0.42;
1139 jcm.tolerance_above = 0.01;
1140 jcm.tolerance_below = 0.05;
1142 jcm.joint_name =
"r_shoulder_pan_joint";
1144 std::vector<kinematic_constraints::JointConstraint> js;
1146 EXPECT_TRUE(seeded_sampler1.
configure(js));
1150 EXPECT_TRUE(seeded_sampler1.
sample(ks, ks, 1));
1152 const std::vector<double> joint_positions_v(joint_positions, joint_positions + ks.
getVariableCount());
1155 EXPECT_TRUE(seeded_sampler2.
configure(js));
1157 EXPECT_TRUE(seeded_sampler2.
sample(ks, ks, 1));
1159 const std::vector<double> joint_positions_v2(joint_positions2, joint_positions2 + ks.
getVariableCount());
1161 EXPECT_THAT(joint_positions_v, ContainerEq(joint_positions_v2));
1164 EXPECT_TRUE(seeded_sampler3.
configure(js));
1166 EXPECT_TRUE(seeded_sampler3.
sample(ks, ks, 5));
1168 const std::vector<double> joint_positions_v3(joint_positions3, joint_positions3 + ks.
getVariableCount());
1169 EXPECT_THAT(joint_positions_v, Not(ContainerEq(joint_positions_v3)));
1170 EXPECT_THAT(joint_positions_v2, Not(ContainerEq(joint_positions_v3)));
1176 moveit_msgs::msg::PositionConstraint pcm;
1178 pcm.link_name =
"l_wrist_roll_link";
1179 pcm.target_point_offset.x = 0;
1180 pcm.target_point_offset.y = 0;
1181 pcm.target_point_offset.z = 0;
1182 pcm.constraint_region.primitives.resize(1);
1183 pcm.constraint_region.primitives[0].type = shape_msgs::msg::SolidPrimitive::SPHERE;
1184 pcm.constraint_region.primitives[0].dimensions.resize(1);
1185 pcm.constraint_region.primitives[0].dimensions[0] = 0.001;
1187 pcm.constraint_region.primitive_poses.resize(1);
1188 pcm.constraint_region.primitive_poses[0].position.x = 0.55;
1189 pcm.constraint_region.primitive_poses[0].position.y = 0.2;
1190 pcm.constraint_region.primitive_poses[0].position.z = 1.25;
1191 pcm.constraint_region.primitive_poses[0].orientation.x = 0.0;
1192 pcm.constraint_region.primitive_poses[0].orientation.y = 0.0;
1193 pcm.constraint_region.primitive_poses[0].orientation.z = 0.0;
1194 pcm.constraint_region.primitive_poses[0].orientation.w = 1.0;
1197 pcm.header.frame_id = robot_model_->getModelFrame();
1208 EXPECT_TRUE(seeded_sampler1.
sample(ks, ks, 1));
1211 const Eigen::Isometry3d root_to_left_tool1 = ks.
getFrameTransform(
"l_gripper_tool_frame", &found);
1218 EXPECT_TRUE(seeded_sampler2.
sample(ks, ks, 1));
1221 const Eigen::Isometry3d root_to_left_tool2 = ks.
getFrameTransform(
"l_gripper_tool_frame", &found);
1228 EXPECT_TRUE(seeded_sampler3.
sample(ks, ks, 5));
1231 const Eigen::Isometry3d root_to_left_tool3 = ks.
getFrameTransform(
"l_gripper_tool_frame", &found);
1234 EXPECT_TRUE((root_to_left_tool1 * root_to_left_tool2.inverse()).matrix().isIdentity(1e-7));
1235 EXPECT_FALSE((root_to_left_tool1 * root_to_left_tool3.inverse()).matrix().isIdentity(1e-7));
1236 EXPECT_FALSE((root_to_left_tool2 * root_to_left_tool3.inverse()).matrix().isIdentity(1e-7));
1241 rclcpp::init(argc, argv);
1242 testing::InitGoogleTest(&argc, argv);
1243 return RUN_ALL_TESTS();
moveit::core::RobotModelPtr robot_model_
kinematics::KinematicsBasePtr getKinematicsSolverLeftArm(const moveit::core::JointModelGroup *)
kinematics::KinematicsBasePtr getKinematicsSolverRightArm(const moveit::core::JointModelGroup *)
rclcpp::Node::SharedPtr node_
moveit::core::SolverAllocatorFn func_left_arm_
pr2_arm_kinematics::PR2ArmKinematicsPluginPtr pr2_kinematics_plugin_right_arm_
planning_scene::PlanningScenePtr ps_
moveit::core::SolverAllocatorFn func_right_arm_
pr2_arm_kinematics::PR2ArmKinematicsPluginPtr pr2_kinematics_plugin_left_arm_
static ConstraintSamplerPtr selectDefaultSampler(const planning_scene::PlanningSceneConstPtr &scene, const std::string &group_name, const moveit_msgs::msg::Constraints &constr)
Default logic to select a ConstraintSampler given a constraints message.
bool isValid() const
Returns whether or not the constraint sampler is valid or not. To be valid, the joint model group mus...
const moveit::core::JointModelGroup * getJointModelGroup() const
Gets the joint model group.
A class that allows the sampling of IK constraints.
bool configure(const moveit_msgs::msg::Constraints &constr) override
Configures the IK constraint given a constraints message.
const kinematic_constraints::PositionConstraintPtr & getPositionConstraint() const
Gets the position constraint associated with this sampler.
const kinematic_constraints::OrientationConstraintPtr & getOrientationConstraint() const
Gets the orientation constraint associated with this sampler.
bool sample(moveit::core::RobotState &state, const moveit::core::RobotState &reference_state, unsigned int max_attempts) override
Produces an IK sample.
JointConstraintSampler is a class that allows the sampling of joints in a particular group of the rob...
std::size_t getUnconstrainedJointCount() const
Gets the number of unconstrained joints - joint that have no additional bound beyond the joint limits...
bool configure(const moveit_msgs::msg::Constraints &constr) override
Configures a joint constraint given a Constraints message.
bool sample(moveit::core::RobotState &state, const moveit::core::RobotState &ks, unsigned int max_attempts) override
Samples given the constraints, populating state. This function allows the parameter max_attempts to b...
std::size_t getConstrainedJointCount() const
Gets the number of constrained joints - joints that have an additional bound beyond the joint limits.
This class exists as a union of constraint samplers. It contains a vector of constraint samplers,...
const std::vector< ConstraintSamplerPtr > & getSamplers() const
Gets the sorted internal list of constraint samplers.
bool sample(moveit::core::RobotState &state, const moveit::core::RobotState &reference_state, unsigned int max_attempts) override
Produces a sample from all configured samplers.
Class for handling single DOF joint constraints.
ConstraintEvaluationResult decide(const moveit::core::RobotState &state, bool verbose=false) const override
Decide whether the constraint is satisfied in the indicated state.
bool configure(const moveit_msgs::msg::JointConstraint &jc)
Configure the constraint based on a moveit_msgs::msg::JointConstraint.
A class that contains many different constraints, and can check RobotState *versus the full set....
bool add(const moveit_msgs::msg::Constraints &c, const moveit::core::Transforms &tf)
Add all known constraints.
ConstraintEvaluationResult decide(const moveit::core::RobotState &state, bool verbose=false) const
Determines whether all constraints are satisfied by state, returning a single evaluation result.
Class for constraints on the orientation of a link.
bool configure(const moveit_msgs::msg::OrientationConstraint &oc, const moveit::core::Transforms &tf)
Configure the constraint based on a moveit_msgs::msg::OrientationConstraint.
ConstraintEvaluationResult decide(const moveit::core::RobotState &state, bool verbose=false) const override
Decide whether the constraint is satisfied in the indicated state.
Class for constraints on the XYZ position of a link.
bool configure(const moveit_msgs::msg::PositionConstraint &pc, const moveit::core::Transforms &tf)
Configure the constraint based on a moveit_msgs::msg::PositionConstraint.
ConstraintEvaluationResult decide(const moveit::core::RobotState &state, bool verbose=false) const override
Decide whether the constraint is satisfied in the indicated state.
const std::string & getName() const
Get the name of the joint group.
Representation of a robot's state. This includes position, velocity, acceleration and effort.
double * getVariablePositions()
Get a raw pointer to the positions of the variables stored in this state. Use carefully....
void updateLinkTransforms()
Update the reference frame transforms for links. This call is needed before using the transforms of l...
const Eigen::Isometry3d & getFrameTransform(const std::string &frame_id, bool *frame_found=nullptr)
Get the transformation matrix from the model frame (root of model) to the frame identified by frame_i...
double getVariablePosition(const std::string &variable) const
Get the position of a particular variable. An exception is thrown if the variable is not known.
void update(bool force=false)
Update all transforms.
void setToDefaultValues()
Set all joints to their default positions. The default position is 0, or if that is not within bounds...
std::size_t getVariableCount() const
Get the number of variables that make up this state.
moveit::core::RobotModelPtr loadTestingRobotModel(const std::string &package_name, const std::string &urdf_relative_path, const std::string &srdf_relative_path)
Loads a robot model given a URDF and SRDF file in a package.
std::function< kinematics::KinematicsBasePtr(const JointModelGroup *)> SolverAllocatorFn
Function type that allocates a kinematics solver for a particular group.
A structure for potentially holding a position constraint and an orientation constraint for use durin...
bool satisfied
Whether or not the constraint or constraints were satisfied.
TEST_F(LoadPlanningModelsPr2, JointConstraintsSamplerSimple)
int main(int argc, char **argv)