Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
BallAndBeam.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
BallAndBeam.jl
Commits
0fa5164c
Commit
0fa5164c
authored
Aug 21, 2017
by
Fredrik Bagge Carlson
Browse files
Options
Downloads
Patches
Plain Diff
Bugfixes from lab
parent
3b940c26
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
REQUIRE
+0
-1
0 additions, 1 deletion
REQUIRE
src/BallAndBeam.jl
+11
-10
11 additions, 10 deletions
src/BallAndBeam.jl
with
11 additions
and
11 deletions
REQUIRE
+
0
−
1
View file @
0fa5164c
...
@@ -5,4 +5,3 @@ Polynomials
...
@@ -5,4 +5,3 @@ Polynomials
ProgressMeter
ProgressMeter
JLD
JLD
Documenter
Documenter
LabProcesses
This diff is collapsed.
Click to expand it.
src/BallAndBeam.jl
+
11
−
10
View file @
0fa5164c
...
@@ -3,7 +3,7 @@ if "LabProcesses" ∉ keys(installed_packages)
...
@@ -3,7 +3,7 @@ if "LabProcesses" ∉ keys(installed_packages)
Pkg
.
clone
(
"https://gitlab.control.lth.se/processes/LabProcesses.jl.git"
)
Pkg
.
clone
(
"https://gitlab.control.lth.se/processes/LabProcesses.jl.git"
)
end
end
__precompile__
()
#
__precompile__()
"""
"""
This module contains a controller for the Ball and Beam. It connects to the
This module contains a controller for the Ball and Beam. It connects to the
...
@@ -26,8 +26,9 @@ using LabProcesses, Plots, Polynomials, ControlSystems, ProgressMeter
...
@@ -26,8 +26,9 @@ using LabProcesses, Plots, Polynomials, ControlSystems, ProgressMeter
Perform fra-experiemnt For a single frequency `ω`. Called from inside `fra`
Perform fra-experiemnt For a single frequency `ω`. Called from inside `fra`
"""
"""
function
run_experiment
(
P
::
BallAndBeamType
,
ω
,
duration
,
settling_time
,
amplitude
,
bias
)
function
run_experiment
(
P
::
BallAndBeamType
,
ω
,
duration
,
settling_time
,
amplitude
,
bias
)
h
=
sampletime
(
P
)
data
=
zeros
(
0
:
h
:
duration
)
data
=
zeros
(
0
:
h
:
duration
)
initialize
(
P
)
LabProcesses
.
initialize
(
P
)
for
t
=
0
:
h
:
settling_time
for
t
=
0
:
h
:
settling_time
@periodically
h
begin
@periodically
h
begin
u
=
amplitude
*
sin
(
ω
*
t
)
u
=
amplitude
*
sin
(
ω
*
t
)
...
@@ -41,16 +42,16 @@ function run_experiment(P::BallAndBeamType, ω, duration, settling_time, amplitu
...
@@ -41,16 +42,16 @@ function run_experiment(P::BallAndBeamType, ω, duration, settling_time, amplitu
control
(
P
,
u
)
control
(
P
,
u
)
end
end
end
end
finalize
(
P
)
LabProcesses
.
finalize
(
P
)
data
data
end
end
"""
"""
∫ = integrate(fun::Function, data::Vector, ω::Real)
∫ = integrate(fun::Function, data::Vector, ω::Real
,h
)
Calculate sin or cos channel, call like this `integrate(sin, data, ω)` for sin-channel
Calculate sin or cos channel, call like this `integrate(sin, data, ω
,h
)` for sin-channel
integration
integration
"""
"""
integrate
(
fun
,
data
,
ω
)
=
h
*
sum
(
fun
(
ω
*
(
i
-
1
)
*
h
)
.*
data
[
i
]
for
i
=
1
:
length
(
data
))
integrate
(
fun
,
data
,
ω
,
h
)
=
h
*
sum
(
fun
(
ω
*
(
i
-
1
)
*
h
)
.*
data
[
i
]
for
i
=
1
:
length
(
data
))
"""
"""
fra(Ω::AbstractVector; kwargs...)
fra(Ω::AbstractVector; kwargs...)
...
@@ -66,7 +67,7 @@ function fra(P::BallAndBeamType, Ω::AbstractVector;
...
@@ -66,7 +67,7 @@ function fra(P::BallAndBeamType, Ω::AbstractVector;
settling_time
=
2
,
settling_time
=
2
,
nbr_of_periods
=
10
,
nbr_of_periods
=
10
,
amplitude
=
1
)
amplitude
=
1
)
h
=
sampletime
(
P
)
G
=
zeros
(
Complex
,
size
(
Ω
))
# Transfer function
G
=
zeros
(
Complex
,
size
(
Ω
))
# Transfer function
@showprogress
1
"Running experiments"
for
(
i
,
ω
)
=
enumerate
(
Ω
)
@showprogress
1
"Running experiments"
for
(
i
,
ω
)
=
enumerate
(
Ω
)
...
@@ -74,8 +75,8 @@ function fra(P::BallAndBeamType, Ω::AbstractVector;
...
@@ -74,8 +75,8 @@ function fra(P::BallAndBeamType, Ω::AbstractVector;
settling_time_i
=
ceil
(
settling_time
/
T
)
*
T
# Settling time even number of periods
settling_time_i
=
ceil
(
settling_time
/
T
)
*
T
# Settling time even number of periods
duration
=
nbr_of_periods
*
T
duration
=
nbr_of_periods
*
T
data
=
run_experiment
(
P
,
ω
,
duration
,
settling_time_i
,
amplitude
,
bias
)
data
=
run_experiment
(
P
,
ω
,
duration
,
settling_time_i
,
amplitude
,
bias
)
sin_channel
=
integrate
(
sin
,
data
,
ω
)
sin_channel
=
integrate
(
sin
,
data
,
ω
,
h
)
cos_channel
=
integrate
(
cos
,
data
,
ω
)
cos_channel
=
integrate
(
cos
,
data
,
ω
,
h
)
G
[
i
]
=
2
/
(
amplitude
*
duration
)
*
Complex
(
sin_channel
,
cos_channel
)
G
[
i
]
=
2
/
(
amplitude
*
duration
)
*
Complex
(
sin_channel
,
cos_channel
)
end
end
Number
[
Ω
G
]
Number
[
Ω
G
]
...
@@ -92,7 +93,7 @@ end
...
@@ -92,7 +93,7 @@ end
function
bopl!
(
G
;
kwargs
...
)
function
bopl!
(
G
;
kwargs
...
)
plot!
(
G
[
:
,
1
]
.*
(
180
/
π
),
abs
.
(
G
[
:
,
2
]);
ylabel
=
"Magnitude"
,
title
=
"Bode plot"
,
xscale
=:
log10
,
yscale
=:
log10
,
subplot
=
1
,
kwargs
...
)
plot!
(
G
[
:
,
1
]
.*
(
180
/
π
),
abs
.
(
G
[
:
,
2
]);
ylabel
=
"Magnitude"
,
title
=
"Bode plot"
,
xscale
=:
log10
,
yscale
=:
log10
,
subplot
=
1
,
kwargs
...
)
plot!
(
G
[
:
,
1
]
.*
(
180
/
π
),
angle
.
(
G
[
:
,
2
]);
xlabel
=
"Frequency [1/s]"
,
ylabel
=
"Phase"
,
xscale
=:
log10
,
subplot
=
2
,
kwargs
...
)
plot!
(
G
[
:
,
1
]
.*
(
180
/
π
),
angle
.
(
G
[
:
,
2
])
.*
(
180
/
π
)
;
xlabel
=
"Frequency [1/s]"
,
ylabel
=
"Phase"
,
xscale
=:
log10
,
subplot
=
2
,
kwargs
...
)
plot!
(
link
=:
x
)
plot!
(
link
=:
x
)
end
end
...
...
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