GCode Variables and Loops

My programmer brain is going off the deep end on how useful variables and loops could be in GCode. I know FluidNC doesn’t support this. I’m looking for feedback on if this is crazy or not and what current functionality exists elsewhere.

I want to be able to do things like this without having to create new GCode:

  • Cut the same thing in materials of different thicknesses. If I could specify the thickness and depth per pass, it could loop over the shape to handle any thickness.
  • Scale a part.
  • Adjust tolerances for fit.
  • Adjust speeds. I know there’s an override in the WebUI but I’d like to specify it directly.

I am oversimplifying this a bit and it would certainly have limitations. Some of these options would be easier than others. This really only applies to flat parts.

My thoughts are that this could be implemented in the WebUI of FluidNC. It could certainly be added to FluidNC itself, but C++ programming isn’t my strength. Basically, it would have to read a header of the GCode file, prompt for the parameters, and then basically transpile this special GCode into standard GCode using JavaScript. I think this generated file could then be automatically “uploaded” and run on the fly.

Getting a GCode file in this special format would likely require some manual editing and/or some kind of post processor.

I’m not sure if it would be worth the effort to try and implement this or how often I would actually want to utilize this functionality.

Best I know of is gcode playlists. Not sure if Fluid allows this or not…maybe becuase some use it for the Zenxy.

I will say though, all of those things are very simple in CAM as well. Scaling and depth per pass would also recalculate to keep proper chip load as well.

The one feature I think would be ultra useful is cut recovery. Being able to back up from the current location and resume the file, or rehome and fast forward through the file and chose a place to start. If you break a bit you could re home and pickup where you left off instead of rerunning the whole file or manually editing it.

1 Like

I saw that for ZenXY they were using an Octoprint plugin with M32. It doesn’t appear that FluidNC supports that.

I agree it’s simple in CAM but that requires me going on my computer instead of being able to do it from a tablet/phone. It’s all a matter of unnecessary convenience. I only have a basic understanding of chip loads.

That’s an interesting idea. It could list each part as a sort of bookmark (assuming I actually name parts in Estlcam) to choose a starting place. Perhaps then let you choose a specific line. Or you could drive it to the X/Y position where it failed and have it automatically find the closest gcode lines to choose from.

1 Like

If you just scaled up your gcode you would also scale the speed and quickly get in trouble. Moves are combined with speed, so if you scaled both it would be disaster (move further and arrive faster), if you only scaled size (move further and arrive at the same time…still faster). The only way that could work is if you scaled speed inversely.

If you want to use CMA on your phone tablet, use Kiri:moto.

Not sure how it would work, I also use linuxCNC and it has it. Looks just like feedrate control, You can move forward and reverse, even shows a display of where that line of code is.

Klipper running on a raspberry Pi with glorious amounts of memory relative to current ESP32s supports macros, variables, conditions, loops, etc… Klipper supports templated gcode via Jinja Commands templates - Klipper documentation

I need to look at kiri:moto. But was hopeful we’d see a mobile/tablet friendly parametric STL/SVG/DXF to CAM/gcode tool by now, maybe kiri or something else does this well?

Thought we’d see something that nailed 80% use case scenarios with a web frontend wrapping WebAssembly implemented version of OpenScad, with CAM/gcode support, or something with less declarative/functional, more imperative GitHub - jscad/OpenJSCAD.org: JSCAD is an open source set of modular, browser and command line tools for creating parametric 2D and 3D designs with JavaScript code. It provides a quick, precise and reproducible method for generating 3D models, and is especially useful for 3D printing applications.

There’s GitHub - MaslowCNC/Maslow-Create: A community cloud CAD program for cooperative design. too

And GitHub - vector76/Web_OpenSCAD_Customizer: Client side OpenSCAD customizer

I think so. It is set up differently from most other CAM but if you watch a quick video of it in use I think you will get it quickly. Browser based CAM.

RepRap Firmware (typically for Duet boards, but a port for then SKR Pro 1.2 exists) supports looping structures, variables and conditionals.

They are a very simple structure, of course, but they are useful.

I have used them for things like changing coordinate systems for multiple cuts of the same objects, and a few repetitive tasks, but really it’s not generally useful.

I suppose that I could use it for some hand-coded Gcode projects, but those are few and far between.

Yes, the Klipper functionality sounds like what I was hoping for. Due to the limited amount of memory of the ESP32, that’s why I was thinking of using JavaScript on the client side to generate the gcode.

kiri:moto looks interesting but not sure I want to deviate from Estlcam yet. It’s also only helpful if I run FluidNC in STA mode so I don’t have to switch networks to get internet access. The docs recommend AP mode but the FluidNC wiki suggests STA. Although, I understand that recommendation based on networking knowledge. I’ll give that a shot anyway.

EstlCam is implemented in VB.net, technically portable to webassembly/blazor/maui, but then I guess everything is. File format is compressed binary serialized types. Was hoping an export EstlCam 11 to documented json format, that can be imported to EstlCam 12 would help EstlCam Customers migrate their existing projects.

But, this could also create an opportunity for 3rd party, opensource tools to generate json that EstlCam 12 can import. Just a thought… @christian-knuell :blush:

:100:

2 Likes

Remember, when you scale a part to let’s say 120%, the diameter of the bit is not changed so the coordinates of the path are not simply scaled by 120%. Given the tool path and the bit radius, you can calculate the edge of the part or the hole, then scale that path by the scale factor, then offset again by the bit radius to get the path of the tool center. Not a simple operation.

2 Likes

I knew that one was more difficult but I hadn’t considered that detail. That would be way more difficult than I would want to attempt.