Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.

Commit bd53490

Browse files
authored
Fix OrientationConstraint::decide (moveit#2414)
* Fix OrientationConstraint::decide * Add new test case for OrientationConstraintsSimple * Add comments for clarity
1 parent f56e175 commit bd53490

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

moveit_core/kinematic_constraints/src/kinematic_constraint.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -620,9 +620,10 @@ ConstraintEvaluationResult OrientationConstraint::decide(const moveit::core::Rob
620620
xyz = diff.linear().eulerAngles(0, 1, 2); // 0,1,2 corresponds to XYZ, the convention used in sampling constraints
621621
}
622622

623-
xyz(0) = std::min(fabs(xyz(0)), boost::math::constants::pi<double>() - fabs(xyz(0)));
624-
xyz(1) = std::min(fabs(xyz(1)), boost::math::constants::pi<double>() - fabs(xyz(1)));
625-
xyz(2) = std::min(fabs(xyz(2)), boost::math::constants::pi<double>() - fabs(xyz(2)));
623+
// Account for angle wrapping
624+
xyz(0) = std::min(fabs(xyz(0)), boost::math::constants::two_pi<double>() - fabs(xyz(0)));
625+
xyz(1) = std::min(fabs(xyz(1)), boost::math::constants::two_pi<double>() - fabs(xyz(1)));
626+
xyz(2) = std::min(fabs(xyz(2)), boost::math::constants::two_pi<double>() - fabs(xyz(2)));
626627
bool result = xyz(2) < absolute_z_axis_tolerance_ + std::numeric_limits<double>::epsilon() &&
627628
xyz(1) < absolute_y_axis_tolerance_ + std::numeric_limits<double>::epsilon() &&
628629
xyz(0) < absolute_x_axis_tolerance_ + std::numeric_limits<double>::epsilon();

moveit_core/kinematic_constraints/test/test_constraints.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <fstream>
4141
#include <tf2_eigen/tf2_eigen.h>
4242
#include <moveit/utils/robot_model_test_utils.h>
43+
#include <boost/math/constants/constants.hpp>
4344

4445
class LoadPlanningModelsPr2 : public testing::Test
4546
{
@@ -652,6 +653,12 @@ TEST_F(LoadPlanningModelsPr2, OrientationConstraintsSimple)
652653
robot_state.setVariablePositions(jvals);
653654
robot_state.update();
654655
EXPECT_FALSE(oc.decide(robot_state).satisfied);
656+
657+
// rotation by pi does not wrap to zero
658+
jvals["r_wrist_roll_joint"] = boost::math::constants::pi<double>();
659+
robot_state.setVariablePositions(jvals);
660+
robot_state.update();
661+
EXPECT_FALSE(oc.decide(robot_state).satisfied);
655662
}
656663

657664
TEST_F(LoadPlanningModelsPr2, VisibilityConstraintsSimple)

0 commit comments

Comments
 (0)