Skip to content

Commit baa85f1

Browse files
add rotational intertia calculation script (#94)
* add rotational intertia calculation script * current status * move printing to seperate function + add main conponent * update README.md * style changes and settings printing * Minor fixes --------- Co-authored-by: Uwe Fechner <[email protected]>
1 parent c96a279 commit baa85f1

File tree

2 files changed

+109
-1
lines changed

2 files changed

+109
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ If you intend to modify or extend the code, it is suggested to fork the `KiteMod
7777
git clone https://github.com/USERNAME/KiteModels.jl
7878
```
7979
where USERNAME is your github username.
80-
The compile a system image:
80+
Then compile a system image:
8181
```bash
8282
cd KiteModels.jl/bin
8383
./create_sys_image --update
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
using KiteUtils
2+
3+
function calculate_rotational_inertia(X::Vector, Y::Vector, Z::Vector, M::Vector, around_center_of_mass::Bool=true,
4+
rotation_point::Vector=[0, 0, 0])
5+
@assert size(X) == size(Y) == size(Z) == size(M)
6+
7+
if around_center_of_mass
8+
# First loop to determine the center of mass
9+
x_com = y_com = z_com = m_total = 0.0
10+
for (x, y, z, m) in zip(X, Y, Z, M)
11+
x_com += x * m
12+
y_com += y * m
13+
z_com += z * m
14+
m_total += m
15+
end
16+
17+
x_com = x_com / m_total
18+
y_com = y_com / m_total
19+
z_com = z_com / m_total
20+
else
21+
x_com = rotation_point[begin]
22+
y_com = rotation_point[begin+1]
23+
z_com = rotation_point[begin+2]
24+
end
25+
26+
Ixx = Ixy = Ixz = Iyy = Iyz = Izz = 0
27+
28+
# Second loop using the distance between the point and the center of mass
29+
for (x, y, z, m) in zip(X .- x_com, Y .- y_com, Z .- z_com, M)
30+
Ixx += m * (y^2 + z^2)
31+
Iyy += m * (x^2 + z^2)
32+
Izz += m * (x^2 + y^2)
33+
34+
Ixy += m * x * y
35+
Ixz += m * x * z
36+
Iyz += m * y * z
37+
end
38+
39+
Ixx, Ixy, Ixz, Iyy, Iyz, Izz
40+
end
41+
42+
43+
function calculate_intertia_for_setting(settings_file::String, include_kcu::Bool=true, around_kcu::Bool=false)
44+
set_data_path("data")
45+
set = deepcopy(load_settings(settings_file))
46+
47+
points = KiteUtils.get_particles(set.height_k, set.h_bridle, set.width, set.m_k, [0, 0, 0], [0, 0, -1], [10, 0, 0])
48+
49+
pos_matrix = [points[begin+1] points[begin+2] points[begin+3] points[begin+4] points[begin+5]]
50+
X = pos_matrix[begin, :]
51+
Y = pos_matrix[begin+1, :]
52+
Z = pos_matrix[begin+2, :]
53+
54+
k2 = set.rel_top_mass * (1.0 - set.rel_nose_mass)
55+
k3 = 0.5 * (1.0 - set.rel_top_mass) * (1.0 - set.rel_nose_mass)
56+
M = [set.kcu_mass, set.rel_nose_mass * set.mass, k2 * set.mass, k3 * set.mass, k3 * set.mass]
57+
58+
if !include_kcu
59+
X = X[begin+1:end]
60+
Y = Y[begin+1:end]
61+
Z = Z[begin+1:end]
62+
M = M[begin+1:end]
63+
end
64+
65+
if around_kcu
66+
Ixx, Ixy, Ixz, Iyy, Iyz, Izz = calculate_rotational_inertia(X, Y, Z, M, false, points[begin+1])
67+
else
68+
Ixx, Ixy, Ixz, Iyy, Iyz, Izz = calculate_rotational_inertia(X, Y, Z, M)
69+
end
70+
71+
Ixx, Ixy, Ixz, Iyy, Iyz, Izz
72+
end
73+
74+
75+
function print_inertia_matrix(Ixx, Ixy, Ixz, Iyy, Iyz, Izz)
76+
println("Inertia matrix [kgm²]:")
77+
println(" Ixx Ixy Ixz: [$Ixx $Ixy $Ixz] ")
78+
println(" Ixy Iyy Iyz: [$Ixy $Iyy $Iyz] ")
79+
println(" Ixz Iyz Izz: [$Ixz $Iyz $Izz] ")
80+
end
81+
82+
83+
function print_settings(include_kcu::Bool=true, around_kcu::Bool=false)
84+
out = ""
85+
86+
if include_kcu
87+
out *= "Calculating the inertia for kcu and kite"
88+
else
89+
out *= "Calculating the inertia for kite alone"
90+
end
91+
92+
if around_kcu
93+
out *= " around the kcu."
94+
else
95+
out *= " around the center of mass."
96+
end
97+
98+
println(out)
99+
end
100+
101+
102+
SETFILE = "system_v9.yaml"
103+
INCLKCU = false
104+
ARROUNDKCU = false
105+
106+
print_settings(INCLKCU, ARROUNDKCU)
107+
IXX, IXY, IXZ, IYY, IYZ, IZZ = calculate_intertia_for_setting(SETFILE, INCLKCU, ARROUNDKCU)
108+
print_inertia_matrix(IXX, IXY, IXZ, IYY, IYZ, IZZ)

0 commit comments

Comments
 (0)