fixes from IchGucksLive for drilling simulation. Tweaks to linuxcnc post
This commit is contained in:
committed by
Yorik van Havre
parent
0c54e0dc3a
commit
5bca294d16
@@ -21,8 +21,16 @@
|
||||
# * *
|
||||
# ***************************************************************************/
|
||||
from __future__ import print_function
|
||||
import FreeCAD
|
||||
from FreeCAD import Units
|
||||
import Path
|
||||
import argparse
|
||||
import datetime
|
||||
import shlex
|
||||
from PathScripts import PostUtils
|
||||
from PathScripts import PathUtils
|
||||
|
||||
TOOLTIP='''
|
||||
TOOLTIP = '''
|
||||
This is a postprocessor file for the Path workbench. It is used to
|
||||
take a pseudo-gcode fragment outputted by a Path object, and output
|
||||
real GCode suitable for a linuxcnc 3 axis mill. This postprocessor, once placed
|
||||
@@ -33,14 +41,6 @@ import linuxcnc_post
|
||||
linuxcnc_post.export(object,"/path/to/file.ncc","")
|
||||
'''
|
||||
|
||||
import FreeCAD
|
||||
from FreeCAD import Units
|
||||
import argparse
|
||||
import datetime
|
||||
import shlex
|
||||
from PathScripts import PostUtils
|
||||
from PathScripts import PathUtils
|
||||
|
||||
now = datetime.datetime.now()
|
||||
|
||||
parser = argparse.ArgumentParser(prog='linuxcnc', add_help=False)
|
||||
@@ -52,12 +52,14 @@ parser.add_argument('--line-numbers', action='store_true', help='prefix with lin
|
||||
parser.add_argument('--no-line-numbers', action='store_true', help='don\'t prefix with line numbers (default)')
|
||||
parser.add_argument('--show-editor', action='store_true', help='pop up editor before writing output (default)')
|
||||
parser.add_argument('--no-show-editor', action='store_true', help='don\'t pop up editor before writing output')
|
||||
parser.add_argument('--precision', default='4', help='number of digits of precision, default=4')
|
||||
parser.add_argument('--precision', default='3', help='number of digits of precision, default=4')
|
||||
parser.add_argument('--preamble', help='set commands to be issued before the first command, default="G17\nG90"')
|
||||
parser.add_argument('--postamble', help='set commands to be issued after the last command, default="M05\nG17 G90\nM2"')
|
||||
parser.add_argument('--inches', action='store_true', help='Convert output for US imperial mode (G20)')
|
||||
parser.add_argument('--modal', action='store_true', help='Dont output the Same Gcommand Name USE Modal Mode')
|
||||
parser.add_argument('--no-doubles', action='store_true', help='Dont output the Same Axis Value Mode')
|
||||
|
||||
TOOLTIP_ARGS=parser.format_help()
|
||||
TOOLTIP_ARGS = parser.format_help()
|
||||
|
||||
# These globals set common customization preferences
|
||||
OUTPUT_COMMENTS = True
|
||||
@@ -65,6 +67,7 @@ OUTPUT_HEADER = True
|
||||
OUTPUT_LINE_NUMBERS = False
|
||||
SHOW_EDITOR = True
|
||||
MODAL = False # if true commands are suppressed if the same as previous line.
|
||||
OUTPUT_DOUBLES = True
|
||||
COMMAND_SPACE = " "
|
||||
LINENR = 100 # line number starting value
|
||||
|
||||
@@ -76,7 +79,7 @@ UNIT_FORMAT = 'mm'
|
||||
MACHINE_NAME = "LinuxCNC"
|
||||
CORNER_MIN = {'x': 0, 'y': 0, 'z': 0}
|
||||
CORNER_MAX = {'x': 500, 'y': 300, 'z': 300}
|
||||
PRECISION=4
|
||||
PRECISION = 3
|
||||
|
||||
# Preamble text will appear at the beginning of the GCODE output file.
|
||||
PREAMBLE = '''G17 G90
|
||||
@@ -103,6 +106,7 @@ TOOL_CHANGE = ''''''
|
||||
if open.__module__ == '__builtin__':
|
||||
pythonopen = open
|
||||
|
||||
|
||||
def processArguments(argstring):
|
||||
global OUTPUT_HEADER
|
||||
global OUTPUT_COMMENTS
|
||||
@@ -114,6 +118,8 @@ def processArguments(argstring):
|
||||
global UNITS
|
||||
global UNIT_SPEED_FORMAT
|
||||
global UNIT_FORMAT
|
||||
global MODAL
|
||||
global OUTPUT_DOUBLES
|
||||
|
||||
try:
|
||||
args = parser.parse_args(shlex.split(argstring))
|
||||
@@ -143,12 +149,18 @@ def processArguments(argstring):
|
||||
UNITS = 'G20'
|
||||
UNIT_SPEED_FORMAT = 'in/min'
|
||||
UNIT_FORMAT = 'in'
|
||||
PRECISION = 4
|
||||
if args.modal:
|
||||
MODAL = True
|
||||
if args.no_doubles:
|
||||
OUTPUT_DOUBLES = False
|
||||
|
||||
except:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def export(objectslist, filename, argstring):
|
||||
if not processArguments(argstring):
|
||||
return None
|
||||
@@ -183,17 +195,16 @@ def export(objectslist, filename, argstring):
|
||||
|
||||
myMachine = 'not set'
|
||||
|
||||
if hasattr(job,"MachineName"):
|
||||
if hasattr(job, "MachineName"):
|
||||
myMachine = job.MachineName
|
||||
|
||||
if hasattr(job, "MachineUnits"):
|
||||
if job.MachineUnits == "Metric":
|
||||
UNITS = "G21"
|
||||
UNIT_SPEED_FORMAT = 'mm/min'
|
||||
|
||||
UNITS = "G21"
|
||||
UNIT_SPEED_FORMAT = 'mm/min'
|
||||
else:
|
||||
UNITS = "G20"
|
||||
UNIT_SPEED_FORMAT = 'in/min'
|
||||
UNITS = "G20"
|
||||
UNIT_SPEED_FORMAT = 'in/min'
|
||||
|
||||
# do the pre_op
|
||||
if OUTPUT_COMMENTS:
|
||||
@@ -245,16 +256,24 @@ def linenumber():
|
||||
return "N" + str(LINENR) + " "
|
||||
return ""
|
||||
|
||||
|
||||
def parse(pathobj):
|
||||
global PRECISION
|
||||
global MODAL
|
||||
global OUTPUT_DOUBLES
|
||||
|
||||
out = ""
|
||||
lastcommand = None
|
||||
precision_string = '.' + str(PRECISION) +'f'
|
||||
precision_string = '.' + str(PRECISION) + 'f'
|
||||
|
||||
# params = ['X','Y','Z','A','B','I','J','K','F','S'] #This list control
|
||||
# the order of parameters
|
||||
# linuxcnc doesn't want K properties on XY plane Arcs need work.
|
||||
params = ['X', 'Y', 'Z', 'A', 'B', 'I', 'J', 'F', 'S', 'T', 'Q', 'R', 'L', 'H']
|
||||
params = ['X', 'Y', 'Z', 'A', 'B', 'C', 'I', 'J', 'F', 'S', 'T', 'Q', 'R', 'L', 'H', 'D', 'P']
|
||||
# keep track for no doubles
|
||||
currLocation = {}
|
||||
firstmove = Path.Command("G0", {"X": -1, "Y": -1, "Z": -1, "F": -1})
|
||||
currLocation.update(firstmove.Parameters)
|
||||
|
||||
if hasattr(pathobj, "Group"): # We have a compound or project.
|
||||
# if OUTPUT_COMMENTS:
|
||||
@@ -284,22 +303,31 @@ def parse(pathobj):
|
||||
# Now add the remaining parameters in order
|
||||
for param in params:
|
||||
if param in c.Parameters:
|
||||
if param == 'F':
|
||||
if c.Name not in ["G0", "G00"]: #linuxcnc doesn't use rapid speeds
|
||||
if param == 'F' and (currLocation[param] == c.Parameters[param] and OUTPUT_DOUBLES):
|
||||
if c.Name not in ["G0", "G00"]: # linuxcnc doesn't use rapid speeds
|
||||
speed = Units.Quantity(c.Parameters['F'], FreeCAD.Units.Velocity)
|
||||
outstring.append(
|
||||
param + format(float(speed.getValueAs(UNIT_SPEED_FORMAT)), precision_string) )
|
||||
param + format(float(speed.getValueAs(UNIT_SPEED_FORMAT)), precision_string))
|
||||
elif param == 'T':
|
||||
outstring.append(param + str(int(c.Parameters['T'])))
|
||||
elif param == 'H':
|
||||
outstring.append(param + str(int(c.Parameters['H'])))
|
||||
elif param == 'D':
|
||||
outstring.append(param + str(int(c.Parameters['D'])))
|
||||
elif param == 'S':
|
||||
outstring.append(param + str(int(c.Parameters['S'])))
|
||||
else:
|
||||
pos = Units.Quantity(c.Parameters[param], FreeCAD.Units.Length)
|
||||
outstring.append(
|
||||
param + format(float(pos.getValueAs(UNIT_FORMAT)), precision_string) )
|
||||
#param + format(c.Parameters[param], precision_string))
|
||||
|
||||
if (not OUTPUT_DOUBLES) and (param in currLocation) and (currLocation[param] == c.Parameters[param]):
|
||||
continue
|
||||
else:
|
||||
pos = Units.Quantity(c.Parameters[param], FreeCAD.Units.Length)
|
||||
outstring.append(
|
||||
param + format(float(pos.getValueAs(UNIT_FORMAT)), precision_string))
|
||||
# param + format(c.Parameters[param], precision_string))
|
||||
|
||||
# store the latest command
|
||||
lastcommand = command
|
||||
currLocation.update(c.Parameters)
|
||||
|
||||
# Check for Tool Change:
|
||||
if command == 'M6':
|
||||
|
||||
Reference in New Issue
Block a user