This is a repl.it. it is just an easy way to run python code. If you don’t have another way to run it.
You can either just open the code and copy the main.py to run it somewhere else, or fork the project and use the browser to run it.
It opens a file sandify.thr
and outputs transformed.gcode
. in repl.it, it is all in the browser, so you have to upload a new thr file and download the gcode from that workspace. If you’re running it locally, those two files will be where you ran it.
I don’t know what your coding experience is, but I tried to keep it simple enough so anyone can read it. Obviously, if you’ve never seen python, there are details that won’t be clear.
import math
# Config
THETA_UNITS_PER_ROTATION = 6.0
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
outfile.write(line.replace('#',';'))
continue
else:
(theta, rho) = parts[0].split()
# Here, we're actually doing the math.
x = THETA_UNITS_PER_ROTATION * float(theta) / (2*math.pi)
y = float(rho)
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.
xmod = x % THETA_UNITS_PER_ROTATION
outfile.write("G92 X{:0.03f} ; Reset the coordinates\n".format(xmod))
IIRC, the thr file in there is a square that gets bigger and bigger.