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

No sleep in control loop for simulated process

parent e62aa7b9
No related branches found
No related tags found
No related merge requests found
......@@ -30,9 +30,10 @@ function run_control_2DOF(P::AbstractProcess,sysFB, sysFF=nothing; duration = 10
ui + bias(P)
end
simulation = isa(P, SimulatedProcess)
initialize(P)
for (i,t) = enumerate(0:h:duration)
@periodically h begin
@periodically h simulation begin
y[:,i] = measure(P)
r[:,i] = reference(t)
u[:,i] = calc_control(i) # y,r must be updated before u
......
......@@ -87,5 +87,5 @@ initialize(p::AbstractBeamOrBallAndBeam) = ccall((:comedi_start, comedipath),Int
finalize(p::AbstractBeamOrBallAndBeam) = (control(p,0);ccall((:comedi_stop, comedipath),Int32,(Int32,), 0))
initialize(p::BallAndBeamSimulator) = nothing
finalize(p::BallAndBeamSimulator) = nothing
initialize(p::BeamSimulator) = nothing
initialize(p::BeamSimulator) = p.state .*= 0
finalize(p::BeamSimulator) = nothing
......@@ -13,6 +13,20 @@ macro periodically(h, body)
end
end
"""
@periodically(h, simulation::Bool, body)
Ensures that the body is run with an interval of `h >= 0.001` seconds.
If `simulation == false`, no sleep is done
"""
macro periodically(h, simulation, body)
quote
local start_time = time()
$(esc(body))
local execution_time = time()-start_time
$(esc(simulation)) || sleep(max(0,$(esc(h))-execution_time))
end
end
"""
state = init_sysfilter(sys::StateSpace)
Use together with [`sysfilter!`](@ref)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment