Skip to content

Commit a48df79

Browse files
committed
All controllers autotuned
1 parent 384c09a commit a48df79

File tree

1 file changed

+41
-13
lines changed

1 file changed

+41
-13
lines changed

scripts/autotune.jl

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,25 @@ function simulate_lfc(x::Vector{Cdouble}; return_lg::Bool = false)
9898
simulate(wcs; return_lg)
9999
end
100100

101+
function simulate_ufc(x::Vector{Cdouble}; return_lg::Bool = false)
102+
wcs = WCSettings(dt=0.02)
103+
update(wcs)
104+
wcs.test = true
105+
wcs.pf_high = x[1] # set the higher force controller gain
106+
wcs.if_high = x[2] # set the higher force controller integral gain
107+
simulate(wcs; return_lg)
108+
end
109+
101110
function autotune(controller::WinchControllerState)
102111
global x, info, lg, TUNED
103112
if TUNED
104113
load_settings("system_tuned.yaml")
105114
else
106115
load_settings("system.yaml")
107116
end
108-
117+
wcs = WCSettings(dt=0.02)
118+
update(wcs)
119+
wcs.test = true
109120
if controller == wcsSpeedControl
110121
println("Autotuning speed controller...")
111122
# Define the parameters for the autotuning
@@ -127,8 +138,16 @@ function autotune(controller::WinchControllerState)
127138
rhobeg = minimum(x0)/4,
128139
maxfun = 500
129140
)
130-
elseif controller == wcsUpperForceControl
141+
elseif controller == wcsUpperForceLimit
131142
println("Autotuning upper force control...")
143+
# Define the parameters for the autotuning
144+
x0 = [wcs.pf_high, wcs.if_high] # initial guess for the speed controller gain
145+
x, info = bobyqa(simulate_lfc, x0;
146+
xl = 0.25 .* x0,
147+
xu = 2.0 .* x0,
148+
rhobeg = minimum(x0)/4,
149+
maxfun = 500
150+
)
132151
else
133152
error("Unknown controller state: $controller")
134153
return
@@ -145,7 +164,7 @@ function autotune(controller::WinchControllerState)
145164
wcs, lg = simulate_sc(x; return_lg=true)
146165
elseif controller == wcsLowerForceLimit
147166
wcs, lg = simulate_lfc(x; return_lg=true)
148-
elseif controller == wcsUpperForceControl
167+
elseif controller == wcsUpperForceLimit
149168
wcs, lg = simulate_ufc(x; return_lg=true)
150169
end
151170

@@ -173,23 +192,32 @@ function update_settings(wcs::WCSettings)
173192
lines = change_value(lines, "t_blend:", wcs.t_blend)
174193
lines = change_value(lines, "pf_low:", wcs.pf_low)
175194
lines = change_value(lines, "if_low:", wcs.if_low)
195+
lines = change_value(lines, "pf_high:", wcs.pf_high)
196+
lines = change_value(lines, "if_high:", wcs.if_high)
176197
KiteUtils.writefile(lines, "data/wc_settings_tuned.yaml")
177198
end
178199

179-
println(KiteUtils.wc_settings())
180-
wcs = autotune(wcsSpeedControl)
181-
# set = load_settings("system_tuned.yaml")
182-
if ! isnothing(wcs)
183-
copy_settings()
184-
update_settings(wcs)
185-
println()
186-
println(KiteUtils.wc_settings())
187-
wcs = autotune(wcsLowerForceLimit)
200+
function tune_all()
201+
wcs = autotune(wcsSpeedControl)
188202
if ! isnothing(wcs)
203+
copy_settings()
189204
update_settings(wcs)
205+
println()
206+
wcs = autotune(wcsLowerForceLimit)
207+
if ! isnothing(wcs)
208+
update_settings(wcs)
209+
println()
210+
wcs = autotune(wcsUpperForceLimit)
211+
if ! isnothing(wcs)
212+
update_settings(wcs)
213+
end
214+
end
215+
@info "Tuned settings saved to data/wc_settings_tuned.yaml"
190216
end
191-
@info "Tuned settings saved to data/wc_settings_tuned.yaml"
192217
end
193218

219+
tune_all()
220+
tune_all()
221+
194222

195223
# autotune(wcsUpperForceControl)

0 commit comments

Comments
 (0)