Hello,
I have the following struct:
using Rotations, StaticArrays
const MyFloat = Float32
const SEGMENTS = 7 # number of tether segments
struct SysState
time::Float64 # time since launch in seconds
orient::Quat # orientation of the kite
X::MVector{SEGMENTS+1, MyFloat} # vector of particle positions in x
Y::MVector{SEGMENTS+1, MyFloat} # vector of particle positions in y
Z::MVector{SEGMENTS+1, MyFloat} # vector of particle positions in z
end
Then I create an array of these structs:
# create a demo state with a given height and time
function demo_state(height=6.0, time=0.0)
a = 10
X = range(0, stop=10, length=SEGMENTS+1)
Y = zeros(length(X))
Z = (a .* cosh.(X./a) .- a) * height/ 5.430806
orient = UnitQuaternion(1.0,0,0,0)
return SysState(time, orient, X, Y, Z)
end
# create a demo flight log with given name [String] and duration [s]
const SAMPLE_FREQ=20
function demo_log(name="Test flight", duration=10)
delta_t = 1.0 / SAMPLE_FREQ
t_max = 10.0
max_height = 6.0
steps = Int(t_max * SAMPLE_FREQ) + 1
log = Vector{SysState}(undef, steps)
for i in range(0, length=steps)
log[i+1] = demo_state(max_height * i/steps, i*delta_t)
end
return log
end
Finally I want to create a struct of vectors (sov) out of this vector of structs (vos) to be able to access the elements easily, like that:
vos = demo_log()
sov = vos2sov(vos) # how can I implement this function?
println(sov.time) # should print a vector of Float64
println(sov.orient) # should print a vector of quaternions
How can I implement the function vos2sov?
I looked at the package StructArrays.jl, but it seams as if it cannot handle structs that are composed of different types.