fix out-of-scope issue with the D variable in PIDs

This commit is contained in:
2026-06-29 23:35:43 -05:00
parent 61c8f88d40
commit 46c04bf646

View File

@@ -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)