Any interest in writing software for the MPCNC?

@Cobalt

One (and the first) of the outputs will be gcode in a file.

The lines generated in the diagrams above are an intermediate H/L representation. So I hold them as JSON structures. e.g.

[[{"p1":{"X":15,"Y":29},"p2":{"X":185,"Y":29},"cut":true},{"p1":{"X":185,"Y":29},"p2":{"X":185,"Y":44},"cut":true},
{"p1":{"X":185,"Y":44},"p2":{"X":15,"Y":44},"cut":true},{"p1":{"X":15,"Y":44},"p2":{"X":15,"Y":59},"cut":true},
{"p1":{"X":15,"Y":59},"p2":{"X":185,"Y":59},"cut":true},{"p1":{"X":185,"Y":59},"p2":{"X":185,"Y":74},"cut":true},
{"p1":{"X":185,"Y":74},"p2":{"X":15,"Y":74},"cut":true},{"p1":{"X":15,"Y":74},"p2":{"X":15,"Y":89},"cut":true},
{"p1":{"X":15,"Y":89},"p2":{"X":185,"Y":89},"cut":true},{"p1":{"X":185,"Y":89},"p2":{"X":185,"Y":104},"cut":true},
{"p1":{"X":185,"Y":104},"p2":{"X":15,"Y":104},"cut":true},{"p1":{"X":15,"Y":104},"p2":{"X":15,"Y":119},"cut":true},
{"p1":{"X":15,"Y":119},"p2":{"X":185,"Y":119},"cut":true},{"p1":{"X":185,"Y":119},"p2":{"X":185,"Y":134},"cut":true},
{"p1":{"X":185,"Y":134},"p2":{"X":15,"Y":134},"cut":true},{"p1":{"X":15,"Y":134},"p2":{"X":15,"Y":149},"cut":true},
{"p1":{"X":15,"Y":149},"p2":{"X":185,"Y":149},"cut":true},{"p1":{"X":185,"Y":149},"p2":{"X":185,"Y":164},"cut":true},
{"p1":{"X":185,"Y":164},"p2":{"X":15,"Y":164},"cut":true},{"p1":{"X":15,"Y":164},"p2":{"X":15,"Y":179},"cut":true},
{"p1":{"X":15,"Y":179},"p2":{"X":185,"Y":179},"cut":true}]]

There will be thousands of these lines, each with a tool applied to it, be it a 3mm tool or a 15mm tool. Some will be cuts and some will be travel movement with no cuts. Some will iterate around as a cut may be a number of loops to get the depth.

The next piece of code I write will be to take these high level instructions and generate gcode from them.

However there is nothing to say that it must be gcode, it could be another output form. Could be PostScript :slight_smile: However the only things I have that understand anything are a CNC machine and a 3d printer, so I’ll generate a file and test it on gcode simulators.

This model of intermediate forms is quite common, in some respects I think of the drawings as the code, my program as the compiler and the gcode output as the binary code.

My knowledge of gcode is zero at the moment, but I’ve looked at the gcode specs and can see what it does so am hoping that’s not a major fag. It can’t be any worse than assembler (or I hope not).

Now as this is a specific output, it shouldn’t be a problem to have a different ouptut. Famous last words.

Does this explain things?

Rob

1 Like

Yep, it sure does, lol.

I’m a low-level junkie, bitwise operations and assembly are my favorite. I do lots of embedded design, so I’m usually poking around on custom hardware and making firmware for it. I really respect all of the high-level programming like you are doing because its actually hard for me to wrap my head around.

@Cobalt

I think of this work as similar to a compiler, I have written a number for profit and pleasure.

The design element is the program or the instructions. We don’t have a LR or LL grammer, but we do have semantics and prioritisation.

The h/l intermediate format is the p-code or the library.

The gcode is the assembler.

The analogy works quite well as:

  1. The instructions to cut a pattern can be considered a subroutine.
  2. We could generate different outputs for different cutting machines.
  3. The gcode can be optimised to reduce the number of operations.

We should get exactly the same results each time we run the code.

I’m just thinking through the next steps to handle the loops necessary to cut the patterns and how to make code to turn the intermediate form into gcode so that it’s modular and somebody else could write a function to run over the intermediate form to produce a different but valid output.

