Skip to content

Commit c2c4d91

Browse files
committed
Update shannon.py
1 parent 7c9d8b3 commit c2c4d91

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

tools/shannon.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
import numpy as np
22
import concore
33
setpoint = 67.5
4+
Kp = 0.1
5+
Ki = 0.01
6+
Kd = 0.01
7+
dT = 0.1
8+
global Prev_Error, I
9+
Prev_Error = 0
10+
I = 0
411

512

6-
def bangbang_controller(ym):
7-
amp = 0
8-
if ym[0]>setpoint +2.5:
9-
amp = 3
10-
elif ym[0]<setpoint -2.5:
11-
amp = 1
12-
13-
13+
def pid_controller(ym):
14+
global Prev_Error, I
15+
Error = setpoint- ym[0]
16+
P = Error
17+
I = I + Error*dT
18+
D = (Error - Prev_Error )/dT
19+
amp = Kp*P + Ki*I + Kd*D
20+
Prev_Error = Error
1421
ustar = np.array([amp,30])
1522
return ustar
1623

@@ -26,7 +33,8 @@ def bangbang_controller(ym):
2633
ym = concore.read(1,"ym",init_simtime_ym)
2734
ym = np.array(ym)
2835

29-
ustar = bangbang_controller(ym)
36+
ustar = pid_controller(ym)
3037

3138
print(str(concore.simtime) + " u="+str(ustar) + "ym="+str(ym))
3239
concore.write(1,"u",list(ustar),delta=0)
40+

0 commit comments

Comments
 (0)