Skip to content

Commit 52b0c3b

Browse files
refactor: consolidate duplicate PID controller (pidmayuresh3 wrapper)
Replace the duplicate PID implementation in tools/pidmayuresh3.py with a thin backward-compatibility wrapper that re-exports from pidmayuresh.py. - pidmayuresh.py remains the canonical implementation (uses logging) - pidmayuresh3.py now imports from pidmayuresh.py with a DeprecationWarning - No PID logic, API, or default parameters changed - All existing imports of pidmayuresh3 continue to work Closes #378
1 parent 93a8759 commit 52b0c3b

1 file changed

Lines changed: 23 additions & 49 deletions

File tree

tools/pidmayuresh3.py

Lines changed: 23 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,26 @@
1-
import numpy as np
2-
import math
3-
import concore
4-
dT = 0.1
5-
6-
sp = concore.tryparam('sp', 67.5)
7-
Kp = concore.tryparam('Kp', 0.075)
8-
Ki = concore.tryparam('Ki', 0.02)
9-
Kd = concore.tryparam('Kd', 0.005)
10-
freq = concore.tryparam('freq',30)
11-
sigout = concore.tryparam('sigout',True)
12-
cin = concore.tryparam('cin', 'hr')
13-
14-
def pid_controller(state, ym, sp, Kp, Ki, Kd, sigout, cin, low, up):
15-
Prev_Error = state[0]
16-
I = state[1]
17-
if cin == 'hr':
18-
Error = sp - ym[1]
19-
elif cin == 'map':
20-
Error = sp - ym[0]
21-
else:
22-
print('invalid control input '+cin)
23-
quit()
24-
P = Error
25-
I = I + Error*dT
26-
D = (Error - Prev_Error )/dT
27-
amp = Kp*P + Ki*I + Kd*D
28-
Prev_Error = Error
29-
if sigout:
30-
amp = (up-low)/(1.0 + math.exp(amp)) + low
31-
state = [Prev_Error, I]
32-
return (state, amp)
33-
34-
35-
concore.default_maxtime(150)
36-
concore.delay = 0.02
37-
init_simtime_ym = "[0.0, 70.0,91]"
38-
ym = np.array(concore.initval(init_simtime_ym))
39-
state = [0.0, 0.0]
40-
print("Mayuresh's PID controller: sp is "+str(sp))
41-
print(concore.params)
42-
while(concore.simtime<concore.maxtime):
43-
while concore.unchanged():
44-
ym = concore.read(1,"ym",init_simtime_ym)
45-
ym = np.array(ym)
46-
(state,amp) = pid_controller(state,ym,sp,Kp,Ki,Kd,sigout,cin,0,3)
47-
u = np.array([amp,freq])
48-
print(str(concore.simtime) + " u="+str(u) + "ym="+str(ym))
49-
concore.write(1,"u",list(u),delta=0)
1+
"""
2+
Backward-compatibility wrapper for pidmayuresh.py.
3+
4+
This file previously contained a duplicate PID controller implementation
5+
that used print() instead of logging. The canonical implementation now
6+
lives in pidmayuresh.py (which uses the logging module).
7+
8+
This wrapper re-exports everything so that any existing import of
9+
pidmayuresh3 continues to work without modification.
10+
11+
See: https://github.com/ControlCore-Project/concore/issues/378
12+
"""
13+
14+
import warnings
15+
warnings.warn(
16+
"pidmayuresh3 is deprecated — use pidmayuresh instead.",
17+
DeprecationWarning,
18+
stacklevel=2,
19+
)
20+
21+
# Re-execute the canonical module so run-time behaviour is identical
22+
# when this file is invoked directly (e.g., via a study graph).
23+
from pidmayuresh import * # noqa: F401,F403
5024

5125

5226

0 commit comments

Comments
 (0)