diff --git a/src/BallAndBeam.jl b/src/BallAndBeam.jl index 508f2cfc62547e63f21f93378fd50b20fe1bcddd..55692e7daf7fa47193e96e4fa7e5ed557560aa0e 100644 --- a/src/BallAndBeam.jl +++ b/src/BallAndBeam.jl @@ -26,21 +26,21 @@ using LabProcesses, Plots, Polynomials, ControlSystems, ProgressMeter run_experiment(P::AbstractBeam, ω, duration, settling_time, amplitude, bias) Perform fra-experiemnt For a single frequency `ω`. Called from inside `fra` """ -function run_experiment(P::AbstractBeam, ω, duration, settling_time, amplitude, bias) +function run_experiment(P::AbstractBeam, ω, duration, settling_time, amplitude) h = sampletime(P) data = zeros(0:h:duration) LabProcesses.initialize(P) for t = 0:h:settling_time @periodically h begin u = amplitude*sin(ω*t) - control(P, u+bias) + control(P, u + bias(P)) end end for (i,t) = enumerate(0:h:duration) @periodically h begin data[i] = measure(P) u = amplitude*sin(ω*t) - control(P, u) + control(P, u + bias(P)) end end LabProcesses.finalize(P) @@ -58,13 +58,11 @@ integrate(fun,data,ω,h) = h*sum(fun(ω*(i-1)*h).*data[i] for i = 1:length(data) fra(Ω::AbstractVector; kwargs...) # Arguments -- `bias = 0`: Change the bias if the beam angle is drifting over time - `settling_time = 2`: In seconds, rounded up to closest integer periods - `nbr_of_periods = 10`: - `amplitude = 1`: Very low freqs might require smaller amplitude """ function fra(P::AbstractBeam, Ω::AbstractVector; - bias = 0, settling_time = 2, nbr_of_periods = 10, amplitude = 1) @@ -75,7 +73,7 @@ function fra(P::AbstractBeam, Ω::AbstractVector; T = 2π/ω # Period time settling_time_i = ceil(settling_time/T)*T # Settling time even number of periods duration = nbr_of_periods*T - data = run_experiment(P,ω,duration,settling_time_i, amplitude,bias) + data = run_experiment(P,ω,duration,settling_time_i, amplitude) sin_channel = integrate(sin, data, ω, h) cos_channel = integrate(cos, data, ω, h) G[i] = 2/(amplitude*duration)*Complex(sin_channel, cos_channel) diff --git a/src/FRTN35_lab1.jl b/src/FRTN35_lab1.jl index abcd4d87bf98ba413e9e12d4c5c2c9fc71df22bc..5bc0612d1c06b26d01b97ce479e87d11750cf72c 100644 --- a/src/FRTN35_lab1.jl +++ b/src/FRTN35_lab1.jl @@ -1,34 +1,34 @@ -using BallAndBeam, LabProcesses, ControlSystems, JLD +using BallAndBeam, ControlSystems, JLD, LabProcesses # @load "workspace.jld" # Run this command to restore a saved workspace -bias = 0.01 # Change this if your process drifts over time -P = LabProcesses.Beam(0.01, bias) +bias = 0.01 # Change this if your process drifts over time +P = LabProcesses.Beam(0.01) # Replace for BeamSimulator to run simulations h = sampletime(P) settling_time = 1 -nbr_of_periods = 5 +nbr_of_periods = 3 # Below we define some frequency vectors (using logarithmic spacing) # and run three experiments. You may modify the freqency vectors # any way you want and add/remove experiments as needed. w1_100 = logspace(log10(1),log10(300),8) -G1 = fra(P, w1_100, amplitude=1, bias=bias, nbr_of_periods=nbr_of_periods, settling_time=settling_time) +G1 = fra(P, w1_100, amplitude=1, nbr_of_periods=nbr_of_periods, settling_time=settling_time) @save "workspace.jld" w1_200 = logspace(log10(5),log10(50),20) -G2 = fra(P, w1_200, amplitude=2, bias=bias, nbr_of_periods=nbr_of_periods, settling_time=settling_time) +G2 = fra(P, w1_200, amplitude=2, nbr_of_periods=nbr_of_periods, settling_time=settling_time) @save "workspace.jld" w1_300 = logspace(log10(10),log10(30),20) -G3 = fra(P, w1_300, amplitude=2, bias=bias, nbr_of_periods=nbr_of_periods, settling_time=settling_time) +G3 = fra(P, w1_300, amplitude=2, nbr_of_periods=nbr_of_periods, settling_time=settling_time) @save "workspace.jld" # Concatenate (overlapping) estimates to be used and sort based on freq G123 = sortfqs([G1; G2; G3]) bopl(G123, m=:star) -nypl(G123) +nypl(G123, m=:star) ## Control ================================================================================== polevect = [-10]