adjust PID update function return value
This commit is contained in:
10
main.lua
10
main.lua
@@ -864,13 +864,13 @@ function CreatePID(kp, ki, kd)
|
||||
minOutput = 0.0,
|
||||
maxOutput = 64.0,
|
||||
update = function(self, setpoint, pv, dt)
|
||||
if dt <= 0 then return 0.0 end
|
||||
|
||||
local error = setpoint - pv
|
||||
|
||||
local P = self.kp * error
|
||||
|
||||
local D = 0
|
||||
if dt > 0 then D = self.kd * ((error - self.lastError) / dt) else D = 0 end
|
||||
local D = self.kd * ((error - self.lastError) / dt)
|
||||
|
||||
local potential_i = self.integral + (self.ki * error * dt)
|
||||
|
||||
@@ -880,7 +880,7 @@ function CreatePID(kp, ki, kd)
|
||||
|
||||
local clampedOutput = 0
|
||||
|
||||
if self.minOutput <= potential_i and potential_i <= self.maxOutput then
|
||||
if raw_output >= self.minOutput and raw_output <= self.maxOutput then
|
||||
self.integral = potential_i
|
||||
clampedOutput = raw_output
|
||||
else
|
||||
@@ -889,9 +889,7 @@ function CreatePID(kp, ki, kd)
|
||||
|
||||
self.lastError = error
|
||||
|
||||
local normalizedOutput = (clampedOutput - self.minOutput) / (self.maxOutput - self.minOutput)
|
||||
|
||||
return normalizedOutput
|
||||
return clampedOutput
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user