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

Verified to work on BeamSimulator

parent 8bf75d40
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -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)
......
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)
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]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment