diff --git a/README.md b/README.md index 7592e7b06860ff063d31af5c4fa9dec55fc932e0..b82a5eaa05cfc7a2df5bd531f065ebdb6563063b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +[](https://gitlab.control.lth.se/processes/BallAndBeam.jl/commits/master) +[](https://gitlab.control.lth.se/processes/BallAndBeam.jl/commits/master) + # Installation (specific to lab 1 FRTN35: Frequency response analysis) 1. Open a terminal 2. Type `mkdir FRTN35_lab1; cd FRTN35_lab1` diff --git a/src/BallAndBeam.jl b/src/BallAndBeam.jl index ec52790d3e654f46373403b0d3febcb717e5898c..33dc2ced3bcf9ec1b0d4a8a993f0acbf21769cf4 100644 --- a/src/BallAndBeam.jl +++ b/src/BallAndBeam.jl @@ -16,7 +16,7 @@ module BallAndBeam export run_experiment, fra, sortfqs, bopl, bopl!, nypl, nypl!, plot, fbdesign, ffdesign, opendoc -export init_sysfilter, sysfilter!, run_control_2DOF # For documentation +export SysFilter, init_sysfilter, sysfilter!, run_control_2DOF # For documentation using LabProcesses, Plots, Polynomials, ControlSystems, ProgressMeter @@ -194,6 +194,12 @@ dynamical system, i.e., `U(z) = C(z)E(z)`. Initialize `state` using [`init_sysfi """ sysfilter! +""" + sf = SysFilter(sys::StateSpace) +Create a SysFilter object that can be used to implement control loops and simulators with LTI systems, i.e., `U(z) = C(z)E(z)`. See [`sysfilter!`](@ref) for usage. +""" +SysFilter + """ y,u,r = run_control_2DOF(process, sysFB[, sysFF]; duration = 10, reference(t) = sign(sin(2π*t))) Perform control experiemnt on process where the feedback and feedforward controllers are given by diff --git a/src/FRTN35_lab1.jl b/src/FRTN35_lab1.jl index 4134330e323adaebaaaf80d86821c289da1bae86..d8d912a591a24bc3c94b161d840614d8bec998de 100644 --- a/src/FRTN35_lab1.jl +++ b/src/FRTN35_lab1.jl @@ -72,6 +72,6 @@ nb = 5 # Order of B polynomial arxtf = arx(h, y, u, na, nb) # Estimate trasfer function with ARX method mag, phase, ω = bode(arxtf, logspace(-1,3,200)) -bopl(G1, lab="Measured transfer function") +bopl(G123, lab="Measured transfer function") plot!(ω, mag[:], subplot=1, lab = "ARX estimate") plot!(ω, phase[:], subplot=2) diff --git a/test/runtests.jl b/test/runtests.jl index ccd72776ab913fc6e4f28a588cc660168588281c..da621af70840675041437e0afb30791a2762892e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -6,22 +6,7 @@ P = LabProcesses.Beam(0.01,0.) h = sampletime(P) @test h == 0.01 -function test_sysfilter() - N = 10 - u = randn(N) - b = [1, 1] - a = [1, 0.1, 1] - sys = ss(tf(b,a,1)) - state = init_sysfilter(sys) - yf = filt(b,a,u) - yff = similar(yf) - for i in eachindex(u) - yff[i] = sysfilter!(state, sys, u[i])[1] - end - @test sum(abs,yf - yff) < √(eps()) -end -test_sysfilter() settling_time = 1 nbr_of_periods = 5 @@ -61,7 +46,7 @@ nbr_of_periods = 2 w1_100 = logspace(-1,log10(300),500) G1 = fra(P, w1_100, amplitude=1, nbr_of_periods=nbr_of_periods, settling_time=settling_time) -true_resp = freqresp(P.sys, w1_100) +true_resp = freqresp(P.s.sys, w1_100) @test sum(abs, log.(abs.(G1[:,2])) - log.(abs.(true_resp[1][:]))) < 3.2 # Some numerical errors expected phase_id = angle.(G1[:,2]) |> ControlSystems.unwrap phase_true = angle.(true_resp[1][:]) |> ControlSystems.unwrap @@ -87,7 +72,7 @@ nb = 5 arxtf = arx(h, y[:], u, na, nb; λ = 0) w1_100 = logspace(-1,log10(100),500) -true_resp = freqresp(P.sys, w1_100) +true_resp = freqresp(P.s.sys, w1_100) phase_true = angle.(true_resp[1][:]) |> ControlSystems.unwrap arx_resp = freqresp(arxtf, w1_100) @test sum(abs, log.(abs.(arx_resp[1][:])) - log.(abs.(true_resp[1][:]))) < 1.25