Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
processes
LabProcesses.jl
Commits
127b12ad
Commit
127b12ad
authored
Aug 22, 2017
by
Fredrik Bagge Carlson
Browse files
Change Union type naming to Abstract
parent
7411773b
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/interface_implementations/ballandbeam.jl
View file @
127b12ad
# Interface implementation Ball And Beam ====================================================
export
Beam
,
BeamSimulator
,
BeamType
,
BallAndBeam
,
BallAndBeamSimulator
,
BeamOrBallAndBeam
# The ball and beam can be used in two modes, either just the Beam, in which case there is a
# single output (measurement signal) or the BallAndBeam, in which case there are two.
# There are a few union types defined for convenience, these are
# AbstractBeam = Union{Beam, BeamSimulator}
# AbstractBallAndBeam = Union{BallAndBeam, BallAndBeamSimulator}
# AbstractBeamOrBallAndBeam = All types
# Although not Abstract per se, the names AbstractBeam etc. were chosen since this reflects
# their usage in dispatch.
export
Beam
,
BeamSimulator
,
AbstractBeam
,
BallAndBeam
,
BallAndBeamSimulator
,
AbstractBeamOrBallAndBeam
struct
Beam
<:
PhysicalProcess
h
::
Float64
...
...
@@ -27,26 +36,26 @@ end
BallAndBeamSimulator
()
=
BallAndBeamSimulator
(
0.01
,
zeros
(
4
))
const
BeamType
=
Union
{
Beam
,
BeamSimulator
}
const
BallAndBeam
Type
=
Union
{
BallAndBeam
,
BallAndBeamSimulator
}
const
BeamOrBallAndBeam
=
Union
{
BeamType
,
BallAndBeam
Type
}
const
AbstractBeam
=
Union
{
Beam
,
BeamSimulator
}
const
Abstract
BallAndBeam
=
Union
{
BallAndBeam
,
BallAndBeamSimulator
}
const
Abstract
BeamOrBallAndBeam
=
Union
{
AbstractBeam
,
Abstract
BallAndBeam
}
num_outputs
(
p
::
BeamType
)
=
1
num_outputs
(
p
::
BallAndBeam
Type
)
=
2
num_inputs
(
p
::
BeamOrBallAndBeam
)
=
1
outputrange
(
p
::
Beam
)
=
[(
-
10
,
10
)]
outputrange
(
p
::
BallAndBeam
Type
)
=
[(
-
10
,
10
),(
-
1
,
1
)]
# Beam angle, Ball position
inputrange
(
p
::
BeamOrBallAndBeam
)
=
[(
-
10
,
10
)]
isstable
(
p
::
Beam
)
=
true
isstable
(
p
::
BallAndBeam
Type
)
=
false
isasstable
(
p
::
BeamOrBallAndBeam
)
=
false
sampletime
(
p
::
BeamOrBallAndBeam
)
=
p
.
h
bias
(
p
::
BeamOrBallAndBeam
)
=
p
.
bias
bias
(
p
::
BallAndBeamSimulator
)
=
0
num_outputs
(
p
::
AbstractBeam
)
=
1
num_outputs
(
p
::
Abstract
BallAndBeam
)
=
2
num_inputs
(
p
::
Abstract
BeamOrBallAndBeam
)
=
1
outputrange
(
p
::
Beam
)
=
[(
-
10
,
10
)]
outputrange
(
p
::
Abstract
BallAndBeam
)
=
[(
-
10
,
10
),(
-
1
,
1
)]
# Beam angle, Ball position
inputrange
(
p
::
Abstract
BeamOrBallAndBeam
)
=
[(
-
10
,
10
)]
isstable
(
p
::
Beam
)
=
true
isstable
(
p
::
Abstract
BallAndBeam
)
=
false
isasstable
(
p
::
Abstract
BeamOrBallAndBeam
)
=
false
sampletime
(
p
::
Abstract
BeamOrBallAndBeam
)
=
p
.
h
bias
(
p
::
Abstract
BeamOrBallAndBeam
)
=
p
.
bias
bias
(
p
::
BallAndBeamSimulator
)
=
0
control
(
p
::
BeamOrBallAndBeam
,
u
)
=
ccall
((
:
comedi_write
,
comedipath
),
Int32
,
control
(
p
::
Abstract
BeamOrBallAndBeam
,
u
)
=
ccall
((
:
comedi_write
,
comedipath
),
Int32
,
(
Int32
,
Int32
,
Int32
,
Int32
),
0
,
1
,
1
,
num2io
(
u
[
1
]
+
p
.
bias
))
measure
(
p
::
Beam
)
=
io2num
(
ccall
((
:
comedi_read
,
comedipath
),
Int32
,
(
Int32
,
Int32
,
Int32
),
0
,
0
,
0
))
...
...
@@ -61,7 +70,7 @@ const conversion = 65535/20
io2num
(
x
)
=
x
/
conversion
-
10
# Converts from io to float
num2io
(
x
)
=
round
(
Int32
,
x
*
100
+
2048
)
# Converts from regular number to io
initialize
(
p
::
BeamOrBallAndBeam
)
=
ccall
((
:
comedi_start
,
comedipath
),
Int32
,(
Int32
,),
0
)
finalize
(
p
::
BeamOrBallAndBeam
)
=
(
control
(
p
,
0
);
ccall
((
:
comedi_stop
,
comedipath
),
Int32
,(
Int32
,),
0
))
initialize
(
p
::
BallAndBeamSimulator
)
=
nothing
finalize
(
p
::
BallAndBeamSimulator
)
=
nothing
initialize
(
p
::
Abstract
BeamOrBallAndBeam
)
=
ccall
((
:
comedi_start
,
comedipath
),
Int32
,(
Int32
,),
0
)
finalize
(
p
::
Abstract
BeamOrBallAndBeam
)
=
(
control
(
p
,
0
);
ccall
((
:
comedi_stop
,
comedipath
),
Int32
,(
Int32
,),
0
))
initialize
(
p
::
BallAndBeamSimulator
)
=
nothing
finalize
(
p
::
BallAndBeamSimulator
)
=
nothing
src/interface_implementations/eth_helicopter.jl
View file @
127b12ad
# Interface implementation Ball And Beam ====================================================
export
ETHHelicopter
,
ETHHelicopterSimulator
,
ETHHelicopterType
# 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
struct
ETHHelicopter
<:
PhysicalProcess
h
::
Float64
bias
::
Float64
end
ETHHelicopter
()
=
ETHHelicopter
(
0.050
)
ETHHelicopter
()
=
ETHHelicopter
(
0.050
,
0.
)
struct
ETHHelicopterSimulator
<:
SimulatedProcess
h
::
Float64
...
...
@@ -15,15 +20,15 @@ struct ETHHelicopterSimulator <: SimulatedProcess
end
ETHHelicopterSimulator
()
=
ETHHelicopterSimulator
(
0.01
,
zeros
(
4
))
const
ETHHelicopter
Type
=
Union
{
ETHHelicopter
,
ETHHelicopterSimulator
}
num_outputs
(
p
::
ETHHelicopter
Type
)
=
2
num_inputs
(
p
::
ETHHelicopter
Type
)
=
2
outputrange
(
p
::
ETHHelicopter
Type
)
=
[(
-
10
,
10
),(
-
10
,
10
)]
# Beam angle, Ball position
inputrange
(
p
::
ETHHelicopter
Type
)
=
[(
-
10
,
10
)]
isstable
(
p
::
ETHHelicopter
Type
)
=
false
isasstable
(
p
::
ETHHelicopter
Type
)
=
false
sampletime
(
p
::
ETHHelicopter
Type
)
=
p
.
h
bias
(
p
::
ETHHelicopter
Type
)
=
p
.
bias
const
Abstract
ETHHelicopter
=
Union
{
ETHHelicopter
,
ETHHelicopterSimulator
}
num_outputs
(
p
::
Abstract
ETHHelicopter
)
=
2
num_inputs
(
p
::
Abstract
ETHHelicopter
)
=
2
outputrange
(
p
::
Abstract
ETHHelicopter
)
=
[(
-
10
,
10
),(
-
10
,
10
)]
inputrange
(
p
::
Abstract
ETHHelicopter
)
=
[(
-
10
,
10
)
,(
-
10
,
10
)
]
isstable
(
p
::
Abstract
ETHHelicopter
)
=
false
isasstable
(
p
::
Abstract
ETHHelicopter
)
=
false
sampletime
(
p
::
Abstract
ETHHelicopter
)
=
p
.
h
bias
(
p
::
Abstract
ETHHelicopter
)
=
p
.
bias
function
control
(
p
::
ETHHelicopter
,
u
)
...
...
@@ -42,7 +47,7 @@ const conversion = 65535/20
io2num
(
x
)
=
x
/
conversion
-
10
# Converts from io to float
num2io
(
x
)
=
round
(
Int32
,(
x
+
10
)
*
conversion
)
# Converts from regular number to io
initialize
(
p
::
ETHHelicopter
)
=
ccall
((
:
comedi_start
,
comedipath
),
Int32
,(
Int32
,),
0
)
finalize
(
p
::
ETHHelicopter
)
=
(
control
(
p
,
0
);
ccall
((
:
comedi_stop
,
comedipath
),
Int32
,(
Int32
,),
0
))
initialize
(
p
::
ETHHelicopterSimulator
)
=
nothing
finalize
(
p
::
ETHHelicopterSimulator
)
=
nothing
initialize
(
p
::
ETHHelicopter
)
=
ccall
((
:
comedi_start
,
comedipath
),
Int32
,(
Int32
,),
0
)
finalize
(
p
::
ETHHelicopter
)
=
(
control
(
p
,
0
);
ccall
((
:
comedi_stop
,
comedipath
),
Int32
,(
Int32
,),
0
))
initialize
(
p
::
ETHHelicopterSimulator
)
=
nothing
finalize
(
p
::
ETHHelicopterSimulator
)
=
nothing
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment