Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 3 additions & 3 deletions source/isaaclab/isaaclab/utils/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions source/isaaclab/test/utils/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down