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
7e6b6fa9
Commit
7e6b6fa9
authored
Dec 10, 2018
by
Fredrik Bagge Carlson
Browse files
Merge branch 'julia1' into 'master'
Julia1 See merge request
processes/LabProcesses.jl!2
parents
eac09291
9b59712d
Pipeline
#674
failed with stage
in 5 minutes and 31 seconds
Changes
8
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
7e6b6fa9
## News
2018-12-07: Update to julia v1.0 is ongoing, check branch
`julia1`
[

](https://gitlab.control.lth.se/processes/LabProcesses.jl/commits/master)
[

](https://gitlab.control.lth.se/processes/LabProcesses.jl/commits/master)
...
...
@@ -37,4 +40,4 @@ och lägga till tre rader som
När .gitlab-ci.yml uppdateras i master triggas en pipline. Om denna lyckas kommer dokumentationen finnas under
http://processes.gitlab.control.lth.se/documentation/myfoldername/
\ No newline at end of file
http://processes.gitlab.control.lth.se/documentation/myfoldername/
REQUIRE
View file @
7e6b6fa9
julia 0.
6
julia 0.
7
ControlSystems
Parameters
DSP
src/LabProcesses.jl
View file @
7e6b6fa9
# __precompile__()
using
Pkg
installed_packages
=
Pkg
.
installed
()
if
"LabConnections"
∉
keys
(
installed_packages
)
Pkg
.
clone
(
"https://gitlab.control.lth.se/cont-frb/LabConnections.jl"
)
...
...
@@ -8,7 +9,7 @@ end
module
LabProcesses
using
ControlSystems
,
LabConnections
.
Computer
,
Parameters
using
ControlSystems
,
LabConnections
.
Computer
,
Parameters
,
DSP
,
LinearAlgebra
include
(
"utilities.jl"
)
...
...
src/controllers.jl
View file @
7e6b6fa9
...
...
@@ -27,16 +27,16 @@ function run_control_2DOF(P::AbstractProcess,sysFB, sysFF=nothing; duration = 10
rf
=
sysFF
==
nothing
?
r
[
:
,
i
]
:
Gff
(
r
[
:
,
i
])
e
=
rf
-
y
[
:
,
i
]
ui
=
Gfb
(
e
)
ui
+
bias
(
P
)
ui
.
+
bias
(
P
)
end
simulation
=
isa
(
P
,
SimulatedProcess
)
initialize
(
P
)
for
(
i
,
t
)
=
enumerate
(
0
:
h
:
duration
)
@periodically
h
simulation
begin
y
[
:
,
i
]
=
measure
(
P
)
r
[
:
,
i
]
=
reference
(
t
)
u
[
:
,
i
]
=
calc_control
(
i
)
# y,r must be updated before u
y
[
:
,
i
]
.
=
measure
(
P
)
r
[
:
,
i
]
.
=
reference
(
t
)
u
[
:
,
i
]
.
=
calc_control
(
i
)
# y,r must be updated before u
control
(
P
,
[
clamp
.
(
u
[
j
,
i
],
inputrange
(
P
)[
j
]
...
)
for
j
=
1
:
nu
])
end
end
...
...
src/interface_implementations/ballandbeam.jl
View file @
7e6b6fa9
...
...
@@ -48,7 +48,7 @@ const beam_system, nice_beam_controller = define_beam_system()
struct
BeamSimulator
<:
SimulatedProcess
h
::
Float64
s
::
SysFilter
BeamSimulator
(;
h
::
Real
=
0.01
)
=
new
(
Float64
(
h
),
SysFilter
(
beam_system
,
h
))
BeamSimulator
(;
h
::
Real
=
0.01
,
bias
=
0
)
=
new
(
Float64
(
h
),
SysFilter
(
beam_system
,
h
))
end
struct
BallAndBeam
<:
PhysicalProcess
...
...
@@ -96,7 +96,7 @@ bias(p::BallAndBeamSimulator) = 0
function
control
(
p
::
AbstractBeamOrBallAndBeam
,
u
::
AbstractArray
)
length
(
u
)
==
1
||
error
(
"Process
$
(typeof(p)) only accepts one control signal, tried to send u=
$
u."
)
send
(
p
.
control
,
u
[
1
])
control
(
p
,
u
[
1
])
end
control
(
p
::
AbstractBeamOrBallAndBeam
,
u
::
Number
)
=
send
(
p
.
control
,
u
)
control
(
p
::
BeamSimulator
,
u
::
Number
)
=
p
.
s
(
u
)
...
...
@@ -104,7 +104,7 @@ control(p::BallAndBeamSimulator, u::Number) = error("Not yet implemented")
measure
(
p
::
Beam
)
=
read
(
p
.
measure
)
measure
(
p
::
BallAndBeam
)
=
[
read
(
p
.
measure1
),
read
(
p
.
measure2
)]
measure
(
p
::
BeamSimulator
)
=
vec
dot
(
p
.
s
.
sys
.
C
,
p
.
s
.
state
)
measure
(
p
::
BeamSimulator
)
=
dot
(
p
.
s
.
sys
.
C
,
p
.
s
.
state
)
measure
(
p
::
BallAndBeamSimulator
)
=
error
(
"Not yet implemented"
)
...
...
src/interface_implementations/define_beam_system.jl
View file @
7e6b6fa9
using
ControlSystems
using
ControlSystems
,
DSP
"""
beammodel, beamcontroller = define_beam_system(;doplot=false)
...
...
src/utilities.jl
View file @
7e6b6fa9
...
...
@@ -9,7 +9,7 @@ macro periodically(h, body)
local
start_time
=
time
()
$
(
esc
(
body
))
local
execution_time
=
time
()
-
start_time
sleep
(
max
(
0
,
$
(
esc
(
h
))
-
execution_time
))
Libc
.
system
sleep
(
max
(
0
,
$
(
esc
(
h
))
-
execution_time
))
end
end
...
...
@@ -37,22 +37,22 @@ Create a SysFilter object that can be used to implement control loops and simula
with LTI systems, i.e., `U(z) = C(z)E(z)`. To filter a signal `u` through the filter,
call like `y = Csf(u)`. Calculates the filtered output `y` in `y = Cx+Du, x'=Ax+Bu`
"""
struct
SysFilter
sys
::
StateSpace
struct
SysFilter
{
T
<:
StateSpace
}
sys
::
T
state
::
Vector
{
Float64
}
function
SysFilter
(
sys
::
StateSpace
,
state
::
AbstractVector
)
@assert
!
ControlSystems
.
iscontinuous
(
sys
)
"Can not filter using continuous time model."
@assert
length
(
state
)
==
sys
.
nx
"length(state) != sys.nx"
new
(
sys
,
state
)
new
{
typeof
(
sys
)}
(
sys
,
state
)
end
function
SysFilter
(
sys
::
StateSpace
)
@assert
!
ControlSystems
.
iscontinuous
(
sys
)
"Can not filter using continuous time model. Supply sample time."
new
(
sys
,
init_sysfilter
(
sys
))
new
{
typeof
(
sys
)}
(
sys
,
init_sysfilter
(
sys
))
end
function
SysFilter
(
sys
::
StateSpace
,
h
::
Real
)
@assert
ControlSystems
.
iscontinuous
(
sys
)
"Sample time supplied byt system model is already in discrete time."
sysd
=
c2d
(
sys
,
h
)[
1
]
new
(
sysd
,
init_sysfilter
(
sysd
))
new
{
typeof
(
sysd
)}
(
sysd
,
init_sysfilter
(
sysd
))
end
end
(
s
::
SysFilter
)(
input
)
=
sysfilter!
(
s
.
state
,
s
.
sys
,
input
)
...
...
test/runtests.jl
View file @
7e6b6fa9
using
LabProcesses
,
ControlSystems
using
Base
.
Test
using
LabProcesses
,
ControlSystems
,
DSP
using
Test
# Reference generators
r
=
PRBSGenerator
(
Int
(
4
))
...
...
@@ -8,14 +8,14 @@ seq = [r() for i = 1:10]
foreach
(
r
,
1
:
10_000
)
function
test_sysfilter
()
N
=
10
u
=
randn
(
N
)
b
=
[
1
,
1
]
a
=
[
1
,
0.1
,
1
]
sys
=
ss
(
tf
(
b
,
a
,
1
))
N
=
10
u
=
randn
(
N
)
b
=
[
1
,
1
]
a
=
[
1
,
0.1
,
1
]
sys
=
ss
(
tf
(
b
,
a
,
1
))
state
=
init_sysfilter
(
sys
)
yf
=
filt
(
b
,
a
,
u
)
yff
=
similar
(
yf
)
yf
=
filt
(
b
,
a
,
u
)
yff
=
similar
(
yf
)
for
i
in
eachindex
(
u
)
yff
[
i
]
=
sysfilter!
(
state
,
sys
,
u
[
i
])[
1
]
end
...
...
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