From 9ac4d039a591c273a3dd6bc8ed67fa6da78a1077 Mon Sep 17 00:00:00 2001 From: Cas Bex Date: Thu, 29 Jun 2023 10:03:06 +0200 Subject: [PATCH 1/2] Add zero-integral test for P controller with saturation --- test/runtests.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 59d4adc..2edb274 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -134,9 +134,10 @@ res2 = lsim(P, ctrl, 3) # plot([res, res2], plotu=true) @test maximum(res2.u) == umax +@test pid.I == 0.0 @test DiscretePID(Ts=1f0) isa DiscretePID{Float32} @test DiscretePID(Ts=1.0) isa DiscretePID{Float64} -end \ No newline at end of file +end From 211ac8ba328475ef61e8148b140940f0db686d7b Mon Sep 17 00:00:00 2001 From: Cas Bex Date: Thu, 29 Jun 2023 10:04:48 +0200 Subject: [PATCH 2/2] Fix anti-windup for P controller --- src/DiscretePIDs.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/DiscretePIDs.jl b/src/DiscretePIDs.jl index 487bd0e..d3c9680 100644 --- a/src/DiscretePIDs.jl +++ b/src/DiscretePIDs.jl @@ -75,7 +75,11 @@ function DiscretePID(; 0 ≤ b ≤ 1 || throw(ArgumentError("b must be ∈ [0, 1]")) umax > umin || throw(ArgumentError("umax must be greater than umin")) - ar = Ts / Tt + if Ti > 0 + ar = Ts / Tt + else + ar = zero(Ts / Tt) + end ad = Td / (Td + N * Ts) bd = K * N * ad