This repository has been archived by the owner on Dec 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgrbl-laser.patch
167 lines (155 loc) · 6.25 KB
/
grbl-laser.patch
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
diff --git a/grbl laser copy.cps b/grbl laser.cps
index 91d493a..989659d 100644
--- a/grbl laser copy.cps
+++ b/grbl laser.cps
@@ -40,9 +40,12 @@ properties = {
sequenceNumberStart: 10, // first sequence number
sequenceNumberIncrement: 1, // increment for sequence numbers
separateWordsWithSpace: true, // specifies that the words should be separated with a white space
- throughPower: 255, // set the Laser Power for though cutting
- etchPower: 50, // set the power for etching
- vaporizePower: 255 // set the power for vaporize
+ maxPowerLevel: 1000, // maximum power level to scale power vars against
+ throughPower: 1, // set the Laser Power for though cutting
+ etchPower: 0.25, // set the power for etching
+ vaporizePower: 1, // set the power for vaporize
+ throughPassCount: 1,
+ writeThroughPassCountComment: true
};
// user-defined property definitions
@@ -52,9 +55,12 @@ propertyDefinitions = {
sequenceNumberStart: {title:"Start sequence number", description:"The number at which to start the sequence numbers.", group:1, type:"integer"},
sequenceNumberIncrement: {title:"Sequence number increment", description:"The amount by which the sequence number is incremented by in each block.", group:1, type:"integer"},
separateWordsWithSpace: {title:"Separate words with space", description:"Adds spaces between words if 'yes' is selected.", type:"boolean"},
+ maxPowerLevel: {title: "Max power level", description: "Max laser power used to scale power levels (corresponds to spindle RPM/$30).", type: "integer"},
throughPower: {title: "Through power", description: "Sets the laser power used for through cutting.", type: "number"},
etchPower: {title:"Etch power", description:"Sets the laser power used for etching.", type:"number"},
- vaporizePower: {title:"Vaporize power", description:"Sets the laser power used for vaporize cutting.", type:"number"}
+ vaporizePower: {title:"Vaporize power", description:"Sets the laser power used for vaporize cutting.", type:"number"},
+ throughPassCount: {title: "Through pass count", description: "Pass count for through cutting operations.", type: "integer"},
+ writeThroughPassCountComment: {title: "Write through pass count comment", description:"Sets whether to write comments for through pass section duplications.", type: "boolean"}
};
var gFormat = createFormat({prefix:"G", decimals:0});
@@ -88,10 +94,17 @@ var WARNING_WORK_OFFSET = 0;
var sequenceNumber;
var currentWorkOffset;
+var isWritingSection = false;
+var currentSectionBuffer = [];
+
/**
Writes the specified block.
*/
function writeBlock() {
+ if (isWritingSection) {
+ currentSectionBuffer.push(arguments);
+ }
+
if (properties.showSequenceNumbers) {
writeWords2("N" + sequenceNumber, arguments);
sequenceNumber += properties.sequenceNumberIncrement;
@@ -206,6 +219,7 @@ function forceAny() {
}
function onSection() {
+ isWritingSection = true;
writeln("");
@@ -224,22 +238,6 @@ function onSection() {
error(localize("The CNC does not support the required tool/process. Only laser cutting is supported."));
return;
}
-
- var power = 0;
- switch (currentSection.jetMode) {
- case JET_MODE_THROUGH:
- power = properties.throughPower;
- break;
- case JET_MODE_ETCHING:
- power = properties.etchPower;
- break;
- case JET_MODE_VAPORIZE:
- power = properties.vaporizePower;
- break;
- default:
- error(localize("Unsupported cutting mode."));
- return;
- }
} else {
error(localize("The CNC does not support the required tool/process. Only laser cutting is supported."));
return;
@@ -272,7 +270,9 @@ function onSection() {
setRotation(remaining);
}
- writeBlock(gMotionModal.format(0), sOutput.format(power), mFormat.format(getPowerMode(currentSection)));
+ // Only write G0 instruction, let #onPower call #writeBlock for spindle ON/OFF commands
+ // writeBlock(gMotionModal.format(0), sOutput.format(power), mFormat.format(getPowerMode(currentSection)));
+ writeBlock(gMotionModal.format(0));
var initialPosition = getFramePosition(currentSection.getInitialPosition());
writeBlock(gMotionModal.format(0), xOutput.format(initialPosition.x), yOutput.format(initialPosition.y));
@@ -292,7 +292,44 @@ function onRadiusCompensation() {
pendingRadiusCompensation = radiusCompensation;
}
+var lastPower = false;
+
function onPower(power) {
+ if (power === lastPower) {
+ return;
+ }
+ lastPower = power;
+
+ if (power) {
+ // Duplicated from original code within #onSection
+ // Moved into function for use in #onPower and removed from #onSection
+ var powerLevel;
+
+ switch (currentSection.jetMode) {
+ case JET_MODE_THROUGH:
+ powerLevel = properties.throughPower;
+ break;
+ case JET_MODE_ETCHING:
+ powerLevel = properties.etchPower;
+ break;
+ case JET_MODE_VAPORIZE:
+ powerLevel = properties.vaporizePower;
+ break;
+ default:
+ error(localize("Unsupported cutting mode."));
+ return;
+ }
+
+ // Scale powerLevel against maxPowerLevel
+ // Round to avoid decimals and clamp to prevent over/under values
+ powerLevel = clamp(0, Math.round(powerLevel * properties.maxPowerLevel), properties.maxPowerLevel);
+
+ var powerMode = getPowerMode(currentSection);
+
+ writeBlock(sOutput.format(powerLevel), mFormat.format(powerMode));
+ } else {
+ writeBlock(sOutput.format(0));
+ }
}
function onRapid(_x, _y, _z) {
@@ -430,6 +467,27 @@ function onCommand(command) {
function onSectionEnd() {
forceAny();
+
+ if (isWritingSection) {
+ isWritingSection = false;
+
+ // Repush the currentSectionBuffer into #writeBlock
+ if (currentSectionBuffer.length > 0) {
+ for (var pass = 0; pass < properties.throughPassCount - 1; pass++) {
+ writeln("");
+
+ if (properties.writeThroughPassCountComment) {
+ writeComment("throughPass Copy " + (pass + 1));
+ }
+
+ for (var block = 0; block < currentSectionBuffer.length; block++) {
+ writeBlock(currentSectionBuffer[block]);
+ }
+ }
+
+ currentSectionBuffer = [];
+ }
+ }
}
function onClose() {