It is supposed to be configurable by users who are able to set the value of constants but are not familiar with python programming itself. Since it makes a gcode program more readable and since older machines have very limited memory it seems sensible to reduce the number of commands and parameters, like e.g. suppress the units in the header and at every hop.
I have a couple of questions to the FreeCAD community:
- Is this the right place to discuss? If not could a moderator please move it. Perhaps it should be in the Install/Compile subforum?
- Is it desirable to have such a generic_post.py? If yes, is it sensible to put the configuration constants in a dedicated configuration file?
- Where should I put the code; should I post it here in the forum or send to some maintainer?
- And a concrete question concering the configuration (see below): Should I use a function to generate the header or should I use placeholders?
- I would like to discuss some portions of the implementation as well, should I do it here or is it merely annoying?
Code: Select all
#Explanation of the configuration.
#***************************************************************************
# user editable stuff here
MACHINE_NAME = 'Maho 600E'
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
UNITS = 'G21' # use metric units
# possible values:
# 'G20' for inches,
# 'G21' for metric units.
# a mapping to different GCodes is handled in the GCODE MAP below
UNITS_INCLUDED = False # do not include the units in the GCode program
# possible values:
# True if units should be included
# False if units should not be included
# usually the units to be used are defined in the machine constants and almost never change,
# so this can be set to False.
COMMENT = ''
# possible values:
# ';' centroid or sinumerik comment symbol,
# '' leave blank for bracketed comments style "(comment comment comment)"
# '...' any other symbol to start comments
# currently this can be only one symbol, if it should be a sequence of characters
# in PostUtils.py the line
# if len(commentsym)==1:
# should be changed to
# if len(commentsym)>1:
SHOW_EDITOR = True
# possible values:
# True before the file is written it is shown to the user for inspection
# False the file is written directly
LINENUMBERS = True
# possible values:
# True if linenumbers of the form N1 N2 ... should be included
# False linennumbers are suppressed
# if linenumbers are used, header and footer get numbered as well
STARTLINENR = 100 # first linenumber used
# possible values:
# any integer value >= 0
# to have the possibility to change some initial values directly at the CNC machine
# without renumbering the rest it is possible to start the numbering of the file with some value > 0
LINENUMBER_INCREMENT = 10
# possible values:
# any integer value > 0
# similar to STARTLINENR it is possible to leave gaps in the linenumbering of subsequent lines
MODAL = True
# possible values:
# True repeated GCodes in subsequent lines are suppressed, like in the following snippet
# G1 X10 Y20
# X10 Y30
# False repeated GCodes in subsequent lines are repeated in the GCode file
# G1 X10 Y20
# G1 X10 Y30
MODALPARAMS = ['X','Y','Z','S','F'] # suppress these parameters if they haven't changed
# possible values:
# any list of GCode parameters
# if a parameter doesn't change from one line to the next ( or even further) it is suppressed.
# Example:
# G1 X10 Y20
# G1 Y30
# If in addition MODAL is set to True, the generated GCode chages to
# G1 X10 Y20
# Y30
SWAP_G2_G3 = True # some machines have the sign of the X-axis swapped, so the behave like milling from the bottom
# possible values:
# True if left and right turns are to be swapped
# False don't swap
# this might be special with some maho machines or even with mine and might be changed in the machine constants as well
SWAP_Y_Z = True # machines with an angle milling head do not switch axes, so we do it here
# possible values:
# True if Y and Z values have to be swapped
# False do not swap
# For horizontal milling machines the Z-axis is horizontal (of course).
# If they have an angle milling head, they mill vertical, alas the Z-axis stays horizontal.
# With this parameter we can swap the output values of Y and Z.
# For commands G2 and G3 this means that J and K are swapped as well
ABSOLUTE_CIRCLE_CENTER = True
# possible values:
# True use absolute values for the circle center in commands G2, G3
# False values for I, J, K are given relative to the last point
USE_RADIUS_IF_POSSIBLE = True
# possible values:
# True if in commands G2 and G3 the usage of radius R is preferred
# False if in commands G2 and G3 we use always I and J
# When milling arcs there are two reasons to use the radius instead of the center:
# 1. the GCode program might be easier to understand
# 2. Some machines seem to have a different scheme for calculating / rounding the values of the center
# Thus it is possible that the machine complains, that the endpoint of the arc does not lie on the arc.
# Using the radius instead avoids this problem.
# The post processor takes care of the fact, that only angles <= 180 degrees can be used with R
# for larger angles the center is used independent of the setting of this constant
RADIUS_COMMENT = True
# possible values:
# True for better understanding the radius of an arc is included as a comment
# False no additional comment is included
# In case the comments are included they are always included with the bracketing syntax like '(R20.456)'
# and never with the comment symbol, because the radius might appear in the middle of a line.
GCODE_MAP = {'M1':'M0', 'G20':'G70', 'G21':'G71'} # cb: this could be used to swap G2/G3
# possible values:
# Comma separated list of values of the form 'sourceGCode':'targetGCode'
#
# Although the basic movement commands G0, G1, G2 seem to be used uniformly in different GCode dialects,
# this is not the case for all commands.
# E.g the Maho dialect uses G70 and G71 for the units inches vs. metric.
# The map {'M1':'M0', 'G20':'G70', 'G21':'G71'} maps the optional stop command M1 to M0, because my
# machine does not have the optional button on its panel
# in addition it maps inches G20 to G70 and metric G21 to G71
AXIS_DECIMALS = 3
# possible values:
# integer >= 0
FEED_DECIMALS = 2
# possible values:
# integer >= 0
SPINDLE_DECIMALS = 0
# possible values:
# integer >= 0
# The header is divided into two parts, one is dynamic, the other is a static GCode header.
# If the current selection and the current time should be included in the header,
# it has to be generated at execution time, and thus it cannot be held in constant values.
# The last linefeed should be ommitted, it is inserted automatically
# linenumbers are inserted automatically if LINENUMBERS is True
# if you don't want to use this header you have to provide a minimal function
# def mkHeader(selection):
# return ''
def mkHeader(selection):
# this is within a function, because otherwise filename and time don't change when changing the FreeCAD project
now = datetime.datetime.now()
originfile = FreeCAD.ActiveDocument.FileName
header = ""
header += "("+ selection[0].Description + " Output Time:" + str(now) + ")\n"
header += "(CAM file: " + originfile + ")\n"
header += "(Exported by FreeCAD)\n"
header += "(Post Processor: " + __name__ +")\n"
header += "(Target machine: " + MACHINE_NAME + ")"
return linenumberify(header)
GCODE_HEADER = "G40 G90" # do not terminate with a newline, it is inserted by linenumberify
#possible values:
# any sequence of GCode, multiple lines are welcome
# this constant header follows the text generated by the function mkheader
# linenumbers are inserted automatically if LINENUMBERS is True
GCODE_FOOTER = "M30" # do not terminate with a newline, it is inserted by linenumberify
#possible values:
# any sequence of GCode, multiple lines are welcome
# the footer is used to clean things up, reset modal commands and stop the machine
# linenumbers are inserted automatically if LINENUMBERS is True