Skip to content

resample_trajectory drops the final timestep (np.arange endpoint exclusion) #2

Description

@midasbal

Summary

resample_trajectory builds its output time grid with
np.arange(t_start, t_end, target_dt), which excludes the endpoint. As a
result every resampled trajectory loses its final timestep, including the
terminal robot configuration.

Location

smooth_resampled_traj.py, in resample_trajectory (grid built around line 338):

t_start, t_end = float(times[0]), float(times[-1])
new_times = np.arange(t_start, t_end, target_dt)

Reproduction

import numpy as np
t_start, t_end, target_dt = 0.0, 1.0, 0.1
new_times = np.arange(t_start, t_end, target_dt)
print(new_times[-1])   # 0.9, expected to reach ~1.0

A trajectory spanning 0.0 to 1.0 s resampled at dt=0.1 ends at 0.9 s. The
frame at 1.0 s is dropped.

Impact

  • The terminal frame is usually the most meaningful one in teleoperation data
    (final arm pose, gripper closed on the object), and it is silently discarded.
  • The truncation propagates through process_single_trajectory into the saved
    joints and the interpolated extra state, so the whole output is one step short.
  • When target_dt does not evenly divide the span, floating point accumulation
    can further shift the final grid point.

Suggested fix

Construct the grid so it reaches the endpoint while keeping uniform spacing,
by computing the step count and landing on (or just past) t_end instead of
stopping short.

One design question before implementing: do you want strict uniform dt, where
the final point may not equal t_end exactly when the span is not a multiple of
dt, or an exact landing on t_end, where the final interval is slightly
shorter than dt? Both are reasonable and I did not want to assume.

Offer

I'm happy to open a PR with the fix and a small regression test covering the
grid endpoint, once you confirm which of the two behaviors you prefer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions