extensive debugging- IT WORKS NOW!

This commit is contained in:
bakedpotatolord 2025-06-01 15:12:02 -06:00
commit b9d32be214

View file

@ -325,7 +325,7 @@ function prepEach(widget, settings, print, firstPoint, update) {
* @param {number} opts.factor speed scale factor * @param {number} opts.factor speed scale factor
*/ */
function camOut(point, cut,opts) { function camOut(point, cut,opts) {
console.log({camOut: point, cut, opts})
let { let {
radius = 0, radius = 0,
clockwise = true, clockwise = true,
@ -334,6 +334,7 @@ function prepEach(widget, settings, print, firstPoint, update) {
factor = 1, factor = 1,
} = opts ?? {} } = opts ?? {}
// console.log({radius})
const isArc = radius > 0; const isArc = radius > 0;
point = point.clone(); point = point.clone();
@ -471,8 +472,9 @@ function prepEach(widget, settings, print, firstPoint, update) {
if(isArc) { if(isArc) {
console.log("arc recieved"); layerOut.mode = currentOp;
layerPush( layerOut.spindle = spindle;
lastPoint = layerPush(
point, point,
clockwise ? 2 : 3, clockwise ? 2 : 3,
rate, rate,
@ -725,8 +727,8 @@ function prepEach(widget, settings, print, firstPoint, update) {
*/ */
function polyEmit(poly, index, count, fromPoint) { function polyEmit(poly, index, count, fromPoint) {
const arcDist = 1, const arcDist = 0.1, // minimum dist for arc
arcRes = 2, //2 degs max arcRes = 4, //4 degs max
arcMax = Infinity; // no max arc radius arcMax = Infinity; // no max arc radius
// console.log('polyEmit', poly, index, count); // console.log('polyEmit', poly, index, count);
@ -734,11 +736,10 @@ function prepEach(widget, settings, print, firstPoint, update) {
let arcQ = []; let arcQ = [];
function arcExport(point,lastp){ function arcExport(point,lastp){
console.log("start",point,lastp)
let dist = lastp? point.distTo2D(lastp) : 0; let dist = lastp? point.distTo2D(lastp) : 0;
if (lastp) { if (lastp) {
if (arcDist) { if (dist >arcDist) {
let rec = Object.assign(point,{dist}); let rec = Object.assign(point,{dist});
arcQ.push(rec); arcQ.push(rec);
let desp = false; // do arcQ[0] and rec have differing move speeds? let desp = false; // do arcQ[0] and rec have differing move speeds?
@ -826,15 +827,13 @@ function prepEach(widget, settings, print, firstPoint, update) {
} }
} }
} else { } else {
// emitMM = emitPerMM * out.emit * dist; // if dist to small, output as a cut
emitMM = extrudeMM(dist, emitPerMM, out.emit); camOut(point, 1);
camOut({x, y, e:emitMM}, true,);
emitted += emitMM;
} }
} else { } else {
// if no last point, emit and set // if first point, emit and set
drainQ();
camOut(point,1 ); arcExport(point,point);
// TODO disabling out of plane z moves until a better mechanism // TODO disabling out of plane z moves until a better mechanism
// can be built that doesn't rely on computed zpos from layer heights... // can be built that doesn't rely on computed zpos from layer heights...
// when making z moves (like polishing) allow slowdown vs fast seek // when making z moves (like polishing) allow slowdown vs fast seek
@ -853,7 +852,7 @@ function prepEach(widget, settings, print, firstPoint, update) {
// ondebug({arcQ}); // ondebug({arcQ});
let vec1 = new THREE.Vector2(arcQ[1].x - arcQ[0].x, arcQ[1].y - arcQ[0].y); let vec1 = new THREE.Vector2(arcQ[1].x - arcQ[0].x, arcQ[1].y - arcQ[0].y);
let vec2 = new THREE.Vector2(arcQ.center[0].x - arcQ[0].x, arcQ.center[0].y - arcQ[0].y); let vec2 = new THREE.Vector2(arcQ.center[0].x - arcQ[0].x, arcQ.center[0].y - arcQ[0].y);
let clockwise = vec1.cross(vec2) < 0 ? 'G2' : 'G3'; let clockwise = vec1.cross(vec2) < 0
let from = arcQ[0]; let from = arcQ[0];
let to = arcQ.peek(); let to = arcQ.peek();
arcQ.xSum = arcQ.center.reduce( (t, v) => t + v.x , 0 ); arcQ.xSum = arcQ.center.reduce( (t, v) => t + v.x , 0 );
@ -861,28 +860,32 @@ function prepEach(widget, settings, print, firstPoint, update) {
arcQ.rSum = arcQ.center.reduce( (t, v) => t + v.r , 0 ); arcQ.rSum = arcQ.center.reduce( (t, v) => t + v.r , 0 );
let cl = arcQ.center.length; let cl = arcQ.center.length;
let cc; let cc;
let radius = arcQ.rSum / cl;
// calculate angle between first and last point, relative to arc center
let angle = util.thetaDiff( let angle = util.thetaDiff(
Math.atan2((from.y - arcQ.ySum / cl), (from.x - arcQ.xSum / cl)), Math.atan2((from.y - arcQ.ySum / cl), (from.x - arcQ.xSum / cl)),
Math.atan2((to.y - arcQ.ySum / cl), (to.x - arcQ.xSum / cl)), Math.atan2((to.y - arcQ.ySum / cl), (to.x - arcQ.xSum / cl)),
clockwise clockwise
); );
// if angle is less than 135 degrees (3PI/4)
if (Math.abs(angle) <= 3 * Math.PI / 4) { if (Math.abs(angle) <= 3 * Math.PI / 4) {
cc = util.center2pr(from, to, arcQ.rSum / cl, !clockwise); cc = util.center2pr(from, to, radius, clockwise);
cc.r = radius;
} }
if (!cc) { if (!cc) {
cc = {x:arcQ.xSum/cl, y:arcQ.ySum/cl, z:arcQ[0].z, r:arcQ.rSum/cl}; cc = {x:arcQ.xSum/cl, y:arcQ.ySum/cl, z:arcQ[0].z,};
} }
// first arc point // first arc point
camOut(from,true); camOut(from,true);
// rest of arc to final point // rest of arc to final point
// XYR form // XYR form
// let pre = `${clockwise? 'G2' : 'G3'} X${to.x.toFixed(decimals)} Y${to.y.toFixed(decimals)} R${cc.r.toFixed(decimals)} `; // let pre = `${clockwise? 'G2' : 'G3'} X${to.x.toFixed(decimals)} Y${to.y.toFixed(decimals)} R${cc.r.toFixed(decimals)} `;
camOut(to,1,{radius:cc.r, clockwise, arcPoints:[...arcQ]});
camOut(to,1,{radius, clockwise, arcPoints:[...arcQ]});
// XYIJ form // XYIJ form
// let pre = `${clockwise? 'G2' : 'G3'} X${to.x.toFixed(decimals)} Y${to.y.toFixed(decimals)} I${(cc.x - pos.x).toFixed(decimals)} J${(cc.y - pos.y).toFixed(decimals)} E${emit.toFixed(decimals)}`; // let pre = `${clockwise? 'G2' : 'G3'} X${to.x.toFixed(decimals)} Y${to.y.toFixed(decimals)} I${(cc.x - pos.x).toFixed(decimals)} J${(cc.y - pos.y).toFixed(decimals)} E${emit.toFixed(decimals)}`;
// let add = pos.f !== from.speedMMM ? ` E${from.speedMMM}` : ''; // let add = pos.f !== from.speedMMM ? ` E${from.speedMMM}` : '';
@ -893,6 +896,7 @@ function prepEach(widget, settings, print, firstPoint, update) {
camOut(rec,1); camOut(rec,1);
} }
} }
last = arcQ.peek();
arcQ.length = 0; arcQ.length = 0;
arcQ.center = undefined; arcQ.center = undefined;
} }
@ -915,9 +919,9 @@ function prepEach(widget, settings, print, firstPoint, update) {
}, poly.isClosed(), last); }, poly.isClosed(), last);
// console.log("at end of arcExport",structuredClone(arcQ)); // console.log("at end of arcExport",structuredClone(arcQ));
drainQ(); while (arcQ.length){
// console.log("at end of arcExport",structuredClone(arcQ)); camOut(arcQ.shift(),1);
}
newLayer(); newLayer();
return last; return last;