Update to the api - local file update

@stewart Hi Steward, I’m trying to update my local copy of kiri_pool and kiri_work to get the latest updates but for some reason can’t seem to find them or curl them from the grid.space page. Is it still the case that i need to run these files locally or should i just load the engine script.

1 Like

are you wanting to use the engine api which is demo’d here:

4.2 should use the same urls as previous releases, but 4.3 onward uses a new location for those assets. Also starting with 4.3 you can override the url location of the pool and work assets. curl may not work because the server uses cookies to determine which asset version is served on shared urls. it’s best to use the browser to download to ensure you’re getting the matching code version.

that’s the theory anyway. I’m testing the 4.2 engine on grid.space and it appears that the worker is now bundled into the engine code and loaded from memory. this was code that I was testing, but did not think I’d enabled in production. I’ll need to investigate further tonight or tomorrow.

2 Likes

Yes, that’s the one i’m trying to use. I had it implemented using pool and worker locally, but hoping to update to 4.3 since i need the new fixes to pockets.

Thank you, I’ll try getting from the browser. Let me know if you have any other insights.

1 Like

I was able to succesfully update to 4.2 but i’m still somewhat unclear on how to get the 4.3 update. Do I still need to retrieve the pool and work assets locally? And if so, any idea on how to get to those?

4.3 is still in beta. I’m not sure what the plan is for implementing the engine in the new paradigm, but it will likely get ironed out before 4.3 becomes the default version. I’m interested in bundling the engine into an NPM library, but we’ll see if that comes to fruition. If you’d like to work on that, help is always appreciated.

2 Likes

your_dir/index.html (that loads engine.js)
your_dir/engine.js
your_dir/worker.js
wasm/manifold.wasm

the wasm directory must be one level up from your_dir

then your index.html uses the engine like this:

new Engine({ workURL: "./worker.js" })
.setListener(display_message)
.load("cube.stl")
...

notice the new workURL directive. using the chooser sets a cookie on your browser which allows you to fetch 4.3 assets which is why curl and wget will not work.

I setup an off-site example for you to look at.

2 Likes

I think that this is a brilliant idea :grinning_face:

1 Like

agree this would be a good step. I’d like to get the encapsulation cleaned up first.

2 Likes

That’s reasonable, I just wanted to throw in my 2cents that I think the engine is a brilliant tool that would find a lot of use in the world :grin:

Thank you so much for this. This looks like exactly what I am missing. I’m going to give this a try.

Thank you so much for these instructions. I was able to update and run 4.3 on our project!

I’m still however struggling to replicate the slicing results i get on the grid.space using the same file and process settings. What I’m expecting is the result on the right but what i get is a version that seems to go include outside roughing and go through and beyond the depth of the part.

Do you have any sense on what might be causing this error or what settings I might need to take a second look at? The only process setting i set differently was the “camZBottom: -25,” to get around the bug, otherwise every process setting is the same as i grabbed it from grid.space.

1 Like

this looks like a z / stock alignment issue. it’s introducing a lot of cuts above the part that match the stock profile. please send me your workspace .kmz and engine code (settings/profile) to replicate and I’ll figure out where in the engine code the calculation is going wrong.

workspace_abudance_test_grid.kmz (173.4 KB)

Thank you. Here they are!

These are the settings i’ve been trying:

import { Engine } from "./engine.js";

const display_message = (message) => {
  console.log(message);
};

const kiriEngine = new Engine({ workURL: "./worker.js" });
console.log(kiriEngine);

