rename (t|q)(a|c|d) to (t|q)(1|2|) in traptraj
[liba.git] / python / test / traptraj.py
blob735734036d2b86dd29a2ddcd39df202948ada366
1 #!/usr/bin/env python
2 import os, sys
4 sys.path.insert(0, os.getcwd())
5 prefix = os.path.join(sys.path[0], "build")
6 if not os.path.exists(prefix):
7 os.mkdir(prefix)
8 try:
9 import liba as a
10 import numpy as np
11 import matplotlib.pyplot as plt
12 except Exception as e:
13 print(e)
14 exit()
16 traj = a.traptraj(10, 2, 2, -2)
17 data = np.arange(0, traj.t, 0.01)
18 plt.figure("trapezoidal velocity profile trajectory")
20 plt.subplot(311)
21 plt.title("trapezoidal velocity profile trajectory")
22 plt.ylabel("Position")
23 plt.plot(data, traj.pos(data), "r-", label="q")
24 plt.legend()
26 plt.subplot(312)
27 plt.ylabel("Velocity")
28 plt.plot(data, traj.vel(data), "b-", label="v")
29 plt.legend()
31 plt.subplot(313)
32 plt.ylabel("Acceleration")
33 plt.plot(data, traj.acc(data), "g-", label="a")
34 plt.legend()
36 plt.xlabel("t")
37 plt.savefig(os.path.join(prefix, "trapezoidal_trajectory.png"))