From 52b0c3b855a8b0b684d684da7639a47bf26d0178 Mon Sep 17 00:00:00 2001 From: Ganesh Patil <7030871503ganeshpatil@gmail.com> Date: Fri, 20 Feb 2026 11:46:46 +0530 Subject: [PATCH 1/2] 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 --- tools/pidmayuresh3.py | 72 ++++++++++++++----------------------------- 1 file changed, 23 insertions(+), 49 deletions(-) diff --git a/tools/pidmayuresh3.py b/tools/pidmayuresh3.py index 900d32f5..af369fd9 100644 --- a/tools/pidmayuresh3.py +++ b/tools/pidmayuresh3.py @@ -1,52 +1,26 @@ -import numpy as np -import math -import concore -dT = 0.1 - -sp = concore.tryparam('sp', 67.5) -Kp = concore.tryparam('Kp', 0.075) -Ki = concore.tryparam('Ki', 0.02) -Kd = concore.tryparam('Kd', 0.005) -freq = concore.tryparam('freq',30) -sigout = concore.tryparam('sigout',True) -cin = concore.tryparam('cin', 'hr') - -def pid_controller(state, ym, sp, Kp, Ki, Kd, sigout, cin, low, up): - Prev_Error = state[0] - I = state[1] - if cin == 'hr': - Error = sp - ym[1] - elif cin == 'map': - Error = sp - ym[0] - else: - print('invalid control input '+cin) - quit() - P = Error - I = I + Error*dT - D = (Error - Prev_Error )/dT - amp = Kp*P + Ki*I + Kd*D - Prev_Error = Error - if sigout: - amp = (up-low)/(1.0 + math.exp(amp)) + low - state = [Prev_Error, I] - return (state, amp) - - -concore.default_maxtime(150) -concore.delay = 0.02 -init_simtime_ym = "[0.0, 70.0,91]" -ym = np.array(concore.initval(init_simtime_ym)) -state = [0.0, 0.0] -print("Mayuresh's PID controller: sp is "+str(sp)) -print(concore.params) -while(concore.simtime Date: Fri, 20 Feb 2026 11:53:08 +0530 Subject: [PATCH 2/2] fix: use try/except for relative+absolute import in pidmayuresh3 wrapper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Apply Copilot review suggestion — try relative import first (from .pidmayuresh) for package-style usage, with fallback to absolute import for direct script execution. --- tools/pidmayuresh3.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/pidmayuresh3.py b/tools/pidmayuresh3.py index af369fd9..1fd1f2d8 100644 --- a/tools/pidmayuresh3.py +++ b/tools/pidmayuresh3.py @@ -20,7 +20,12 @@ # Re-execute the canonical module so run-time behaviour is identical # when this file is invoked directly (e.g., via a study graph). -from pidmayuresh import * # noqa: F401,F403 +try: + # Prefer relative import when part of the tools package + from .pidmayuresh import * # type: ignore[attr-defined] # noqa: F401,F403 +except ImportError: + # Fallback for script-style execution (e.g., `python tools/pidmayuresh3.py`) + from pidmayuresh import * # noqa: F401,F403