const generateGcode = (
  stlUrl,
  centerPos,
  toolSize,
  passes,
  speed,
  extra,
  gcodeCallback
) => {
  console.log("passes", passes);
  if (!stlUrl) {
    console.error("STL URL is not available.");
    return;
  }

  kiriEngine
    .setListener((message) => {
      console.log("Kiri:Moto Message:", message);
    })
    .load(stlUrl)
    .then((eng) => {
      console.log(centerPos);
      return eng.move(centerPos[0], centerPos[1], 0); //Move the model to line up with where the parts were before
    })
    .then((eng) => {
      return eng.setMode("CAM");
    })
    .then((eng) => {
      const bounds = eng.widget.getBoundingBox();
      const x = bounds.max.x - bounds.min.x;
      const y = bounds.max.y - bounds.min.y;
      const z = bounds.max.z - bounds.min.z;
      eng.setStock({
        x: x + 10,
        y: y + 10,
        z: z,
        center: {
          x: x / 2,
          y: y / 2,
          z: z / 2,
        },
      });
      return eng;
    })
    .then((eng) =>
      eng.setTools([
        {
          id: 1000,
          number: 1,
          type: "endmill",
          name: "end 1/4",
          metric: false,
          shaft_diam: toolSize,
          shaft_len: 1,
          flute_diam: 0.25,
          flute_len: 2,
          taper_tip: 0,
        },
      ])
    )
    .then((eng) => {
      const bounds = eng.widget.getBoundingBox();
      const z = bounds.max.z - bounds.min.z;
      eng.setProcess({
        processName: "default",
        camLevelTool: 1000,
        camLevelSpindle: 1000,
        camLevelOver: 0.5,
        camLevelSpeed: 1000,
        camLevelDown: 0,
        camLevelStock: true,
        camRoughTool: 1000,
        camRoughSpindle: 1000,
        camRoughDown: 4,
        camRoughOver: 0.4,
        camRoughSpeed: 1000,
        camRoughPlunge: 250,
        camRoughStock: 0,
        camRoughStockZ: 0,
        camRoughAll: false,
        camRoughVoid: true,
        camRoughFlat: true,
        camRoughTop: true,
        camRoughIn: true,
        camRoughOn: true,
        camRoughOmitVoid: false,
        camOutlineTool: 1000,
        camOutlineSpindle: 1000,
        camOutlineTop: true,
        camOutlineDown: 3,
        camOutlineOver: 0.4,
        camOutlineOverCount: 1,
        camOutlineSpeed: 800,
        camOutlinePlunge: 250,
        camOutlineWide: false,
        camOutlineDogbone: false,
        camOutlineOmitThru: false,
        camOutlineOmitVoid: true,
        camOutlineOut: true,
        camOutlineIn: false,
        camOutlineOn: true,
        camContourTool: 1000,
        camContourSpindle: 1000,
        camContourOver: 0.5,
        camContourSpeed: 1000,
        camContourAngle: 85,
        camContourLeave: 0,
        camContourReduce: 2,
        camContourBottom: false,
        camContourCurves: false,
        camContourIn: false,
        camContourXOn: true,
        camContourYOn: true,
        camLatheTool: 1000,
        camLatheSpindle: 1000,
        camLatheOver: 0.1,
        camLatheAngle: 1,
        camLatheSpeed: 500,
        camLatheLinear: true,
        camTolerance: 0,
        camTraceTool: 1000,
        camTraceSpindle: 1000,
        camTraceType: "follow",
        camTraceOver: 0.5,
        camTraceDown: 0,
        camTraceThru: 0,
        camTraceSpeed: 250,
        camTracePlunge: 200,
        camTraceOffOver: 0,
        camTraceDogbone: false,
        camTraceMerge: false,
        camTraceLines: false,
        camTraceZTop: 0,
        camTraceZBottom: 0,
        camPocketSpindle: 1000,
        camPocketTool: 1000,
        camPocketOver: 0.25,
        camPocketDown: 1,
        camPocketSpeed: 250,
        camPocketPlunge: 200,
        camPocketExpand: 0,
        camPocketSmooth: 0,
        camPocketRefine: 20,
        camPocketFollow: 5,
        camPocketContour: true,
        camPocketEngrave: false,
        camPocketOutline: false,
        camPocketZTop: 0,
        camPocketZBottom: 0,
        camDrillTool: 1006,
        camDrillSpindle: 1000,
        camDrillDownSpeed: 250,
        camDrillDown: 5,
        camDrillDwell: 250,
        camDrillLift: 2,
        camDrillMark: false,
        camDrillFromStockTop: false,
        camDrillThru: 5,
        camDrillPrecision: 1,
        camDrillingOn: false,
        camRegisterSpeed: 1000,
        camRegisterThru: 5,
        camFlipAxis: "X",
        camFlipOther: "",
        camLaserEnable: ["M321"],
        camLaserDisable: ["M322"],
        camLaserOn: ["M3"],
        camLaserOff: ["M5"],
        camLaserSpeed: 100,
        camLaserPower: 1,
        camLaserAdaptive: false,
        camLaserAdaptMod: false,
        camLaserFlatten: false,
        camLaserFlatZ: 0,
        camLaserPowerMin: 0,
        camLaserPowerMax: 1,
        camLaserZMin: 0,
        camLaserZMax: 0,
        camTabsWidth: 5,
        camTabsHeight: 5,
        camTabsDepth: 5,
        camTabsMidline: false,
        camDepthFirst: false,
        camEaseDown: false,
        camEaseAngle: 10,
        camOriginTop: true,
        camZAnchor: "middle",
        camZOffset: 0,
        camZTop: 0,
        camZBottom: -25,
        camZClearance: 1,
        camZThru: 0,
        camFastFeed: 6000,
        camFastFeedZ: 300,
        camFlatness: 0.001,
        camContourBridge: 0,
        camStockX: 5,
        camStockY: 5,
        camStockZ: 5,
        camStockOffset: true,
        camStockClipTo: false,
        camStockIndexed: false,
        camStockIndexGrid: true,
        camIndexAxis: 0,
        camIndexAbs: true,
        camConventional: false,
        camOriginCenter: true,
        camOriginOffX: 0,
        camOriginOffY: 0,
        camOriginOffZ: 0,
        outputInvertX: false,
        outputInvertY: false,
        camExpertFast: false,
        camTrueShadow: false,
        camArcEnabled: false,
        camArcTolerance: 0.15,
        camArcResolution: 5,
        camForceZMax: false,
        camFirstZMax: false,
        camToolInit: true,
        camFullEngage: 0.8,
        ops: [
          {
            type: "rough",
            tool: 1000,
            spindle: 1000,
            down: 4,
            step: 0.4,
            rate: 1000,
            plunge: 250,
            leave: 0,
            leavez: 0,
            all: false,
            voids: true,
            flats: true,
            inside: true,
            omitthru: false,
            ov_topz: 0,
            ov_botz: 0,
            ov_conv: false,
          },
          {
            type: "|",
          },
        ],
        op2: [],
        camLevelStepZ: 0,
        camLevelInset: 0.5,
        camRegisterOffset: 10,
        camHelicalTool: 1000,
        camHelicalSpindle: 1000,
        camHelicalDownSpeed: 250,
        camHelicalSpeed: 1000,
        camHelicalDown: 5,
        camHelicalBottomFinish: true,
        camHelicalThru: 0,
        camHelicalOffset: "auto",
        camHelicalForceStartAngle: false,
        camHelicalStartAngle: 0,
        camHelicalOffsetOverride: 0,
        camHelicalEntry: false,
        camHelicalEntryOffset: 0,
        camHelicalReverse: false,
        camHelicalClockwise: true,
        camRoughOmitThru: false,
        "~camConventional": false,
      });
      return eng;
    })
    .then((eng) =>
      eng.setDevice({
        mode: "CAM",
        internal: 0,
        bedHeight: 2.5,
        bedWidth: 10000,
        bedDepth: 175,
        maxHeight: 300,
        originCenter: false,
        spindleMax: 0,
        gcodePre: [
          "G21 ; set units to MM (required)",
          "G90 ; absolute position mode (required)",
        ],
        gcodePost: ["M30 ; program end"],
        gcodeDwell: ["G4 P{time} ; dwell for {time}ms"],
        gcodeSpindle: [],
        gcodeChange: ["M6 T{tool} ; change tool to '{tool_name}'"],
        gcodeFExt: "nc",
        gcodeSpace: true,
        gcodeStrip: true,
        new: false,
        deviceName: "Any.Generic.Grbl",
        imageURL: "",
        useLaser: false,
      })
    )
    .then((eng) => eng.slice())
    .then((eng) => eng.prepare())
    .then((eng) => eng.export())
    .then((gcode) => {
      gcodeCallback(gcode); // Only call the callback, don't download
      console.log(gcode);
    })
    .catch((error) => {
      console.error("Kiri:Moto Error:", error);
    })
    .finally(() => {
      // Clean up the temporary URL after generation
      setTimeout(() => URL.revokeObjectURL(stlUrl), 1000);
    });
};

Object.assign(window, {
  generateGcode,
});

I’m working on a fix for you.

1 Like

Any luck figuring out what might be going on? Thanks again for helping me with this. I’m also happy to set up a more complete example how my use case if it seems like it might not be a settings issue.

I have made partial frustrating progress. The back end engine still depends on a few variables being set by the front end and tracing this can be time consuming since I can’t easily automate ingestion of gcode artifacts. I ran out of time the other day and will get back to it shortly.

Ah, that makes sense. Thank you for putting time into it. Look forward to hearing what you find!