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.
Pkg.add(["ControlSystems"])
import Pkg;
Pkg.add("ControlSystems")
using ControlSystems
G = zpk([], [-5, -5, -10], 100)
C1 = pid(0, 4.4; form=:parallel)
CL1 = feedback(G*C1)
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.
step(CL1)
plot([step(G), step(CL1)], label=["G" "CL1"])
xlims!(0,7)
hline!([1], linecolor=:black, style=:dash, label=:false)
If you send multiple function objects step
as 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.
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)
You can set your own color and graph style for each transition process by changing the parameters. linestyle
and color
.