def test_get_point(self): # Stationary trajectory traj = Trajectory(self.control_points, pixel_size=1 * q.m, furthest_point=1 * q.m) np.testing.assert_equal(traj.get_point(1 * q.s), traj.control_points[0]) tck = interp.splprep(list(zip(*self.control_points)), s=0)[0] def evaluate_point(t): if t > 1: t = 1 return interp.splev(t, tck) * q.m # Create velocity profile which goes until the trajectory end. # We need to scale the sine amplitude in order to # max(sin(x)) = trajectory.length times = np.linspace(0, 2 * np.pi, self.n) * q.s # Normalize for not going below zero. dist = (self.traj.length + self.traj.length * np.sin(times.magnitude)) * q.m traj = Trajectory( self.control_points, pixel_size=1 * q.m, furthest_point=1 * q.m, time_dist=list(zip(times, dist)), ) for i in range(len(times)): np.testing.assert_almost_equal(traj.get_point(times[i]), evaluate_point(dist[i] / traj.length), decimal=4)
def test_get_point(self): # Stationary trajectory traj = Trajectory(self.control_points, pixel_size=1 * q.m, furthest_point=1 * q.m) np.testing.assert_equal(traj.get_point(1 * q.s), traj.control_points[0]) tck = interp.splprep(zip(*self.control_points), s=0)[0] def evaluate_point(t): if t > 1: t = 1 return interp.splev(t, tck) * q.m # Create velocity profile which goes until the trajectory end. # We need to scale the sine amplitude in order to # max(sin(x)) = trajectory.length times = np.linspace(0, 2 * np.pi, self.n) * q.s # Normalize for not going below zero. dist = (self.traj.length + self.traj.length * np.sin(times.magnitude)) * q.m traj = Trajectory(self.control_points, pixel_size=1 * q.m, furthest_point=1 * q.m, time_dist=zip(times, dist)) for i in range(len(times)): np.testing.assert_almost_equal(traj.get_point(times[i]), evaluate_point(dist[i] / traj.length), decimal=4)
def test_get_next_time(self): """Very small rotation circle but large object extent.""" def pr(v, decimals=2): return np.round(v, decimals) points = make_circle(n=128) * 1e-3 x, y, z = list(zip(*points)) furthest = 1 * q.mm ps = 10 * q.um tr = Trajectory(points, ps, furthest, velocity=1 * q.mm / q.s) t_0 = 0 * q.s t_1 = 0 * q.s max_diff = 0 * q.m while t_1 != np.inf * q.s: t_1 = tr.get_next_time(t_0) p_0 = tr.get_point(t_0) p_1 = tr.get_point(t_1) d_0 = tr.get_direction(t_0, norm=True) d_1 = tr.get_direction(t_1, norm=True) dp = np.abs(p_1 - p_0) dd = np.abs(d_1 - d_0) * furthest total = dp + dd ds = max(total) if ds > max_diff: max_diff = ds t_0 = t_1 max_diff = max_diff.rescale(q.um).magnitude ps = ps.rescale(q.um).magnitude np.testing.assert_almost_equal(ps, max_diff, decimal=2)
def test_get_next_time(self): """Very small rotation circle but large object extent.""" def pr(v, decimals=2): return np.round(v, decimals) points = make_circle(n=128) * 1e-3 x, y, z = zip(*points) furthest = 1 * q.mm ps = 10 * q.um tr = Trajectory(points, ps, furthest, velocity=1 * q.mm / q.s) t_0 = 0 * q.s t_1 = 0 * q.s max_diff = 0 * q.m while t_1 != np.inf * q.s: t_1 = tr.get_next_time(t_0) p_0 = tr.get_point(t_0) p_1 = tr.get_point(t_1) d_0 = tr.get_direction(t_0, norm=True) d_1 = tr.get_direction(t_1, norm=True) dp = np.abs(p_1 - p_0) dd = np.abs(d_1 - d_0) * furthest total = dp + dd ds = max(total) if ds > max_diff: max_diff = ds t_0 = t_1 max_diff = max_diff.rescale(q.um).magnitude ps = ps.rescale(q.um).magnitude np.testing.assert_almost_equal(ps, max_diff, decimal=2)