GRBL and Polar Tables

I have really tried to search through the existing posts on the forums to solve this as I have seen some existing discussions from @jeffeb3 regarding Sandify output for polar machines. I created a SCARA machine a year ago and it is working great thanks alot to Jeff’s help! As a new challenge, I am trying to build a compact polar machine using a mechanism such as “Sandtrails” - a polar sand table . I am using an Arduino uno + CNC shield running GRBL.

The X axis controls the linear rail atop the rotating central axis
The Y Axis spins the central pivot point,

g1x50 command extends the linear axis to its full radius,
g1y360 command spins a full rotation of the central pivot

20 tooth pulleys
200 tooth central pulley

Here is the output of my $$ in grbl:

Grbl 1.1h [‘$’ for help]
[MSG:‘$H’|‘$X’ to unlock]

I am trying to figure out how I could get sandify output compatible with this setup?

I’d appreciate any tips or help. Thanks in advance!


1 Like

You have to use a post processor.

Do you have any scripting experience? Python? Perl?

The thr format is simple, it has an angle (radians) and a radius (normalized):

0,1 ← zero angle, full extension
6.28, 0.5 ← One full rotation, half extension

628, 0.0 ← 100 rotations, no extension

Your machine is only one easy step from these pilar coordinates. The theta needs to be multiplied by 180/pi. The radius needs to be multiplied by 50.0.

You need a little script that reads in the number from a thr file (generated in sandify). For each coordinate, spit out the G1 X(blah) Y(blah).

I wrote one program like this before. It is around here somewhere. I posted a But your scaling might be a little different.

If you can’t figure it out, I will try to get a minute on a keyboard and make the script.

Since this is the third such request, I might add it to sandify. But probably not for a long time.

1 Like

Thanks as always Jeff! I did see that script somewhere. I think I got confused because I thought that individual wasn’t sending via GRBL, but I could be wrong. I’ll go look through it and see what I can sort out with my admittedly limited scripting skills. I really appreciate your help. I am sure I will be back with some broken code at some point :slight_smile:

1 Like

OK Jeff, I found your python code on and adjusted it to the best of my ability:

import math

# Config
INPUT_NAME = 'sandify.thr'
OUTPUT_NAME = 'transformed.gcode'

# Open the files.
with open(INPUT_NAME, 'r') as infile:
  with open(OUTPUT_NAME, 'w') as outfile:

    for line in infile:

      # First, separate by content and comments
      parts = line.strip().split('#')

      if len(parts[0].strip()) == 0:
        # This line doesn't have anything that isn't a comment

        (theta, rho) = parts[0].split()

        # Here, we're actually doing the math.
        #m1 = float(theta) + math.acos(float(rho))
        #m2 = float(theta) - math.acos(float(rho))

        x = float(rho) * 100
        y = float(theta) * 180 / (math.pi)
        outfile.write("G1 X{:0.03f} Y{:0.03f}\n".format(x, y))          

    # We just moved each motor a bunch. A whole lot.
    # When we start the next file, we don't want it to unroll
    # So we will make the current coordinate something that is small, but the same.

    outfile.write("G92 X{:0.03f} Y{:0.03f} ; Reset the coordinates\n".format(xmod, ymod))


It is now exporting the gcode in a nice converted form. There is only one issue I am trying to wrap my head around. Here is a picture of my current setup:

My X-axis is the full diameter, when it is homed (x=0) it is at the perimeter and when it is fully extended (x=100) it is again at the perimeter. the problem is that a rho value of 0 corresponds with the middle of the table in sandify as far as I can tell, but that converts to an x of 0, which is back at the perimeter. Am I making sense? Trying to wrap my brain around it, but it is late. I’ll hit it again tomorrow. Appreciate any guidance you have!


1 Like

Change that to:

x = 50.0 + float(rho) * 50.0

It may not matter, but get in the habit of adding the .0 on any numbers you want to have precise math on. In some case, leaving that off creates integers, and integer math drops anything after the decimal place. So also change the 180 to 180.0.

But the real story here is to just always start at 50 and scale the rho by 50. Hopefully 50 is close enough to the center. If not, you can adjust the two 50 values to get them right.

1 Like