38 #include <gtest/gtest.h>
39 #include <urdf_parser/urdf_parser.h>
41 #include <tf2_eigen/tf2_eigen.hpp>
68 moveit_msgs::msg::JointConstraint jcm;
69 jcm.joint_name =
"head_pan_joint";
71 jcm.tolerance_above = 0.1;
72 jcm.tolerance_below = 0.05;
83 EXPECT_NEAR(p1.
distance, jcm.position, 1e-6);
91 EXPECT_NEAR(p2.
distance, 0.01, 1e-6);
100 jval = 0.35 - std::numeric_limits<double>::epsilon();
106 jval = 0.35 - 3 * std::numeric_limits<double>::epsilon();
111 jcm.tolerance_below = -0.05;
114 jcm.tolerance_below = 0.05;
141 EXPECT_TRUE(jc.
equal(jc2, 1e-12));
144 jcm.joint_name =
"head_tilt_joint";
146 EXPECT_FALSE(jc.
equal(jc2, 1e-12));
149 jcm.joint_name =
"head_pan_joint";
152 EXPECT_FALSE(jc.
equal(jc2, 1e-12));
154 EXPECT_FALSE(jc.
equal(jc2, .1));
155 EXPECT_TRUE(jc.
equal(jc2, .101));
162 EXPECT_FALSE(jc.
equal(jc2, 1e-12));
165 jcm.joint_name =
"base_footprint_joint";
169 jcm.joint_name =
"head_pan_joint";
173 EXPECT_FALSE(jc.
equal(jc2, 1e-12));
184 moveit_msgs::msg::JointConstraint jcm;
186 jcm.joint_name =
"l_wrist_roll_joint";
188 jcm.tolerance_above = 0.04;
189 jcm.tolerance_below = 0.02;
194 std::map<std::string, double> jvals;
200 jvals[jcm.joint_name] = .03;
206 jvals[jcm.joint_name] = .05;
212 jvals[jcm.joint_name] = -.01;
217 jvals[jcm.joint_name] = -.03;
226 jvals[jcm.joint_name] = 3.17;
230 EXPECT_NEAR(p1.
distance, 0.03, 1e-6);
233 jvals[jcm.joint_name] = -3.14;
237 EXPECT_NEAR(p2.
distance, 0.003185, 1e-4);
240 jvals[jcm.joint_name] = 3.19;
246 jvals[jcm.joint_name] = -3.11;
251 jvals[jcm.joint_name] = -3.09;
257 jvals[jcm.joint_name] = 3.13;
262 jvals[jcm.joint_name] = 3.11;
267 jcm.position = -3.14;
271 jvals[jcm.joint_name] = -3.11;
276 jvals[jcm.joint_name] = -3.09;
281 jvals[jcm.joint_name] = 3.13;
286 jvals[jcm.joint_name] = 3.12;
295 jvals[jcm.joint_name] = 0.0;
300 moveit_msgs::msg::JointConstraint jcm2 = jcm;
301 jcm2.position = -6.28;
313 moveit_msgs::msg::JointConstraint jcm;
314 jcm.joint_name =
"world_joint";
316 jcm.tolerance_above = 0.1;
317 jcm.tolerance_below = 0.05;
324 jcm.joint_name =
"world_joint/x";
327 std::map<std::string, double> jvals;
328 jvals[jcm.joint_name] = 3.2;
333 jvals[jcm.joint_name] = 3.25;
338 jvals[jcm.joint_name] = -3.14;
344 jcm.joint_name =
"world_joint/theta";
347 jvals[jcm.joint_name] = -3.14;
352 jvals[jcm.joint_name] = 3.25;
365 moveit_msgs::msg::PositionConstraint pcm;
370 pcm.link_name =
"l_wrist_roll_link";
371 pcm.target_point_offset.x = 0;
372 pcm.target_point_offset.y = 0;
373 pcm.target_point_offset.z = 0;
374 pcm.constraint_region.primitives.resize(1);
375 pcm.constraint_region.primitives[0].type = shape_msgs::msg::SolidPrimitive::SPHERE;
380 pcm.constraint_region.primitives[0].dimensions.resize(1);
381 pcm.constraint_region.primitives[0].dimensions[0] = 0.2;
386 pcm.constraint_region.primitive_poses.resize(1);
387 pcm.constraint_region.primitive_poses[0].position.x = 0.55;
388 pcm.constraint_region.primitive_poses[0].position.y = 0.2;
389 pcm.constraint_region.primitive_poses[0].position.z = 1.25;
390 pcm.constraint_region.primitive_poses[0].orientation.x = 0.0;
391 pcm.constraint_region.primitive_poses[0].orientation.y = 0.0;
392 pcm.constraint_region.primitive_poses[0].orientation.z = 0.0;
393 pcm.constraint_region.primitive_poses[0].orientation.w = 1.0;
399 pcm.header.frame_id = robot_model_->getModelFrame();
405 std::map<std::string, double> jvals;
406 jvals[
"torso_lift_joint"] = 0.4;
410 EXPECT_TRUE(pc.
equal(pc, 1e-12));
413 pcm.target_point_offset.x = 0;
414 pcm.target_point_offset.y = 0;
415 pcm.target_point_offset.z = .15;
425 pcm.constraint_region.primitive_poses[0].orientation.x = 0.0;
426 pcm.constraint_region.primitive_poses[0].orientation.y = 0.0;
427 pcm.constraint_region.primitive_poses[0].orientation.z = 0.0;
428 pcm.constraint_region.primitive_poses[0].orientation.w = 0.0;
442 moveit_msgs::msg::PositionConstraint pcm;
444 pcm.link_name =
"l_wrist_roll_link";
445 pcm.target_point_offset.x = 0;
446 pcm.target_point_offset.y = 0;
447 pcm.target_point_offset.z = 0;
449 pcm.constraint_region.primitives.resize(1);
450 pcm.constraint_region.primitives[0].type = shape_msgs::msg::SolidPrimitive::SPHERE;
451 pcm.constraint_region.primitives[0].dimensions.resize(1);
452 pcm.constraint_region.primitives[0].dimensions[shape_msgs::msg::SolidPrimitive::BOX_X] = 0.38 * 2.0;
454 pcm.header.frame_id =
"r_wrist_roll_link";
456 pcm.constraint_region.primitive_poses.resize(1);
457 pcm.constraint_region.primitive_poses[0].position.x = 0.0;
458 pcm.constraint_region.primitive_poses[0].position.y = 0.6;
459 pcm.constraint_region.primitive_poses[0].position.z = 0.0;
460 pcm.constraint_region.primitive_poses[0].orientation.x = 0.0;
461 pcm.constraint_region.primitive_poses[0].orientation.y = 0.0;
462 pcm.constraint_region.primitive_poses[0].orientation.z = 0.0;
463 pcm.constraint_region.primitive_poses[0].orientation.w = 1.0;
472 pcm.constraint_region.primitives[0].type = shape_msgs::msg::SolidPrimitive::BOX;
473 pcm.constraint_region.primitives[0].dimensions.resize(3);
474 pcm.constraint_region.primitives[0].dimensions[shape_msgs::msg::SolidPrimitive::BOX_X] = 0.1;
475 pcm.constraint_region.primitives[0].dimensions[shape_msgs::msg::SolidPrimitive::BOX_Y] = 0.1;
476 pcm.constraint_region.primitives[0].dimensions[shape_msgs::msg::SolidPrimitive::BOX_Z] = 0.1;
479 std::map<std::string, double> jvals;
480 jvals[
"l_shoulder_pan_joint"] = 0.4;
484 EXPECT_TRUE(pc.
equal(pc, 1e-12));
486 jvals[
"l_shoulder_pan_joint"] = -0.4;
492 pcm.constraint_region.primitive_poses.resize(2);
493 pcm.constraint_region.primitive_poses[1].position.x = 0.0;
494 pcm.constraint_region.primitive_poses[1].position.y = 0.1;
495 pcm.constraint_region.primitive_poses[1].position.z = 0.0;
496 pcm.constraint_region.primitive_poses[1].orientation.x = 0.0;
497 pcm.constraint_region.primitive_poses[1].orientation.y = 0.0;
498 pcm.constraint_region.primitive_poses[1].orientation.z = 0.0;
499 pcm.constraint_region.primitive_poses[1].orientation.w = 1.0;
501 pcm.constraint_region.primitives.resize(2);
502 pcm.constraint_region.primitives[1].type = shape_msgs::msg::SolidPrimitive::BOX;
503 pcm.constraint_region.primitives[1].dimensions.resize(3);
504 pcm.constraint_region.primitives[1].dimensions[shape_msgs::msg::SolidPrimitive::BOX_X] = 0.1;
505 pcm.constraint_region.primitives[1].dimensions[shape_msgs::msg::SolidPrimitive::BOX_Y] = 0.1;
506 pcm.constraint_region.primitives[1].dimensions[shape_msgs::msg::SolidPrimitive::BOX_Z] = 0.1;
519 moveit_msgs::msg::PositionConstraint pcm;
521 pcm.link_name =
"l_wrist_roll_link";
522 pcm.target_point_offset.x = 0;
523 pcm.target_point_offset.y = 0;
524 pcm.target_point_offset.z = 0;
526 pcm.constraint_region.primitives.resize(2);
527 pcm.constraint_region.primitives[0].type = shape_msgs::msg::SolidPrimitive::SPHERE;
528 pcm.constraint_region.primitives[0].dimensions.resize(1);
529 pcm.constraint_region.primitives[0].dimensions[0] = 0.38 * 2.0;
530 pcm.constraint_region.primitives[1].type = shape_msgs::msg::SolidPrimitive::BOX;
531 pcm.constraint_region.primitives[1].dimensions.resize(3);
532 pcm.constraint_region.primitives[1].dimensions[shape_msgs::msg::SolidPrimitive::BOX_X] = 2.0;
533 pcm.constraint_region.primitives[1].dimensions[shape_msgs::msg::SolidPrimitive::BOX_Y] = 2.0;
534 pcm.constraint_region.primitives[1].dimensions[shape_msgs::msg::SolidPrimitive::BOX_Z] = 2.0;
536 pcm.header.frame_id =
"r_wrist_roll_link";
537 pcm.constraint_region.primitive_poses.resize(2);
538 pcm.constraint_region.primitive_poses[0].position.x = 0.0;
539 pcm.constraint_region.primitive_poses[0].position.y = 0.6;
540 pcm.constraint_region.primitive_poses[0].position.z = 0.0;
541 pcm.constraint_region.primitive_poses[0].orientation.w = 1.0;
542 pcm.constraint_region.primitive_poses[1].position.x = 2.0;
543 pcm.constraint_region.primitive_poses[1].position.y = 0.0;
544 pcm.constraint_region.primitive_poses[1].position.z = 0.0;
545 pcm.constraint_region.primitive_poses[1].orientation.w = 1.0;
551 EXPECT_TRUE(pc.
equal(pc2, .001));
552 EXPECT_TRUE(pc2.
equal(pc, .001));
555 moveit_msgs::msg::PositionConstraint pcm2 = pcm;
556 pcm2.constraint_region.primitives[0] = pcm.constraint_region.primitives[1];
557 pcm2.constraint_region.primitives[1] = pcm.constraint_region.primitives[0];
559 pcm2.constraint_region.primitive_poses[0] = pcm.constraint_region.primitive_poses[1];
560 pcm2.constraint_region.primitive_poses[1] = pcm.constraint_region.primitive_poses[0];
563 EXPECT_TRUE(pc.
equal(pc2, .001));
564 EXPECT_TRUE(pc2.
equal(pc, .001));
567 pcm2.constraint_region.primitive_poses[0].position.z = .01;
569 EXPECT_FALSE(pc.
equal(pc2, .001));
570 EXPECT_FALSE(pc2.
equal(pc, .001));
571 EXPECT_TRUE(pc.
equal(pc2, .1));
572 EXPECT_TRUE(pc2.
equal(pc, .1));
575 pcm2.constraint_region.primitive_poses[0].position.z = 0.0;
576 pcm2.constraint_region.primitives.resize(3);
577 pcm2.constraint_region.primitive_poses.resize(3);
578 pcm2.constraint_region.primitives[2] = pcm2.constraint_region.primitives[0];
579 pcm2.constraint_region.primitive_poses[2] = pcm2.constraint_region.primitive_poses[0];
581 EXPECT_TRUE(pc.
equal(pc2, .001));
582 EXPECT_TRUE(pc2.
equal(pc, .001));
585 pcm2.constraint_region.primitives[2].dimensions[0] = 3.0;
587 EXPECT_FALSE(pc.
equal(pc2, .001));
588 EXPECT_FALSE(pc2.
equal(pc, .001));
591 pcm2.constraint_region.primitives[2].dimensions[0] = pcm2.constraint_region.primitives[0].dimensions[0];
592 pcm2.constraint_region.primitives[2].type = shape_msgs::msg::SolidPrimitive::SPHERE;
594 EXPECT_FALSE(pc.
equal(pc2, .001));
606 moveit_msgs::msg::OrientationConstraint ocm;
610 ocm.link_name =
"r_wrist_roll_link";
615 ocm.header.frame_id = robot_model_->getModelFrame();
616 ocm.orientation.x = 0.0;
617 ocm.orientation.y = 0.0;
618 ocm.orientation.z = 0.0;
619 ocm.orientation.w = 1.0;
620 ocm.absolute_x_axis_tolerance = 0.1;
621 ocm.absolute_y_axis_tolerance = 0.1;
622 ocm.absolute_z_axis_tolerance = 0.1;
630 ocm.header.frame_id = ocm.link_name;
634 EXPECT_TRUE(oc.
equal(oc, 1e-12));
641 ocm.orientation =
p.orientation;
642 ocm.header.frame_id = robot_model_->getModelFrame();
646 std::map<std::string, double> jvals;
647 jvals[
"r_wrist_roll_joint"] = .05;
652 jvals[
"r_wrist_roll_joint"] = .11;
658 jvals[
"r_wrist_roll_joint"] = M_PI;
672 moveit_msgs::msg::VisibilityConstraint vcm;
676 vcm.sensor_pose.header.frame_id =
"base_footprint";
677 vcm.sensor_pose.pose.position.z = -1.0;
678 vcm.sensor_pose.pose.orientation.x = 0.0;
679 vcm.sensor_pose.pose.orientation.y = 1.0;
680 vcm.sensor_pose.pose.orientation.z = 0.0;
681 vcm.sensor_pose.pose.orientation.w = 0.0;
683 vcm.target_pose.header.frame_id =
"base_footprint";
684 vcm.target_pose.pose.position.z = -2.0;
685 vcm.target_pose.pose.orientation.y = 0.0;
686 vcm.target_pose.pose.orientation.w = 1.0;
688 vcm.target_radius = .2;
690 vcm.max_view_angle = 0.0;
691 vcm.max_range_angle = 0.0;
692 vcm.sensor_view_direction = moveit_msgs::msg::VisibilityConstraint::SENSOR_Z;
699 vcm.max_view_angle = .1;
706 vcm.target_pose.pose.orientation.y = 0.03;
707 vcm.target_pose.pose.orientation.w = sqrt(1 - pow(vcm.target_pose.pose.orientation.y, 2));
712 vcm.target_pose.pose.orientation.y = 0.06;
713 vcm.target_pose.pose.orientation.w = sqrt(1 - pow(vcm.target_pose.pose.orientation.y, 2));
726 moveit_msgs::msg::VisibilityConstraint vcm;
728 vcm.sensor_pose.header.frame_id =
"narrow_stereo_optical_frame";
729 vcm.sensor_pose.pose.position.z = 0.05;
730 vcm.sensor_pose.pose.orientation.w = 1.0;
732 vcm.target_pose.header.frame_id =
"l_gripper_r_finger_tip_link";
733 vcm.target_pose.pose.position.z = 0.03;
734 vcm.target_pose.pose.orientation.w = 1.0;
737 vcm.max_view_angle = 0.0;
738 vcm.max_range_angle = 0.0;
739 vcm.sensor_view_direction = moveit_msgs::msg::VisibilityConstraint::SENSOR_Z;
746 vcm.target_radius = .05;
751 std::map<std::string, double> state_values;
752 state_values[
"l_shoulder_lift_joint"] = .5;
753 state_values[
"r_shoulder_pan_joint"] = .5;
754 state_values[
"r_elbow_flex_joint"] = -1.4;
760 state_values[
"r_shoulder_pan_joint"] = .4;
766 state_values[
"l_shoulder_lift_joint"] = 0;
767 state_values[
"r_shoulder_pan_joint"] = .5;
768 state_values[
"r_elbow_flex_joint"] = -.6;
774 vcm.sensor_view_direction = moveit_msgs::msg::VisibilityConstraint::SENSOR_X;
780 vcm.target_radius = .01;
781 vcm.target_pose.pose.position.z = 0.00;
782 vcm.target_pose.pose.position.x = 0.035;
787 vcm.target_radius = .05;
799 EXPECT_TRUE(kcs.
empty());
801 moveit_msgs::msg::JointConstraint jcm;
802 jcm.joint_name =
"head_pan_joint";
804 jcm.tolerance_above = 0.1;
805 jcm.tolerance_below = 0.05;
809 std::vector<moveit_msgs::msg::JointConstraint> jcv;
811 EXPECT_TRUE(kcs.
add(jcv));
817 std::map<std::string, double> jvals;
818 jvals[jcm.joint_name] = 0.41;
824 EXPECT_FALSE(kcs.
empty());
826 EXPECT_TRUE(kcs.
empty());
828 jcv.back().joint_name =
"head_tilt_joint";
829 EXPECT_TRUE(kcs.
add(jcv));
835 jvals[jcv.back().joint_name] = 0.41;
840 jvals[jcv.back().joint_name] = 0.51;
846 jcv.back().joint_name =
"no_joint";
847 EXPECT_FALSE(kcs.
add(jcv));
853 jvals[
"head_pan_joint"] = 0.51;
867 moveit_msgs::msg::JointConstraint jcm;
868 jcm.joint_name =
"head_pan_joint";
870 jcm.tolerance_above = 0.1;
871 jcm.tolerance_below = 0.05;
874 moveit_msgs::msg::PositionConstraint pcm;
875 pcm.link_name =
"l_wrist_roll_link";
876 pcm.target_point_offset.x = 0;
877 pcm.target_point_offset.y = 0;
878 pcm.target_point_offset.z = 0;
879 pcm.constraint_region.primitives.resize(1);
880 pcm.constraint_region.primitives[0].type = shape_msgs::msg::SolidPrimitive::SPHERE;
881 pcm.constraint_region.primitives[0].dimensions.resize(1);
882 pcm.constraint_region.primitives[0].dimensions[0] = 0.2;
884 pcm.constraint_region.primitive_poses.resize(1);
885 pcm.constraint_region.primitive_poses[0].position.x = 0.55;
886 pcm.constraint_region.primitive_poses[0].position.y = 0.2;
887 pcm.constraint_region.primitive_poses[0].position.z = 1.25;
888 pcm.constraint_region.primitive_poses[0].orientation.x = 0.0;
889 pcm.constraint_region.primitive_poses[0].orientation.y = 0.0;
890 pcm.constraint_region.primitive_poses[0].orientation.z = 0.0;
891 pcm.constraint_region.primitive_poses[0].orientation.w = 1.0;
894 pcm.header.frame_id = robot_model_->getModelFrame();
897 std::vector<moveit_msgs::msg::JointConstraint> jcv;
899 EXPECT_TRUE(kcs.
add(jcv));
901 std::vector<moveit_msgs::msg::PositionConstraint> pcv;
903 EXPECT_TRUE(kcs.
add(pcv, tf));
906 EXPECT_TRUE(kcs2.
add(pcv, tf));
907 EXPECT_TRUE(kcs2.
add(jcv));
910 EXPECT_TRUE(kcs.
equal(kcs2, .001));
911 EXPECT_TRUE(kcs2.
equal(kcs, .001));
915 EXPECT_TRUE(kcs2.
add(jcv));
917 EXPECT_TRUE(kcs.
equal(kcs2, .001));
918 EXPECT_TRUE(kcs2.
equal(kcs, .001));
920 jcm.joint_name =
"head_pan_joint";
922 jcm.tolerance_above = 0.1;
923 jcm.tolerance_below = 0.05;
927 EXPECT_TRUE(kcs2.
add(jcv));
929 EXPECT_FALSE(kcs.
equal(kcs2, .001));
930 EXPECT_FALSE(kcs2.
equal(kcs, .001));
933 EXPECT_TRUE(kcs.
equal(kcs2, .1));
934 EXPECT_TRUE(kcs2.
equal(kcs, .1));
937 int main(
int argc,
char** argv)
939 testing::InitGoogleTest(&argc, argv);
940 return RUN_ALL_TESTS();
moveit::core::RobotModelPtr robot_model_
Class for handling single DOF joint constraints.
bool equal(const KinematicConstraint &other, double margin) const override
Check if two joint constraints are the same.
ConstraintEvaluationResult decide(const moveit::core::RobotState &state, bool verbose=false) const override
Decide whether the constraint is satisfied in the indicated state.
void clear() override
Clear the stored constraint.
bool configure(const moveit_msgs::msg::JointConstraint &jc)
Configure the constraint based on a moveit_msgs::msg::JointConstraint.
bool enabled() const override
This function returns true if this constraint is configured and able to decide whether states do meet...
A class that contains many different constraints, and can check RobotState *versus the full set....
void clear()
Clear the stored constraints.
bool equal(const KinematicConstraintSet &other, double margin) const
Whether or not another KinematicConstraintSet is equal to this one.
bool empty() const
Returns whether or not there are any constraints in the 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.
double getConstraintWeight() const
The weight of a constraint is a multiplicative factor associated to the distance computed by the deci...
Class for constraints on the orientation of a link.
bool equal(const KinematicConstraint &other, double margin) const override
Check if two orientation constraints are the same.
bool mobileReferenceFrame() const
Whether or not a mobile reference frame is being employed.
bool configure(const moveit_msgs::msg::OrientationConstraint &oc, const moveit::core::Transforms &tf)
Configure the constraint based on a moveit_msgs::msg::OrientationConstraint.
const moveit::core::LinkModel * getLinkModel() const
Gets the subject link model.
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 enabled() const override
This function returns true if this constraint is configured and able to decide whether states do meet...
void clear() override
Clear the stored constraint.
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.
bool mobileReferenceFrame() const
If enabled and the specified frame is a mobile frame, return true. Otherwise, returns false.
bool equal(const KinematicConstraint &other, double margin) const override
Check if two constraints are the same. For position constraints this means that:
bool hasLinkOffset() const
If the constraint is enabled and the link offset is substantially different than zero.
Class for constraints on the visibility relationship between a sensor and a target.
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::VisibilityConstraint &vc, const moveit::core::Transforms &tf)
Configure the constraint based on a moveit_msgs::msg::VisibilityConstraint.
const std::string & getName() const
The name of this link.
Representation of a robot's state. This includes position, velocity, acceleration and effort.
void setVariablePositions(const double *position)
It is assumed positions is an array containing the new positions for all variables in this state....
const Eigen::Isometry3d & getGlobalLinkTransform(const std::string &link_name)
Get the link transform w.r.t. the root link (model frame) of the RobotModel. This is typically the ro...
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...
void setJointPositions(const std::string &joint_name, const double *position)
moveit::core::RobotModelPtr loadTestingRobotModel(const std::string &robot_name)
Loads a robot from moveit_resources.
Struct for containing the results of constraint evaluation.
bool satisfied
Whether or not the constraint or constraints were satisfied.
double distance
The distance evaluation from the constraint or constraints.
TEST_F(LoadPlanningModelsPr2, JointConstraintsSimple)
int main(int argc, char **argv)