1 from __future__
import print_function, division
3 import matplotlib.pyplot
as plt
6 __all__ = [
"sig_int_handler",
"publish_pose",
"publish_trajectory",
7 "publish_time_indexed_trajectory",
"plot"]
11 raise KeyboardInterrupt
15 problem.get_scene().update(q, t)
16 problem.get_scene().get_kinematic_tree().publish_frames()
21 Plays back a trajectory by updating the scene in a problem and publishing the corresponding tf transforms.
24 traj (list[list[]]): A trajectory consisting of a list of configurations which can be either Python lists or np.array.
25 T (float): Time taken for playback. The timestep between configurations is assumed constant and is calculated as T/len(traj)
26 problem (pyexotica.PlanningProblem): The planning problem whose Scene will be used for playback
27 once (bool): Whether to play the trajectory once or in a loop. By default, will play back the trajectory until a KeyboardInterrupt has been received.
30 raise ValueError(
"Trajectory has zero elements")
31 signal.signal(signal.SIGINT, sig_int_handler)
32 print(
'Playing back trajectory ' + str(T) +
's')
33 dt = float(T) / float(len(traj))
39 if t >= len(traj) - 1
and once:
41 t = (t + 1) % len(traj)
42 except KeyboardInterrupt:
48 raise ValueError(
"Trajectory has zero elements")
49 signal.signal(signal.SIGINT, sig_int_handler)
50 print(
'Playing back trajectory ' + str(len(Ts)) +
51 ' states in ' + str(Ts[len(Ts) - 1]))
55 for i
in range(1, len(Ts) - 1):
57 sleep(Ts[i] - Ts[i-1])
60 except KeyboardInterrupt:
65 def plot(solution, labels=None, yscale=None):
66 print(
'Plotting the solution')
67 plt.plot(solution,
'.-')
68 if labels
is not None:
70 if yscale
is not None: