Skip to content

Commit

Permalink
Updated centroid post
Browse files Browse the repository at this point in the history
  • Loading branch information
Schildkroet committed Jan 2, 2021
1 parent 50c3cbf commit ae76158
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/Mod/Path/PathScripts/post/centroid_post.py
Expand Up @@ -48,6 +48,7 @@
--show-editor, --no-show-editor ... pop up editor before writing output(--show-editor)
--feed-precision=1 ... number of digits of precision for feed rate. Default=1
--axis-precision=4 ... number of digits of precision for axis moves. Default=4
--inches ... Convert output for US imperial mode (G20)
'''
now = datetime.datetime.now()

Expand All @@ -65,8 +66,9 @@
LINENR = 100 # line number starting value

# These globals will be reflected in the Machine configuration of the project
UNITS = "G20" # G21 for metric, G20 for us standard
UNIT_FORMAT = 'mm/min'
UNITS = "G21" # G21 for metric, G20 for us standard
UNIT_FORMAT = 'mm'
UNIT_SPEED_FORMAT = 'mm/min'
MACHINE_NAME = "Centroid"
CORNER_MIN = {'x': -609.6, 'y': -152.4, 'z': 0} # use metric for internal units
CORNER_MAX = {'x': 609.6, 'y': 152.4, 'z': 304.8} # use metric for internal units
Expand Down Expand Up @@ -125,6 +127,9 @@ def processArguments(argstring):
global SHOW_EDITOR
global AXIS_PRECISION
global FEED_PRECISION
global UNIT_SPEED_FORMAT
global UNIT_FORMAT
global UNITS

for arg in argstring.split():
if arg == '--header':
Expand All @@ -147,6 +152,10 @@ def processArguments(argstring):
AXIS_PRECISION = arg.split('=')[1]
elif arg.split('=')[0] == '--feed-precision':
FEED_PRECISION = arg.split('=')[1]
elif arg == '--inches':
UNITS = 'G20'
UNIT_SPEED_FORMAT = 'in/min'
UNIT_FORMAT = 'in'


def export(objectslist, filename, argstring):
Expand All @@ -156,6 +165,7 @@ def export(objectslist, filename, argstring):
print(i.Name)
global UNITS
global UNIT_FORMAT
global UNIT_SPEED_FORMAT

print("postprocessing...")
gcode = ""
Expand All @@ -169,11 +179,7 @@ def export(objectslist, filename, argstring):
# Write the preamble
if OUTPUT_COMMENTS:
for item in objectslist:
if hasattr(item, "Proxy"):
itm_trgt = item.Proxy
else:
itm_trgt = item
if isinstance(itm_trgt, PathScripts.PathToolController.ToolController):
if hasattr(item, "Proxy") and isinstance(item.Proxy, PathScripts.PathToolController.ToolController):
gcode += ";T{}={}\n".format(item.ToolNumber, item.Name)
gcode += linenumber() + ";begin preamble\n"
for line in PREAMBLE.splitlines(True):
Expand Down Expand Up @@ -283,16 +289,17 @@ def parse(pathobj):
if c.Name not in ["G0", "G00"]: # centroid doesn't use rapid speeds
speed = Units.Quantity(c.Parameters['F'], FreeCAD.Units.Velocity)
commandlist.append(
param + format(float(speed.getValueAs(UNIT_FORMAT)), feed_precision_string))
param + format(float(speed.getValueAs(UNIT_SPEED_FORMAT)), feed_precision_string))
elif param == 'H':
commandlist.append(param + str(int(c.Parameters['H'])))
elif param == 'S':
commandlist.append(param + PostUtils.fmt(c.Parameters['S'], SPINDLE_DECIMALS, "G21"))
elif param == 'T':
commandlist.append(param + str(int(c.Parameters['T'])))
else:
pos = Units.Quantity(c.Parameters[param], FreeCAD.Units.Length)
commandlist.append(
param + format(c.Parameters[param], axis_precision_string))
param + format(float(pos.getValueAs(UNIT_FORMAT)), axis_precision_string))
outstr = str(commandlist)
outstr = outstr.replace('[', '')
outstr = outstr.replace(']', '')
Expand Down Expand Up @@ -328,4 +335,4 @@ def parse(pathobj):
return out


# print(__name__ + " gcode postprocessor loaded.")
print(__name__ + " gcode postprocessor loaded.")

0 comments on commit ae76158

Please sign in to comment.