-
Notifications
You must be signed in to change notification settings - Fork 0
/
filament_approx_klipper.cfg
81 lines (71 loc) · 2.99 KB
/
filament_approx_klipper.cfg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
[gcode_macro filament_length]
gcode:
{% set r1 = params.R1|float %}
{% set r2 = params.R2|float %}
{% set b = params.B|float %}
{% set d_f = params.D_F|default(1.75)|float %}
{% set density = params.DENSITY|default(1.25)|float %}
# use namespace to add to (not possible with normal variabel)
{% set ns = namespace(f=0) %}
{% set n = (r2 - r1) / d_f %}
{% set rows = (b / d_f) - 1 %}
# rounding down the values
{% set n = n|int %}
{% set rows = rows|int %}
{% set A = 3.14159 * (d_f / 2) ** 2 %}
# used to ensure, that there is no exessive calculation
# if you have large spools you can make this number bigger
{% if n > 80 %}
SHOW_MSG MSG="Number of Layers: { n } is too big!"
{% else %}
{% for k in range(1, n + 1) %}
{% set l = 2 * 3.14159 * (r1 + d_f * k - d_f / 2) * rows %}
{% set ns.f = ns.f + l %}
{% endfor %}
# calculate end values
{% set V = 0.9 * 10 ** -3 * ns.f %}
{% set Vol = A * V %}
{% set m = Vol * density %}
# these warnings may warn you if you entered incorrect values
# you can disable them by setting it to False
{% set warnings = True %}
{% if warnings %}
{% if r1 >= r2 %}
SHOW_MSG MSG="r2 needs to be greater than r1: { V } is not the length of your filament!"
{% endif %}
{% if r1 > b %}
SHOW_MSG MSG="r1 = { r1 } is greater than b = { b }. Are you sure you entered the right parameters?"
{% endif %}
{% if d_f > 3 %}
SHOW_MSG MSG="d_f = { d_f } is greater than 3. Are you sure you entered the right parameters?"
{% endif %}
{% if r1 <= 0 or r2 <= 0 or b <= 0 or d_f <= 0 or density <= 0 %}
SHOW_MSG MSG="Some values are smaller than 0. The calculation is wrong! (negative values)"
{% endif %}
{% endif %}
# print values in terminal
SHOW_MSG MSG="density used: { density } [g/cm^3]"
SHOW_MSG MSG="{ n } layers"
SHOW_MSG MSG="{ m } [g]"
SHOW_MSG MSG="{ V } [m]"
{% endif %}
# You can save the measurements of your spools by defining a macro like the following
# to add more simply change the name of the macro and change the values
[gcode_macro Giantarm]
gcode:
{% set r1 = 40|float %}
{% set r2 = params.R2|float %}
{% set b = 53|float %}
{% set d_f = 1.75|float %}
{% set density = params.DENSITY|default(1.25)|float %}
# calling the other macro with fixed values to the spool
filament_length R1={r1} R2={r2} B={b} D_F={d_f} DENSITY={density}
[gcode_macro E_Sun]
gcode:
{% set r1 =95/2|float %}
{% set r2 = params.R2|float %}
{% set b = 57|float %}
{% set d_f = 1.75|float %}
{% set density = params.DENSITY|default(1.25)|float %}
# calling the other macro with fixed values to the spool
filament_length R1={r1} R2={r2} B={b} D_F={d_f} DENSITY={density}