-
Notifications
You must be signed in to change notification settings - Fork 7
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
create pid subsystem problem? #25
Comments
modify |
Hi @hzgzh
Of course, As you pointed out, the problem is not related to Now the code block you gave above works as you want. But do not forget to check out the master branch.
|
Hi@zekeriyasari
|
I forget link add to pid,I will try again |
I tried to simulate the following control system given in this tutorial page. Here is the full script. # This is an example for PID control.
using Jusdl
using Plots
# PID parameters
kp, ki, kd = 350, 300, 50
function sfunc(dx, x, u, t)
dx[1] = x[2]
dx[2] = -20 * x[1] - 10 * x[2] + u[1](t)
end
ofunc(x, u, t) = x[1, :]
plant = ODESystem(sfunc, ofunc, zeros(2), 0., Inport(), Outport())
# Construct the model
model = Model(clock=Clock(0., 0.01, 5.))
addnode!(model, StepGenerator() , label=:gen)
addnode!(model, Adder((+,-)) , label=:adder1)
addnode!(model, Gain(gain=kp) , label=:gain)
addnode!(model, Integrator(ki=ki) , label=:int)
addnode!(model, Differentiator(kd=kd), label=:dif)
addnode!(model, Adder((+,+,+)) , label=:adder2)
addnode!(model, plant, label=:plant)
addnode!(model, Writer(Inport(2)), label=:writer)
addbranch!(model, :gen => :adder1, 1 => 1)
addbranch!(model, :adder1 => :gain, 1 => 1)
addbranch!(model, :adder1 => :int, 1 => 1)
addbranch!(model, :adder1 => :dif, 1 => 1)
addbranch!(model, :gain => :adder2, 1 => 1)
addbranch!(model, :int => :adder2, 1 => 2)
addbranch!(model, :dif => :adder2, 1 => 3)
addbranch!(model, :adder2 => :plant, 1 => 1)
addbranch!(model, :plant => :adder1, 1 => 2)
addbranch!(model, :gen => :writer, 1 => 1)
addbranch!(model, :plant => :writer, 1 => 2)
# Simulate the model
simulate!(model)
# Plot results
t, x = read(getnode(model, :writer).component)
plot(t, x[:, 1], label=:r)
plot!(t, x[:, 2], label=:y) NOTE: that there is not |
If your want to implement pid controller as a using Jusdl
using Plots
# Time settings
ti, dt, tf = 0., 0.01, 5.
# Construct PID
kp, ki, kd = 350, 300, 50
gain = Gain(gain=kp)
int = Integrator(ki=ki)
dif = Differentiator(kd=kd)
adderpid = Adder((+, +, +))
connect!(gain.output, adderpid.input[1])
connect!(int.output, adderpid.input[2])
connect!(dif.output, adderpid.input[3])
pid = SubSystem([gain, int, dif, adderpid], [gain.input[1], dif.input[1], int.input[1]], adderpid.output)
# Contruct plant
function sfunc(dx, x, u, t)
dx[1] = x[2]
dx[2] = -20 * x[1] - 10 * x[2] + u[1](t)
end
ofunc(x, u, t) = x[1, :]
plant = ODESystem(sfunc, ofunc, zeros(2), 0., Inport(), Outport())
# Construct remaining components of the control system.
adder = Adder((+, -))
gen = StepGenerator()
writer = Writer(Inport(2))
mem = Memory(dt)
# Construct the model
model = Model(clock=Clock(ti, dt, tf))
addnode!(model, gen, label=:gen)
addnode!(model, adder, label=:adder)
addnode!(model, pid, label=:pid)
addnode!(model, plant, label=:plant)
addnode!(model, mem, label=:mem)
addnode!(model, writer, label=:writer)
addbranch!(model, :gen => :adder, 1 => 1)
addbranch!(model, :adder => :pid, 1 => 1)
addbranch!(model, :adder => :pid, 1 => 2)
addbranch!(model, :adder => :pid, 1 => 3)
addbranch!(model, :pid => :plant, 1 => 1)
addbranch!(model, :plant => :mem, 1 => 1)
addbranch!(model, :mem => :adder, 1 => 2)
addbranch!(model, :gen => :writer, 1 => 1)
addbranch!(model, :plant => :writer, 1 => 2)
# Simulate the model
simulate!(model)
# Plot results
t, x = read(getnode(model, :writer).component)
plot(t, x[:, 1], label=:r)
plot!(t, x[:, 2], label=:y) |
You may take a look at here if you would like to, |
according you example,I change my program,it's success,run time about 0.9s |
another advise is to seperate simulate to two step,first phase to initialize model,second to simulate model,when using some simple component like "gain,integrator",only change component parameter,not initialize model again when simulate model,so reduce the running time when perform parameter estimate I found this function
if terminate!(model) is called,second start simulate may be terminate,that is right? |
There is nothing wrong with changing The problem may be re-simulating the model. During the simulation, data flow through the connections of the model is carried out through Julia
All the functions of the using Jusdl
# Construct model
model = Model()
addnode!(model, SinewaveGenerator(), label=:gen)
addnode!(model, Writer(), label=:writer)
addbranch!(model, :gen => :writer)
# Call simulation steps individually.
inspect!(model)
initialize!(model)
run!(model)
terminate!(model) |
I want to create a pid subsystem like this:
how to fix it,does the subsystem can't support the component like integrator,diffentiator component?
The text was updated successfully, but these errors were encountered: