-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
83 lines (75 loc) · 2.17 KB
/
example.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import numpy as np
import matplotlib.pyplot as plt
from minjerk import (
plotMinJerkTraj,
get_multi_interval_minjerk_xyz,
get_multi_interval_multi_dim_minjerk_samples,
get_multi_interval_multi_dim_minjerk_lambda
)
if __name__ == "__main__":
dt = 0.004
smooth_acc = False
smooth_start = False
i_a_end = -1
tt = [0.0, 0.5, 0.6, 0.8, 1.0]
xx = np.array([[0.0, 0.0, -0.1, 0.3, 1.0], [0.0, 0.6, 0.0, 0.2, 0.0]]).T
uu = np.array([[0.0, 3.4, -0.2, 1.1, 0.0], [0.0, 2.2, 0.0, 2.0, 0.0]]).T
# 1. straight forward
xxx, vvv, aaa, jjj = get_multi_interval_minjerk_xyz(
dt, tt, xx, uu, smooth_acc, smooth_start, i_a_end=i_a_end
)
# 2. functional approach values
xxx1, vvv1, aaa1, jjj1 = get_multi_interval_multi_dim_minjerk_samples(
dt, tt, xx, uu, smooth_acc, smooth_start, i_a_end
)
# 3. functional approach lambdas
ttt = np.linspace(tt[0], tt[-1], 1 + int((tt[-1] - tt[0]) / dt))
func = get_multi_interval_multi_dim_minjerk_lambda(
tt, xx, uu, smooth_acc, smooth_start, i_a_end
)
xxx2, vvv2, aaa2, jjj2 = func(ttt)
print(np.linalg.norm(xxx2 - xxx1) / xxx1.size)
print(np.linalg.norm(xxx - xxx1) / xxx.size)
print(np.linalg.norm(vvv - vvv1) / vvv.size)
print(np.linalg.norm(aaa - aaa1) / vvv.size)
print(np.linalg.norm(jjj - jjj1) / vvv.size)
plt.plot(ttt, aaa[:, 0], "b")
plt.plot(ttt, aaa1[:, 0], "r")
plt.title("Differences: straight forward vs functional approach")
plotMinJerkTraj(
xxx[:, 0],
vvv[:, 0],
aaa[:, 0],
jjj[:, 0],
dt,
"straight forward approach",
block=False,
tt=tt,
xx=xx[:, 0],
uu=uu[:, 0],
)
plotMinJerkTraj(
xxx1[:, 0],
vvv1[:, 0],
aaa1[:, 0],
jjj1[:, 0],
dt,
"functional approach values",
block=False,
tt=tt,
xx=xx[:, 0],
uu=uu[:, 0],
)
plotMinJerkTraj(
xxx1[:, 0],
vvv2[:, 0],
aaa2[:, 0],
jjj2[:, 0],
dt,
"functional approach lambdas",
block=False,
tt=tt,
xx=xx[:, 0],
uu=uu[:, 0],
)
plt.show()