Sandify pattern optimizer

I have written a perl program to optimize sandify pattern files. All my tests so far have had good results.

The program cuts out all back and forth motion along the edges of the table, eliminates all circling around the edges of the table, and forces shortest path around the table through 2 and 3 corners (3 corner paths are replaced by a single corner path). The result is usually greatly reduced pattern file size, faster drawing on the table because movement along the edge uses longest segment length (think acceleration/deceleration), excess motion is gone, and it’s a lot less boring to watch because the unproductive edge motion is greatly reduced. It will save wear and tear on the table mechanism as well. All this leaves the pattern on the table unchanged except the edges sometimes looks a little ragged because there’s little motion along the edges to clean it up.

You can grab the program here.

It’s extremely easy to use. Start it up by typing “perl sandify_trim_all.pl” and then enter the pattern file name. Output is in a file called “clean.gcode”.

I wrote it using Strawberry Perl in windoze, but I think it should work in any recent perl 5 install.

 

 

3 Likes

Wow, I am going to have to figure out perl now!

This is the first thing I have ever written in perl. It took me less than a week to write it (after thinking about it for months and abandoning every idea I had in that time). All you need to do is install perl and run the program- that should be easy.

I used strawberry perl in windows, if that helps, and it was very easy to set up. I think the code will be usable in any recent Perl 5 install.

1 Like

I ran into a couple patterns that contained some residual useless motion after running trimify. I found that a second run of trimify on the “clean” output file eliminated the residue. I then edited the program to make two full passes on the input pattern and it seems to work. I have yet to find any patterns that still contain any residue after running the new version of the program. The new program is called trimify2x.pl which you can grab here.

The new version now names the output file based on the input file name. if you enter “starz.gcode” the output file name will be “starz_clean.gcode”.

Unless someone finds a bug, I’m not planning any more changes.

More here: https://drmrehorst.blogspot.com/2019/11/developing-post-processing-program-to.html

2 Likes

Thanks for doing this. I’m currently working on v1pi, trying to cut another image. But I hope to integrate this into sandify, and having the algorithm written out and tested in detail really helps.

Great! The two pass version probably only needs to rerun the edge trimming to eliminate the residue that comes from the first pass. I don’t think it’s necessary to run the corner trimming / substitution a second time.

Have you tried running trimmed files on your table?

I have not. My table is still very much a prototype, so it requires lots of care each time I run it.

Here are three demo videos- poor quality, but you can see what the program does very clearly:

This is the original pattern straight out of sandify:
https://vimeo.com/376736096

Here is the result of running my original trimify program:

And here’s the result of running trimify2x:
https://vimeo.com/376548917

This particular pattern, as produced by Sandify, requires about 2 hours to complete. With identical speed and acceleration settings, the “clean” version from trimify2x finishes in about 57 minutes.

3 Likes

Where did that pattern originally come from?

That came from your creation- Sandify. I’ve played with all the settings, quite a lot…
One of the things that trimify2x enables is patterns made with very high cycle counts. It trims out all the crap that would otherwise make those patterns too long and boring to watch.

Here’s the header from the file:

; Created by Sandify
;
; https://sandify.org
;
; Sandify Version: 0.1.4
;
; Machine Type: Rectangular
; MinX: 5 MaxX: 710 MinY: 5 MaxY: 1600
; Content Type: Shapes
; Starting Size: 300
; Offset: X: 51 Y: -1000
; Selected Shape: Circle
; Circle Lobes: 1.47
; Number of Loops: 244
; Spin: true
; Spin Value: -0.6
; Spin Switchbacks: 0
; Grow: true
; Grow Value: 5
; Track: true
; Track Count: -34
; Track Size: 880.45
; Track Grow: false
; Path Reversed: false
;
; filename: ‘mishegoss3’

I never would have thought of that. I’m not even sure what that means.

I figured that you put that in there intentionally…

Polygons and even your new reuleaux can have fractional number of sides.

Here’s another good one based on using a heart as the starting shape- the header list the shape as “none”- another minor bug, I think.

; Created by Sandify
;
; https://jeffeb3.github.io/sandify/
;
; Sandify Version: 0.1.3
;
; Machine Type: Rectangular
; MinX: 5 MaxX: 710 MinY: 5 MaxY: 1570
; Content Type: Shapes
; Starting Size: 331
; Offset: X: -1 Y: 81
; Selected Shape: None
; Number of Loops: 156
; Spin: true
; Spin Value: 0.4
; Spin Switchbacks: 7
; Grow: true
; Grow Value: -6
; Track: true
; Track Count: 8
; Track Size: 804
; Track Grow: false
; Path Reversed: true
;
; filename: ‘heartfuzz1.gcode’

I find that playing with the track size and length can yield some very nice jagged lines.

I noticed that and fixed it in the current version.

I really understand a lot more why you want to limit the extra moves and see the unclipped pattern. It’s like you’re zoomed into a tiny facet of an incredibly complex pattern. Very neat.

The first part of the trimify2x.pl strips out excessive motion along each side of the table. That leaves sequences of corner statements that the second part of the program tries to reduce to minimum. I have detected a flaw in the algorithm that minimizes corner to corner sequences. If the corners are designated A, B, C, and D, you can have sequences like ABA or AA or ABAAD, etc., in which there are duplicates and reversals that the current algorithm doesn’t recognize and treat appropriately. I’m reviewing it now to see what needs to be done to fix it.

I’ve only seen problem behavior in one or two pattern files- the program works for 99% of pattern files.

1 Like