forked from 5axes/Calibration-Shapes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpeedTower.py
172 lines (155 loc) · 8.25 KB
/
SpeedTower.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#------------------------------------------------------------------------------------------------------------------------------------
#
# Cura PostProcessingPlugin
# Author: 5axes
# Date: February 29, 2020
#
# Description: postprocessing-script to easily define a Speed Tower
# Option for Speed
# Acceleration
# Junction Deviation
# Marlin Linear Advance
# RepRap Pressure Adance
#
# Version 1.0 29/02/2020
# Version 1.1 29/01/2021
# Version 1.2 05/04/2021 by dotdash32(https://github.com/dotdash32) for Marlin Linear Advance & RepRap Pressure Advance
# Version 1.3 18/04/2021 : ChangeLayerOffset += 2
# Version 1.4 18/05/2021 : float
#
#------------------------------------------------------------------------------------------------------------------------------------
from ..Script import Script
from UM.Application import Application
from UM.Logger import Logger
import re #To perform the search
__version__ = '1.4'
class SpeedTower(Script):
def __init__(self):
super().__init__()
def getSettingDataString(self):
return """{
"name": "SpeedTower",
"key": "SpeedTower",
"metadata": {},
"version": 2,
"settings":
{
"command": {
"label": "Command",
"description": "GCode Commande",
"type": "enum",
"options": {
"acceleration": "Acceleration",
"jerk": "Jerk",
"junction": "Junction Deviation",
"marlinadv": "Marlin Linear",
"rrfpresure": "RepRap Pressure"
},
"default_value": "acceleration"
},
"startValue":
{
"label": "Starting value",
"description": "the starting value of the Tower.",
"type": "float",
"default_value": 8.0
},
"valueChange":
{
"label": "Value Increment",
"description": "the value change of each block, can be positive or negative. I you want 50 and then 40, you need to set this to -10.",
"type": "float",
"default_value": 4.0
},
"changelayer":
{
"label": "Change Layer",
"description": "how many layers needs to be printed before the value should be changed.",
"type": "float",
"default_value": 30,
"minimum_value": 1,
"maximum_value": 1000,
"maximum_value_warning": 100
},
"changelayeroffset":
{
"label": "Change Layer Offset",
"description": "if the Tower has a base, put the layer high off it here",
"type": "float",
"default_value": 4,
"minimum_value": 0,
"maximum_value": 1000,
"maximum_value_warning": 100
},
"lcdfeedback":
{
"label": "Display details on LCD",
"description": "This setting will insert M117 gcode instructions, to display current modification in the G-Code is being used.",
"type": "bool",
"default_value": true
}
}
}"""
def execute(self, data):
UseLcd = self.getSettingValueByKey("lcdfeedback")
Instruction = self.getSettingValueByKey("command")
StartValue = float(self.getSettingValueByKey("startValue"))
ValueChange = float(self.getSettingValueByKey("valueChange"))
ChangeLayer = self.getSettingValueByKey("changelayer")
ChangeLayerOffset = self.getSettingValueByKey("changelayeroffset")
ChangeLayerOffset += 2 # Modification to take into account the numbering offset in Gcode
# layer_index = 0 for initial Block 1= Start Gcode normaly first layer = 0
CurrentValue = StartValue
Command=""
idl=0
for layer in data:
layer_index = data.index(layer)
lines = layer.split("\n")
for line in lines:
if line.startswith(";LAYER:"):
line_index = lines.index(line)
# Logger.log('d', 'Instruction : {}'.format(Instruction))
if (layer_index==ChangeLayerOffset):
if (Instruction=='acceleration'):
Command = "M204 S{:d}".format(int(CurrentValue))
lcd_gcode = "M117 Acceleration S{:d}".format(int(CurrentValue))
if (Instruction=='jerk'):
Command = "M205 X{:d} Y{:d}".format(int(CurrentValue), int(CurrentValue))
lcd_gcode = "M117 Jerk X{:d} Y{:d}".format(int(CurrentValue), int(CurrentValue))
if (Instruction=='junction'):
Command = "M205 J{:.3f}".format(float(CurrentValue))
lcd_gcode = "M117 Junction J{:.3f}".format(float(CurrentValue))
if (Instruction=='marlinadv'):
Command = "M900 K{:.3f}".format(float(CurrentValue))
lcd_gcode = "M117 Linear Advance K{:.3f}".format(float(CurrentValue))
if (Instruction=='rrfpresure'):
Command = "M572 D0 S{:.3f}".format(float(CurrentValue))
lcd_gcode = "M117 Pressure Advance S{:.3f}".format(float(CurrentValue))
lines.insert(line_index + 1, ";TYPE:CUSTOM LAYER")
lines.insert(line_index + 2, Command)
if UseLcd == True :
lines.insert(line_index + 3, lcd_gcode)
if ((layer_index-ChangeLayerOffset) % ChangeLayer == 0) and ((layer_index-ChangeLayerOffset)>0):
CurrentValue += ValueChange
if (Instruction=='acceleration'):
Command = "M204 S{:d}".format(int(CurrentValue))
lcd_gcode = "M117 Acceleration S{:d}".format(int(CurrentValue))
if (Instruction=='jerk'):
Command = "M205 X{:d} Y{:d}".format(int(CurrentValue), int(CurrentValue))
lcd_gcode = "M117 Jerk X{:d} Y{:d}".format(int(CurrentValue), int(CurrentValue))
if (Instruction=='junction'):
Command = "M205 J{:.3f}".format(float(CurrentValue))
lcd_gcode = "M117 Junction J{:.3f}".format(float(CurrentValue))
if (Instruction=='marlinadv'):
Command = "M900 K{:.3f}".format(float(CurrentValue))
lcd_gcode = "M117 Linear Advance K{:.3f}".format(float(CurrentValue))
if (Instruction=='rrfpresure'):
Command = "M572 D0 S{:.3f}".format(float(CurrentValue))
lcd_gcode = "M117 Pressure Advance S{:.3f}".format(float(CurrentValue))
lines.insert(line_index + 1, ";TYPE:CUSTOM VALUE")
lines.insert(line_index + 2, Command)
if UseLcd == True :
lines.insert(line_index + 3, lcd_gcode)
result = "\n".join(lines)
data[layer_index] = result
return data