Skip to content

Commit 383e0b6

Browse files
authored
docstrings updates (#646)
1 parent dba4ea8 commit 383e0b6

File tree

6 files changed

+52
-39
lines changed

6 files changed

+52
-39
lines changed

src/analysis.jl

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ function poles(sys::TransferFunction{<:TimeEvolution,SisoZpk{T,TR}}) where {T, T
3535
return lcmpoles
3636
end
3737

38+
# TODO: Improve implementation, should be more efficient ways.
39+
# Calculates the same minors several times in some cases.
3840
"""
3941
minorpoles(sys)
4042
4143
Compute the poles of all minors of the system."""
42-
# TODO: Improve implementation, should be more efficient ways.
43-
# Calculates the same minors several times in some cases.
4444
function minorpoles(sys::Matrix{SisoZpk{T, TR}}) where {T, TR}
4545
minors = Array{TR,1}[]
4646
ny, nu = size(sys)
@@ -68,11 +68,11 @@ function minorpoles(sys::Matrix{SisoZpk{T, TR}}) where {T, TR}
6868
return minors
6969
end
7070

71+
# TODO: improve this implementation, should be more efficient ones
7172
"""
7273
det(sys)
7374
7475
Compute the determinant of the Matrix `sys` of SisoTf systems, returns a SisoTf system."""
75-
# TODO: improve this implementation, should be more efficient ones
7676
function det(sys::Matrix{S}) where {S<:SisoZpk}
7777
ny, nu = size(sys)
7878
ny == nu || throw(ArgumentError("sys matrix is not square"))
@@ -146,13 +146,13 @@ poles, `ps`, of `sys`"""
146146
function damp(sys::LTISystem)
147147
ps = poles(sys)
148148
if isdiscrete(sys)
149-
ps = log.(complex.(ps))/sys.Ts
149+
ps = @. log(complex(ps))/sys.Ts
150150
end
151151
Wn = abs.(ps)
152152
order = sortperm(Wn; by=z->(abs(z), real(z), imag(z)))
153153
Wn = Wn[order]
154154
ps = ps[order]
155-
ζ = -cos.(angle.(ps))
155+
ζ = @. -cos(angle(ps))
156156
return Wn, ζ, ps
157157
end
158158

@@ -279,8 +279,7 @@ function reduce_sys(A::AbstractMatrix, B::AbstractMatrix, C::AbstractMatrix, D::
279279
end
280280

281281
# Compress columns of Ctilde
282-
V = qr(Ctilde').Q
283-
V = reverse(V,dims=2)
282+
V = reverse(qr(Ctilde').Q, dims=2)
284283
Sj = Ctilde*V
285284
rho = fastrank(Sj', meps)
286285
nu = size(Sj, 2) - rho
@@ -294,7 +293,7 @@ function reduce_sys(A::AbstractMatrix, B::AbstractMatrix, C::AbstractMatrix, D::
294293
end
295294
# Update System
296295
n, m = size(B)
297-
Vm = [V zeros(T, n, m); zeros(T, m, n) Matrix{T}(I, m, m)]
296+
Vm = [V zeros(T, n, m); zeros(T, m, n) Matrix{T}(I, m, m)] # I(m) is not used for type stability reasons (as of julia v1.7)
298297
if sigma > 0
299298
M = [A B; Cbar Dbar]
300299
Vs = [V' zeros(T, n, sigma) ; zeros(T, sigma, n) Matrix{T}(I, sigma, sigma)]
@@ -403,14 +402,13 @@ function relative_gain_array(A::AbstractMatrix; tol = 1e-15)
403402
end
404403

405404
"""
406-
`ωgₘ, gₘ, ωϕₘ, ϕₘ = margin{S<:Real}(sys::LTISystem, w::AbstractVector{S}; full=false, allMargins=false)`
405+
ωgₘ, gₘ, ωϕₘ, ϕₘ = margin(sys::LTISystem, w::Vector; full=false, allMargins=false)
407406
408407
returns frequencies for gain margins, gain margins, frequencies for phase margins, phase margins
409408
410409
If `!allMargins`, return only the smallest margin
411410
412411
If `full` return also `fullPhase`
413-
414412
"""
415413
function margin(sys::LTISystem, w::AbstractVector{<:Real}; full=false, allMargins=false)
416414
ny, nu = size(sys)
@@ -441,7 +439,7 @@ function margin(sys::LTISystem, w::AbstractVector{<:Real}; full=false, allMargin
441439
end
442440

443441
"""
444-
`ωgₘ, gₘ, ωϕₘ, ϕₘ = sisomargin{S<:Real}(sys::LTISystem, w::AbstractVector{S}; full=false, allMargins=false)`
442+
ωgₘ, gₘ, ωϕₘ, ϕₘ = sisomargin(sys::LTISystem, w::Vector; full=false, allMargins=false)
445443
446444
returns frequencies for gain margins, gain margins, frequencies for phase margins, phase margins
447445
"""
@@ -588,19 +586,13 @@ end
588586
Given transfer functions describing the Plant `P`, the controller `C` and a feed forward block `F`,
589587
computes the four transfer functions in the Gang-of-Four and the transferfunctions corresponding to the feed forward.
590588
591-
`S = 1/(1+PC)` Sensitivity function
592-
593-
`PS = P/(1+PC)`
594-
595-
`CS = C/(1+PC)`
596-
597-
`T = PC/(1+PC)` Complementary sensitivity function
598-
599-
`RY = PCF/(1+PC)`
600-
601-
`RU = CF/(1+P*C)`
602-
603-
`RE = F/(1+P*C)`
589+
- `S = 1/(1+PC)` Sensitivity function
590+
- `PS = P/(1+PC)`
591+
- `CS = C/(1+PC)`
592+
- `T = PC/(1+PC)` Complementary sensitivity function
593+
- `RY = PCF/(1+PC)`
594+
- `RU = CF/(1+P*C)`
595+
- `RE = F/(1+P*C)`
604596
605597
Only supports SISO systems"""
606598
function gangofseven(P::TransferFunction, C::TransferFunction, F::TransferFunction)

src/freqresp.jl

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ function _evalfr_return_type(sys::AbstractStateSpace, s::Number)
147147
end
148148

149149
"""
150-
`evalfr(sys, x)` Evaluate the transfer function of the LTI system sys
150+
evalfr(sys, x)
151+
152+
Evaluate the transfer function of the LTI system sys
151153
at the complex number s=x (continuous-time) or z=x (discrete-time).
152154
153155
For many values of `x`, use `freqresp` instead.
@@ -198,10 +200,11 @@ function (sys::TransferFunction)(z_or_omegas::AbstractVector, map_to_unit_circle
198200
[v[i,j] for v in vals, i in 1:nu, j in 1:ny]
199201
end
200202

201-
"""`mag, phase, w = bode(sys[, w])`
203+
"""
204+
mag, phase, w = bode(sys[, w])
202205
203206
Compute the magnitude and phase parts of the frequency response of system `sys`
204-
at frequencies `w`
207+
at frequencies `w`. See also [`bodeplot`](@ref)
205208
206209
`mag` and `phase` has size `(length(w), ny, nu)`"""
207210
@autovec (1, 2) function bode(sys::LTISystem, w::AbstractVector)
@@ -210,10 +213,11 @@ at frequencies `w`
210213
end
211214
@autovec (1, 2) bode(sys::LTISystem) = bode(sys, _default_freq_vector(sys, Val{:bode}()))
212215

213-
"""`re, im, w = nyquist(sys[, w])`
216+
"""
217+
re, im, w = nyquist(sys[, w])
214218
215219
Compute the real and imaginary parts of the frequency response of system `sys`
216-
at frequencies `w`
220+
at frequencies `w`. See also [`nyquistplot`](@ref)
217221
218222
`re` and `im` has size `(length(w), ny, nu)`"""
219223
@autovec (1, 2) function nyquist(sys::LTISystem, w::AbstractVector)
@@ -222,10 +226,11 @@ at frequencies `w`
222226
end
223227
@autovec (1, 2) nyquist(sys::LTISystem) = nyquist(sys, _default_freq_vector(sys, Val{:nyquist}()))
224228

225-
"""`sv, w = sigma(sys[, w])`
229+
"""
230+
sv, w = sigma(sys[, w])
226231
227232
Compute the singular values `sv` of the frequency response of system `sys` at
228-
frequencies `w`
233+
frequencies `w`. See also [`sigmaplot`](@ref)
229234
230235
`sv` has size `(length(w), max(ny, nu))`"""
231236
@autovec (1) function sigma(sys::LTISystem, w::AbstractVector)
@@ -258,8 +263,8 @@ function _bounds_and_features(sys::LTISystem, plot::Val)
258263
zp = vcat(zpType[], zs..., ps...) # Emty vector to avoid type unstable vcat()
259264
zp = zp[imag(zp) .>= 0.0]
260265
else
261-
# For sigma plots, use the MIMO poles and zeros
262-
zp = [tzeros(sys); poles(sys)]
266+
# For sigma plots, use the MIMO poles and zeros
267+
zp = [tzeros(sys); poles(sys)]
263268
end
264269
# Get the frequencies of the features, ignoring low frequency dynamics
265270
fzp = log10.(abs.(zp))

src/pid_design.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ function leadlinkat(ω, N, K; h=nothing, Ts=0)
224224
end
225225

226226
"""
227-
leadlinkcurve(start=1)
227+
leadlinkcurve(start=1)
228228
229229
Plot the phase advance as a function of `N` for a lead link (phase advance link)
230230
If an input argument `s` is given, the curve is plotted from `s` to 10, else from 1 to 10.

src/timeresp.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
99
Calculate the step response of system `sys`. If the final time `tfinal` or time
1010
vector `t` is not provided, one is calculated based on the system pole
11-
locations.
11+
locations. The return value is a structure of type `SimResult` that can be plotted or destructured as `y, t, x = result`.
1212
1313
`y` has size `(ny, length(t), nu)`, `x` has size `(nx, length(t), nu)`"""
1414
function Base.step(sys::AbstractStateSpace, t::AbstractVector; method=:cont, kwargs...)
@@ -40,7 +40,7 @@ Base.step(sys::TransferFunction, t::AbstractVector; kwargs...) = step(ss(sys), t
4040
4141
Calculate the impulse response of system `sys`. If the final time `tfinal` or time
4242
vector `t` is not provided, one is calculated based on the system pole
43-
locations.
43+
locations. The return value is a structure of type `SimResult` that can be plotted or destructured as `y, t, x = result`.
4444
4545
`y` has size `(ny, length(t), nu)`, `x` has size `(nx, length(t), nu)`"""
4646
function impulse(sys::AbstractStateSpace, t::AbstractVector; kwargs...)

src/types/DelayLtiSystem.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,22 @@ function feedback(sys1::DelayLtiSystem, sys2::DelayLtiSystem)
192192
end
193193

194194
"""
195+
delay(tau)
195196
delay(T::Type{<:Number}, tau)
196197
197198
Create a pure time delay of length `τ` of type `T`.
198199
199200
The type `T` defaults to `promote_type(Float64, typeof(tau))`
200-
"""
201201
202+
# Example:
203+
Create a LTI system with an input delay of `L`
204+
```julia
205+
L = 1
206+
tf(1, [1, 1])*delay(L)
207+
s = tf("s")
208+
tf(1, [1, 1])*exp(-s*L) # Equivalent to the version above
209+
```
210+
"""
202211
function delay(T::Type{<:Number}, τ)
203212
return DelayLtiSystem(ControlSystems.ss([zero(T) one(T); one(T) zero(T)], Continuous()), [T(τ)])
204213
end

src/utilities.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,16 @@ function unwrap!(M::Array, dim=1)
127127
end
128128

129129
#Collect will create a copy and collect the elements
130+
"""
131+
unwrap(m::AbstractArray, args...)
132+
133+
Unwrap a vector of phase angles (radians) in (-π, π) such that it does not wrap around the edges -π and π, i.e., the result may leave the range (-π, π).
134+
"""
130135
unwrap(m::AbstractArray, args...) = unwrap!(collect(m), args...)
131136
unwrap(x::Number) = x
132137

133-
"""outs = index2range(ind1, ind2)
138+
"""
139+
outs = index2range(ind1, ind2)
134140
135141
Helper function to convert indexes with scalars to ranges. Used to avoid dropping dimensions
136142
"""
@@ -139,7 +145,8 @@ index2range(ind::T) where {T<:Number} = ind:ind
139145
index2range(ind::T) where {T<:AbstractArray} = ind
140146
index2range(ind::Colon) = ind
141147

142-
"""@autovec (indices...) f() = (a, b, c)
148+
"""
149+
@autovec (indices...) f() = (a, b, c)
143150
144151
A macro that helps in creating versions of functions where excessive dimensions are
145152
removed automatically for specific outputs. `indices` contains each index for which

0 commit comments

Comments
 (0)