Skip to content

Commit b61f090

Browse files
committed
Fixes
1 parent ee946e2 commit b61f090

File tree

1 file changed

+48
-48
lines changed

1 file changed

+48
-48
lines changed

examples/test_heading.jl

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -291,53 +291,53 @@ function plot_heading_and_position(turn_angles, theta, ys_all, zs_all, headings_
291291
plt.show(block=false)
292292
end
293293

294-
# plot_heading_and_position(turn_angles, theta, ys_all, zs_all, headings_all, psi_dot_all, h_labels, pd_labels)
295-
296-
# Print orientation and position for each turn angle, and create SysState structs
297-
println("turn_angle => orientation (roll, pitch, yaw) and position (x, y, z)")
298-
viewer::Viewer3D = Viewer3D(true);
299-
segments = viewer.set.segments # default: 6
300-
N = segments + 1 # number of tether particles (including ground and kite)
301-
t = 0.0
302-
θ = 30.0
303-
dt = 0.05
304-
prev_heading = calc_kite_heading(deg2rad(turn_angles[1]))
305-
for θ in theta
306-
for ta in turn_angles
307-
global t, prev_heading, dt
308-
r = tether_length * sin(deg2rad(θ))
309-
x = r / tan(deg2rad(θ))
310-
roll, pitch, yaw = calc_orientation(deg2rad(ta); x=x, z=0.0, r=r)
311-
pos = calc_kite_pos(deg2rad(ta); x=x, z=0.0, r=r)
312-
el, az = calc_elevation_azimuth(deg2rad(ta))
313-
heading = calc_kite_heading(deg2rad(ta))
314-
heading_rate = (heading - prev_heading) / dt
315-
prev_heading = heading
316-
# Build quaternion directly from rotation matrix to avoid Euler angle wrapping glitches
317-
q = calc_orient_quat(deg2rad(ta); x=x, z=0.0, r=r)
318-
# Interpolate tether particle positions from origin to kite position
319-
xs = MVector{N, Float64}([pos[1] * i / segments for i in 0:segments])
320-
ys = MVector{N, Float64}([pos[2] * i / segments for i in 0:segments])
321-
zs = MVector{N, Float64}([pos[3] * i / segments for i in 0:segments])
322-
state = SysState{N}(
323-
time = t,
324-
l_tether = MVector{4, Float64}(norm(pos), 0.0, 0.0, 0.0),
325-
orient = MVector{4, Float32}(Rotations.params(q)),
326-
elevation = el,
327-
azimuth = az,
328-
heading = heading,
329-
course = heading_rate,
330-
heading_rate = heading_rate,
331-
roll = roll,
332-
pitch = pitch,
333-
yaw = yaw,
334-
X = xs,
335-
Y = ys,
336-
Z = zs,
337-
)
338-
t += 0.05
339-
update_system(viewer, state; scale=0.25, kite_scale=0.25, ned=true)
340-
sleep(dt)
341-
# println(" $(ta)° => orientation: ($(round(rad2deg(roll), digits=2))°, $(round(rad2deg(pitch), digits=2))°, $(round(rad2deg(yaw), digits=2))°) position: ($(round(pos[1], digits=2)), $(round(pos[2], digits=2)), $(round(pos[3], digits=2)))")
294+
function play_circle_flight_video(θ)
295+
# Print orientation and position for each turn angle, and create SysState structs
296+
println("turn_angle => orientation (roll, pitch, yaw) and position (x, y, z)")
297+
viewer = Viewer3D(true)
298+
segments = viewer.set.segments # default: 6
299+
N = segments + 1 # number of tether particles (including ground and kite)
300+
t = 0.0
301+
dt = 0.05
302+
prev_heading = calc_kite_heading(deg2rad(turn_angles[1]))
303+
for _ in 1:3 # repeat the circle flight a few times
304+
for ta in turn_angles
305+
r = tether_length * sin(deg2rad(θ))
306+
x = r / tan(deg2rad(θ))
307+
roll, pitch, yaw = calc_orientation(deg2rad(ta); x=x, z=0.0, r=r)
308+
pos = calc_kite_pos(deg2rad(ta); x=x, z=0.0, r=r)
309+
el, az = calc_elevation_azimuth(deg2rad(ta))
310+
heading = calc_kite_heading(deg2rad(ta); x=x, z=0.0, r=r)
311+
heading_rate = (heading - prev_heading) / dt
312+
prev_heading = heading
313+
# Build quaternion directly from rotation matrix to avoid Euler angle wrapping glitches
314+
q = calc_orient_quat(deg2rad(ta); x=x, z=0.0, r=r)
315+
# Interpolate tether particle positions from origin to kite position
316+
xs = MVector{N, Float64}([pos[1] * i / segments for i in 0:segments])
317+
ys = MVector{N, Float64}([pos[2] * i / segments for i in 0:segments])
318+
zs = MVector{N, Float64}([pos[3] * i / segments for i in 0:segments])
319+
state = SysState{N}(
320+
time = t,
321+
l_tether = MVector{4, Float64}(norm(pos), 0.0, 0.0, 0.0),
322+
orient = MVector{4, Float32}(Rotations.params(q)),
323+
elevation = el,
324+
azimuth = az,
325+
heading = heading,
326+
course = heading_rate,
327+
heading_rate = heading_rate,
328+
roll = roll,
329+
pitch = pitch,
330+
yaw = yaw,
331+
X = xs,
332+
Y = ys,
333+
Z = zs,
334+
)
335+
t += 0.05
336+
update_system(viewer, state; scale=0.25, kite_scale=0.25, ned=true)
337+
sleep(dt)
338+
end
342339
end
343340
end
341+
342+
# plot_heading_and_position(turn_angles, theta, ys_all, zs_all, headings_all, psi_dot_all, h_labels, pd_labels)
343+
play_circle_flight_video(30)

0 commit comments

Comments
 (0)