zekeriyasari / Causal.jl

Causal.jl - A modeling and simulation framework adopting causal modeling approach.
https://zekeriyasari.github.io/Causal.jl/dev/
Other
115 stars 7 forks source link

how to write a pid component #21

Closed hzgzh closed 4 years ago

hzgzh commented 4 years ago

don't know how to represent the differential part of pid algorithm,how to differential the input, can the author give some example

zekeriyasari commented 4 years ago

Thank you for filing this issue @hzgzh

I included Differentiator and Integrator components to Jusdl. Here are the examples.

model = Model(clock=Clock(0, 0.01, 4π)) addnode!(model, FunctionGenerator(t -> sin(t)), label=:gen) addnode!(model, Differentiator(), label=:dif) addnode!(model, Writer(Inport(2)), label=:writer) addbranch!(model, :gen => :dif, 1 => 1) addbranch!(model, :gen => :writer, 1 => 1) addbranch!(model, :dif => :writer, 1 => 2) simulate!(model)

t, x = read(getnode(model, :writer).component) scatter(t, x[:, 1], markersize=2, label=:gen) scatter!(t, x[:, 2], markersize=2, label=:dif)


![diff](https://user-images.githubusercontent.com/24751240/81756983-0239cf80-94c6-11ea-80a6-e3c7a5869386.png)

* Integration
```julia 
using Jusdl 
using Plots 

model = Model(clock=Clock(0, 0.001, 4)) 
addnode!(model, FunctionGenerator(t -> 2 * t), label=:gen)
addnode!(model, Integrator(), label=:integ)
addnode!(model, Writer(Inport(2)), label=:writer)
addbranch!(model, :gen => :integ, 1 => 1)
addbranch!(model, :gen => :writer, 1 => 1)
addbranch!(model, :integ => :writer, 1 => 2)
simulate!(model)

t, x = read(getnode(model, :writer).component)
scatter(t, x[:, 1], markersize=2, label=:gen)
scatter!(t, x[:, 2], markersize=2, label=:integ)

integ

Remainder : Do not forget to check out the master branch for the updates!

] add Jusdl#master

I will also include a complete PID controller example to the docs. So, thank you for your contribution by opening this issue.

hzgzh commented 4 years ago

It's work.thank very much,wish this software can instead simulink.