From 8a8f4d8485fc398ef0f4ae81a4f5d98c63845132 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Mon, 16 Jan 2023 13:56:08 -0500 Subject: [PATCH] stub in topo4 / lathe op --- src/kiri-mode/cam/client.js | 48 ++++++++++++++--- src/kiri-mode/cam/ops.js | 83 ++++++++++++++++++++++++++++-- src/kiri-mode/cam/topo4.js | 100 ++++++++++++++++++++++++++++++++++++ src/kiri/conf.js | 5 ++ src/kiri/consts.js | 4 ++ web/kiri/index.css | 3 -- web/kiri/index.html | 5 +- 7 files changed, 232 insertions(+), 16 deletions(-) create mode 100644 src/kiri-mode/cam/topo4.js diff --git a/src/kiri-mode/cam/client.js b/src/kiri-mode/cam/client.js index 748f4558..d5725635 100644 --- a/src/kiri-mode/cam/client.js +++ b/src/kiri-mode/cam/client.js @@ -83,7 +83,12 @@ CAM.init = function(kiri, api) { animVer = isIndexed ? 1 : 0; SPACE.platform.setVisible(!isIndexed); SPACE.platform.showGrid2(!isIndexed || camStockIndexGrid); - $('cam-index').style.display = isIndexed ? '' : 'none'; + const showIndexed = isIndexed ? '' : 'none'; + const showNonIndexed = isIndexed ? 'none' : ''; + $('cam-index').style.display = showIndexed; + $('cam-lathe').style.display = showIndexed; + $('cam-flip').style.display = showNonIndexed; + $('cam-reg').style.display = showNonIndexed; if (!changed) { return; } @@ -282,13 +287,21 @@ CAM.init = function(kiri, api) { case "rough": return func.opAddRough(); case "outline": return func.opAddOutline(); case "contour": - let oplist = current.process.ops, axis = "X"; - for (let op of oplist) { + let caxis = "X"; + for (let op of current.process.ops) { if (op.type === "contour" && op.axis === "X") { - axis = "Y"; + caxis = "Y"; } } - return func.opAddContour(axis); + return func.opAddContour(caxis); + case "lathe": + let laxis = "X"; + for (let op of current.process.ops) { + if (op.type === "lathe" && op.axis === "X") { + laxis = "Y"; + } + } + return func.opAddLathe(laxis); case "register": return func.opAddRegister('X', 2); case "drill": return func.opAddDrill(); case "trace": return func.opAddTrace(); @@ -344,6 +357,12 @@ CAM.init = function(kiri, api) { func.opAdd(rec); }; + func.opAddLathe = (axis) => { + let rec = popOp.lathe.new(); + rec.axis = axis.toUpperCase(); + func.opAdd(rec); + }; + func.opAddTrace = () => { let rec = popOp.trace.new(); rec.areas = { /* widget.id: [ polygons... ] */ }; @@ -1285,7 +1304,7 @@ CAM.init = function(kiri, api) { axis: 'X' }).inputs = { tool: UC.newSelect(LANG.cc_tool, {}, "tools"), - axis: UC.newSelect(LANG.cd_axis, {}, "regaxis"), + axis: UC.newSelect(LANG.cd_axis, {}, "xyaxis"), sep: UC.newBlank({class:"pop-sep"}), spindle: UC.newInput(LANG.cc_spnd_s, {title:LANG.cc_spnd_l, convert:UC.toInt, show:hasSpindle}), rate: UC.newInput(LANG.cc_feed_s, {title:LANG.cc_feed_l, convert:UC.toInt, units:true}), @@ -1302,6 +1321,23 @@ CAM.init = function(kiri, api) { bottom: UC.newBoolean(LANG.cf_botm_s, undefined, {title:LANG.cf_botm_l, show:(op,conf) => conf ? conf.process.camZBottom : 0}) }; + createPopOp('lathe', { + tool: 'camLatheTool', + spindle: 'camLatheSpindle', + step: 'camLatheOver', + rate: 'camLatheSpeed', + tolerance: 'camTolerance', + axis: 'X' + }).inputs = { + tool: UC.newSelect(LANG.cc_tool, {}, "tools"), + axis: UC.newSelect(LANG.cd_axis, {}, "xyaxis"), + sep: UC.newBlank({class:"pop-sep"}), + spindle: UC.newInput(LANG.cc_spnd_s, {title:LANG.cc_spnd_l, convert:UC.toInt, show:hasSpindle}), + rate: UC.newInput(LANG.cc_feed_s, {title:LANG.cc_feed_l, convert:UC.toInt, units:true}), + step: UC.newInput(LANG.cc_sovr_s, {title:LANG.cc_sovr_l, convert:UC.toFloat, bound:UC.bound(0.01,2.0)}), + tolerance: UC.newInput(LANG.ou_toll_s, {title:LANG.ou_toll_l, convert:UC.toFloat, bound:UC.bound(0,10.0), units:true, round:4}), + }; + createPopOp('trace', { mode: 'camTraceType', offset: 'camTraceOffset', diff --git a/src/kiri-mode/cam/ops.js b/src/kiri-mode/cam/ops.js index 28c27bcf..5ef118f1 100644 --- a/src/kiri-mode/cam/ops.js +++ b/src/kiri-mode/cam/ops.js @@ -9,6 +9,7 @@ // dep: geo.slicer // dep: kiri.slice // use: kiri-mode.cam.topo +// use: kiri-mode.cam.topo4 gapp.register("kiri-mode.cam.ops", [], (root, exports) => { const { base, kiri } = root; @@ -767,16 +768,15 @@ class OpContour extends CamOp { prepare(ops, progress) { let { op, state, sliceOut } = this; - let { setTolerance, setTool, setSpindle, setPrintPoint } = ops; - let { polyEmit } = ops; - let { camOut, newLayer, printPoint, lastPoint } = ops; - let { bounds, zmax } = ops; let { settings, widget } = state; let { process } = settings; + let { setTolerance, setTool, setSpindle, setPrintPoint } = ops; + let { camOut, polyEmit, newLayer, printPoint, lastPoint } = ops; + let { bounds, zmax } = ops; + let toolDiam = this.toolDiam = new CAM.Tool(settings, op.tool).fluteDiameter(); let stepover = toolDiam * op.step * 2; - let cutdir = process.camConventional; let depthFirst = process.camDepthFirst; let depthData = []; @@ -830,6 +830,78 @@ class OpContour extends CamOp { } } +class OpLathe extends CamOp { + constructor(state, op) { + super(state, op); + } + + async slice(progress) { + let { op, state } = this; + let { addSlices } = state; + + this.topo = await CAM.Topo4({ + op, + state: state, + onupdate: (pct, msg) => { + progress(pct, msg); + }, + ondone: (slices) => { + this.slices = slices; + addSlices(slices); + } + }); + } + + prepare(ops, progress) { + let { op, state, slices, topo } = this; + let { settings, widget } = state; + let { process } = settings; + + let { setTolerance, setTool, setSpindle, setPrintPoint } = ops; + let { camOut, newLayer, polyEmit, printPoint, lastPoint } = ops; + let { bounds, zmax } = ops; + + let toolDiam = new CAM.Tool(settings, op.tool).fluteDiameter(); + let stepover = toolDiam * op.step * 2; + let cutdir = process.camConventional; + let depthFirst = process.camDepthFirst; + let depthData = []; + + setTool(op.tool, op.rate, op.plunge); + setSpindle(op.spindle); + setTolerance(topo.tolerance); + + // start top center, X = 0, Y = 0 closest to 4th axis chuck + printPoint = newPoint(0, 0, zmax); + + for (let slice of slices) { + // ignore debug slices + if (!slice.camLines) { + continue; + } + + let polys = [], poly, emit; + slice.camLines.forEach(poly => { + polys.push({ first:poly.first(), last:poly.last(), poly:poly }); + }); + + printPoint = tip2tipEmit(polys, printPoint, (el, point, count) => { + poly = el.poly; + if (poly.last() === point) { + poly.reverse(); + } + poly.forEachPoint((point, pidx) => { + camOut(point.clone(), pidx > 0, stepover); + }, false); + }); + + newLayer(); + } + + setPrintPoint(printPoint); + } +} + class OpTrace extends CamOp { constructor(state, op) { super(state, op); @@ -1701,6 +1773,7 @@ CAM.OPS = CamOp.MAP = { "outline": OpOutline, "contour": OpContour, "pocket": OpPocket, + "lathe": OpLathe, "trace": OpTrace, "drill": OpDrill, "register": OpRegister, diff --git a/src/kiri-mode/cam/topo4.js b/src/kiri-mode/cam/topo4.js new file mode 100644 index 00000000..624c5a99 --- /dev/null +++ b/src/kiri-mode/cam/topo4.js @@ -0,0 +1,100 @@ +/** Copyright Stewart Allen -- All Rights Reserved */ + +"use strict"; + +// dep: geo.base +// dep: geo.line +// dep: geo.point +// dep: geo.polygon +// dep: geo.polygons +// dep: kiri.slice +// dep: kiri-mode.cam.driver +// dep: kiri-mode.cam.slicer2 +// dep: moto.broker +gapp.register("kiri-mode.cam.topo", [], (root, exports) => { + +const { base, kiri } = root; +const { driver, newSlice } = kiri; +const { CAM } = driver; +const { polygons, newLine, newSlope, newPoint, newPolygon } = base; + +const PRO = CAM.process; +const POLY = polygons; +const RAD2DEG = 180 / Math.PI; + +class Topo4 { + constructor() { } + + async generate(opt = {}) { + let { state, op, onupdate, ondone } = opt; + let { widget, settings, tabs } = opt.state; + let { controller, process } = settings; + + let axis = op.axis.toLowerCase(), + tool = new CAM.Tool(settings, op.tool), + bounds = widget.getBoundingBox().clone(), + density = parseInt(controller.animesh || 100) * 2500, + { min, max } = bounds, + span = { + x: max.x - min.x, + y: max.y - min.y + }, + contour = { + x: axis === "x", + y: axis === "y" + }, + tolerance = op.tolerance, + zMin = min.z + 0.0001, + resolution = tolerance ? tolerance : 1 / Math.sqrt(density / (span.x * span.y)), + toolOffset = tool.generateProfile(resolution).profile, + toolDiameter = tool.fluteDiameter(), + toolStep = toolDiameter * op.step, + steps = { + x: Math.ceil(span.x / resolution), + y: Math.ceil(span.y / resolution) + }; + + if (tolerance === 0) { + console.log(widget.id, 'topo4 auto tolerance', resolution.round(4)); + } + + this.tolerance = resolution; + + onupdate(0, "lathe"); + onupdate(1, "lathe"); + + ondone([]); + } +} + +CAM.Topo4 = async function(opt) { + return new Topo4().generate(opt); +}; + +moto.broker.subscribe("minion.started", msg => { + const { funcs, cache, reply, log } = msg; + + funcs.topo4_raster = (data, seq) => { + }; + + funcs.trace4_init = data => { + }; + + funcs.trace4_y = (data, seq) => { + }; + + funcs.trace4_x = (data, seq) => { + const { cache } = self; + const { trace } = cache.trace; + trace.crossX_sync(data.params, slice => { + slice = kiri.codec.encode(slice); + reply({ seq, slice }); + }); + }; + + funcs.trace4_cleanup = () => { + delete cache.trace; + }; +}); + +}); diff --git a/src/kiri/conf.js b/src/kiri/conf.js index 33cc721f..3a8cea37 100644 --- a/src/kiri/conf.js +++ b/src/kiri/conf.js @@ -498,6 +498,11 @@ const conf = exports({ camContourIn: false, camContourXOn: true, camContourYOn: true, + camLatheTool: 1000, + camLatheSpindle: 1000, + camLatheOver: 0.1, + camLatheSpeed: 500, + camTolerance: 0, camTraceTool: 1000, camTraceSpindle: 1000, camTraceType: "follow", diff --git a/src/kiri/consts.js b/src/kiri/consts.js index eb73b0b6..686c063f 100644 --- a/src/kiri/consts.js +++ b/src/kiri/consts.js @@ -101,6 +101,10 @@ const LISTS = { { name: "middle" }, { name: "bottom" } ], + xyaxis: [ + { name: "X" }, + { name: "Y" } + ], regaxis: [ { name: "X" }, { name: "Y" }, diff --git a/web/kiri/index.css b/web/kiri/index.css index d47cbaa7..900d5003 100644 --- a/web/kiri/index.css +++ b/web/kiri/index.css @@ -938,9 +938,6 @@ th, tr, td, label { align-items: center; gap: 5px; } -#cam-index { - grid-column-start: span 2; -} #op-add-list { padding: 4px; display: flex; diff --git a/web/kiri/index.html b/web/kiri/index.html index 5692461b..fa636bfc 100644 --- a/web/kiri/index.html +++ b/web/kiri/index.html @@ -485,10 +485,11 @@
index
+
lathe
laser on
laser off
-
flip
-
register
+
flip
+
register
drill
level
trace