Skip to content

Commit 614dfc6

Browse files
authored
Merge pull request #19 from OpenSourceAWE/jerk
Use different formula for damage calculation
2 parents c35f262 + 6f8efc8 commit 614dfc6

File tree

8 files changed

+107
-52
lines changed

8 files changed

+107
-52
lines changed

Project.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
88
KiteUtils = "90980105-b163-44e5-ba9f-8b1c83bb0533"
99
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1010
NLsolve = "2774e3e8-f4cf-5e23-947b-6d7e65073b56"
11-
NOMAD = "02130f1c-4665-5b79-af82-ff1385104aa0"
1211
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
1312
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
1413
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
@@ -27,7 +26,6 @@ KiteUtils = "0.10.7"
2726
LinearAlgebra = "1.10, 1.11"
2827
NLsolve = "4.5.1"
2928
NOMAD = "2.4.1"
30-
PRIMA = "0.2.2"
3129
Parameters = "0.12.3"
3230
Pkg = "1.10, 1.11"
3331
StaticArrays = "1.9.13"
@@ -41,10 +39,10 @@ julia = "1.10, 1.11"
4139

4240
[extras]
4341
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
42+
NOMAD = "02130f1c-4665-5b79-af82-ff1385104aa0"
4443
ControlPlots = "23c2ee80-7a9e-4350-b264-8e670f12517c"
4544
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
46-
PRIMA = "0a7d04aa-8ac2-47b3-b7a7-9dbd6ad661ed"
4745
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
4846

4947
[targets]
50-
test = ["Test", "ControlPlots", "Documenter", "Aqua", "PRIMA"]
48+
test = ["Test", "ControlPlots", "Documenter", "Aqua", "NOMAD"]

data/wc_settings.yaml

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
wc_settings:
2-
dt: 0.02 # time step of the winch controller
2+
dt: 0.02 # time step of the winch controller
33
test: false
4-
fac: 1.0 # factor for I and P of lower force controller
5-
max_iter: 100 # max iterations limit for the PID solvers
6-
iter: 0 # actual max iterations of the PID solvers
7-
t_startup: 0.25 # startup time for soft start
8-
t_blend: 0.1 # blending time of the mixers in seconds
9-
v_sat_error: 1.0 # limit of reel-out speed error, used by the input sat block of the speed controller
10-
v_sat: 8.0 # limit of reel-out speed, used by the output sat block of the speed controller
11-
v_ri_max: 8.0 # maximal reel-in speed [m/s]
12-
p_speed: 0.125 # P value of the speed controller
13-
i_speed: 6.0 # I value of the speed controller
14-
kb_speed: 4.0 # back calculation constant for the anti-windup loop of the speed controller
15-
kt_speed: 5.0 # tracking constant of the speed controller
16-
vf_max: 2.75 # reel-out velocity where the set force should reach it's maximum
17-
pf_low: 0.00014 # P constant of the lower force controller 0.013, 0.00014 also works
18-
if_low: 0.01125 # I constant of the lower force controller 0.0225, 0.01125 also works
4+
fac: 1.0 # factor for I and P of lower force controller
5+
max_iter: 100 # max iterations limit for the PID solvers
6+
iter: 0 # actual max iterations of the PID solvers
7+
t_startup: 0.25 # startup time for soft start
8+
t_blend: 0.1 # blending time of the mixers in seconds
9+
v_sat_error: 1.0 # limit of reel-out speed error, used by the input sat block of the speed controller
10+
v_sat: 8.0 # limit of reel-out speed, used by the output sat block of the speed controller
11+
v_ri_max: 8.0 # maximal reel-in speed [m/s]
12+
p_speed: 0.125 # P value of the speed controller
13+
i_speed: 6.0 # I value of the speed controller
14+
kb_speed: 4.0 # back calculation constant for the anti-windup loop of the speed controller
15+
kt_speed: 5.0 # tracking constant of the speed controller
16+
vf_max: 2.75 # reel-out velocity where the set force should reach it's maximum
17+
pf_low: 0.00014 # P constant of the lower force controller 0.013, 0.00014 also works
18+
if_low: 0.01125 # I constant of the lower force controller 0.0225, 0.01125 also works
1919

20-
df_low: 0.0 # D constant of lower force controller 0.000017
21-
nf_low: 0 # filter constant n of lower force controller
22-
kbf_low: 8.0 # back calculation constant for the anti-windup loop of the lower force controller
23-
ktf_low: 8.0 # tracking constant of the lower force controller
24-
f_low: 350 # lower force limit [N]
25-
f_reelin: 700 # set force for reel-in phase [N]
26-
f_high: 3800 # upper force limit [N]
27-
pf_high: 0.0002304 # P constant of upper force controller
28-
if_high: 0.012 # I constant of upper force controller
29-
df_high: 2.4e-5 # D constant of upper force controller
30-
nf_high: 15.0 # filter constant n of upper force controller
31-
kbf_high: 1.0 # back calculation constant for the anti-windup loop of the upper force controller
32-
ktf_high: 10.0 # tracking constant of the upper force controller
33-
winch_iter: 10 # iterations of the winch model
34-
max_acc: 8.0 # maximal acceleration of the winch (derivative of the set value of the reel-out speed)
35-
damage_factor: 0.4 # damage at max acceleration for jerk_factor=0
36-
jerk_factor: 0.9 # factor for the jerk (derivative of the acceleration), 0..1
37-
kv: 0.06 # proportional factor of the square root law, see function calc_vro
20+
df_low: 0.0 # D constant of lower force controller 0.000017
21+
nf_low: 0 # filter constant n of lower force controller
22+
kbf_low: 8.0 # back calculation constant for the anti-windup loop of the lower force controller
23+
ktf_low: 8.0 # tracking constant of the lower force controller
24+
f_low: 350 # lower force limit [N]
25+
f_reelin: 700 # set force for reel-in phase [N]
26+
f_high: 3800 # upper force limit [N]
27+
pf_high: 0.0002304 # P constant of upper force controller
28+
if_high: 0.012 # I constant of upper force controller
29+
df_high: 2.4e-5 # D constant of upper force controller
30+
nf_high: 15.0 # filter constant n of upper force controller
31+
kbf_high: 1.0 # back calculation constant for the anti-windup loop of the upper force controller
32+
ktf_high: 10.0 # tracking constant of the upper force controller
33+
winch_iter: 10 # iterations of the winch model
34+
max_acc: 8.0 # maximal acceleration of the winch (derivative of the set value of the reel-out speed)
35+
damage_factor: 0.05 # damage at max acceleration for jerk_factor=0
36+
jerk_factor: 0.90 # factor for the jerk (derivative of the acceleration), 0..1
37+
kv: 0.06 # proportional factor of the square root law, see function calc_vro
3838

docs/make.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ makedocs(;
2222
"Winchcontroller" => "winchcontroller.md",
2323
"Winchcontroller Settings" => "settings.md",
2424
"Performance Indicators" => "performance_indicators.md",
25+
"Autotuning" => "autotuning.md",
2526
"Tests" => "tests.md",
2627
],
2728
)

