-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsingle_pend_balance.py
66 lines (61 loc) · 1.47 KB
/
single_pend_balance.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
from SI import data_collection as Pendulum
from time import sleep
from SI.sim import single_pendulum_model_stepper
import numpy as np
import sympy as sp
# up
Q = np.diag([500, 100, 40, 100])
R = np.diag([10])
eigs = np.array([
[-3],
[-3.5],
[-4],
[-5.5],
])*5
sp = [0, sp.pi, 0]
# down
# Q = np.diag([10000, 70, 1, 700])
# R = np.diag([50])
model = (single_pendulum_model_stepper.dipc_model()
.set_constants([0.225, 0.126, 0.13, 0.0027, 10, 10])#[0.24, 0.11, 0.1, 0.001, 10, 10])
.set_constants([0.225, 0.126, 0.13, 0.0027, 10, 10])#[0.24, 0.11, 0.1, 0.001, 10, 10])
.linearize(op_point = sp[:2]+[0, 0])
.construct_PP(eigs)
.construct_LQR(Q, R))
print(model.A)
print(model.B)
# exit()
PP, LQR = list(model.K['PP'][0]), list(model.K['LQR'][0])
print(PP, LQR)
print(model.get_eigs('PP'))
LQR.insert(2, 0)
LQR.append(0)
PP.insert(2, 0)
PP.append(0)
# LQR[0]*= 1
# LQR *= -1
# LQR[0] *= -1
# LQR[1] *= -1
# LQR[2] *= -1
# LQR[3] *= -1
print('PP eigs:')
print(np.linalg.eig(model.A - [email protected]['PP']))
print('LQR eigs:')
print(np.linalg.eig(model.A - [email protected]['LQR']))
print(PP)
print(LQR)
with Pendulum.Pendulum(file = '/dev/null') as p:
p.set_mode('usb')
p.set(0)
sleep(0.1)
print(PP)
p.set_K(LQR)
# down
# p.set_SP([0, -0.01, 0])
# up
p.set_SP([0, np.pi-0.008, 0])
input('Press [enter] to start balancing.')
p.set_mode('local')
input('Press [enter] to stop balancing.')
p.set_mode('usb')
p.set(0)