Skip to content

Commit 13b60ea

Browse files
committed
First tests pass
1 parent ad46173 commit 13b60ea

File tree

9 files changed

+1008
-3
lines changed

9 files changed

+1008
-3
lines changed

Project.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ uuid = "9e74470a-8ab1-4f32-b878-f32ebd236ea2"
33
authors = ["Uwe Fechner <[email protected]> and contributors"]
44
version = "1.0.0-DEV"
55

6+
[deps]
7+
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
8+
StructTypes = "856f2bd8-1eba-4b0a-8007-ebc267875bd4"
9+
610
[compat]
11+
Parameters = "0.12.3"
12+
StructTypes = "1.11.0"
713
julia = "1.6.7"
814

915
[extras]

data/wc_settings.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
wc_settings:
2+
dt: 0.02 # time step of the winch controller
3+
test: false
4+
fac: 0.25 # 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: 4.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
19+
20+
df_low: 0.0 # D constant of upper force controller 0.000017
21+
nf_low: 0 # filter constant n of upper 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: 0.000034 # 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+
kv: 0.06 # proportional factor of the square root law, see function calc_vro
36+

src/WinchControllers.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
module WinchControllers
22

3+
using Parameters, StructTypes
4+
5+
export WCSettings
6+
37
# Write your package code here.
8+
include("utils.jl")
9+
include("wc_settings.jl")
410

511
end

src/utils.jl

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
"""
2+
A collection of control functions for discrete control
3+
4+
Functions:
5+
6+
- saturate
7+
- limit
8+
- merge_angles
9+
- moving_average
10+
11+
Implemented as described in the PhD thesis of Uwe Fechner.
12+
"""
13+
14+
""" Calculate a saturated value, that stays within the given limits. """
15+
function saturate(value, min_, max_)
16+
result = value
17+
if result > max_
18+
result = max_
19+
elseif result < min_
20+
result = min_
21+
end
22+
result
23+
end
24+
25+
"""
26+
Limit the value of a variable.
27+
28+
Usage:
29+
@limit x 1 4 # limits the value to the range 1 .. 4, modifies x
30+
@limit x 10 # limits the value to the range -inf .. 10, modifies x
31+
32+
"""
33+
macro limit(name, min, max=nothing)
34+
if isnothing(max)
35+
max = min
36+
min = :(typemin($min))
37+
end
38+
39+
return esc( :($name = clamp($name, $min, $max)) )
40+
end
41+
42+
"""
43+
merge_angles(alpha, beta, factor_beta)
44+
45+
Calculate the weighted average of two angles. The weight of beta,
46+
factor_beta must be between 0 and 1.
47+
"""
48+
function merge_angles(alpha, beta, factor_beta)
49+
x1 = sin(alpha)
50+
y1 = cos(alpha)
51+
x2 = sin(beta)
52+
y2 = cos(beta)
53+
x = x1 * (1.0 - factor_beta) + x2 * factor_beta
54+
y = y1 * (1.0 - factor_beta) + y2 * factor_beta
55+
atan(x, y)
56+
end
57+
58+
# calculate the moving average of a vector over a window
59+
function moving_average(data, window)
60+
local result
61+
if length(data) <= window
62+
result = mean(data)
63+
else
64+
result = mean(data[length(data)-window:end])
65+
end
66+
result
67+
end

0 commit comments

Comments
 (0)