docs/src/autotuning.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
```@meta
2+
CurrentModule = WinchControllers
3+
```
4+
5+
# Autotuning
6+
7+
## Introduction
8+
The winch controller has 34 parameters (see [Winchcontroller Settings](@ref)). To determine and optimize all of them manually is time consuming and error prone, in particular if the physical system is changing. Therefore some form of automated tuning is desirable.
9+
10+
## Methodology
11+
When the [Performance Indicators](@ref) are defined, an optimizer can be used to determine the controller parameters. The controller is using three PID controllers and a mixer. The following parameters are tuned automatically:
12+
```julia
13+
wcs.i_speed # the speed controller gain
14+
wcs.p_speed # the speed controller proportional gain
15+
wcs.t_blend # the blending time for switching between controllers
16+
wcs.pf_low # the lower force controller gain
17+
wcs.if_low # the lower force controller proportional gain
18+
wcs.pf_high # the upper force controller gain
19+
wcs.if_high # the upper force controller integral gain
20+
wcs.df_high # the differential gain of the upper force controller
21+
```
22+
The global, blackbox optimizer package [NOMAD.jl](https://github.com/bbopt/NOMAD.jl) is used for the optimization process, together with a test case that mimics extreme wind conditions.
23+
With a very simple system model it allows to find an optimal solution within less than one minute.
24+
25+
## Example
26+
To run the auto-tuning script, launch Julia and execute:
27+
```julia
28+
include("scripts/autotune.jl")
29+
```
30+
It will use the initial conditions provided in the file "data/wc_settings.yaml" and save the result in "data/wc_settings_tuned.yaml".
31+
32+
All values are limited to $\hat x \le 2.5x~\land~\hat x \le x/2.5$, where $x$ is the original value and $\hat x$ the optimized value. Therefore make sure that none of the original values is zero.
33+
34+
Example output:
35+
```julia
36+
Blackbox evaluations: 897
37+
Total model evaluations: 116337
38+
Cache hits: 107
39+
Total number of evaluations: 1004
40+
Autotuning results: [14.999895, 0.125, 0.1090168, 2.24464e-5, 0.04164095, 3.83195e-5, 0.0271663, 4.0008673e-6]
41+
Running simulation with tuned parameters...
42+
43+
Performance of force controllers: 92.86 %
44+
Performance of speed controller: 93.82 %
45+
Damage with jerk: 1.19 %
46+
Combined performance γ: 92.06 %
47+
48+
[ Info: Tuned settings saved to data/wc_settings_tuned.yaml
49+
```
50+
You can plot the result with the command:
51+
```julia
52+
plot(lg)
53+
```

docs/src/performance_indicators.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,21 @@ $\bar{v} = \frac{1}{n} \sum_{i=1}^{n} \lvert v_\mathrm{set} \rvert$
2222
The reason to use the mean square error for the velocity is that in this mode of operation the error only reduces the power output. Short peak errors are usually not a problem.
2323

2424
## Damage
25-
While the performance shall be maximized, the damage shall be minimized. Here, a very simple
25+
While the performance shall be maximized, the damage shall be minimized. Here, a simple
2626
damage model is presented,
2727

28-
$\epsilon = \frac{\Delta}{a_\mathrm{max}}~{(\max |a|)^2}$,
28+
$\epsilon = \Delta~\left((1-\zeta)\left(\frac{\max |a|}{a_\mathrm{max}}\right)^2~+~\zeta \left(\frac{\mathrm{rms}(j)}{a_\mathrm{max}^2}\right)^4\right)$,
2929

30-
where $a$ is the actual acceleration, $a_{max}$ the specified, maximal acceleration and $\Delta$ the damage that occurs at $a=a_\mathrm{max}$. The default value used is $\Delta=0.2$, but in the end this value needs to be determined based on the specification of the Winch. Control-codesign can be used to determine this parameter.
30+
where $a$ is the actual acceleration, $a_{max}$ the specified, maximal acceleration, $\mathrm{rms}(j)$ the root-mean-square of the jerk, the derivative of the acceleration, $\Delta$ the damage that occurs at $a=a_\mathrm{max}$ and $\zeta$ the jerk factor. The default values used are $\Delta=0.05$ and $\zeta = 0.9$, but in the end this value needs to be determined based on the specification of the Winch. Control-codesign can be used to determine this parameter.
31+
32+
Using the forth potence of the jerk has proven to be effective in suppressing any oscillations and reducing overshoot of the controller while keeping it fast and stable.
3133

3234
## Combined performance
3335
The combined performance indicator $\gamma$ in the range of 0..1 is defined as
3436

35-
$\gamma = 1 - \frac{1}{2}(F_\mathrm{err} + v_\mathrm{err})~-~\epsilon~$,
37+
$\gamma = 1 - \frac{1}{2.5}(1.5F_\mathrm{err} + v_\mathrm{err})~-~\epsilon~$,
3638

37-
the average of the error of the speed and the force controllers minus the damage caused by the acceleration of the winch.
39+
the average of the error of the speed and the force controllers minus the damage caused by the acceleration of the winch. The force error has a slightly higher weight, because it is more critical for the controller performance.
3840

3941
## TODO
4042
- Quantify the robustness. This could be done by linearizing the system and checking gain and phase margin (for example), or by varying the model parameters (e.g. inertia of the drum) and checking if the combined performance stays above a required minimum. Possible robustness requirements:

scripts/autotune.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# this script tunes the controller parameters (well, eight of them)
22
using Pkg
3-
if ! ("ControlPlots" keys(Pkg.project().dependencies))
3+
if ! ("NOMAD" keys(Pkg.project().dependencies))
44
using TestEnv; TestEnv.activate()
55
using Test
66
end
7-
using WinchControllers, KiteUtils, PRIMA, NOMAD, ControlPlots
7+
using WinchControllers, KiteUtils, NOMAD, ControlPlots
88

9+
LF = 2.5 # limit factor
910
TUNED::Bool = false
1011
load_settings("system.yaml")
1112

@@ -116,8 +117,8 @@ function autotune(max_iter=1000)
116117
1, # number of outputs of the blackbox
117118
["OBJ"], # type of outputs of the blackbox
118119
eval_fct;
119-
lower_bound = 0.5 .* x0,
120-
upper_bound = 2.0 .* x0)
120+
lower_bound = 1/LF .* x0,
121+
upper_bound = LF .* x0)
121122
pb.options.max_bb_eval = max_iter
122123
result = solve(pb, x0)
123124
x = result.x_best_feas
@@ -140,7 +141,7 @@ function copy_settings()
140141
load_settings("system_tuned.yaml")
141142
end
142143
function change_value(lines, varname, value::Union{Integer, Float64})
143-
KiteUtils.change_value(lines, varname, repr(round(value, digits=5)))
144+
KiteUtils.change_value(lines, varname, repr(round(value, digits=6)))
144145
end
145146
function update_settings(wcs::WCSettings)
146147
lines = KiteUtils.readfile("data/wc_settings_tuned.yaml")

