Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions tools/shannon.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import numpy as np
import concore
setpoint = 67.5
Kp = 0.1
Ki = 0.01
Kd = 0.01
dT = 0.1
global Prev_Error, I
Prev_Error = 0
I = 0


def bangbang_controller(ym):
amp = 0
if ym[0]>setpoint +2.5:
amp = 3
elif ym[0]<setpoint -2.5:
amp = 1

def pid_controller(ym):
global Prev_Error, I
Error = setpoint- ym[0]
P = Error
I = I + Error*dT
D = (Error - Prev_Error )/dT
amp = Kp*P + Ki*I + Kd*D
Prev_Error = Error
ustar = np.array([amp,30])
return ustar

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

ustar = bangbang_controller(ym)
ustar = pid_controller(ym)

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