|
1 | | -import numpy as np |
2 | | -import math |
3 | | -import concore |
4 | | -import sys |
5 | | -dT = 0.1 |
6 | | - |
7 | | -sp = concore.tryparam('sp', 67.5) |
8 | | -Kp = concore.tryparam('Kp', 0.075) |
9 | | -Ki = concore.tryparam('Ki', 0.02) |
10 | | -Kd = concore.tryparam('Kd', 0.005) |
11 | | -freq = concore.tryparam('freq',30) |
12 | | -sigout = concore.tryparam('sigout',True) |
13 | | -cin = concore.tryparam('cin', 'hr') |
14 | | - |
15 | | -def pid_controller(state, ym, sp, Kp, Ki, Kd, sigout, cin, low, up): |
16 | | - Prev_Error = state[0] |
17 | | - I = state[1] |
18 | | - if cin == 'hr': |
19 | | - Error = sp - ym[1] |
20 | | - elif cin == 'map': |
21 | | - Error = sp - ym[0] |
22 | | - else: |
23 | | - print('invalid control input '+cin) |
24 | | - sys.exit(1) |
25 | | - P = Error |
26 | | - I = I + Error*dT |
27 | | - D = (Error - Prev_Error )/dT |
28 | | - amp = Kp*P + Ki*I + Kd*D |
29 | | - Prev_Error = Error |
30 | | - if sigout: |
31 | | - amp = (up-low)/(1.0 + math.exp(amp)) + low |
32 | | - state = [Prev_Error, I] |
33 | | - return (state, amp) |
34 | | - |
35 | | - |
36 | | -concore.default_maxtime(150) |
37 | | -concore.delay = 0.02 |
38 | | -init_simtime_ym = "[0.0, 70.0,91]" |
39 | | -ym = np.array(concore.initval(init_simtime_ym)) |
40 | | -state = [0.0, 0.0] |
41 | | -print("Mayuresh's PID controller: sp is "+str(sp)) |
42 | | -print(concore.params) |
43 | | -while(concore.simtime<concore.maxtime): |
44 | | - while concore.unchanged(): |
45 | | - ym = concore.read(1,"ym",init_simtime_ym) |
46 | | - ym = np.array(ym) |
47 | | - (state,amp) = pid_controller(state,ym,sp,Kp,Ki,Kd,sigout,cin,0,3) |
48 | | - u = np.array([amp,freq]) |
49 | | - print(str(concore.simtime) + " u="+str(u) + "ym="+str(ym)) |
50 | | - 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 | +try: |
| 24 | + # Prefer relative import when part of the tools package |
| 25 | + from .pidmayuresh import * # type: ignore[attr-defined] # noqa: F401,F403 |
| 26 | +except ImportError: |
| 27 | + # Fallback for script-style execution (e.g., `python tools/pidmayuresh3.py`) |
| 28 | + from pidmayuresh import * # noqa: F401,F403 |
51 | 29 |
|
52 | 30 |
|
53 | 31 |
|
0 commit comments