support for some unittests in CMake
[liba.git] / python / test / 3rd / trajtrap.py
blob541bd1caf5f74dd0a7ec5ef59c09c29ee66f64c2
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 numpy as np
10 import matplotlib.pyplot as plt
11 except Exception as e:
12 print(e)
13 exit()
15 import liba # type: ignore
17 traj = liba.trajtrap()
18 traj.gen(2, 2, -2, 0, 4)
19 data = np.arange(0, traj.t, traj.t / 1000)
21 plt.figure("trapezoidal velocity trajectory")
23 plt.subplot(311)
24 plt.title("trapezoidal velocity trajectory")
25 plt.ylabel("Position")
26 plt.plot(data, traj.pos(data), "r-", label="q")
27 plt.legend()
29 plt.subplot(312)
30 plt.ylabel("Velocity")
31 plt.plot(data, traj.vel(data), "b-", label="v")
32 plt.legend()
34 plt.subplot(313)
35 plt.ylabel("Acceleration")
36 plt.plot(data, traj.acc(data), "g-", label="a")
37 plt.legend()
39 plt.xlabel("t")
40 plt.savefig(os.path.join(prefix, "trapezoidal_trajectory.png"))
41 plt.show()