4 base
= os
.path
.dirname(__file__
)
5 path
= os
.path
.dirname(base
)
6 path
= os
.path
.dirname(path
)
7 sys
.path
.insert(0, path
)
10 import matplotlib
.pyplot
as plt
11 except Exception as e
:
17 import control
.matlab
as ct
19 sysc
= ct
.tf(133, [1, 25, 0])
20 sysd
= ct
.c2d(sysc
, Ts
)
23 [[num
]], [[den
]] = ct
.tfdata(sysd
)
24 except ModuleNotFoundError
:
25 num
= [6.59492796e-05, 6.54019884e-05]
26 den
= [1.0, -1.97530991, 0.97530991]
27 except Exception as e
:
30 import liba
# type: ignore
39 tf
= liba
.tf(num
, den
[1:])
40 pid
= liba
.pid().set_kpid(kp
, ki
, kd
)
45 data
= np
.arange(0, 0.2, Ts
)
46 setpoint
= [r
] * len(data
)
48 title
= "Proportional Integral Derivative Position"
73 u
= kp
* x
[0] + x
[1] + kd
* x
[2]
85 plt
.plot(data
, setpoint
, "r-", data
, feedback1
, "b-", data
, feedback2
, "g-")
89 plt
.plot(data
, error1
, "b-", data
, error2
, "g-")
93 plt
.savefig(os
.path
.join(base
, "pid_pos.png"))
95 title
= "Proportional Integral Derivative Increment"
120 x
[2] = e
[0] - e
[1] * 2 + e
[2]
121 u
+= kp
* x
[0] + ki
* x
[1] + kd
* x
[2]
134 plt
.plot(data
, setpoint
, "r-", data
, feedback1
, "b-", data
, feedback2
, "g-")
138 plt
.plot(data
, error1
, "b-", data
, error2
, "g-")
140 plt
.xlabel("time(s)")
142 plt
.savefig(os
.path
.join(base
, "pid_inc.png"))