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
7144dbc5
Commit
7144dbc5
authored
Aug 29, 2017
by
Fredrik Bagge Carlson
Browse files
Implement LabConnection for ballandbeam
parent
b8b24b14
Changes
3
Hide whitespace changes
Inline
Side-by-side
REQUIRE
View file @
7144dbc5
julia 0.6
ControlSystems
Parameters
src/LabProcesses.jl
View file @
7144dbc5
...
...
@@ -7,7 +7,7 @@ end
module
LabProcesses
using
ControlSystems
,
LabConnection
.
Computer
using
ControlSystems
,
LabConnection
.
Computer
,
Parameters
include
(
"utilities.jl"
)
...
...
src/interface_implementations/ballandbeam.jl
View file @
7144dbc5
...
...
@@ -11,11 +11,13 @@
export
Beam
,
BeamSimulator
,
AbstractBeam
,
BallAndBeam
,
BallAndBeamSimulator
,
AbstractBeamOrBallAndBeam
struct
Beam
<:
PhysicalProcess
h
::
Float64
bias
::
Float64
@with_kw
struct
Beam
<:
PhysicalProcess
h
::
Float64
=
0.01
bias
::
Float64
=
0.0
stream
::
LabStream
=
ComediStream
()
measure
::
AnalogInput10V
=
AnalogInput10V
(
0
)
control
::
AnalogOutput10V
=
AnalogOutput10V
(
1
)
end
Beam
()
=
Beam
(
0.01
,
0.0
)
include
(
"define_beam_system.jl"
)
const
beam_system
,
nice_beam_controller
=
define_beam_system
()
...
...
@@ -27,24 +29,24 @@ struct BeamSimulator <: SimulatedProcess
BeamSimulator
(
h
::
Real
)
=
new
(
Float64
(
h
),
SysFilter
(
beam_system
,
h
))
end
struct
BallAndBeam
<:
PhysicalProcess
h
::
Float64
bias
::
Float64
@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
)
end
BallAndBeam
()
=
BallAndBeam
(
0.01
,
0.0
)
struct
BallAndBeamSimulator
<:
SimulatedProcess
h
::
Float64
s
::
SysFilter
end
const
AbstractBeam
=
Union
{
Beam
,
BeamSimulator
}
const
AbstractBallAndBeam
=
Union
{
BallAndBeam
,
BallAndBeamSimulator
}
const
AbstractBeamOrBallAndBeam
=
Union
{
AbstractBeam
,
AbstractBallAndBeam
}
num_outputs
(
p
::
AbstractBeam
)
=
1
num_outputs
(
p
::
AbstractBallAndBeam
)
=
2
num_inputs
(
p
::
AbstractBeamOrBallAndBeam
)
=
1
...
...
@@ -60,30 +62,21 @@ bias(p::BeamSimulator) = 0
bias
(
p
::
BallAndBeamSimulator
)
=
0
control
(
p
::
AbstractBeamOrBallAndBeam
,
u
)
=
ccall
((
:
comedi_write
,
comedipath
),
Int32
,
(
Int32
,
Int32
,
Int32
,
Int32
),
0
,
1
,
1
,
num2io
(
u
[
1
]
+
p
.
bias
))
control
(
p
::
BeamSimulator
,
u
)
=
p
.
s
(
u
)
control
(
p
::
BallAndBeamSimulator
,
u
)
=
error
(
"Not yet implemented"
)
measure
(
p
::
Beam
)
=
io2num
(
ccall
((
:
comedi_read
,
comedipath
),
Int32
,
(
Int32
,
Int32
,
Int32
),
0
,
0
,
0
))
measure
(
p
::
BallAndBeam
)
=
[
io2num
(
ccall
((
:
comedi_read
,
comedipath
),
Int32
,
(
Int32
,
Int32
,
Int32
),
0
,
0
,
i
))
for
i
=
0
:
1
]
measure
(
p
::
BeamSimulator
)
=
vecdot
(
p
.
s
.
sys
.
C
,
p
.
s
.
state
)
measure
(
p
::
BallAndBeamSimulator
)
=
error
(
"Not yet implemented"
)
control
(
p
::
AbstractBeamOrBallAndBeam
,
u
)
=
send
(
p
.
control
,
u
)
control
(
p
::
BeamSimulator
,
u
)
=
p
.
s
(
u
)
control
(
p
::
BallAndBeamSimulator
,
u
)
=
error
(
"Not yet implemented"
)
measure
(
p
::
Beam
)
=
read
(
p
.
measure
)
measure
(
p
::
BallAndBeam
)
=
[
read
(
p
.
measure1
),
read
(
p
.
measure2
)]
measure
(
p
::
BeamSimulator
)
=
vecdot
(
p
.
s
.
sys
.
C
,
p
.
s
.
state
)
measure
(
p
::
BallAndBeamSimulator
)
=
error
(
"Not yet implemented"
)
const
comedipath
=
Pkg
.
dir
(
"LabProcesses"
,
"c"
,
"comedi_bridge.so"
)
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
::
AbstractBeamOrBallAndBeam
)
=
ccall
((
:
comedi_start
,
comedipath
),
Int32
,(
Int32
,),
0
)
finalize
(
p
::
AbstractBeamOrBallAndBeam
)
=
(
control
(
p
,
0
);
ccall
((
:
comedi_stop
,
comedipath
),
Int32
,(
Int32
,),
0
))
initialize
(
p
::
BallAndBeamSimulator
)
=
nothing
finalize
(
p
::
BallAndBeamSimulator
)
=
nothing
initialize
(
p
::
BeamSimulator
)
=
p
.
s
.
state
.*=
0
finalize
(
p
::
BeamSimulator
)
=
nothing
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
::
BallAndBeamSimulator
)
=
nothing
finalize
(
p
::
BallAndBeamSimulator
)
=
nothing
initialize
(
p
::
BeamSimulator
)
=
p
.
s
.
state
.*=
0
finalize
(
p
::
BeamSimulator
)
=
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