diff --git a/source/isaaclab/changelog.d/fix-pose-interpolation-perturbation.fixed.rst b/source/isaaclab/changelog.d/fix-pose-interpolation-perturbation.fixed.rst new file mode 100644 index 000000000000..ad378b55a98d --- /dev/null +++ b/source/isaaclab/changelog.d/fix-pose-interpolation-perturbation.fixed.rst @@ -0,0 +1,2 @@ +* Fixed :func:`~isaaclab.utils.math.interpolate_poses` skipping the last intermediate position when + position perturbation was enabled. Both endpoints remained unchanged. diff --git a/source/isaaclab/isaaclab/utils/math.py b/source/isaaclab/isaaclab/utils/math.py index c27747152ffb..8a80f6340376 100644 --- a/source/isaaclab/isaaclab/utils/math.py +++ b/source/isaaclab/isaaclab/utils/math.py @@ -1909,9 +1909,9 @@ def interpolate_poses( pos_step_size = delta_pos / num_steps grid = torch.arange(num_steps, dtype=torch.float32) if perturb: - # Move interpolation grid points by up to half-size forward or backward - perturbations = torch.rand(num_steps - 2) - 0.5 - grid[1:-1] += perturbations + # Keep the start fixed. The endpoint is appended after interpolation. + perturbations = torch.rand(num_steps - 1) - 0.5 + grid[1:] += perturbations pos_steps = torch.stack([pos1 + grid[i] * pos_step_size for i in range(num_steps)]) # Add in endpoint diff --git a/source/isaaclab/test/utils/test_math.py b/source/isaaclab/test/utils/test_math.py index bf2d30eb9369..51d2712fb1e9 100644 --- a/source/isaaclab/test/utils/test_math.py +++ b/source/isaaclab/test/utils/test_math.py @@ -599,6 +599,24 @@ def test_interpolate_poses(): np.testing.assert_array_almost_equal(result_pos, expected_pos, decimal=DECIMAL_PRECISION) +@pytest.mark.kitless +def test_interpolate_poses_perturbs_single_interior_point() -> None: + """Perturb the only intermediate position while preserving both endpoints.""" + start = torch.eye(4) + end = start.clone() + end[0, 3] = 1.0 + + with torch.random.fork_rng(devices=[]): + torch.random.default_generator.manual_seed(0) + poses, num_steps = math_utils.interpolate_poses(start, end, num_steps=1, perturb=True) + + assert num_steps == 1 + torch.testing.assert_close(poses[[0, -1]], torch.stack([start, end])) + x = poses[1, 0, 3].item() + assert 0.25 <= x <= 0.75 + assert x != 0.5 + + def test_interpolate_poses_without_interpolation(): """Test that interpolate_poses with num_steps=0 returns just the start and end poses.""" pose_1 = math_utils.generate_random_transformation_matrix()