-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotting.py
42 lines (34 loc) · 1.23 KB
/
plotting.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import matplotlib.pyplot as plt
import numpy as np
from constants import ACCELERATION_ID, SPEED_ID, POSITION_ID
def plot_trajectory(traj, dt):
"""
Plots the acceleration, speed, and position profiles of a given trajectory.
Parameters:
traj (Trajectory): The trajectory object containing the profiles.
dt (float): The time step for the profiles.
Returns:
None
"""
dof = traj.dof
timesteps = int(max(traj.time) / dt)
time = np.linspace(0, max(traj.time), timesteps)
p_list = [traj(t) for t in time]
profiles = np.asarray(p_list)
r_profiles = np.zeros((dof, 3, timesteps))
for d in range(dof):
for p in range(3):
r_profiles[d, p, :] = profiles[:, d, p]
fig = plt.figure(0)
for i, profile in zip(range(dof), r_profiles):
plt.subplot(300 + dof * 10 + (i + 1))
plt.title("Acceleration profile")
plt.plot(time, profile[ACCELERATION_ID][:])
plt.subplot(300 + dof * 10 + (i + 1) + dof)
plt.title("Speed profile")
plt.plot(time, profile[SPEED_ID][:])
plt.subplot(300 + dof * 10 + (i + 1) + dof * 2)
plt.title("Position profile")
plt.plot(time, profile[POSITION_ID][:])
plt.tight_layout()
plt.show()