diff --git a/REQUIRE b/REQUIRE index c1d1fd863fc812ce4cd25dffe2cca6d024e64335..ac8656465a4e7bb5e245010a93cdf061e44b0652 100644 --- a/REQUIRE +++ b/REQUIRE @@ -5,4 +5,3 @@ Polynomials ProgressMeter JLD Documenter -LabProcesses diff --git a/src/BallAndBeam.jl b/src/BallAndBeam.jl index 10550e25a1ee525fac0caa1ca848b4a963969e98..6b48b48f69c8403c1bc9b97e86c67bf0bce20e86 100644 --- a/src/BallAndBeam.jl +++ b/src/BallAndBeam.jl @@ -3,7 +3,7 @@ if "LabProcesses" ∉ keys(installed_packages) Pkg.clone("https://gitlab.control.lth.se/processes/LabProcesses.jl.git") end -__precompile__() +#__precompile__() """ This module contains a controller for the Ball and Beam. It connects to the @@ -26,8 +26,9 @@ using LabProcesses, Plots, Polynomials, ControlSystems, ProgressMeter Perform fra-experiemnt For a single frequency `ω`. Called from inside `fra` """ function run_experiment(P::BallAndBeamType, ω, duration, settling_time, amplitude, bias) + h = sampletime(P) data = zeros(0:h:duration) - initialize(P) + LabProcesses.initialize(P) for t = 0:h:settling_time @periodically h begin u = amplitude*sin(ω*t) @@ -41,16 +42,16 @@ function run_experiment(P::BallAndBeamType, ω, duration, settling_time, amplitu control(P, u) end end - finalize(P) + LabProcesses.finalize(P) data end """ - ∫ = integrate(fun::Function, data::Vector, ω::Real) -Calculate sin or cos channel, call like this `integrate(sin, data, ω)` for sin-channel + ∫ = integrate(fun::Function, data::Vector, ω::Real,h) +Calculate sin or cos channel, call like this `integrate(sin, data, ω,h)` for sin-channel integration """ -integrate(fun,data,ω) = h*sum(fun(ω*(i-1)*h).*data[i] for i = 1:length(data)) +integrate(fun,data,ω,h) = h*sum(fun(ω*(i-1)*h).*data[i] for i = 1:length(data)) """ fra(Ω::AbstractVector; kwargs...) @@ -66,7 +67,7 @@ function fra(P::BallAndBeamType, Ω::AbstractVector; settling_time = 2, nbr_of_periods = 10, amplitude = 1) - + h = sampletime(P) G = zeros(Complex, size(Ω)) # Transfer function @showprogress 1 "Running experiments" for (i,ω) = enumerate(Ω) @@ -74,8 +75,8 @@ function fra(P::BallAndBeamType, Ω::AbstractVector; 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) - sin_channel = integrate(sin, data, ω) - cos_channel = integrate(cos, data, ω) + sin_channel = integrate(sin, data, ω, h) + cos_channel = integrate(cos, data, ω, h) G[i] = 2/(amplitude*duration)*Complex(sin_channel, cos_channel) end Number[Ω G] @@ -92,7 +93,7 @@ end function bopl!(G; kwargs...) plot!(G[:,1].*(180/π), abs.(G[:,2]); ylabel="Magnitude", title="Bode plot", xscale=:log10, yscale=:log10, subplot=1, kwargs...) - plot!(G[:,1].*(180/π), angle.(G[:,2]); xlabel="Frequency [1/s]", ylabel="Phase", xscale=:log10, subplot=2, kwargs...) + plot!(G[:,1].*(180/π), angle.(G[:,2]).*(180/π); xlabel="Frequency [1/s]", ylabel="Phase", xscale=:log10, subplot=2, kwargs...) plot!(link=:x) end