1

I'm working on an application for generating a path for custom-made CNC machine. It is based on a PLC controller which does not support G-code, therefore I need to define the whole path as a list of commands.

I'm having a trouble with defining the toolpath for pocket milling. As an input, I use DXF files with different kind of shapes in it. Each shape is located on different layer and built of simple elements such as LINE, ARC etc. What I need is to analyze these simple elements as a closed contour and generate toolpath for milling the whole material inside this contour. Do you know of any library or simple algorithm where I can define the shape (in this case, based on the DXF data) and the lib/algorithm would generate the whole toolpath, taking the tool diameter into consideration?

For simple shapes like circles or rectangles, I'm able to generate such toolpath manually but when the shape is more complex (e.g. like below) I'm running out of ideas how to do so.

Example shape

There is a lot of freeware CAM software in the internet and each of them generates the toolpath in form of G-Code, so I assume such kind of algorithm is implemented there somehow. I thought about using such CAM software but the G-code output is not usable for me, besides I do not need any GUI. Most of them is also written in higher-level languages whilst I'm writing my app in JavaScript running under node.js.

Spektre
  • 49,595
  • 11
  • 110
  • 380
artnew
  • 11
  • 1
  • if you already have a SW that generated G-code it will be most likely much easier to write a G-code parser that convert it back to your vector path ... You just need the reference docs for machine G-code the SW is used for... anyway if you want to make your own motion planer then see these: https://stackoverflow.com/a/22068534/2521214 https://stackoverflow.com/a/25052821/2521214 https://stackoverflow.com/a/31013424/2521214 anyway the "weird" shapes are usually done with CUBIC curves (BEZIER,SPLINE) so you just sample it to lines and offset it by tool radius as any other lines ... – Spektre Jul 17 '21 at 06:55

1 Answers1

0

Do you mean you know how to process each entity individually and don't know how to combine them together? Since they touch you just need to find the next entity according to its starting/ending point (1), from the current entity's ending point. And if the point (1) was an ending point of that entity, you will need to process the found entity in reverse, or process it in normal order and reverse the resulting line. Of course taking care to offset it in the correct direction.

For faster neighbor search sort them first by either X or Y coordinate of both their starting and ending points.

Will Ness
  • 70,110
  • 9
  • 98
  • 181