Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
7c8f218
use dierkcx instead of datainterpolations
1-Bart-1 Sep 5, 2024
e62eb66
pass motor to calc acc
1-Bart-1 Sep 5, 2024
035974c
getting there
1-Bart-1 Sep 9, 2024
56ff28b
add xfoil
1-Bart-1 Sep 9, 2024
89e8f91
add model formulas
1-Bart-1 Sep 10, 2024
36640de
make scripts
1-Bart-1 Sep 10, 2024
059d058
working model at around 1 times realtime
1-Bart-1 Sep 11, 2024
24959fa
looks pretty good
1-Bart-1 Sep 11, 2024
8214316
oscillations because of no perpendicular damping
1-Bart-1 Sep 11, 2024
813cc90
better creation and loading of polars
1-Bart-1 Sep 12, 2024
10fc45a
works but oscillates
1-Bart-1 Sep 13, 2024
7952ec2
working speed control
1-Bart-1 Sep 13, 2024
91ee3b0
small fix
1-Bart-1 Sep 13, 2024
4fc799d
working example
1-Bart-1 Sep 13, 2024
d4e8471
proper init
1-Bart-1 Sep 13, 2024
afa0fe2
works for shorter lines as well
1-Bart-1 Sep 14, 2024
d2514c3
working stable state
1-Bart-1 Sep 14, 2024
ba4eeff
fast and works well
1-Bart-1 Sep 15, 2024
0ab6e74
fix project toml
1-Bart-1 Sep 15, 2024
4cd93e7
add better flap damping
1-Bart-1 Sep 16, 2024
5b7b8dd
fixed wrong ram force
1-Bart-1 Sep 16, 2024
dd20d62
improve ram pressure
1-Bart-1 Sep 16, 2024
ce4167e
faster init
1-Bart-1 Sep 17, 2024
20fb5f9
add default foil shape file
1-Bart-1 Sep 17, 2024
729c6f8
faster solver
1-Bart-1 Sep 17, 2024
62fa0bb
add error handling
1-Bart-1 Sep 17, 2024
250a14a
add assertion
1-Bart-1 Sep 18, 2024
e22e58a
better polars
1-Bart-1 Sep 19, 2024
9b01534
Merge branch 'main' into feat/xfoil-polars
ufechner7 Sep 19, 2024
cb1019c
remove DataInterpolations
ufechner7 Sep 19, 2024
9c031d1
fix drag, oscillation and heading direction
1-Bart-1 Sep 21, 2024
6eade90
Merge branch 'feat/xfoil-polars' of https://github.com/ufechner7/Kite…
1-Bart-1 Sep 21, 2024
4436553
add gravity to flaps
1-Bart-1 Sep 21, 2024
7d8c952
no stabilizing
1-Bart-1 Sep 21, 2024
b671f18
solve overdetermined system
1-Bart-1 Sep 21, 2024
2e74d77
fix tests
1-Bart-1 Sep 23, 2024
fe8b89c
use float32
1-Bart-1 Sep 23, 2024
ce21966
fix precompile and remove dtmin
1-Bart-1 Sep 23, 2024
a2840ad
use succes function
1-Bart-1 Sep 24, 2024
05bff43
don't use reinit
1-Bart-1 Sep 24, 2024
b3b63ad
make model! usable from outside package
1-Bart-1 Sep 25, 2024
9e01a60
set s.torque_control in init
1-Bart-1 Sep 25, 2024
9b8d1f1
add set_values to variables
1-Bart-1 Sep 25, 2024
9d7c040
temp remove modelingtoolkit version
1-Bart-1 Sep 26, 2024
a270b81
update mtk to latest
1-Bart-1 Sep 26, 2024
26a20f1
remove mtk version requirements
1-Bart-1 Sep 29, 2024
ac4b8fe
Merge branch 'main' into feat/xfoil-polars
1-Bart-1 Sep 29, 2024
30698d1
remove datainterp
1-Bart-1 Sep 29, 2024
62b8b99
fix 2 segment model
1-Bart-1 Sep 30, 2024
a7e67e8
rm true statement
1-Bart-1 Sep 30, 2024
711004e
change to bin and interpolations.jl
1-Bart-1 Oct 1, 2024
39a855d
fixed tests
1-Bart-1 Oct 2, 2024
ab79cc0
use smooth sign
1-Bart-1 Oct 3, 2024
8a6c6d8
fix rad deg mistake
1-Bart-1 Oct 3, 2024
3271d29
fix annoying test
1-Bart-1 Oct 3, 2024
931b527
positive height
1-Bart-1 Oct 3, 2024
a558918
add bin and dat file
1-Bart-1 Oct 4, 2024
dbac4c6
fix test data path
1-Bart-1 Oct 4, 2024
b9ca7ab
add quadratic spline for forwarddiff
1-Bart-1 Oct 6, 2024
26515ab
less smooth sign and safe asin
1-Bart-1 Oct 7, 2024
8643fd2
Merge branch 'main' into fix/improve-for-mpc
1-Bart-1 Oct 14, 2024
c7394c6
removing unnecessary derivatives makes solving faster
1-Bart-1 Oct 14, 2024
42176b6
add normalized winch force
1-Bart-1 Oct 14, 2024
eeaa1c0
fix echo
1-Bart-1 Oct 15, 2024
496199a
update packages
1-Bart-1 Oct 15, 2024
0dbf415
Merge branch 'main' into fix/improve-for-mpc
1-Bart-1 Oct 15, 2024
03abfa9
Merge branch 'main' into fix/improve-for-mpc
1-Bart-1 Oct 15, 2024
88cb174
tests pass without brakes
1-Bart-1 Oct 16, 2024
763e695
add heading to model
1-Bart-1 Oct 16, 2024
68b2f52
fix tests
1-Bart-1 Oct 16, 2024
7e53293
remove a lot of state updates
1-Bart-1 Oct 16, 2024
6a846ff
tests pass
1-Bart-1 Oct 16, 2024
9cffca8
fix example and add y heading
1-Bart-1 Oct 19, 2024
481d7b5
add initial set values
1-Bart-1 Oct 20, 2024
9a30da4
fix init values and add depower var
1-Bart-1 Oct 21, 2024
4b4a297
1 sec damping
1-Bart-1 Oct 21, 2024
f377ee6
reset to correct time
1-Bart-1 Oct 21, 2024
4095c9d
dont override wm function
1-Bart-1 Oct 24, 2024
7f46474
add adjustable smooth sign
1-Bart-1 Oct 24, 2024
923dc7a
remove if-statements
1-Bart-1 Oct 24, 2024
6246a80
remove last if statements
1-Bart-1 Oct 24, 2024
0f71634
add heading derivative
1-Bart-1 Oct 26, 2024
05b84db
less damping on flaps
1-Bart-1 Oct 27, 2024
c27e694
add depower vel
1-Bart-1 Oct 29, 2024
2f53825
fix winch force
1-Bart-1 Oct 30, 2024
7aa433b
add flap damping
1-Bart-1 Oct 30, 2024
002b145
removed gravity bug
1-Bart-1 Oct 31, 2024
89f3625
find good ratios
1-Bart-1 Oct 31, 2024
d772fc9
fix small example bug
1-Bart-1 Oct 31, 2024
3e3ff80
add linear example
1-Bart-1 Nov 1, 2024
37f8b85
remove linear example
1-Bart-1 Nov 1, 2024
6676ea7
add set diff
1-Bart-1 Nov 1, 2024
a9273ee
correct name
1-Bart-1 Nov 4, 2024
a4ab6ff
add power vel
1-Bart-1 Nov 4, 2024
98400cd
better naming
1-Bart-1 Nov 4, 2024
8e67f85
update mtk
1-Bart-1 Nov 5, 2024
36567a9
fix if statement
1-Bart-1 Nov 12, 2024
4868877
Merge branch 'main' into fix/improve-for-mpc
1-Bart-1 Nov 12, 2024
98152ee
remove _mtk suffix
1-Bart-1 Nov 12, 2024
eba60d4
Merge branch 'main' into fix/improve-for-mpc
1-Bart-1 Nov 12, 2024
10dd76b
fix decimal point vs comma error
1-Bart-1 Nov 12, 2024
ef8f4af
fix main merge
1-Bart-1 Nov 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ Interpolations = "0.15"
KitePodModels = "0.3.6"
KiteUtils = "0.9.0"
LaTeXStrings = "1.4.0"
ModelingToolkit = "~9.42.0"
ModelingToolkit = "9.49.0"
NLsolve = "4.5"
OrdinaryDiffEqBDF = "1.1.1"
OrdinaryDiffEqCore = "1.4.0"
OrdinaryDiffEqBDF = "1.1.2"
OrdinaryDiffEqCore = "1.7.1"
OrdinaryDiffEqSDIRK = "1.1.0"
PackageCompiler = "2.0"
Parameters = "0.12"
Expand Down
3 changes: 1 addition & 2 deletions bin/create_sys_image
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ else
exit 1
fi

totalmem=$(grep MemTotal /proc/meminfo | awk '{print $2 / 1024}')
totalmem=${totalmem%.*}
totalmem=$(grep MemTotal /proc/meminfo | awk '{printf "%i", $2 / 1024}')
if [[ $totalmem -lt 27000 ]]; then
echo "Warning: Less than 27GB of memory detected. Using only one thread for sysimage compilation."
export JULIA_IMAGE_THREADS=1
Expand Down
2 changes: 1 addition & 1 deletion bin/run_julia
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if [[ $julia_major == "1.1" ]]; then
fi

if [ -d .git ] || git rev-parse --git-dir > /dev/null 2>&1 ; then
branch=$(git rev-parse --abbrev-ref HEAD)
branch=$(git rev-parse --abbrev-ref HEAD | sed 's/\//-/g')
else
branch=""
fi
Expand Down
2 changes: 1 addition & 1 deletion data/settings_3l.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ kite:
cd_list: [ 0.5, 0.5, 0.5, 1.0, 0.2, 0.1, 0.2, 1.0, 0.5, 0.5, 0.5]

kps4:
alpha_zero: 10.0 # should be 4..10 [degrees]
alpha_zero: 6.0 # should be 4..10 [degrees]
alpha_ztip: 10.0 # [degrees]
m_k: 0.2 # relative nose distance; increasing m_k increases C2 of the turn-rate law
rel_nose_mass: 0.47 # relative nose mass
Expand Down
99 changes: 99 additions & 0 deletions examples/simple_3l_control.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using Revise, KiteModels, LinearAlgebra
using Base: summarysize

using Pkg
if ! ("ControlPlots" ∈ keys(Pkg.project().dependencies))
using TestEnv; TestEnv.activate()
end
using ControlPlots, StatsBase

set = deepcopy(load_settings("system_3l.yaml"))
# set.elevation = 71
dt = 0.05
total_time = 10.0

steps = Int(round(total_time / dt))
logger = Logger(3*set.segments + 6, steps)

s::KPS4_3L = KPS4_3L(KCU(set))
s.set = update_settings()
s.set.abs_tol = 0.0006
s.set.rel_tol = 0.001
s.set.l_tether = 21.0
# s.set.damping = 473
s.set.elevation = 87
init_set_values = [-0.1, -0.1, -120.0]
@time KiteModels.init_sim!(s; prn=true, torque_control=true, init_set_values, ϵ=1e-3, flap_damping=0.1)
# @time next_step!(s; set_values=[0.0, 0.0, 0.0], dt=2.0)
println("vel ", mean(norm.(s.integrator[s.simple_sys.force])))
sys_state = KiteModels.SysState(s)

println("stepping")
total_step_time = 0.0
steering = init_set_values
amount = 0.3
sign = 1
for i in 1:steps
global total_step_time, sys_state, steering, sign
time = (i-1) * dt
Core.println("time: ", time)
# if time > 1.0 steering = [-1, -20, -200.0] end
# if time > 5.0 steering = [-10, -1, -200.0] end
steering .= -winch_force(s)*0.11
if (2.0 > time > 0.0) steering[2] += 5.0 end
if (2.0 > time > 0.0) steering[1] -= 5.0 end
if (4.0 > time > 2.0) steering[2] -= 1.0 end
if (4.0 > time > 2.0) steering[1] += 1.0 end
if (10.0 > time > 4.0) steering[2] -= 2.0 end
if (10.0 > time > 4.0) steering[1] += 2.0 end

# if time < 1.0
# steering[1] = 0.6
# steering[2] = -0.6
# else
# steering .= 0.0
# end

sys_state.var_01 = rad2deg(s.get_flap_angle(s.integrator)[1])
sys_state.var_02 = rad2deg(s.get_flap_angle(s.integrator)[2])
sys_state.var_03 = rad2deg(s.integrator[s.simple_sys.power_angle])
sys_state.var_04 = s.tether_lengths[1]
sys_state.var_05 = s.tether_lengths[2]
sys_state.var_06 = s.tether_lengths[3]
sys_state.var_07 = s.integrator[s.simple_sys.turn_rate_y]
sys_state.var_08 = s.integrator[s.simple_sys.heading_y]
sys_state.var_09 = s.integrator[s.simple_sys.turn_rate_y] / (s.get_flap_angle(s.integrator)[2] - s.get_flap_angle(s.integrator)[1])
sys_state.var_10 = (s.integrator[s.simple_sys.flap_vel][2] - s.integrator[s.simple_sys.flap_vel][1])
sys_state.var_11 = clamp((s.integrator[s.simple_sys.flap_vel][1] - s.integrator[s.simple_sys.flap_vel][2]) /
(s.get_tether_vels(s.integrator)[1] - s.get_tether_vels(s.integrator)[2]) * 100, -20, 10)

step_time = @elapsed next_step!(s; set_values=steering, dt=dt)
if time > total_time/2
total_step_time += step_time
end

KiteModels.update_sys_state!(sys_state, s)
log!(logger, sys_state)
l = s.set.l_tether+10
plot2d(s.pos, time; zoom=true, front=false, xlim=(-l/2, l/2), ylim=(0, l))
end

times_reltime = (total_time/2) / total_step_time
println("times realtime MTK model: ", times_reltime)
# println("avg steptime MTK model: ", total_step_time/steps)

p=plotx(logger.time_vec,
[logger.var_01_vec, logger.var_02_vec, logger.var_03_vec],
[logger.var_04_vec, logger.var_05_vec, logger.var_06_vec],
[rad2deg.(logger.var_07_vec), rad2deg.(logger.var_08_vec)],
[logger.var_09_vec, logger.var_11_vec],
[logger.var_10_vec];
ylabels=["steering", "length", "heading [deg]", "ratio", "velocity"],
labels=[
["steering pos C", "steering pos D", "power angle"],
["left tether", "right tether", "middle tether"],
["turn_rate_y", "heading_y"],
["turn_rate / flap difference", "flap speed difference / tether speed difference"],
["flap speed difference"]],
fig="Steering and heading MTK model")
display(p)
91 changes: 0 additions & 91 deletions examples/simple_3l_speed_control.jl

This file was deleted.

26 changes: 13 additions & 13 deletions scripts/load_polars.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,27 @@ alphas, d_flap_angles, cl_matrix, cd_matrix, c_te_matrix = deserialize(joinpath(

function replace_nan!(matrix)
rows, cols = size(matrix)

distance = 10
distance = max(rows, cols)
for i in 1:rows
for j in 1:cols
if isnan(matrix[i, j])
neighbors = []
for d in 1:distance
found = false
if i-d >= 1 && !isnan(matrix[i-d, j]);
push!(neighbors, matrix[i-1, j])
push!(neighbors, matrix[i-d, j])
found = true
end
if i+d <= rows && !isnan(matrix[i+d, j])
push!(neighbors, matrix[i+1, j])
push!(neighbors, matrix[i+d, j])
found = true
end
if j-d >= 1 && !isnan(matrix[i, j-d])
push!(neighbors, matrix[i, j-1])
push!(neighbors, matrix[i, j-d])
found = true
end
if j+d <= cols && !isnan(matrix[i, j+d])
push!(neighbors, matrix[i, j+1])
push!(neighbors, matrix[i, j+d])
found = true
end
if found; break; end
Expand All @@ -48,9 +47,9 @@ replace_nan!(cl_matrix) # TODO: RAD2DEG
replace_nan!(cd_matrix)
replace_nan!(c_te_matrix)

cl_interp = linear_interpolation((alphas, d_flap_angles), cl_matrix; extrapolation_bc = NaN)
cd_interp = linear_interpolation((alphas, d_flap_angles), cd_matrix; extrapolation_bc = NaN)
c_te_interp = linear_interpolation((alphas, d_flap_angles), c_te_matrix; extrapolation_bc = NaN)
cl_interp = extrapolate(scale(interpolate(cl_matrix, BSpline(Quadratic())), alphas, d_flap_angles), NaN)
cd_interp = extrapolate(scale(interpolate(cd_matrix, BSpline(Quadratic())), alphas, d_flap_angles), NaN)
c_te_interp = extrapolate(scale(interpolate(c_te_matrix, BSpline(Quadratic())), alphas, d_flap_angles), NaN)

function plot_values(alphas, d_flap_angles, matrix, interp, name)
fig = plt.figure()
Expand All @@ -65,7 +64,7 @@ function plot_values(alphas, d_flap_angles, matrix, interp, name)
X_int = collect(int_d_flap_angles) .+ zeros(length(int_alphas))'
Y_int = collect(int_alphas)' .+ zeros(length(int_d_flap_angles))

# ax.plot_wireframe(X_data, Y_data, matrix, edgecolor="royalblue", lw=0.5, rstride=5, cstride=5, alpha=0.6)
ax.plot_wireframe(X_data, Y_data, matrix, edgecolor="royalblue", lw=0.5, rstride=5, cstride=5, alpha=0.6)
ax.plot_wireframe(X_int, Y_int, interp_matrix, edgecolor="orange", lw=0.5, rstride=5, cstride=5, alpha=0.6)
plt.xlabel("Alpha")
plt.ylabel("Flap angle")
Expand All @@ -77,10 +76,11 @@ function plot_values(alphas, d_flap_angles, matrix, interp, name)
end


# plot_values(alphas, d_flap_angles, cl_matrix, cl_interp, "Cl")
# plot_values(alphas, d_flap_angles, cd_matrix, cd_interp, "Cd")
# plot_values(alphas, d_flap_angles, c_te_matrix, c_te_interp, "C_te")
plot_values(alphas, d_flap_angles, cl_matrix, cl_interp, "Cl")
plot_values(alphas, d_flap_angles, cd_matrix, cd_interp, "Cd")
plot_values(alphas, d_flap_angles, c_te_matrix, c_te_interp, "C_te")
display(plot(alphas, cd_interp.(alphas, 0.0)))
# @show gradient(cd_interp, 10, 0)

# @benchmark cd_interp(rad2deg(rand()),rad2deg(rand()))
# Dierckx
Expand Down
Loading