Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mark some fields that should not be changed as const #10

Merged
merged 4 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
17 changes: 10 additions & 7 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 All @@ -15,17 +17,17 @@ mutable struct DiscretePID{T} <: Function
"Reset time"
Tt::T
"Maximum derivative gain"
N::T
const N::T
"Fraction of set point in prop. term"
b::T
"Low output limit"
umin::T
"High output limit"
umax::T
"Sampling period"
Ts::T
const Ts::T
bi::T
ar::T
const ar::T
bd::T
ad::T
"Integral state"
Expand Down Expand Up @@ -78,8 +80,8 @@ function DiscretePID(;
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),
umin = typemin(typeof(K)),
umax = typemax(typeof(K)),
Ts,
I = zero(typeof(K)),
D = zero(typeof(K)),
Expand Down Expand Up @@ -175,10 +177,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, " %-14.7g,# %s\n", getfield(pid, name), name)
end
println(io, ")")
end


Expand Down
Loading