Skip to content

Commit e08b402

Browse files
committed
added unit test
1 parent 83d411c commit e08b402

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

moveit_core/robot_model/test/test.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,36 @@ TEST(FloatingJointTest, interpolation_test)
172172
}
173173
}
174174

175+
TEST(PlanarJointTest, ComputeVariablePositionsNormalizeYaw)
176+
{
177+
// Create a simple planar joint model with some dummy parameters
178+
moveit::core::PlanarJointModel pjm("joint", 0, 0);
179+
180+
// Test various angles for normalization
181+
std::vector<double> test_angles = {0.0, M_PI/2, -M_PI/2, M_PI, -M_PI, 3.0, -3.0,4.1, -4.1};
182+
for (double angle : test_angles)
183+
{
184+
// Create a transform with the given yaw angle
185+
Eigen::Isometry3d transform = Eigen::Isometry3d::Identity();
186+
Eigen::AngleAxisd q = Eigen::AngleAxisd(angle, Eigen::Vector3d::UnitZ());
187+
transform.linear() = q.toRotationMatrix();
188+
189+
// Compute the variable positions from the transform
190+
double joint_values[3];
191+
pjm.computeVariablePositions(transform, joint_values);
192+
193+
// Check that the x and y values are zero (since we didn't set any translation)
194+
EXPECT_NEAR(joint_values[0], 0.0, 1e-6);
195+
EXPECT_NEAR(joint_values[1], 0.0, 1e-6);
196+
197+
// The yaw value should be normalized to the range [-pi, pi]
198+
double normalized_angle = angle;
199+
while (normalized_angle > M_PI) normalized_angle -= 2.0 * M_PI;
200+
while (normalized_angle < -M_PI) normalized_angle += 2.0 * M_PI;
201+
EXPECT_NEAR(joint_values[2], normalized_angle, 1e-6);
202+
}
203+
}
204+
175205
int main(int argc, char** argv)
176206
{
177207
testing::InitGoogleTest(&argc, argv);

0 commit comments

Comments
 (0)