-
Notifications
You must be signed in to change notification settings - Fork 15
/
teensycnc.cps
188 lines (152 loc) · 3.93 KB
/
teensycnc.cps
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
description = "TeensyCNC";
vendor = "Matt Williams";
vendorUrl = "nitrogl@gmail.com";
legal = "Copyright (C) 2016 by Matt Williams";
certificationLevel = 2;
minimumRevision = 24000;
longDescription = "Post for TeensyCNC";
extension = "nc";
setCodePage("ascii");
capabilities=CAPABILITY_MILLING|CAPABILITY_JET;
tolerance=spatial(0.002, MM);
minimumChordLength=spatial(0.01, MM);
minimumCircularRadius=spatial(0.01, MM);
maximumCircularRadius=spatial(1000, MM);
minimumCircularSweep=toRad(0.01);
maximumCircularSweep=toRad(180);
allowHelicalMoves=true;
allowedCircularPlanes=undefined; // allow any circular motion
// user-defined properties
properties=
{
};
var gFormat=createFormat({prefix:"G", decimals:0});
var mFormat=createFormat({prefix:"M", decimals:0});
var xyzFormat=createFormat({decimals:(unit==MM?3:4), forceDecimal:true});
var feedFormat=createFormat({decimals:(unit==MM?1:2)});
var xOutput=createVariable({prefix:"X", force:true}, xyzFormat);
var yOutput=createVariable({prefix:"Y", force:true}, xyzFormat);
var feedOutput=createVariable({prefix:"F"}, feedFormat);
var iOutput=createReferenceVariable({prefix:"I", force:true}, xyzFormat);
var jOutput=createReferenceVariable({prefix:"J", force:true}, xyzFormat);
var gMotionModal=createModal({force:true}, gFormat); // modal group 1 // G0-G3, ...
var gAbsIncModal=createModal({}, gFormat); // modal group 3 // G90-91
var gUnitModal=createModal({}, gFormat); // modal group 6 // G20-22
function writeBlock()
{
writeWords(arguments);
}
function onOpen()
{
// absolute coordinates and feed per min
writeBlock(gAbsIncModal.format(90));
switch(unit)
{
case IN:
writeBlock(gUnitModal.format(20));
break;
case MM:
writeBlock(gUnitModal.format(21));
break;
}
}
function onComment(message)
{
}
function forceXYZ()
{
xOutput.reset();
yOutput.reset();
}
function forceAny()
{
forceXYZ();
feedOutput.reset();
}
function onSection()
{
forceXYZ();
forceAny();
}
function onRapid(_x, _y, _z)
{
// writeBlock(mFormat.format(8));
writeBlock(gMotionModal.format(0), xOutput.format(_x), yOutput.format(_y));
feedOutput.reset();
// writeBlock(mFormat.format(7));
}
function onLinear(_x, _y, _z, feed)
{
xOutput.reset();
yOutput.reset();
writeBlock(gMotionModal.format(1), xOutput.format(_x), yOutput.format(_y), feedOutput.format(feed));
}
function onCircular(clockwise, cx, cy, cz, x, y, z, feed)
{
var start=getCurrentPosition();
if(isFullCircle())
{
if(isHelical())
{
linearize(tolerance);
return;
}
switch(getCircularPlane())
{
case PLANE_XY:
writeBlock(gMotionModal.format(clockwise?2:3), xOutput.format(x), iOutput.format(cx-start.x, 0), jOutput.format(cy-start.y, 0), feedOutput.format(feed));
break;
default:
linearize(tolerance);
}
}
else
{
switch(getCircularPlane())
{
case PLANE_XY:
writeBlock(gMotionModal.format(clockwise?2:3), xOutput.format(x), yOutput.format(y), iOutput.format(cx-start.x, 0), jOutput.format(cy-start.y, 0), feedOutput.format(feed));
break;
default:
linearize(tolerance);
}
}
}
function onPower(enable)
{
if(enable)
writeBlock(mFormat.format(7));
else
writeBlock(mFormat.format(8));
}
var mapCommand=
{
COMMAND_STOP:0,
COMMAND_OPTIONAL_STOP:1
};
function onCommand(command)
{
switch(command)
{
case COMMAND_POWER_ON:
return;
case COMMAND_POWER_OFF:
return;
}
var mcode=mapCommand[getCommandStringId(command)];
if(mcode!=undefined)
writeBlock(mFormat.format(mcode));
else
onUnsupportedCommand(command);
}
function onSectionEnd()
{
forceAny();
writeBlock(mFormat.format(8)); // head up
}
function onClose()
{
// writeBlock(mFormat.format(8)); // head up
writeBlock(gFormat.format(28)); // home XYZ
writeBlock(gFormat.format(2)); // end
}