From 46c04bf64637c9c10e21140231e64213bcdec469 Mon Sep 17 00:00:00 2001 From: templeofshadow Date: Mon, 29 Jun 2026 23:35:43 -0500 Subject: [PATCH] fix out-of-scope issue with the D variable in PIDs --- main.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.lua b/main.lua index 84b8750..f9524d3 100644 --- a/main.lua +++ b/main.lua @@ -868,7 +868,9 @@ function CreatePID(kp, ki, kd) local error = setpoint - pv local P = self.kp * error - if dt > 0 then local D = self.kd * ((error - self.lastError) / dt) else D = 0 end + + local D = 0 + if dt > 0 then D = self.kd * ((error - self.lastError) / dt) else D = 0 end local potential_i = self.integral + (self.ki * error * dt)