eth_helicopter.jl 1.94 KB
Newer Older
Martin Karlsson's avatar
Martin Karlsson committed
1
2
# Interface implementation Ball And Beam ====================================================

3
4
5
6
7
8
# There is a union type defined for convenience:
# AbstractETHHelicopter = Union{ETHHelicopter, ETHHelicopterSimulator}
# Although not Abstract per se, the names AbstractETHHelicopter etc. were chosen since this
# reflects the usage in dispatch.

export ETHHelicopter, ETHHelicopterSimulator, AbstractETHHelicopter
Martin Karlsson's avatar
Martin Karlsson committed
9
10

struct ETHHelicopter <: PhysicalProcess
11
	h::Float64
12
    bias::Float64
13
14
15
16
17
    stream::LabStream
    measure1::AnalogInput10V
    measure2::AnalogInput10V
    control1::AnalogOutput10V
    control2::AnalogOutput10V
Martin Karlsson's avatar
Martin Karlsson committed
18
end
19
ETHHelicopter() = ETHHelicopter(0.050, 0., ComediStream(), AnalogInput10V(0), AnalogInput10V(1), AnalogOutput10V(0), AnalogOutput10V(1))
Martin Karlsson's avatar
Martin Karlsson committed
20
21
22

struct ETHHelicopterSimulator <: SimulatedProcess
    h::Float64
23
    bias::Float64
Martin Karlsson's avatar
Martin Karlsson committed
24
25
26
27
    state::Vector{Float64}
end
ETHHelicopterSimulator() = ETHHelicopterSimulator(0.01, zeros(4))

28
29
30
31
32
33
34
35
36
const AbstractETHHelicopter = Union{ETHHelicopter, ETHHelicopterSimulator}
num_outputs(p::AbstractETHHelicopter) = 2
num_inputs(p::AbstractETHHelicopter)  = 2
outputrange(p::AbstractETHHelicopter) = [(-10,10),(-10,10)]
inputrange(p::AbstractETHHelicopter)  = [(-10,10),(-10,10)]
isstable(p::AbstractETHHelicopter)    = false
isasstable(p::AbstractETHHelicopter)  = false
sampletime(p::AbstractETHHelicopter)  = p.h
bias(p::AbstractETHHelicopter)        = p.bias
37

Martin Karlsson's avatar
Martin Karlsson committed
38
39

function control(p::ETHHelicopter, u)
40
41
    send(p.control1,u[1])
    send(p.control2,u[2])
Martin Karlsson's avatar
Martin Karlsson committed
42
43
end

44
measure(p::ETHHelicopter) = [read(p.measure1), read(p.measure2)] #i=0 for pitch, i=1 for yaw
Martin Karlsson's avatar
Martin Karlsson committed
45
46
47
48
49
50


control(p::ETHHelicopterSimulator, u)  = error("Not yet implemented")
measure(p::ETHHelicopterSimulator)     = error("Not yet implemented")


51
52
53

initialize(p::ETHHelicopter) = init_devices!(p.stream, p.measure1, p.measure2, p.control1, p.control2)
finalize(p::ETHHelicopter)   = close(p.stream)
54
55
initialize(p::ETHHelicopterSimulator) = nothing
finalize(p::ETHHelicopterSimulator)   = nothing