Skip to content
Snippets Groups Projects
Commit 41e269d1 authored by Fredrik Bagge Carlson's avatar Fredrik Bagge Carlson
Browse files

Update readme and support MIMO in run_control_2dof

parent a38c1b06
Branches
Tags
No related merge requests found
...@@ -17,7 +17,8 @@ to get the latest release. ...@@ -17,7 +17,8 @@ to get the latest release.
2. Install LabProcesses.jl using command `Pkg.clone("https://gitlab.control.lth.se/processes/LabProcesses.jl.git")` Lots of packages will now be installed, this will take some time. If this is your first time using Julia, you might have to run `julia> Pkg.init()` before you install any packages. 2. Install LabProcesses.jl using command `Pkg.clone("https://gitlab.control.lth.se/processes/LabProcesses.jl.git")` Lots of packages will now be installed, this will take some time. If this is your first time using Julia, you might have to run `julia> Pkg.init()` before you install any packages.
## How to implement a new process ## How to implement a new process
1. Locate the file [interface.jl](https://gitlab.control.lth.se/processes/LabProcesses.jl/blob/master/src/interface.jl). (Alternatively, you can copy all definitions from [/interface_implementations/ballandbeam.jl](https://gitlab.control.lth.se/processes/LabProcesses.jl/blob/master/src/interface_implementations/ballandbeam.jl) instead. Maybe it's easier to work from an existing implementaiton.) 1. Locate the file [interface.jl](https://gitlab.control.lth.se/processes/LabProcesses.jl/blob/master/src/interface.jl). When the package is installed, you find its directory under `~/.julia/v0.6/LabProcesses/`, if not, run `julia> Pkg.dir("LabProcesses")` to locate the directory.
(Alternatively, you can copy all definitions from [/interface_implementations/ballandbeam.jl](https://gitlab.control.lth.se/processes/LabProcesses.jl/blob/master/src/interface_implementations/ballandbeam.jl) instead. Maybe it's easier to work from an existing implementaiton.)
2. Copy all function definitions. 2. Copy all function definitions.
3. Create a new file under `/interface_implementations` where you paste all the 3. Create a new file under `/interface_implementations` where you paste all the
copied definitions and implement them. See [/interface_implementations/ballandbeam.jl](https://gitlab.control.lth.se/processes/LabProcesses.jl/blob/master/src/interface_implementations/ballandbeam.jl) for an example. copied definitions and implement them. See [/interface_implementations/ballandbeam.jl](https://gitlab.control.lth.se/processes/LabProcesses.jl/blob/master/src/interface_implementations/ballandbeam.jl) for an example.
......
...@@ -2,7 +2,7 @@ export run_control_2DOF ...@@ -2,7 +2,7 @@ export run_control_2DOF
""" """
y,u,r = run_control(process, sysFB[, sysFF]; duration = 10, reference(t) = sign(sin(2π*t))) y,u,r = run_control(process, sysFB[, sysFF]; duration = 10, reference(t) = sign(sin(2π*t)))
Perform control experiemnt where the feedback and feedforward controllers are given by Perform control experiemnt on process where the feedback and feedforward controllers are given by
`sysFB` and `sysFF`, both of type `StateSpace`. `sysFB` and `sysFF`, both of type `StateSpace`.
`reference` is a reference generating function that accepts a scalar `t` (time in seconds) and outputs a scalar `r`, default is `reference(t) = sign(sin(2π*t))`. `reference` is a reference generating function that accepts a scalar `t` (time in seconds) and outputs a scalar `r`, default is `reference(t) = sign(sin(2π*t))`.
...@@ -11,10 +11,12 @@ The outputs `y,u,r` are the beam angle, control signal and reference respectivel ...@@ -11,10 +11,12 @@ The outputs `y,u,r` are the beam angle, control signal and reference respectivel
![block diagram](docs/feedback4.png) ![block diagram](docs/feedback4.png)
""" """
function run_control_2DOF(P::AbstractProcess,sysFB, sysFF=nothing; duration = 10, reference = t->sign(sin(2π*t))) function run_control_2DOF(P::AbstractProcess,sysFB, sysFF=nothing; duration = 10, reference = t->sign(sin(2π*t)))
nu = num_inputs(P)
ny = num_outputs(P)
h = sampletime(P) h = sampletime(P)
y = zeros(0:h:duration) y = zeros(ny, length(0:h:duration))
u = zeros(0:h:duration) u = zeros(nu, length(0:h:duration))
r = zeros(0:h:duration) r = zeros(ny, length(0:h:duration))
stateFB = init_sysfilter(sysFB) stateFB = init_sysfilter(sysFB)
if sysFF != nothing if sysFF != nothing
...@@ -22,19 +24,19 @@ function run_control_2DOF(P::AbstractProcess,sysFB, sysFF=nothing; duration = 10 ...@@ -22,19 +24,19 @@ function run_control_2DOF(P::AbstractProcess,sysFB, sysFF=nothing; duration = 10
end end
function calc_control(i) function calc_control(i)
rf = sysFF == nothing ? r[i] : sysfilter!(stateFF, sysFF, r[i]) rf = sysFF == nothing ? r[:,i] : sysfilter!(stateFF, sysFF, r[:,i])
e = rf-y[i] e = rf-y[:,i]
ui = sysfilter!(stateFB, sysFB, e)[1] ui = sysfilter!(stateFB, sysFB, e)
ui + bias(P) ui + bias(P)
end end
initialize(P) initialize(P)
for (i,t) = enumerate(0:h:duration) for (i,t) = enumerate(0:h:duration)
@periodically h begin @periodically h begin
y[i] = measure(P) y[:,i] = measure(P)
r[i] = reference(t) r[:,i] = reference(t)
u[i] = calc_control(i) # y,r must be updated before u u[:,i] = calc_control(i) # y,r must be updated before u
control(P, u[i]) control(P, [clamp.(u[j,i], input_range(P)[j]...) for j=1:nu])
end end
end end
finalize(P) finalize(P)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment