Engee documentation
Notebook

Responses of several models in the time domain

This example shows how to compare the stepwise reaction of several models on the same graph using step. This example compares the stepwise reaction of an uncontrolled object with a closed loop and two different PI regulators. You can use similar methods with other reaction commands such as impulse or lsim to get reaction graphs of several models.

In this example, get two models whose time characteristics you want to compare and plot their graphs together. For example, you can compare a third-order system G and the reaction of a closed system G with a regulator C1.

In [ ]:
Pkg.add(["ControlSystems"])
In [ ]:
import Pkg; 
Pkg.add("ControlSystems")
   Resolving package versions...
  No Changes to `~/.project/Project.toml`
  No Changes to `~/.project/Manifest.toml`
In [ ]:
using ControlSystems
In [ ]:
G = zpk([], [-5, -5, -10], 100)
Out[0]:
TransferFunction{Continuous, ControlSystemsBase.SisoZpk{Int64, Int64}}
             1
100----------------------
   (s + 5)(s + 5)(s + 10)

Continuous-time transfer function model
In [ ]:
C1 = pid(0, 4.4; form=:parallel)
Out[0]:
TransferFunction{Continuous, ControlSystemsBase.SisoRational{Float64}}
4.4
----
1.0s

Continuous-time transfer function model
In [ ]:
CL1 = feedback(G*C1)
Out[0]:
TransferFunction{Continuous, ControlSystemsBase.SisoZpk{Float64, ComplexF64}}
                                                                  1.0
440.00000000000006----------------------------------------------------------------------------------------------------
                  (1.0s^2 + 18.182441807113936s + 86.88838599897278)(1.0s^2 + 1.8175581928860574s + 5.063967927833328)

Continuous-time transfer function model

Function step accepts a description of the system as input, and generates an object of the type at the output. ControlSystemsBase.SimResult. If this object is passed to a function plot, then build a timeline of the transition process.

In [ ]:
step(CL1)
Out[0]:
ControlSystemsBase.SimResult{Matrix{Float64}, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, Matrix{Float64}, Matrix{Float64}, StateSpace{Continuous, Float64}}([0.0 1.1101474535917157e-7 … 0.9999999999999879 0.9999999999999879], 0.0:0.0089:55.9988, [0.0 6.459039729988163e-8 … 0.5818181818181747 0.5818181818181747; 0.0 1.4386184767184292e-5 … 5.620737843258297e-15 5.620604012052631e-15; 0.0 0.000597208113779645 … -1.6263032587282567e-18 -2.0599841277224584e-18; 0.0 0.016278755147748875 … -6.938893903907228e-18 -6.938893903907228e-18], [1.0 1.0 … 1.0 1.0], StateSpace{Continuous, Float64}
A = 
  0.0                  2.0                   0.0                  0.0
  0.0                  0.0                   8.0                  0.0
  0.0                  0.0                   0.0                  8.0
 -3.4375000000000044  -3.9062500000000004  -15.625000000000002  -19.999999999999993
B = 
 0.0
 0.0
 0.0
 2.0
C = 
 1.7187500000000002  0.0  0.0  0.0
D = 
 0.0

Continuous-time state-space model)
In [ ]:
plot([step(G), step(CL1)], label=["G" "CL1"])
xlims!(0,7)
hline!([1], linecolor=:black, style=:dash, label=:false)
Out[0]:

If you send multiple function objects stepas input arguments plot, one graph displays the responses of the specified models If you do not specify a time range for plotting, step tries to select a time range that illustrates the dynamics of the model.

Compare the reaction to the feedback model step with the reaction of the other controller. Specify the colors and styles of the graphs for each reaction.

In [ ]:
C2 = pid(2.9, 7.1; form=:parallel)
CL2 = feedback(G * C2)

plot(step(G,7), label="G", color=:blue)
plot!(step(CL1,7), label="CL1", color=:green)
plot!(step(CL2,7), label="CL2", color=:red)

hline!([0.4, 1], linestyle=:dash, color=:black, label=:false)
Out[0]:

You can set your own color and graph style for each transition process by changing the parameters. linestyle and color.