Commit 5dbfdbe8 authored by Fredrik Bagge Carlson's avatar Fredrik Bagge Carlson
Browse files

Update initialize, finalize and constructors

parent 2bde548e
......@@ -24,12 +24,22 @@ Physical beam process
- `measure::AnalogInput10V = AnalogInput10V(0)`
- `control::AnalogOutput10V = AnalogOutput10V(1)`
"""
@with_kw struct Beam <: PhysicalProcess
h::Float64 = 0.01
bias::Float64 = 0.0
stream::LabStream = ComediStream()
measure::AnalogInput10V = AnalogInput10V(0)
control::AnalogOutput10V = AnalogOutput10V(1)
struct Beam <: PhysicalProcess
h::Float64
bias::Float64
stream::LabStream
measure::AnalogInput10V
control::AnalogOutput10V
end
function Beam(;
h::Float64 = 0.01,
bias::Float64 = 0.,
stream::LabStream = ComediStream(),
measure::AnalogInput10V = AnalogInput10V(0),
control::AnalogOutput10V = AnalogOutput10V(1))
p = new(Float64(h),Float64(bias),stream,measure,control)
init_devices!(p.stream, p.measure, p.control)
p
end
include("define_beam_system.jl")
......@@ -41,13 +51,24 @@ struct BeamSimulator <: SimulatedProcess
BeamSimulator(;h::Real = 0.01) = new(Float64(h), SysFilter(beam_system, h))
end
@with_kw struct BallAndBeam <: PhysicalProcess
h::Float64 = 0.01
bias::Float64 = 0.0
stream::LabStream = ComediStream()
measure1::AnalogInput10V = AnalogInput10V(0)
measure2::AnalogInput10V = AnalogInput10V(1)
control::AnalogOutput10V = AnalogOutput10V(0)
struct BallAndBeam <: PhysicalProcess
h::Float64
bias::Float64
stream::LabStream
measure1::AnalogInput10V
measure2::AnalogInput10V
control::AnalogOutput10V
end
function BallAndBeam(;
h = 0.01,
bias = 0.,
stream = ComediStream(),
measure1::AnalogInput10V = AnalogInput10V(0),
measure2::AnalogInput10V = AnalogInput10V(1),
control::AnalogOutput10V = AnalogOutput10V(1))
p = new(h,bias,stream,measure1,measure2,control)
init_devices!(p.stream, p.measure1, p.measure2, p.control)
p
end
struct BallAndBeamSimulator <: SimulatedProcess
......@@ -84,10 +105,9 @@ measure(p::BeamSimulator) = vecdot(p.s.sys.C,p.s.state)
measure(p::BallAndBeamSimulator) = error("Not yet implemented")
initialize(p::Beam) = init_devices!(p.stream, p.measure, p.control)
initialize(p::BallAndBeam) = init_devices!(p.stream, p.measure1,
p.measure2, p.control)
finalize(p::AbstractBeamOrBallAndBeam) = close(p.stream)
initialize(p::Beam) = nothing
initialize(p::BallAndBeam) = nothing
finalize(p::AbstractBeamOrBallAndBeam) = foreach(close, p.stream.devices)
initialize(p::BallAndBeamSimulator) = nothing
finalize(p::BallAndBeamSimulator) = nothing
initialize(p::BeamSimulator) = p.s.state .*= 0
......
......@@ -22,13 +22,25 @@ export ETHHelicopter, ETHHelicopterSimulator, AbstractETHHelicopter
- `control2::AnalogOutput10V = AnalogOutput10V(1)`
"""
@with_kw struct ETHHelicopter <: PhysicalProcess
h::Float64 = 0.05
bias::Float64 = 0.0
stream::LabStream = ComediStream()
measure1::AnalogInput10V = AnalogInput10V(0)
measure2::AnalogInput10V = AnalogInput10V(1)
control1::AnalogOutput10V = AnalogOutput10V(0)
control2::AnalogOutput10V = AnalogOutput10V(1)
h::Float64
bias::Float64
stream::LabStream
measure1::AnalogInput10V
measure2::AnalogInput10V
control1::AnalogOutput10V
control2::AnalogOutput10V
end
function ETHHelicopter(;
h = 0.05,
bias = 0.,
stream = ComediStream(),
measure1::AnalogInput10V = AnalogInput10V(0),
measure2::AnalogInput10V = AnalogInput10V(1),
control1::AnalogOutput10V = AnalogOutput10V(0),
control2::AnalogOutput10V = AnalogOutput10V(1))
p = new(h,bias,stream,measure1,measure2,control1,control2)
init_devices!(p.stream, p.measure1, p.measure2, p.control1, p.control2)
p
end
......@@ -55,15 +67,12 @@ function control(p::ETHHelicopter, u)
send(p.control2,u[2])
end
measure(p::ETHHelicopter) = [read(p.measure1), read(p.measure2)] #i=0 for pitch, i=1 for yaw
measure(p::ETHHelicopter) = [read(p.measure1), read(p.measure2)]
control(p::ETHHelicopterSimulator, u) = error("Not yet implemented")
measure(p::ETHHelicopterSimulator) = error("Not yet implemented")
initialize(p::ETHHelicopter) = init_devices!(p.stream, p.measure1, p.measure2, p.control1, p.control2)
finalize(p::ETHHelicopter) = close(p.stream)
initialize(p::ETHHelicopter) = nothing
finalize(p::ETHHelicopter) = foreach(close, p.stream.devices)
initialize(p::ETHHelicopterSimulator) = nothing
finalize(p::ETHHelicopterSimulator) = nothing
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment