Skip to content

Commit b944bdf

Browse files
1-Bart-1ufechner7
andauthored
3l demo state (#51)
* add 3 line state * fix function names * add xyz * remove kvec3 * rm s * rm pos kite * remove s. * fix sysstate size * add print statements * fix print * fix x assignment * fix x y z assignment * add new functions to documentation * update comment --------- Co-authored-by: Uwe Fechner <[email protected]>
1 parent ed15b4e commit b944bdf

File tree

2 files changed

+106
-1
lines changed

2 files changed

+106
-1
lines changed

docs/src/functions.md

+2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ Also look at the default example: [settings.yaml](https://github.com/ufechner7/K
1919
```@docs
2020
demo_state
2121
demo_state_4p
22+
demo_state_4p_3lines
2223
demo_syslog
2324
demo_log
2425
get_particles
26+
get_particles_3l
2527
```
2628

2729
# Loading, saving and converting log files

src/KiteUtils.jl

+104-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export Settings, SysState, SysLog, Logger, MyFloat
3636
import Base.length
3737
export demo_state, demo_syslog, demo_log, load_log, save_log, export_log # functions for logging
3838
export log!, syslog, length
39-
export demo_state_4p, initial_kite_ref_frame # functions for four point kite model
39+
export demo_state_4p, demo_state_4p_3lines, initial_kite_ref_frame # functions for four point and three line kite
4040
export rot, rot3d, ground_dist, calc_elevation, azimuth_east, acos2 # geometric functions
4141
export fromEG2W, fromENU2EG,fromW2SE, fromKS2EX, fromEX2EG # reference frame transformations
4242
export calc_azimuth, calc_heading_w, calc_heading, calc_course # geometric functions
@@ -305,6 +305,38 @@ function get_particles(height_k, height_b, width, m_k, pos_pod= [ 75., 0., 129.9
305305
[zeros(3), pos0, pos_A, pos_kite, pos_C, pos_D] # 0, p7, p8, p9, p10, p11
306306
end
307307

308+
309+
"""
310+
Calculate the initial positions of the particels representing
311+
a 4-point 3 line kite.
312+
"""
313+
function get_particles_3l(width, radius, middle_length, tip_length, bridle_center_distance, pos_kite = [ 75., 0., 129.90381057],
314+
vec_c=[-15., 0., -25.98076211], v_app=[10.4855, 0, -3.08324])
315+
# inclination angle of the kite; beta = atan(-pos_kite[2], pos_kite[1]) ???
316+
beta = pi/2.0
317+
318+
e_z = normalize(vec_c) # vec_c is the direction of the last two particles
319+
e_y = normalize(cross(v_app, e_z))
320+
e_x = normalize(cross(e_y, e_z))
321+
322+
α_0 = pi/2 - width/2/radius
323+
α_c = α_0 + width*(-2*tip_length + sqrt(2*middle_length^2 + 2*tip_length^2))/(4*(middle_length - tip_length)) / radius
324+
α_d = π - α_c
325+
326+
E = pos_kite
327+
E_c = pos_kite + e_z * (-bridle_center_distance + radius) # E at center of circle on which the kite shape lies
328+
C = E_c + e_y*cos(α_c)*radius - e_z*sin(α_c)*radius
329+
D = E_c + e_y*cos(α_d)*radius - e_z*sin(α_d)*radius
330+
331+
length(α) = α < π/2 ?
332+
(tip_length + (middle_length-tip_length)*α*radius/(0.5*width)) :
333+
(tip_length + (middle_length-tip_length)*-α)*radius/(0.5*width))
334+
P_c = (C+D)./2
335+
A = P_c - e_x*(length(α_c)*(3/4 - 1/4))
336+
337+
[E, C, D, A] # important to have the order E = 1, C = 2, D = 3, A = 4
338+
end
339+
308340
"""
309341
demo_state_4p(P, height=6.0, time=0.0)
310342
@@ -356,6 +388,77 @@ function demo_state_4p(P, height=6.0, time=0.0)
356388
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
357389
end
358390

391+
"""
392+
demo_state_4p_3lines(P, height=6.0, time=0.0)
393+
394+
Create a demo state, using the 4 point kite model with a given height and time. P is the number of tether particles.
395+
396+
Returns a SysState instance.
397+
"""
398+
function demo_state_4p_3lines(P, height=6.0, time=0.0)
399+
num_A = P
400+
num_D = P-1
401+
num_C = P-2
402+
num_E = P-3
403+
pos = zeros(SVector{P, MVector{3, Float64}})
404+
# ground points
405+
[pos[i] .= [0.0, 0.0, 0.0] for i in 1:3]
406+
407+
# middle tether
408+
sin_el, cos_el = sin(deg2rad(se().elevation)), cos(deg2rad(se().elevation))
409+
for (i, j) in enumerate(range(6, step=3, length=se().segments))
410+
radius = i * (se().l_tether/se().segments)
411+
pos[j] .= [cos_el*radius, 0.0, sin_el*radius]
412+
end
413+
414+
# kite points
415+
vec_c = pos[num_E-3] - pos[num_E]
416+
E, C, D, A = get_particles_3l(se().width, se().radius, se().middle_length, se().tip_length, se().bridle_center_distance, pos[num_E], vec_c)
417+
pos[num_A] .= A
418+
pos[num_C] .= C
419+
pos[num_D] .= [pos[num_C][1], -pos[num_C][2], pos[num_C][3]]
420+
421+
# build tether connection points
422+
e_z = normalize(vec_c)
423+
distance_c_l = 0.5 # distance between c and left steering line
424+
pos[num_E-2] .= pos[num_C] + e_z .* (distance_c_l)
425+
pos[num_E-1] .= pos[num_E-2] .* [1.0, -1.0, 1.0]
426+
427+
# build left and right tether points
428+
for (i, j) in enumerate(range(4, step=3, length=se().segments-1))
429+
pos[j] .= pos[num_E-2] ./ se().segments .* i
430+
pos[j+1] .= [pos[j][1], -pos[j][2], pos[j][3]]
431+
end
432+
433+
X = zeros(P)
434+
Y = zeros(P)
435+
Z = zeros(P)
436+
for (i, p) in enumerate(pos)
437+
# println("pos ", pos)
438+
X[i] = p[1]
439+
Y[i] = p[2]
440+
Z[i] = p[3]
441+
end
442+
# println("X ", X)
443+
pos_centre = 0.5 * (C + D)
444+
delta = E - pos_centre
445+
z = normalize(delta)
446+
y = normalize(C - D)
447+
x = y × z
448+
pos_before = pos[num_E] + z
449+
450+
rotation = rot(pos[num_E], pos_before, -x)
451+
q = QuatRotation(rotation)
452+
orient = MVector{4, Float32}(Rotations.params(q))
453+
elevation = calc_elevation([X[end], 0.0, Z[end]])
454+
vel_kite=zeros(3)
455+
t_sim = 0.014
456+
sys_state = 0
457+
e_mech = 0
458+
return SysState{P}(time, t_sim, sys_state, e_mech, orient, elevation,0,0,0,0,0,0,0,0,0,vel_kite, X, Y, Z,
459+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
460+
end
461+
359462
"""
360463
demo_syslog(P, name="Test flight"; duration=10)
361464

0 commit comments

Comments
 (0)