You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I did not find a way to do trajectory alignment by interpolation of the estimated trajectory, which I think is a fairly normal thing to have in a package such as this.
For each time t in the reference trajectory, the code below will find the nearest next timestep t_next and the one before, t_prev. It will then interpolate between the poses at t_next and t_prev according to t.
fromwarningsimportwarnimportnumpyasnpfromevo.core.trajectoryimportPoseTrajectory3Dfromevo.core.transformationsimportquaternion_slerpasqslerpdeflerp(a, b, t):
return (1.0-t)*a+t*b# We need to do linear interpolation, ourselves...defcv_interp(est, ref_timestamps, *, extrapolate_past_end=False):
"Compute points along trajectory *est* at *timestamps* or trajectory *ref*."# Accept trajectories ifhasattr(ref_timestamps, 'timestamps'):
ref_timestamps=ref_timestamps.timestampsref_timestamps=np.array(ref_timestamps, copy=True)
est_tran=est.positions_xyzest_quat=est.orientations_quat_wxyz# Index of closest next estimated timestamp for each pose in *est*.# Must be >= 1 since we look at the previous pose.i=1forj, t_refinenumerate(ref_timestamps):
whilei<est.num_posesandest.timestamps[i] <=t_ref:
i+=1ifnotextrapolate_past_endandest.num_poses<=i:
warn('reference trajectory ends after estimated, cut short')
breakt_prev=est.timestamps[i-1]
t_next=est.timestamps[i]
td= (t_ref-t_prev) / (t_next-t_prev)
quat_j=qslerp(est_quat[i-1], est_quat[i], td)
tran_j=lerp(est_tran[i-1], est_tran[i], td)
yieldnp.r_[t_ref, tran_j, quat_j]
deftrajectory_interpolation(est, timestamps):
poses=np.array(list(cv_interp(est, timestamps)))
times=poses[:, 0]
trans=poses[:, 1:4]
quats=poses[:, 4:8]
returnPoseTrajectory3D(trans, quats, times, meta=est.meta)
I'm sure there is a better way to do this with the stuff in lie.py but the above code works.
The text was updated successfully, but these errors were encountered:
Hi, I did not find a way to do trajectory alignment by interpolation of the estimated trajectory, which I think is a fairly normal thing to have in a package such as this.
For each time
t
in the reference trajectory, the code below will find the nearest next timestept_next
and the one before,t_prev
. It will then interpolate between the poses att_next
andt_prev
according tot
.I'm sure there is a better way to do this with the stuff in
lie.py
but the above code works.The text was updated successfully, but these errors were encountered: