Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
LabProcesses.jl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Heyden
LabProcesses.jl
Commits
127b12ad
Commit
127b12ad
authored
7 years ago
by
Fredrik Bagge Carlson
Browse files
Options
Downloads
Patches
Plain Diff
Change Union type naming to Abstract
parent
7411773b
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/interface_implementations/ballandbeam.jl
+30
-21
30 additions, 21 deletions
src/interface_implementations/ballandbeam.jl
src/interface_implementations/eth_helicopter.jl
+20
-15
20 additions, 15 deletions
src/interface_implementations/eth_helicopter.jl
with
50 additions
and
36 deletions
src/interface_implementations/ballandbeam.jl
+
30
−
21
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
num_outputs
(
p
::
AbstractBeam
)
=
1
num_outputs
(
p
::
Abstract
BallAndBeam
)
=
2
num_inputs
(
p
::
Abstract
BeamOrBallAndBeam
)
=
1
outputrange
(
p
::
Beam
)
=
[(
-
10
,
10
)]
outputrange
(
p
::
BallAndBeam
Type
)
=
[(
-
10
,
10
),(
-
1
,
1
)]
# Beam angle, Ball position
inputrange
(
p
::
BeamOrBallAndBeam
)
=
[(
-
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
::
BallAndBeam
Type
)
=
false
isasstable
(
p
::
BeamOrBallAndBeam
)
=
false
sampletime
(
p
::
BeamOrBallAndBeam
)
=
p
.
h
bias
(
p
::
BeamOrBallAndBeam
)
=
p
.
bias
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
::
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
This diff is collapsed.
Click to expand it.
src/interface_implementations/eth_helicopter.jl
+
20
−
15
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
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment