Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
DoubleTankLab.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
processes
DoubleTankLab.jl
Commits
72a68d99
Commit
72a68d99
authored
Apr 7, 2020
by
Albin Heimerson
Browse files
Options
Downloads
Patches
Plain Diff
add more buttons
parent
9a0eb3d4
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/doubletank.jl
+9
-5
9 additions, 5 deletions
src/doubletank.jl
src/tankdemo.jl
+4
-2
4 additions, 2 deletions
src/tankdemo.jl
src/tankgraphic.jl
+4
-2
4 additions, 2 deletions
src/tankgraphic.jl
src/tanklabgui.jl
+28
-13
28 additions, 13 deletions
src/tanklabgui.jl
with
45 additions
and
22 deletions
src/doubletank.jl
+
9
−
5
View file @
72a68d99
...
@@ -31,8 +31,10 @@ function (p::PID)(r, y, onv=(1,1,1))
...
@@ -31,8 +31,10 @@ function (p::PID)(r, y, onv=(1,1,1))
bd
=
N
*
K
*
Td
/
(
N
*
h
+
Td
)
bd
=
N
*
K
*
Td
/
(
N
*
h
+
Td
)
Tot
=
0.0
Tot
=
0.0
P
=
K
*
(
b
*
r
-
y
)
P
=
0
D
=
0
if
onv
[
1
]
==
1
if
onv
[
1
]
==
1
P
=
K
*
(
b
*
r
-
y
)
Tot
+=
P
Tot
+=
P
end
end
if
onv
[
3
]
==
1
if
onv
[
3
]
==
1
...
@@ -46,6 +48,8 @@ function (p::PID)(r, y, onv=(1,1,1))
...
@@ -46,6 +48,8 @@ function (p::PID)(r, y, onv=(1,1,1))
I
+=
Ichange
I
+=
Ichange
end
end
Tot
+=
I
Tot
+=
I
else
I
=
0
end
end
y_old
=
y
y_old
=
y
@pack
!
p
=
P
,
I
,
D
,
Tot
,
y_old
@pack
!
p
=
P
,
I
,
D
,
Tot
,
y_old
...
@@ -77,14 +81,14 @@ function qu(p, u)
...
@@ -77,14 +81,14 @@ function qu(p, u)
u
*
p
.
α
u
*
p
.
α
end
end
function
control
(
p
::
DoubleTankSimulator
,
u
::
Number
)
function
control
(
p
::
DoubleTankSimulator
,
u
::
Number
,
load
::
Number
,
flow
::
Bool
)
@unpack
a1
,
a2
,
g
,
x
,
A
,
h
,
scale
=
p
@unpack
a1
,
a2
,
g
,
x
,
A
,
h
,
scale
=
p
x
*=
scale
x
*=
scale
#The simulator should operate on physical values but u should be in [0,1]
#The simulator should operate on physical values but u should be in [0,1]
u
=
clamp
(
u
,
inputrange
(
p
)[
1
]
...
)
u
=
clamp
(
u
,
inputrange
(
p
)[
1
]
...
)
+
load
qut
=
a1
*
sqrt
(
2
*
g
*
x
[
1
])
#m^3/s
qut
=
flow
?
a1
*
sqrt
(
2
*
g
*
x
[
1
])
:
0
#m^3/s
dA1
=
qu
(
p
,
u
)
-
qut
#m^3/s
dA1
=
qu
(
p
,
u
)
-
qut
#m^3/s
if
-
dA1
*
h
>
x
[
1
]
*
A
if
-
dA1
*
h
>
x
[
1
]
*
A
...
@@ -95,7 +99,7 @@ function control(p::DoubleTankSimulator, u::Number)
...
@@ -95,7 +99,7 @@ function control(p::DoubleTankSimulator, u::Number)
end
end
dA2
=
qut
-
a2
*
sqrt
(
2
*
g
*
x
[
2
])
#m^3/s
dA2
=
qut
-
a2
*
sqrt
(
2
*
g
*
x
[
2
])
#m^3/s
if
(
-
dA2
*
h
>
x
[
2
]
*
A
)
if
-
dA2
*
h
>
x
[
2
]
*
A
dA2
=
-
x
[
2
]
*
A
/
h
dA2
=
-
x
[
2
]
*
A
/
h
end
end
x
[
1
]
+=
(
dA1
*
h
)
/
A
x
[
1
]
+=
(
dA1
*
h
)
/
A
...
...
This diff is collapsed.
Click to expand it.
src/tankdemo.jl
+
4
−
2
View file @
72a68d99
...
@@ -24,12 +24,14 @@ function runsimulation(;simulated=true, webservice=true, port=8000, σ = 0.001,
...
@@ -24,12 +24,14 @@ function runsimulation(;simulated=true, webservice=true, port=8000, σ = 0.001,
n
=
2
n
=
2
end
end
onv
=
Int
.
([
gui
[
s
]
==
"On"
for
s
in
[
:
pOn
,
:
iOn
,
:
dOn
]])
onv
=
Int
.
([
gui
[
s
]
==
"On"
for
s
in
[
:
pOn
,
:
iOn
,
:
dOn
]])
load
=
gui
[
:
load
]
==
"Upper"
?
0.1
:
0
flow
=
gui
[
:
flow
]
==
"None"
rv
=
pidcontroller
(
r
,
y
,
onv
)
rv
=
pidcontroller
(
r
,
y
,
onv
)
if
gui
[
:
mode
]
==
"Automatic"
if
gui
[
:
mode
]
==
"Automatic"
gui
[
:
u
]
=
clamp
(
round
(
rv
,
digits
=
2
),
0
,
1
)
#u's constructor has only a dummy graphic so this is fine
gui
[
:
u
]
=
clamp
(
round
(
rv
,
digits
=
2
),
0
,
1
)
#u's constructor has only a dummy graphic so this is fine
control
(
P
,
rv
)
control
(
P
,
rv
,
load
,
flow
)
elseif
gui
[
:
mode
]
==
"Manual"
elseif
gui
[
:
mode
]
==
"Manual"
control
(
P
,
gui
[
:
u
])
control
(
P
,
gui
[
:
u
]
,
load
,
flow
)
#bumpless transfer:
#bumpless transfer:
if
gui
[
:
iOn
]
==
"On"
if
gui
[
:
iOn
]
==
"On"
pidcontroller
.
I
=
gui
[
:
u
]
-
(
pidcontroller
.
Tot
-
pidcontroller
.
I
)
pidcontroller
.
I
=
gui
[
:
u
]
-
(
pidcontroller
.
Tot
-
pidcontroller
.
I
)
...
...
This diff is collapsed.
Click to expand it.
src/tankgraphic.jl
+
4
−
2
View file @
72a68d99
...
@@ -54,7 +54,7 @@ function water_container(width, height, fill, x=0, y=0)
...
@@ -54,7 +54,7 @@ function water_container(width, height, fill, x=0, y=0)
end
end
function
tank_construct
(
upper
,
lower
,
pump_speed
=
1
,
tnum
=
0
,
r
=
-
1
)
function
tank_construct
(
upper
,
lower
,
pump_speed
=
1
,
tnum
=
0
,
r
=
-
1
,
load
=
0
,
blocked
=
false
)
height
=
250
height
=
250
width
=
200
width
=
200
...
@@ -86,8 +86,9 @@ function tank_construct(upper, lower, pump_speed = 1, tnum = 0, r = -1)
...
@@ -86,8 +86,9 @@ function tank_construct(upper, lower, pump_speed = 1, tnum = 0, r = -1)
w1
=
mouth_width
*
sqrt
(
max
(
0
,
pump_speed
))
w1
=
mouth_width
*
sqrt
(
max
(
0
,
pump_speed
))
w2
=
mouth_width
*
sqrt
(
max
(
0
,
upper
))
w2
=
blocked
?
0
:
mouth_width
*
sqrt
(
max
(
0
,
upper
))
w3
=
mouth_width
*
sqrt
(
max
(
0
,
lower
))
w3
=
mouth_width
*
sqrt
(
max
(
0
,
lower
))
w4
=
mouth_width
*
sqrt
(
max
(
0
,
load
))
container1
=
water_container
(
width
,
height
,
upper
,
upper_x
,
upper_y
)
container1
=
water_container
(
width
,
height
,
upper
,
upper_x
,
upper_y
)
container2
=
water_container
(
width
,
height
,
lower
,
lower_x
,
lower_y
)
container2
=
water_container
(
width
,
height
,
lower
,
lower_x
,
lower_y
)
...
@@ -98,6 +99,7 @@ function tank_construct(upper, lower, pump_speed = 1, tnum = 0, r = -1)
...
@@ -98,6 +99,7 @@ function tank_construct(upper, lower, pump_speed = 1, tnum = 0, r = -1)
stream
(
w1
,
height
+
50
,
upper_x
+
(
width
-
w1
)
/
2
,
50
)
...
,
stream
(
w1
,
height
+
50
,
upper_x
+
(
width
-
w1
)
/
2
,
50
)
...
,
stream
(
w2
,
height
+
50
,
upper_x
+
(
width
-
w2
)
/
2
,
height
+
100
)
...
,
stream
(
w2
,
height
+
50
,
upper_x
+
(
width
-
w2
)
/
2
,
height
+
100
)
...
,
stream
(
w3
,
100
,
upper_x
+
(
width
-
w3
)
/
2
,
2
*
height
+
150
)
...
,
stream
(
w3
,
100
,
upper_x
+
(
width
-
w3
)
/
2
,
2
*
height
+
150
)
...
,
stream
(
w4
,
height
,
upper_x
,
100
)
...
,
container1
,
container2
,
redarrow
,
container1
,
container2
,
redarrow
,
svg_rect
(
tank_width
,
tank_height
,
tank_x
,
tank_y
),
svg_rect
(
tank_width
,
tank_height
,
tank_x
,
tank_y
),
pipe
,
pipe
,
...
...
This diff is collapsed.
Click to expand it.
src/tanklabgui.jl
+
28
−
13
View file @
72a68d99
...
@@ -10,6 +10,7 @@ function makegui(P, run_process, plottingframerate = 10, guiframerate = 10)
...
@@ -10,6 +10,7 @@ function makegui(P, run_process, plottingframerate = 10, guiframerate = 10)
maxplotlength
=
800
maxplotlength
=
800
gui
=
GUI
()
gui
=
GUI
()
ptfr
=
3.8
#pump to flow ratio, approximate
ptfr
=
3.8
#pump to flow ratio, approximate
plotfreeze
=
-
1
"""
"""
...
@@ -35,6 +36,9 @@ function makegui(P, run_process, plottingframerate = 10, guiframerate = 10)
...
@@ -35,6 +36,9 @@ function makegui(P, run_process, plottingframerate = 10, guiframerate = 10)
pOn
in
togglebuttons
([
"On"
,
"Off"
],
label
=
"P"
),
pOn
in
togglebuttons
([
"On"
,
"Off"
],
label
=
"P"
),
iOn
in
togglebuttons
([
"On"
,
"Off"
],
label
=
"I"
),
iOn
in
togglebuttons
([
"On"
,
"Off"
],
label
=
"I"
),
dOn
in
togglebuttons
([
"On"
,
"Off"
],
label
=
"D"
),
dOn
in
togglebuttons
([
"On"
,
"Off"
],
label
=
"D"
),
load
in
togglebuttons
([
"None"
,
"Upper"
],
label
=
"load disturbance"
),
flow
in
togglebuttons
([
"None"
,
"Upper"
],
label
=
"stop outflow "
),
freeze
in
togglebuttons
([
"On"
,
"Freeze"
],
label
=
"plots "
),
#expcsv in button("Export Data"),
#expcsv in button("Export Data"),
rbox
in
textbox
(
"0.5"
,
label
=
"r"
)
rbox
in
textbox
(
"0.5"
,
label
=
"r"
)
...
@@ -48,7 +52,7 @@ function makegui(P, run_process, plottingframerate = 10, guiframerate = 10)
...
@@ -48,7 +52,7 @@ function makegui(P, run_process, plottingframerate = 10, guiframerate = 10)
rv
=
parse
(
Float64
,
rbox
)
rv
=
parse
(
Float64
,
rbox
)
catch
catch
end
end
if
0.0
<
rv
<
1.0
if
0.0
<
=
rv
<
=
1.0
observe
(
r
)
.
val
=
rv
observe
(
r
)
.
val
=
rv
end
end
end
end
...
@@ -60,11 +64,11 @@ function makegui(P, run_process, plottingframerate = 10, guiframerate = 10)
...
@@ -60,11 +64,11 @@ function makegui(P, run_process, plottingframerate = 10, guiframerate = 10)
if
observe
(
tankno
)[]
==
"Upper"
if
observe
(
tankno
)[]
==
"Upper"
tankg
=
tank_construct
(
measure
(
P
)
...
,
observe
(
u
)[]
*
ptfr
,
1
,
observe
(
r
)
.
val
)
tankg
=
tank_construct
(
measure
(
P
)
...
,
observe
(
u
)[]
*
ptfr
,
1
,
observe
(
r
)
.
val
,
observe
(
load
)[]
==
"Upper"
?
0.1
*
ptfr
:
0
,
observe
(
flow
)[]
==
"Upper"
)
elseif
observe
(
tankno
)[]
==
"Lower"
elseif
observe
(
tankno
)[]
==
"Lower"
tankg
=
tank_construct
(
measure
(
P
)
...
,
observe
(
u
)[]
*
ptfr
,
2
,
observe
(
r
)
.
val
)
tankg
=
tank_construct
(
measure
(
P
)
...
,
observe
(
u
)[]
*
ptfr
,
2
,
observe
(
r
)
.
val
,
else
observe
(
load
)[]
==
"Upper"
?
0.1
*
ptfr
:
0
,
observe
(
flow
)[]
==
"Upper"
)
tankg
=
tank_construct
(
measure
(
P
)
...
,
observe
(
u
)[]
*
ptfr
)
end
end
Node
(
:
div
,
tankg
,
id
=
"tanks"
,
attributes
=
tankattr
)
Node
(
:
div
,
tankg
,
id
=
"tanks"
,
attributes
=
tankattr
)
end
end
...
@@ -73,7 +77,7 @@ function makegui(P, run_process, plottingframerate = 10, guiframerate = 10)
...
@@ -73,7 +77,7 @@ function makegui(P, run_process, plottingframerate = 10, guiframerate = 10)
w2
,
graphic2
=
@construct
for
w2
,
graphic2
=
@construct
for
plotdummy
in
checkbox
(
false
,
label
=
"This button does nothing"
)
plotdummy
in
checkbox
(
false
,
label
=
"This button does nothing"
)
dataln
=
length
(
gui
.
data
[
1
])
dataln
=
plotfreeze
==
-
1
?
length
(
gui
.
data
[
1
])
:
plotfreeze
if
dataln
>
maxplotlength
if
dataln
>
maxplotlength
start
=
dataln
-
maxplotlength
start
=
dataln
-
maxplotlength
else
else
...
@@ -81,12 +85,12 @@ function makegui(P, run_process, plottingframerate = 10, guiframerate = 10)
...
@@ -81,12 +85,12 @@ function makegui(P, run_process, plottingframerate = 10, guiframerate = 10)
end
end
lnv
=
glnv
[
1
:
min
(
dataln
,
maxplotlength
+
1
)]
lnv
=
glnv
[
1
:
min
(
dataln
,
maxplotlength
+
1
)]
p
=
plot
(
layout
=
(
2
,
1
),
size
=
(
700
,
600
),
xlabel
=
"seconds"
)
p
=
plot
(
layout
=
(
2
,
1
),
size
=
(
700
,
600
),
xlabel
=
"seconds"
)
plot!
(
p
[
1
],
lnv
,
gui
.
data
[
1
][
start
:
end
],
label
=
"y"
,
ylim
=
boundsupper
)
plot!
(
p
[
1
],
lnv
,
gui
.
data
[
1
][
start
:
dataln
],
label
=
"y"
,
ylim
=
boundsupper
)
plot!
(
p
[
1
],
lnv
,
gui
.
data
[
2
][
start
:
end
],
label
=
"r"
)
plot!
(
p
[
1
],
lnv
,
gui
.
data
[
2
][
start
:
dataln
],
label
=
"r"
)
plot!
(
p
[
2
],
lnv
,
gui
.
data
[
3
][
start
:
end
],
label
=
"P"
,
ylim
=
boundslower
)
plot!
(
p
[
2
],
lnv
,
gui
.
data
[
3
][
start
:
dataln
],
label
=
"P"
,
ylim
=
boundslower
)
plot!
(
p
[
2
],
lnv
,
gui
.
data
[
4
][
start
:
end
],
label
=
"I"
)
plot!
(
p
[
2
],
lnv
,
gui
.
data
[
4
][
start
:
dataln
],
label
=
"I"
)
plot!
(
p
[
2
],
lnv
,
gui
.
data
[
5
][
start
:
end
],
label
=
"D"
)
plot!
(
p
[
2
],
lnv
,
gui
.
data
[
5
][
start
:
dataln
],
label
=
"D"
)
plot!
(
p
[
2
],
lnv
,
gui
.
data
[
6
][
start
:
end
],
label
=
"Tot"
,
color
=:
black
)
plot!
(
p
[
2
],
lnv
,
gui
.
data
[
6
][
start
:
dataln
],
label
=
"Tot"
,
color
=:
black
)
end
end
@async
run_process
(
P
,
gui
,
tankpid
)
@async
run_process
(
P
,
gui
,
tankpid
)
...
@@ -97,6 +101,14 @@ function makegui(P, run_process, plottingframerate = 10, guiframerate = 10)
...
@@ -97,6 +101,14 @@ function makegui(P, run_process, plottingframerate = 10, guiframerate = 10)
end
end
end
end
on
(
observe
(
freeze
))
do
val
if
val
==
"On"
plotfreeze
=
-
1
else
plotfreeze
=
length
(
gui
.
data
[
1
])
end
end
on
(
observe
(
iOn
))
do
val
on
(
observe
(
iOn
))
do
val
if
val
==
"Off"
if
val
==
"Off"
tankpid
.
I
=
0
tankpid
.
I
=
0
...
@@ -110,7 +122,7 @@ function makegui(P, run_process, plottingframerate = 10, guiframerate = 10)
...
@@ -110,7 +122,7 @@ function makegui(P, run_process, plottingframerate = 10, guiframerate = 10)
add!
(
gui
,
w2
)
add!
(
gui
,
w2
)
layout
=
make_grid
([
100
],
[
50
,
25
,
25
])
layout
=
make_grid
([
100
],
[
50
,
25
,
25
])
settings_element
=
make_grid
(
7
,
1
)
settings_element
=
make_grid
(
10
,
1
)
p_element
=
make_grid
(
2
,
1
)
p_element
=
make_grid
(
2
,
1
)
p_element
=
setindex_
(
p_element
,
dom
"div[display=inline-block]"
(
gui
.
widgets
[
:
pOn
]),
1
,
1
)
p_element
=
setindex_
(
p_element
,
dom
"div[display=inline-block]"
(
gui
.
widgets
[
:
pOn
]),
1
,
1
)
...
@@ -131,6 +143,9 @@ function makegui(P, run_process, plottingframerate = 10, guiframerate = 10)
...
@@ -131,6 +143,9 @@ function makegui(P, run_process, plottingframerate = 10, guiframerate = 10)
settings_element
=
setindex_
(
settings_element
,
p_element
,
5
,
1
)
settings_element
=
setindex_
(
settings_element
,
p_element
,
5
,
1
)
settings_element
=
setindex_
(
settings_element
,
i_element
,
6
,
1
)
settings_element
=
setindex_
(
settings_element
,
i_element
,
6
,
1
)
settings_element
=
setindex_
(
settings_element
,
d_element
,
7
,
1
)
settings_element
=
setindex_
(
settings_element
,
d_element
,
7
,
1
)
settings_element
=
setindex_
(
settings_element
,
dom
"div"
(
gui
.
widgets
[
:
load
]),
8
,
1
)
settings_element
=
setindex_
(
settings_element
,
dom
"div"
(
gui
.
widgets
[
:
flow
]),
9
,
1
)
settings_element
=
setindex_
(
settings_element
,
dom
"div"
(
gui
.
widgets
[
:
freeze
]),
10
,
1
)
layout
=
setindex_
(
layout
,
graphic2
,
1
,
1
)
layout
=
setindex_
(
layout
,
graphic2
,
1
,
1
)
layout
=
setindex_
(
layout
,
Node
(
:
div
,
graphic1
,
dummygraphic1
,
dummygraphic2
,
layout
=
setindex_
(
layout
,
Node
(
:
div
,
graphic1
,
dummygraphic1
,
dummygraphic2
,
...
...
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