diff --git a/src/DiscretePIDs.jl b/src/DiscretePIDs.jl index 74ff495..157311e 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 diff --git a/test/runtests.jl b/test/runtests.jl index 77b45a9..37d0f14 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -144,10 +144,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