Skip to content

Commit

Permalink
make display of PID valid code
Browse files Browse the repository at this point in the history
  • Loading branch information
baggepinnen committed Mar 7, 2024
1 parent 0405a74 commit 6fbc334
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
5 changes: 4 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
name = "DiscretePIDs"
uuid = "c1363496-6848-4723-8758-079b737f6baf"
authors = ["Fredrik Bagge Carlson"]
version = "0.1.3"
version = "0.1.4"

[deps]
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[compat]
julia = "1.7"
Expand Down
25 changes: 15 additions & 10 deletions src/DiscretePIDs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module DiscretePIDs

export DiscretePID, calculate_control!, set_K!, set_Td!, set_Ti!

using Printf

"""
DiscretePID{T}
"""
Expand Down Expand Up @@ -36,6 +38,8 @@ mutable struct DiscretePID{T} <: Function
yold::T
end

floattype(K) = float(typeof(K))

"""
DiscretePID(; K = 1, Ti = false, Td = false, Tt = √(Ti*Td), N = 10, b = 1, umin = -Inf, umax = Inf, Ts, I = 0, D = 0, yold = 0)
Expand Down Expand Up @@ -75,15 +79,15 @@ function DiscretePID(;
K::T = 1f0,
Ti = false,
Td = false,
Tt = Ti > 0 && Td > 0 ? typeof(K)((Ti*Td)) : typeof(K)(10),
N = typeof(K)(10),
b = typeof(K)(1),
umin = typemin(K),
umax = typemax(K),
Tt = Ti > 0 && Td > 0 ? floattype(K)((Ti*Td)) : floattype(K)(10),
N = floattype(K)(10),
b = floattype(K)(1),
umin = typemin(floattype(K)),
umax = typemax(floattype(K)),
Ts,
I = zero(typeof(K)),
D = zero(typeof(K)),
yold = zero(typeof(K)),
I = zero(floattype(K)),
D = zero(floattype(K)),
yold = zero(floattype(K)),
) where T
if Ti > 0
bi = K * Ts / Ti
Expand Down Expand Up @@ -175,10 +179,11 @@ end
(pid::DiscretePID)(args...) = calculate_control!(pid, args...)

function Base.show(io::IO, ::MIME"text/plain", pid::DiscretePID)
println(io, "$(typeof(pid)) with parameters and state:")
println(io, "$(typeof(pid))( # with parameters and state:")
for name in fieldnames(DiscretePID)
println(io, name, ":\t", getfield(pid, name))
@printf(io, " %-12.8g,# %s\n", getfield(pid, name), name)
end
println(io, ")")
end


Expand Down

0 comments on commit 6fbc334

Please sign in to comment.