Skip to content

Commit 14dc1c1

Browse files
authored
Fix bug in linear_trajectory_to method. (#41)
* Fix bug in linear_trajectory_to method. * Add test for linear_trajectory_to method.
1 parent cda081d commit 14dc1c1

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

autolab_core/rigid_transformations.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -377,13 +377,10 @@ def linear_trajectory_to(self, target_tf, traj_len):
377377
"""
378378
if traj_len < 0:
379379
raise ValueError("Traj len must at least 0")
380-
delta_t = 1.0 / (traj_len + 1)
381-
t = 0.0
380+
ts = np.linspace(0.0, 1.0, traj_len)
382381
traj = []
383-
while t < 1.0:
382+
for t in ts:
384383
traj.append(self.interpolate_with(target_tf, t))
385-
t += delta_t
386-
traj.append(target_tf)
387384
return traj
388385

389386
def apply(self, points):

tests/test_rigid_transform.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,18 @@ def test_similarity_transformation(self):
272272
v_b2 = R_a_b.dot(v_a.data)
273273
self.assertTrue(np.allclose(v_b.data, v_b2))
274274

275+
def test_linear_trajectory(self):
276+
R_a = RigidTransform.random_rotation()
277+
t_a = RigidTransform.random_translation()
278+
R_b = RigidTransform.random_rotation()
279+
t_b = RigidTransform.random_translation()
280+
T_a = RigidTransform(R_a, t_a, "w", "a")
281+
T_b = RigidTransform(R_b, t_b, "w", "b")
282+
283+
for i in range(10):
284+
traj = T_a.linear_trajectory_to(T_b, i)
285+
self.assertEqual(len(traj), i, "Trajectory has incorrect length")
286+
275287

276288
if __name__ == "__main__":
277289
unittest.main()

0 commit comments

Comments
 (0)