Best wishes

Rob

Have you been researching gcode much? I’m actually working on a system to read gcode and convert it to movement patterns for the steppers on my MPCNC. I’ve skimmed through the commands, but haven’t jumped into any real code yet. I’m still trying to get a good grasp on what the “universal” language is, or rather what set of instructions would be highly functional. From what I understand, the Marlin variant is the most popular with MPCNC folk.
I’ve also come to discover that file formatting is slightly different from Windows to Linux, which took me a minute to figure out when files that I generated would open fine under Windows but Linux would spit out garbage.
The joys of multiple platforms…

I’ve not done much research but I have looked through a number of programmes and some reference sites.

It looks pretty straightforward as it’s higher level than assembler and lower level than C. The structure is normally an operator followed by some args.

Until I get into it, I won’t really know, but at this moment in time, I’m not that scared of it.

Ah the vagaries of Windows vs Unix file formats. Normally it’s the end of line indicators \r\n on Windows vs \n on Unix, there’s also sometimes the end of file indicator, but that might have been DOS.

I’m just working out the rest of the HL intermediate format, mainly to reduce the number of CNC bit changes and to optimise the tool paths. Once I have that done (or at least an initial version) I’ll then look at working on gcode generation. After that, I’ll write a quick curl routine to interface to Octoprint.

Once I have that, I can create rectangles (can’t save or import them), overlap them, move them, generate an intermediate format, generate gcode and send it to the cnc machine. Then the real work starts…

1 Like

Also, if you are looking to do pattern matching on the gcode, might be sort looking at Flex and or Perl.

Rob

I was planning on doing it on a microcontroller, so it’ll most likely be C. I’ve already put together a prototype. It’s completely custom, not Arduino. :grin:

Ok, using something like a pic18 or similar will make things more interesting. Every byte will count.

What CPU will you use?

My current design is running on a PIC32MZ. It’s currently clocked at 150Mhz, but can reach 200 if needed.
I had started out on a 44-pin, 16-bit dsPIC33, but shifted to my 64-pin PIC32 mainly because I needed more I/O’s. I have a couple dual-core dsPICs that I would love to try out, but I haven’t taken the time to learn their architecture.
There’s more to it, I’m finishing up the proof of concept design right now and plan on making a dedicated topic for it later on.

I’ve wanted to take a run at controller software before, but then I got to thinking about speed limits and accelerations and operation lookaheads, and decided that there were much smarter people then me already working that problem domain, and that I couldn’t offer anything new, and my tears wouldn’t help with any pertinent aspect of my life… So I just created a new world for Dwarf Fortress. :hammer_and_pick: :bearded_person: :mountain:

3 Likes

I think making a new Draft Fortress sounds brilliant :slight_smile:

I also agree that I let other clever people worry about speed limits, aceleration, deceleration and all that stuff. I’ll stick to the simple stuff.

Managed to get the code working on joining all the cut lines together. Also added arrows so I can see which direction the cut is. Adding the arrows turned out to be really useful as the nearest neighbour was not efficient, it is now (for some value of efficiency that I decline to state :slight_smile: ) It goes backwards and forwards quite happily and the number of lifts to move around is reasonably low. However there is no optimum solution this side of the natural heat death of the universe,.

image

Next steps are:

  1. Writing code to work out how unique a CNC bit actually is. This is needed for when somebody wants the same CNC bit to work at different speeds and different stepovers (for example). To minimise the number of CNC changes we need to know how unique a CNC bit actually is. Mostly done but nothing interesting to see.

  2. Once I have that, I then need to look at adding multiple and different types of cutting to a shape, e.g. a pocket, an interior outline, an exterior outline, a tab (need to give that some thought). Some sytems uses islands but I don’t need those immediatetly as my system has an inherent Z-ordering. However once you import an SVG, islands might be useful. Multiple operations on the same shape is a pain from a UI point of view and I might be reaching waaaaay beyond my limits of CSS and UI stuff.

  3. And then finally I can work out how to join the shapes up in the most efficient manner. This code is worked out mentally but not written down. It’s very similar to a syntactic tree in a compiler with lots of semantic hints in it.

That’s probably enough for the next two weeks.

Rob

3 Likes