Skip to content

Commit

Permalink
Adding tabs working, no feedrate
Browse files Browse the repository at this point in the history
  • Loading branch information
BarbourSmith committed Jun 6, 2022
1 parent a6253ca commit 556d28b
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 48 deletions.
7 changes: 1 addition & 6 deletions dist/jsxcad-algorithm-cgal.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions dist/jsxcad-api-shape.js
Original file line number Diff line number Diff line change
Expand Up @@ -4477,6 +4477,10 @@ const toolpath =
// console.log(JSON.stringify(shape));
// console.log(JSON.stringify(toolpath));
for (const { op, from, to } of toolpath.toolpath) {
if (!from.every(isFinite)) {
// This is from an unknown position.
continue;
}
switch (op) {
case 'cut':
cuts.push([lerp(0.2, from, to), to]);
Expand Down
36 changes: 21 additions & 15 deletions dist/jsxcad-convert-gcode.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import { op, visit } from './jsxcad-geometry.js';

const X = 0;
const Y = 1;
const Z = 2;
import { op, visit, transformCoordinate } from './jsxcad-geometry.js';

// FIX: This is actually GRBL.
const toGcode = async (geometry) => {
const toGcode = async (geometry, { jumpHeight = 1 } = {}) => {
const codes = [];

// CHECK: Perhaps this should be a more direct modeling of the GRBL state?
const state = {
// Where is the tool
x: 0,
y: 0,
z: 0,
x: undefined,
y: undefined,
z: undefined,
// How 'fast' the tool is running (rpm or power).
s: 0,
f: 0,
Expand All @@ -31,23 +27,23 @@ const toGcode = async (geometry) => {
};

const pX = (x = state.x) => {
if (x !== state.x) {
if (isFinite(x) && x !== state.x) {
return ` X${value(x)}`;
} else {
return '';
}
};

const pY = (y = state.y) => {
if (y !== state.y) {
if (isFinite(y) && y !== state.y) {
return ` Y${value(y)}`;
} else {
return '';
}
};

const pZ = (z = state.z) => {
if (z !== state.z) {
if (isFinite(z) && z !== state.z) {
return ` Z${value(z)}`;
} else {
return '';
Expand Down Expand Up @@ -128,18 +124,28 @@ const toGcode = async (geometry) => {

cM3();

const processToolpath = ({ toolpath }) => {
const processToolpath = ({ matrix, toolpath }) => {
const update = (original, transformed) =>
isFinite(original) ? transformed : original;
const transform = ([ox, oy, oz]) => {
// Transform the coordinate.
const [x = 0, y = 0, z = 0] = [ox, oy, oz];
const [tx, ty, tz] = transformCoordinate([x, y, z], matrix);
// Making sure that undefined elements remain undefined.
return [update(ox, tx), update(oy, ty), update(oz, tz)];
};
for (const entry of toolpath) {
const [x, y, z] = transform(entry.to);
switch (entry.op) {
case 'jump':
cF({ f: entry.speed });
cS({ s: entry.power });
cG0({ x: entry.to[X], y: entry.to[Y], z: entry.to[Z] });
cG0({ x, y, z: jumpHeight });
break;
case 'cut':
cF({ f: entry.speed });
cS({ s: entry.power });
cG1({ x: entry.to[X], y: entry.to[Y], z: entry.to[Z] });
cG1({ x, y, z });
break;
}
}
Expand Down
51 changes: 26 additions & 25 deletions dist/jsxcad-geometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -912,22 +912,30 @@ const taggedToolpath = ({ tags = [], provenance }, toolpath) => {
const X = 0;
const Y = 1;

const measureDistance = ([ax, ay, az], [bx, by, bz]) => {
const measureDistance = (
[ax = 0, ay = 0, az = 0],
[bx = 0, by = 0, bz = 0]
) => {
const x = bx - ax;
const y = by - ay;
const z = bz - az;
return Math.sqrt(x * x + y * y + z * z);
};
const computeDot = ([ax, ay, az], [bx, by, bz]) => ax * bx + ay * by + az * bz;
const equals = ([ax, ay, az], [bx, by, bz]) =>
const computeDot = ([ax = 0, ay = 0, az = 0], [bx = 0, by = 0, bz = 0]) =>
ax * bx + ay * by + az * bz;
const equals = ([ax = 0, ay = 0, az = 0], [bx = 0, by = 0, bz = 0]) =>
ax === bx && ay === by && az === bz;
const subtract = ([ax, ay, az], [bx, by, bz]) => [ax - bx, ay - by, az - bz];
const subtract = ([ax = 0, ay = 0, az = 0], [bx = 0, by = 0, bz = 0]) => [
ax - bx,
ay - by,
az - bz,
];

const computeToolpath = (
geometry,
{
toolDiameter = 1,
jumpHeight = 1,
toolDiameter = 1,
stepCost = toolDiameter * -2,
turnCost = -2,
neighborCost = -2,
Expand Down Expand Up @@ -1049,12 +1057,12 @@ const computeToolpath = (
}
time('QQ/computeToolpath/Grooves');

const compareCoord = (a, b) => {
const dX = a[X] - b[X];
const compareCoord = ([aX = 0, aY = 0], [bX = 0, bY = 0]) => {
const dX = aX - bX;
if (dX !== 0) {
return dX;
}
return a[Y] - b[Y];
return aY - bY;
};

const compareStart = (a, b) => compareCoord(a.start, b.start);
Expand Down Expand Up @@ -1123,22 +1131,14 @@ const computeToolpath = (
);
time('QQ/computeToolpath/Index');

const jump = (
toolpath,
[fromX = 0, fromY = 0, fromZ = 0],
[toX = 0, toY = 0, toZ = 0]
) =>
const jump = (toolpath, [fromX, fromY, fromZ], [toX, toY, toZ]) =>
toolpath.push({
op: 'jump',
from: [fromX, fromY, fromZ],
to: [toX, toY, toZ],
});

const cut = (
toolpath,
[fromX = 0, fromY = 0, fromZ = 0],
[toX = 0, toY = 0, toZ = 0]
) =>
const cut = (toolpath, [fromX, fromY, fromZ], [toX, toY, toZ]) =>
toolpath.push({
op: 'cut',
from: [fromX, fromY, fromZ],
Expand Down Expand Up @@ -1177,7 +1177,11 @@ const computeToolpath = (
}

const distance = measureDistance(candidate.at.start, target.start);
if ((candidate.at.isFill || target.isFill) && distance < toolDiameter) {
if (
(candidate.at.isFill || target.isFill) &&
distance < toolDiameter &&
candidate.at.start.every(isFinite)
) {
// Reaching a fill point fulfills it, but reaching a profile or groove point won't.
const fulfills = [];
if (target.isFill) {
Expand Down Expand Up @@ -1296,11 +1300,10 @@ const computeToolpath = (
};

let candidate = {
at: { start: [0, 0, 0], ends: [] },
at: { start: [undefined, undefined, undefined], ends: [] },
toolpath: [],
cost: 0,
length: 0,
doNotExpress: true,
};
const fulfilled = new Set();
for (;;) {
Expand Down Expand Up @@ -1335,7 +1338,7 @@ const computeToolpath = (
}
if (nextCandidates.length < subCandidateLimit) {
// From this point they're really jumps.
const [x, y] = candidate.at.start;
const [x = 0, y = 0] = candidate.at.start;
for (let range = 2; range < Infinity; range *= 2) {
const destinations = kd.within(x, y, range);
for (const destination of destinations) {
Expand Down Expand Up @@ -1363,9 +1366,7 @@ const computeToolpath = (
// Note that we include the imaginary seed point.
const history = [];
for (let node = candidate; node; node = node.last) {
if (!node.doNotExpress) {
history.push(node.toolpath);
}
history.push(node.toolpath);
}
const toolpath = [];
while (history.length > 0) {
Expand Down
4 changes: 2 additions & 2 deletions dist/maslowWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ const agent = async ({ ask, message }) => {

const shapeHeight = geometryToGcode.size().height;

const cutDepth = shapeHeight / 5;
const cutDepth = shapeHeight / message.passes;

const oneSlice = geometryToGcode
.section()
Expand All @@ -281,7 +281,7 @@ const agent = async ({ ask, message }) => {

var acumulatedShape = oneSlice.z(-1 * cutDepth);//.toolpath();
var i = 2;
while (i <= 5) {
while (i <= message.passes) {
console.log("In while:");
console.log(oneSlice.z(-i * cutDepth).cut(tabs));
acumulatedShape = api.Group(
Expand Down

0 comments on commit 556d28b

Please sign in to comment.