Skip to content

Instantly share code, notes, and snippets.

@buserror
Created Nov 11, 2015
Embed
What would you like to do?
millcrum.com small test to generate boxes
// examples/all_objects.millcrum - sample showing every basic object and operation
// create the tool options
// units: mm or inch
// diameter: tool diameter in mm or inch
// passDepth: depth to cut per pass in mm or inch, if a cut operation has a deeper depth then multiple passes will occur
// step: how far the bit should step for pocket operations, between 0 and 1 (full step)
// rapid: how fast the tool should move when it is not cutting
// plunge: how fast the tool should move down on the Z axis when cutting
// cut: how fast the tool should move on the X and Y axes when cutting
// zClearance: how high above the surface the tool should be when not cutting
// returnHome: should the tool return to 0,0,0 after finishing, true or false
var tool = {
units: 'mm',
diameter: 3,
passDepth: 2,
step: 1,
rapid: 2000,
plunge: 100,
cut: 600,
zClearance: 5,
returnHome: true
};
// setup a new Millcrum object with that tool
var mc = new Millcrum(tool);
// set the surface dimensions for the viewer
mc.surface(300, 170);
function makeBox(size, thickness, options) {
if (options.tabCount === undefined)
options.tabCount = 3;
function tabbedRect(pos, size, tabCount, inverted) {
var poly = [];
var hin = tabCount[0] % 2 ? 0 : 1,
vin = tabCount[1] % 2 ? 0 : 1;
var x = 0,
y = 0;
var h = [];
var v = [];
for (var si = 0; si <= tabCount[0]; si++) {
h[si] = (si * (size[0] / tabCount[0]));
/* if making 'tabs', make the tabs a noch smaller than the 'holes' */
if (inverted && tabCount[0] > 1 && si > 0 && si < tabCount[0])
h[si] += (si % 2) ? 0.2 : -0.2;
}
for (var si = 0; si <= tabCount[1]; si++) {
v[si] = si * (size[1] / tabCount[1]);
/* if making 'tabs', make the tabs a noch smaller than the 'holes' */
if (inverted && tabCount[1] > 1 && si > 0 && si < tabCount[1])
v[si] += (si % 2) ? 0.5 : -0.5;
}
if (inverted === true) {
if (tabCount[0] > 1) vin = !vin;
if (tabCount[1] > 1) hin = !hin;
} else {
/* if cutting 'holes' also make them a notch deeper for a better fit */
size[2] += 0.2;
}
var start_inv = [hin, vin];
console.log(inverted, hin, vin, "huh", tabCount[0] % 2);
x = 0;
poly.push([
h[x] + hin * size[2],
v[y] + vin * size[2], "origin"
]);
for (var y = 1; y < tabCount[1]; y++) {
var p1 = [
h[x] + hin * size[2],
v[y]
];
var p2 = [
h[x] + !hin * size[2],
v[y]
];
poly.push(p1);
poly.push(p2);
hin = !hin;
}
vin = start_inv[1];
y = tabCount[1];
poly.push([
h[x] + hin * size[2],
v[y] + vin * -size[2], "corner 1"
]);
for (var x = 1; x < tabCount[0]; x++) {
poly.push([h[x],
v[y] + vin * -size[2]
]);
vin = !vin;
poly.push([h[x],
v[y] + vin * -size[2]
]);
}
hin = start_inv[0];
x = tabCount[0];
poly.push([
h[x] + hin * -size[2],
v[y] + vin * -size[2], "corner 2"
]);
for (var y = tabCount[1] - 1; y > 0; y--) {
poly.push([
h[x] + hin * -size[2],
v[y]
]);
hin = !hin;
poly.push([
h[x] + hin * -size[2],
v[y]
]);
}
vin = start_inv[1];
y = 0;
poly.push([
h[x] + hin * -size[2],
v[y] + vin * size[2], "corner 3"
]);
for (var x = tabCount[0] - 1; x > 0; x--) {
poly.push([h[x],
v[y] + vin * size[2]
]);
vin = !vin;
poly.push([h[x],
v[y] + vin * size[2]
]);
}
return poly;
}
var sides = [
/* long end */
tabbedRect(
[0, 0], [size[0], size[2], thickness], [1, 3], false),
/* short end */
tabbedRect(
[0, 0], [size[1], size[2], thickness], [1, 3], true),
];
return sides;
}
BoxSize = [240, 140, 50];
sides = makeBox(BoxSize, 6, {
tabCount: [5, 5, 3]
});
console.log("sides", sides[0]);
// cut the polygon with an outside cut and position it at 10,10
// depth 6, this will be 2 passes with a tool passDepth of 4
mc.cut('outside', {
type: 'polygon',
points: sides[0]
},
6, [20, 5]
);
mc.cut('outside', {
type: 'polygon',
points: sides[0]
},
6, [20, BoxSize[2] + 10]
);
mc.cut('outside', {
type: 'polygon',
points: sides[1]
},
6, [5, (BoxSize[2] * 2) + 15]
);
mc.cut('outside', {
type: 'polygon',
points: sides[1]
},
6, [BoxSize[1] + 10, (BoxSize[2] * 2) + 15]
);
// get the gcode
mc.get();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment