-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_creator.py
78 lines (59 loc) · 1.98 KB
/
test_creator.py
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
import math
prefix="""G21 ; set units to mm
G90 ; set mode to absolute
M83 ; set E to relative
M503 ; get configuration
M92 X80 Y80 Z400 E93 ; set steps/mm
M201 X500 Y500 Z500 E8000 ; set max accel per stepper (mm/s)
M203 X15000 Y15000 Z15000 E15000 ; set max feed rate (mm/min)
M204 P1000 R1000 T1000 ; set acceleration (mm/s^2)
M205 X5 Y5 Z0 T0 ; set jerk in (mm/s)
M121 ; disable endstops on Marlin (ignore error on Duet)
G92 E0 X0 Y0 Z0 ; set position to origin
M302 S0 ; allow cold extrusions
G4 P200 ; wait 200ms for stuff to be added to planner before moving"""
suffix = "M400"
filament_diameter_mm = 1.75
extruder_diameter_mm = 0.4
layer_height_mm = 0.2
layer_width_mm = 0.5
fill_ratio = 1.0
# speed in mm/s
speed_mm_s = 80.0
# create arc
radius = 100
# approximate length of each arc
target_segment_length_mm = 0.2
##################
# END OF OPTIONS #
##################
# segment count
segment_count = round(radius * math.pi / 2 / target_segment_length_mm)
commands = []
x1 = radius
y1 = 0
x2 = radius * math.cos(math.pi / 2 / segment_count)
y2 = radius * math.sin(math.pi / 2 / segment_count)
segment_length_mm = math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
commands.append('G1 F%.6f' % (speed_mm_s * 60))
commands.append('\n')
commands.append('; segments: %d' % segment_count)
commands.append('; segment length %g mm' % segment_length_mm)
commands.append('; speed %g mm/s' % speed_mm_s)
for i in range(segment_count + 1):
x = radius * math.cos(i * math.pi / 2 / segment_count)
y = radius * math.sin(i * math.pi / 2 / segment_count)
if i == 0:
length = 0
else:
length = segment_length_mm
target_material_mm3 = fill_ratio * length * layer_height_mm * layer_width_mm
e = target_material_mm3 / (math.pi / 4 * filament_diameter_mm ** 2)
commands.append('G1 X%.6f Y%.6f E%.6f' % (x, y, e))
commands.append("G1 X0 Y0")
commands.insert(0, "\n")
commands.insert(0, prefix)
commands.append("\n")
commands.append(suffix)
commands = '\n'.join(commands)
print(commands)