|
| 1 | +import matplotlib.pyplot as plt |
| 2 | +import numpy as np |
| 3 | + |
| 4 | +from turtle_loc_oracles.task_space import green_sea_turtle_task_space_trajectory_factory |
| 5 | + |
| 6 | +# the spatial scaling factor |
| 7 | +sf = 1.0 |
| 8 | +# the temporal scaling factor |
| 9 | +sw = 1.0 |
| 10 | +# the positional offset |
| 11 | +x_off = np.array([1.0, 1.0, 1.0]) |
| 12 | + |
| 13 | +if __name__ == "__main__": |
| 14 | + # call the oracle factory function |
| 15 | + x_fn, x_d_fn, x_dd_fn, th_fn, th_d_fn, th_dd_fn = green_sea_turtle_task_space_trajectory_factory( |
| 16 | + sf=sf, sw=sw, x_off=x_off |
| 17 | + ) |
| 18 | + |
| 19 | + # create a vector with time stamps |
| 20 | + ts = np.linspace(0, 10, 1000) |
| 21 | + |
| 22 | + # evaluate the oracle at each time step |
| 23 | + # position, velocity, and acceleration |
| 24 | + x_ts = np.array([x_fn(t) for t in ts]) |
| 25 | + x_d_ts = np.array([x_d_fn(t) for t in ts]) |
| 26 | + x_dd_ts = np.array([x_dd_fn(t) for t in ts]) |
| 27 | + # twist angle, twist angular velocity, and twist angular acceleration |
| 28 | + th_ts = np.array([th_fn(t) for t in ts]) |
| 29 | + th_d_ts = np.array([th_d_fn(t) for t in ts]) |
| 30 | + th_dd_ts = np.array([th_dd_fn(t) for t in ts]) |
| 31 | + |
| 32 | + # plot the oracle |
| 33 | + dpi = 150 |
| 34 | + fig = plt.figure(dpi=dpi) |
| 35 | + ax = fig.gca() |
| 36 | + ax.plot(ts, x_ts[:, 0], label=r"$x$") |
| 37 | + ax.plot(ts, x_ts[:, 1], label=r"$y$") |
| 38 | + ax.plot(ts, x_ts[:, 2], label=r"$z$") |
| 39 | + ax.set_xlabel("Time [s]") |
| 40 | + ax.set_ylabel("Task space position [m]") |
| 41 | + ax.legend() |
| 42 | + ax.grid(True) |
| 43 | + plt.box(True) |
| 44 | + plt.tight_layout() |
| 45 | + plt.show() |
| 46 | + |
| 47 | + fig = plt.figure(dpi=dpi) |
| 48 | + ax = fig.gca() |
| 49 | + ax.plot(ts, x_d_ts[:, 0], label=r"$\dot{x}$") |
| 50 | + ax.plot(ts, x_d_ts[:, 1], label=r"$\dot{y}$") |
| 51 | + ax.plot(ts, x_d_ts[:, 2], label=r"$\dot{z}$") |
| 52 | + ax.set_xlabel("Time [s]") |
| 53 | + ax.set_ylabel("Task space velocity [m/s]") |
| 54 | + ax.legend() |
| 55 | + ax.grid(True) |
| 56 | + plt.box(True) |
| 57 | + plt.tight_layout() |
| 58 | + plt.show() |
| 59 | + |
| 60 | + fig = plt.figure(dpi=dpi) |
| 61 | + ax = fig.gca() |
| 62 | + ax.plot(ts, x_dd_ts[:, 0], label=r"$\ddot{x}$") |
| 63 | + ax.plot(ts, x_dd_ts[:, 1], label=r"$\ddot{y}$") |
| 64 | + ax.plot(ts, x_dd_ts[:, 2], label=r"$\ddot{z}$") |
| 65 | + ax.set_xlabel("Time [s]") |
| 66 | + ax.set_ylabel(r"Task space acceleration [m/s$^2$]") |
| 67 | + ax.legend() |
| 68 | + ax.grid(True) |
| 69 | + plt.box(True) |
| 70 | + plt.tight_layout() |
| 71 | + plt.show() |
| 72 | + |
| 73 | + # plot the position in 3D space with the velocity magnitude as color |
| 74 | + x_d_norm_ts = np.linalg.norm(x_d_ts, axis=1) |
| 75 | + fig = plt.figure() |
| 76 | + ax = fig.add_subplot(111, projection="3d") |
| 77 | + sc = ax.scatter(x_ts[:, 0], x_ts[:, 1], x_ts[:, 2], c=x_d_norm_ts, cmap="coolwarm") |
| 78 | + fig.colorbar(sc, shrink=0.7, label=r"$|\dot{x}|_2$") |
| 79 | + ax.set_xlabel(r"$x$ [m]") |
| 80 | + ax.set_ylabel(r"$y$ [m]") |
| 81 | + ax.set_zlabel(r"$z$ [m]") |
| 82 | + ax.grid(True) |
| 83 | + ax.set_aspect("equal") |
| 84 | + plt.show() |
| 85 | + |
| 86 | + fig = plt.figure(dpi=dpi) |
| 87 | + ax = fig.gca() |
| 88 | + ax.plot(ts, th_ts, label=r"$\theta$") |
| 89 | + ax.set_xlabel("Time [s]") |
| 90 | + ax.set_ylabel("Flipper twist angle [rad]") |
| 91 | + ax.legend() |
| 92 | + ax.grid(True) |
| 93 | + plt.box(True) |
| 94 | + plt.tight_layout() |
| 95 | + plt.show() |
| 96 | + |
| 97 | + fig = plt.figure(dpi=dpi) |
| 98 | + ax = fig.gca() |
| 99 | + ax.plot(ts, th_d_ts, label=r"$\dot{\theta}$") |
| 100 | + ax.set_xlabel("Time [s]") |
| 101 | + ax.set_ylabel("Flipper twist angular velocity [rad/s]") |
| 102 | + ax.legend() |
| 103 | + ax.grid(True) |
| 104 | + plt.box(True) |
| 105 | + plt.tight_layout() |
| 106 | + plt.show() |
| 107 | + |
| 108 | + fig = plt.figure(dpi=dpi) |
| 109 | + ax = fig.gca() |
| 110 | + ax.plot(ts, th_dd_ts, label=r"$\ddot{\theta}$") |
| 111 | + ax.set_xlabel("Time [s]") |
| 112 | + ax.set_ylabel(r"Flipper twist angular acceleration [rad/s$^2$]") |
| 113 | + ax.legend() |
| 114 | + ax.grid(True) |
| 115 | + plt.box(True) |
| 116 | + plt.tight_layout() |
| 117 | + plt.show() |
0 commit comments