Skip to content

Commit 7df21db

Browse files
committed
pidmayuresh returns state
1 parent 08ce4fe commit 7df21db

2 files changed

Lines changed: 70 additions & 5 deletions

File tree

tools/pidmayuresh.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import math
33
import concore
44
dT = 0.1
5-
global Prev_Error, I, freq
5+
global freq
66
Prev_Error = 0
77
I = 0
88

@@ -14,8 +14,8 @@
1414
sigout = concore.tryparam('sigout',True)
1515
cin = concore.tryparam('cin', 'hr')
1616

17-
def pid_controller(ym):
18-
global Prev_Error, I, freq
17+
def pid_controller(Prev_Error, I, ym):
18+
global freq
1919
if cin == 'hr':
2020
Error = sp - ym[1]
2121
elif cin == 'map':
@@ -31,7 +31,7 @@ def pid_controller(ym):
3131
if sigout:
3232
amp = 3.0/(1.0 + math.exp(amp))
3333
ustar = np.array([amp,freq])
34-
return ustar
34+
return (Prev_Error, I, ustar)
3535

3636

3737
concore.default_maxtime(150)
@@ -49,7 +49,7 @@ def pid_controller(ym):
4949
if concore.simtime < 0:
5050
ustar = np.array([0.0,30.0])
5151
else:
52-
ustar = pid_controller(ym)
52+
(Prev_Error, I, ustar) = pid_controller(Prev_Error, I, ym)
5353

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

tools/pidmayuresh1.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import numpy as np
2+
import math
3+
import concore
4+
dT = 0.1
5+
global Prev_Error, I, freq
6+
Prev_Error = 0
7+
I = 0
8+
9+
sp = concore.tryparam('sp', 67.5)
10+
Kp = concore.tryparam('Kp', 0.075)
11+
Ki = concore.tryparam('Ki', 0.02)
12+
Kd = concore.tryparam('Kd', 0.005)
13+
freq = concore.tryparam('freq',30)
14+
sigout = concore.tryparam('sigout',True)
15+
cin = concore.tryparam('cin', 'hr')
16+
17+
def pid_controller(ym):
18+
global Prev_Error, I, freq
19+
if cin == 'hr':
20+
Error = sp - ym[1]
21+
elif cin == 'map':
22+
Error = sp - ym[0]
23+
else:
24+
print('invalid control input '+cin)
25+
quit()
26+
P = Error
27+
I = I + Error*dT
28+
D = (Error - Prev_Error )/dT
29+
amp = Kp*P + Ki*I + Kd*D
30+
Prev_Error = Error
31+
if sigout:
32+
amp = 3.0/(1.0 + math.exp(amp))
33+
ustar = np.array([amp,freq])
34+
return ustar
35+
36+
37+
concore.default_maxtime(150)
38+
concore.delay = 0.02
39+
init_simtime_u = "[0.0, 0.0,0.0]"
40+
init_simtime_ym = "[0.0, 70.0,91]"
41+
u = np.array([concore.initval(init_simtime_u)]).T
42+
print("Mayuresh's and Shannon's PID controller: sp is "+str(sp))
43+
print(concore.params)
44+
while(concore.simtime<concore.maxtime):
45+
while concore.unchanged():
46+
ym = concore.read(1,"ym",init_simtime_ym)
47+
ym = np.array(ym)
48+
49+
if concore.simtime < 0:
50+
ustar = np.array([0.0,30.0])
51+
else:
52+
ustar = pid_controller(ym)
53+
54+
print(str(concore.simtime) + " u="+str(ustar) + "ym="+str(ym))
55+
concore.write(1,"u",list(ustar),delta=0)
56+
57+
58+
59+
#from ast import literal_eval
60+
#try:
61+
# params = literal_eval(open(concore.inpath+"1/concore.params").read())
62+
#except:
63+
# params = dict()
64+
65+

0 commit comments

Comments
 (0)