src/logging.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ end
166166

167167
function damage(logger::WCLogger)
168168
jerk_factor= logger.jerk_factor
169-
logger.damage_factor*((jerk_factor*(rms(logger.jerk) / logger.max_acc^2)^2 +
170-
(1-jerk_factor)*(maximum(norm.(logger.acc)))) / logger.max_acc)^2
169+
logger.damage_factor*(jerk_factor*(rms(logger.jerk) / logger.max_acc^2)^4 +
170+
(1-jerk_factor)*((maximum(norm.(logger.acc)))) / logger.max_acc)^2
171171
end
172172

173173
"""
@@ -183,5 +183,5 @@ the provided logs, stored in the `logger`. See: [Combined performance](@ref).
183183
- The gamma value associated with the log of the used test case.
184184
"""
185185
function gamma(logger::WCLogger)
186-
1 - 0.5 * (f_err(logger) + v_err(logger)) - damage(logger)
186+
1 - 1/2.5 * (1.5*f_err(logger) + v_err(logger)) - damage(logger)
187187
end

test/test_winchcontroller.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ if @isdefined __TEST__
8686
@test V_WIND[Int64(2/0.02)+1] 9.0 rtol=1e-4
8787
@test V_WIND[Int64(4/0.02)+1] 0.0 atol=1e-4
8888
@test V_WIND[Int64(6/0.02)+1] 9.0 rtol=1e-4
89-
@test mean(FORCE) 1783.2979123136008 rtol=1e-4
89+
@test mean(FORCE) 1782.9912136687296 rtol=1e-4
9090
@test maximum(FORCE) < 4295
9191
@test minimum(FORCE[10:end]) > 10.0
9292
@test STATE[Int64(0.5/dt)] == 0

0 commit comments

Comments
 (0)