Skip to content

Commit 76a687b

Browse files
authored
Add rlocus (#766)
* Add rlocus * Improve rlocus' docstring
1 parent 7b4c1aa commit 76a687b

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

src/ControlSystems.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ using StaticArrays
1616
using RecipesBase
1717
using Printf
1818

19-
export Simulator, rlocusplot
19+
export Simulator, rlocus, rlocusplot
2020

2121
include("timeresp.jl")
2222
include("simulators.jl")

src/root_locus.jl

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const Polynomials = ControlSystemsBase.Polynomials
22
@userplot Rlocusplot
3-
@deprecate rlocus(args...;kwargs...) rlocusplot(args...;kwargs...)
43

54

65
function getpoles(G, K)
@@ -15,7 +14,7 @@ function getpoles(G, K)
1514
prevpoles = ComplexF64[]
1615
temppoles = zeros(ComplexF64, nx-1)
1716
f = function (y,_,k)
18-
if k == 0 && length(P) > length(Q)
17+
if k == 0 && length(P) > length(Q)
1918
# More zeros than poles, make sure the vector of roots is of correct length when k = 0
2019
# When this happens, there are fewer poles for k = 0, these poles can be seen as beeing located somewhere at Inf
2120
# We get around the problem by not allowing k = 0 for non-proper systems.
@@ -46,25 +45,34 @@ function getpoles(G, K)
4645
end
4746

4847

48+
"""
49+
roots, Z, K = rlocus(P::LTISystem; K)
50+
51+
Compute the root locus of the SISO LTISystem `P` with a negative feedback loop and feedback gains between 0 and `K`. `rlocus` will use an adaptive step-size algorithm to determine the values of the feedback gains used to generate the plot.
52+
53+
`roots` is a complex matrix containig the poles trajectories of the closed-loop `1+k⋅G(s)` as a function of `k`, `Z` contains the zeros of the open-loop system `G(s)` and `K` the values of the feedback gain.
54+
"""
55+
function rlocus(P; K=500)
56+
K = K isa Number ? range(1e-6,stop=K,length=10000) : K
57+
Z = tzeros(P)
58+
roots, K = getpoles(P,K)
59+
roots, Z, K
60+
end
61+
4962

5063
"""
5164
rlocusplot(P::LTISystem; K)
5265
53-
Computes and plots the root locus of the SISO LTISystem P with
54-
a negative feedback loop and feedback gains between 0 and `K`. `rlocusplot` will use an adaptive step-size algorithm to
55-
determine the values of the feedback gains used to generate the plot.
66+
Plot the root locus of the SISO LTISystem `P` as computed by `rlocus`.
5667
"""
5768
rlocusplot
5869
@recipe function rlocusplot(p::Rlocusplot; K=500)
59-
P = p.args[1]
60-
K = K isa Number ? range(1e-6,stop=K,length=10000) : K
61-
Z = tzeros(P)
62-
roots, K = getpoles(P,K)
70+
roots, Z, K = rlocus(p.args[1]; K=K)
6371
redata = real.(roots)
6472
imdata = imag.(roots)
6573
all_redata = [vec(redata); real.(Z)]
6674
all_imdata = [vec(imdata); imag.(Z)]
67-
75+
6876
ylims --> (max(-50,minimum(all_imdata) - 1), min(50,maximum(all_imdata) + 1))
6977
xlims --> (max(-50,minimum(all_redata) - 1), clamp(maximum(all_redata) + 1, 1, 50))
7078
framestyle --> :zerolines
@@ -92,4 +100,4 @@ rlocusplot
92100
label --> "Open-loop poles"
93101
redata[1,:], imdata[1,:]
94102
end
95-
end
103+
end

0 commit comments

Comments
 (0)