Commits

iorodeo committed 081a027

Added peck drilling cycle. Added minimum overlap for rectangular pockets. Need
minimum due to lack of full coverage in the corners below an overlap of about
0.3.

  • Participants
  • Parent commits a8ebe95

Comments (0)

Files changed (2)

File py2gcode/cnc_pocket.py

             cornerMargin = 0.0
 
         # Check params
-        assert (overlap >= 0.0 and overlap < 1.0), 'overlap must >=0 and < 1'
+        checkRectPocketOverlap(overlap)
+        checkRectPocketOverlap(overlapFinish)
 
         # Get rectangular path parameters
         if self.param['direction'] == 'cw':
 
         # Check params
         assert toolDiam <= thickness, 'toolDiam too large for annulus thickness'
-        assert (overlap >= 0.0) and (overlap < 1.0), 'overlap must >=0 and < 1'
+        checkRectPocketOverlap(overlap)
+        checkRectPocketOverlap(overlapFinish)
 
         # Get sign for rectangular toolpaths based on direction 
         if self.param['direction'] == 'cw':
         self.addEndComment()
 
 
+# Utility functions
+# --------------------------------------------------------------------------------------
+def checkRectPocketOverlap(overlap): 
+    minOverlap = (1.0 - 1.0/math.sqrt(2.0))/1.0
+    assertMsg = ' overlap must be >= {0} and < 1.0'.format(minOverlap)
+    assert (overlap >= minOverlap  and overlap < 1.0), assertMsg 
+
 # ---------------------------------------------------------------------------------------
 if __name__ == '__main__':
 
                 'depth'         : 0.04,
                 'startZ'        : 0.0,
                 'safeZ'         : 0.5,
-                'overlap'       : 0.1,
-                'overlapFinish' : 0.2,
+                'overlap'       : 0.3,
+                'overlapFinish' : 0.5,
                 'maxCutDepth'   : 0.04,
                 'toolDiam'      : 0.25,
                 'cornerCut'     : False,
 
         pocket = RectPocketXY(param)
 
-    if 0:
+    if 1:
         param = {
                 'centerX'       : 0.0,
                 'centerY'       : 0.0,
                 'depth'         : 0.1,
                 'startZ'        : 0.0,
                 'safeZ'         : 0.5,
-                'overlap'       : 0.1,
-                'overlapFinish' : 0.1,
+                'overlap'       : 0.3,
+                'overlapFinish' : 0.6,
                 'maxCutDepth'   : 0.04,
                 'toolDiam'      : 0.2,
                 'cornerCut'     : False,
         pocket = RectAnnulusPocketXY(param)
 
 
-    if 1:
+    if 0:
         param = { 
                 'centerX'        : 0.0, 
                 'centerY'        : 0.0,

File py2gcode/gcode_cmd.py

 # Canned Cycles
 # -----------------------------------------------------------------------------
 
-class DrillCycle(GCodeCmd):
+class DrillCycleBase(GCodeCmd):
+
+    """ Base class for drilling cycles """
+
+    kwargsKeys =  ()
+    requiredKeys = ()
+
+    def __init__(self,*args, **kwargs):
+        super(DrillCycleBase,self).__init__()
+        kwargs = normalizeToKwargs(self.kwargsKeys,args,kwargs)
+        checkRequiredKwargs(self.requiredKeys,kwargs) 
+        self.params = kwargs
+
+    def getCmdList(self):
+        cmdList = super(DrillCycleBase,self).getCmdList()
+        for name in self.kwargsKeys:
+            value = self.params[name]
+            if value is not None:
+                if name != 'l':
+                    value = float(value)
+                else:
+                    value = int(value)
+                cmdList.append('{0}{1}'.format(name.upper(),value))
+        return cmdList
+
+
+class DrillCycle(DrillCycleBase):
 
     kwargsKeys =  ('x','y','z','r','l','p')
     requiredKeys = ('x','y','z','r')
         l = (optional) number of repetitions
         p = (optional) dwell time in secs 
         """
-        super(DrillCycle,self).__init__()
-        kwargs = normalizeToKwargs(self.kwargsKeys,args,kwargs)
-        for k in self.requiredKeys:
-            if kwargs[k] is None:
-                raise ValueError, 'missing value for parameter {0}'.format(k)
-        self.params = kwargs
+        super(DrillCycle,self).__init__(*args,**kwargs)
         if self.params['p'] is None:
             self.code = 'G81'
             self.commentStr = 'Drill cycle'
             self.code = 'G82'
             self.commentStr = 'Drill cycle w/ dwell'
 
-    def getCmdList(self):
-        cmdList = super(DrillCycle,self).getCmdList()
-        for name in self.kwargsKeys:
-            value = self.params[name]
-            if value is not None:
-                if name != 'l':
-                    value = float(value)
-                else:
-                    value = int(value)
-                cmdList.append('{0}{1}'.format(name.upper(),value))
-        return cmdList
-            
 
-class PeckDrillCycle(GCodeCmd):
+class PeckDrillCycle(DrillCycleBase):
 
-    def __init__(self):
-        pass
+    kwargsKeys =  ('x','y','z','r','l','q')
+    requiredKeys = ('x','y','z','r')
+
+    def __init__(self,*args,**kwargs):
+        """
+        x = drill x position
+        y = drill y position
+        z = drill z posiion (final)
+        r = feed start/restract z position
+        l = (optional) number of repetitions
+        q = increment along z axis (must be > 0) 
+        """
+        super(PeckDrillCycle,self).__init__(*args,**kwargs)
+        if self.params['q'] <= 0:
+            raise ValueError, 'increment q must be >= 0'
+        self.code = 'G83'
+        
 
 # Distance Mode 
 # -----------------------------------------------------------------------------
     kwargsDictNorm.update(kwargsDict)
     return kwargsDictNorm
 
+
+def checkRequiredKwargs(requiredKeys,kwargsDict): 
+    for k in requiredKeys: 
+        if kwargsDict[k] is None: 
+            raise ValueError, 'missing value for parameter {0}'.format(k)
+
+
 # -----------------------------------------------------------------------------
 if __name__ == '__main__':
 
 
     cmd = DrillCycle(math.pi,0,-1.0,0.1,None,1.0)
     print(cmd)
+
+    cmd = PeckDrillCycle(x=0,y=0,z=-0.5,r=0.1,q=0.1)
+    print(cmd)
     
     cmd = QuadraticBSplineXY(1.0,1.0,1.1,1.5)
     print(cmd)