forked from pkicki/TSwR_student
-
Notifications
You must be signed in to change notification settings - Fork 0
/
adrflc.py
63 lines (52 loc) · 1.5 KB
/
adrflc.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
import matplotlib.pyplot as plt
import numpy as np
from controllers.adrc_flc_controller import ADRFLController
from trajectory_generators.constant_torque import ConstantTorque
from trajectory_generators.sinusonidal import Sinusoidal
from trajectory_generators.poly3 import Poly3
from utils.simulation import simulate
Tp = 0.001
end = 30
# traj_gen = ConstantTorque(np.array([0., 1.0])[:, np.newaxis])
traj_gen = Sinusoidal(np.array([0., 1.]), np.array([2., 2.]), np.array([0., 0.]))
# traj_gen = Poly3(np.array([0., 0.]), np.array([pi/4, pi/6]), end)
b_est_1 = 2
b_est_2 = 10
kp_est_1 = 100
kp_est_2 = 20
kd_est_1 = 50
kd_est_2 = 10
p1 = 100
p2 = 100
q0, qdot0, _ = traj_gen.generate(0.)
q1_0 = np.array([q0[0], qdot0[0]])
q2_0 = np.array([q0[1], qdot0[1]])
Kp = np.diag([kp_est_1, kp_est_2])
Kd = np.diag([kd_est_1, kd_est_2])
p = np.array([p1, p2])
controller = ADRFLController(Tp, np.concatenate([q0, qdot0]), Kp, Kd, p)
Q, Q_d, u, T = simulate("PYBULLET", traj_gen, controller, Tp, end)
eso = np.array(controller.eso.states)
plt.subplot(221)
plt.plot(T, eso[:, 0])
plt.plot(T, Q[:, 0], 'r')
plt.subplot(222)
plt.plot(T, eso[:, 2])
plt.plot(T, Q[:, 2], 'r')
plt.subplot(223)
plt.plot(T, eso[:, 1])
plt.plot(T, Q[:, 1], 'r')
plt.subplot(224)
plt.plot(T, eso[:, 3])
plt.plot(T, Q[:, 3], 'r')
plt.show()
plt.subplot(221)
plt.plot(T, Q[:, 0], 'r')
plt.plot(T, Q_d[:, 0], 'b')
plt.subplot(222)
plt.plot(T, Q[:, 1], 'r')
plt.plot(T, Q_d[:, 1], 'b')
plt.subplot(223)
plt.plot(T, u[:, 0], 'r')
plt.plot(T, u[:, 1], 'b')
plt.show()