Skip to content

Commit

Permalink
fixes fragmuffin#21 adding Group 9 for can cycles
Browse files Browse the repository at this point in the history
  • Loading branch information
swinman committed Jul 26, 2019
1 parent d1307fa commit 5d82ec9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/pygcode/dialects/linuxcnc.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def CLASS_NUMBER(value):
def CLEAN_NUMBER(v):
if isinstance(v, int):
return str(v)
fstr = "{0:g}".format(round(v, 3))
fstr = "{0:g}".format(round(v, 3)) # FIXME bad practice for inches
if '.' not in fstr:
return fstr + '.'
return fstr
Expand Down
52 changes: 27 additions & 25 deletions src/pygcode/gcodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,21 @@
#
# There are 15 groups:
# ref: http://linuxcnc.org/docs/html/gcode/overview.html#_modal_groups
# ref: https://www.haascnc.com/content/dam/haascnc/en/service/manual/operator/english---mill-ngc---operator's-manual---2017.pdf
#
# Table 5. G-Code Modal Groups
# MODAL GROUP MEANING MEMBER WORDS
# Non-modal codes (Group 0) G4, G10 G28, G30, G53, G92, G92.1, G92.2, G92.3,
# Motion (Group 1) G0, G1, G2, G3, G33, G38.x, G73, G76, G80, G81
# G82, G83, G84, G85, G86, G87, G88,G89
# Motion (Group 1) G0, G1, G2, G3, G33, G38.x,
# Plane selection (Group 2) G17, G18, G19, G17.1, G18.1, G19.1
# Distance Mode (Group 3) G90, G91
# Arc IJK Distance Mode (Group 4) G90.1, G91.1
# Feed Rate Mode (Group 5) G93, G94, G95
# Units (Group 6) G20, G21
# Cutter Diameter Compensation (Group 7) G40, G41, G42, G41.1, G42.1
# Tool Length Offset (Group 8) G43, G43.1, G49
# Can Cycles (Group 9) G73, G76, G80, G81, G82, G83,
# G84, G85, G86, G87, G88, G89
# Canned Cycles Return Mode (Group 10) G98, G99
# Coordinate System (Group 12) G54, G55, G56, G57, G58, G59,
# G59.1, G59.2, G59.3
Expand All @@ -81,6 +83,7 @@
'units': 6,
'cutter_diameter_comp': 7,
'tool_length_offset': 8,
'canned_cycle': 9,
'canned_cycles_return': 10,
'coordinate_system': 12,
'control_mode': 13,
Expand Down Expand Up @@ -393,7 +396,6 @@ def name(self):
# G38.2 - G38.5 Straight Probe
# G33 K Spindle Synchronized Motion
# G33.1 K Rigid Tapping
# G80 Cancel Canned Cycle

class GCodeMotion(GCode):
param_letters = set('XYZABCUVW')
Expand Down Expand Up @@ -509,21 +511,6 @@ class GCodeRigidTapping(GCodeMotion):
word_key = Word('G', 33.1)


class GCodeCancelCannedCycle(GCodeMotion):
"""G80: Cancel Canned Cycle"""
word_key = Word('G', 80)
# Modal Group
# Technically G80 belongs to the motion modal group, however it's often
# expressed in the same line as another motion command.
# This is alowed, but executed just prior to any other motion command
# eg: G00 G80
# will leave the machine in rapid motion mode
# Just running G80 will leave machine with no motion mode.
modal_group = None
exec_order = 241

def WRONG_process(self, machine):
machine.mode.motion = None


# ======================= Canned Cycles =======================
Expand All @@ -536,10 +523,11 @@ def WRONG_process(self, machine):
# G85 R L (P) Boring Cycle, Feed Out
# G89 R L (P) Boring Cycle, Dwell, Feed Out
# G76 P Z I J R K Q H L E Threading Cycle
# G80 Cancel Canned Cycle

class GCodeCannedCycle(GCode):
param_letters = set('XYZUVW')
modal_group = MODAL_GROUP_MAP['motion']
modal_group = MODAL_GROUP_MAP['canned_cycle']
exec_order = 242

def _process(self, machine):
Expand All @@ -554,11 +542,12 @@ def _process(self, machine):
moveto_coords.pop(machine.mode.plane_selection.normal_axis, None)

# Process action 'L' times
loop_count = self.L
if (loop_count is None) or (loop_count <= 0):
loop_count = 1
for i in range(loop_count):
machine.move_to(**moveto_coords)
if hasattr(self, 'L'):
loop_count = self.L
if (loop_count is None) or (loop_count <= 0):
loop_count = 1
for i in range(loop_count):
machine.move_to(**moveto_coords)


class GCodeDrillingCycle(GCodeCannedCycle):
Expand All @@ -577,7 +566,7 @@ class GCodeDrillingCycleDwell(GCodeCannedCycle):

class GCodeDrillingCyclePeck(GCodeCannedCycle):
"""G83: Drilling Cycle, Peck"""
param_letters = GCodeCannedCycle.param_letters | set('RLQ')
param_letters = GCodeCannedCycle.param_letters | set('RLQ') | set('IJK')
word_key = Word('G', 83)
modal_param_letters = GCodeCannedCycle.param_letters | set('RQ')

Expand Down Expand Up @@ -608,6 +597,19 @@ class GCodeThreadingCycle(GCodeCannedCycle):
param_letters = GCodeCannedCycle.param_letters | set('PZIJRKQHLE')
word_key = Word('G', 76)

class GCodeCancelCannedCycle(GCodeCannedCycle):
""" G80: Cancel Canned Cycle """
param_letters = set()
word_key = Word('G', 80)
# Modal Group
# Technically G80 belongs to the motion modal group, however it's often
# expressed in the same line as another motion command.
# This is alowed, but executed just prior to any other motion command
# eg: G00 G80
# will leave the machine in rapid motion mode
# Just running G80 will leave machine with no motion mode.
exec_order = 241


# ======================= Distance Mode =======================
# CODE PARAMETERS DESCRIPTION
Expand Down
8 changes: 8 additions & 0 deletions src/pygcode/machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,14 @@ class Mode(object):
# > $G
# > [GC:G0 G54 G17 G21 G90 G94 M5 M9 T0 F0 S0]
# ref: https://github.com/gnea/grbl/wiki/Grbl-v1.1-Commands#g---view-gcode-parser-state
# NOTE : there is no default mode for some machines (eg haas), so if the
# previous program leaves the machine in G91 it will remain in G91 at the
# beginning of the next program.. it is good practice to start programs
# with a few "safe startup" blocks for example
# G21 ( metric )
# G0 G17 G40 G49 G80 G90
# G54 ( set wcs )

default_mode = '''
G0 (movement: rapid)
G17 (plane_selection: X/Y plane)
Expand Down

0 comments on commit 5d82ec9

Please sign in to comment.