Просмотр исходного кода

- fixed postprocessor files to work with toolchange_xy parameter value = None (no values in Edit - Preferences fields) - actual fix
- fixed Tcl commands CncJob and DrillCncJob to work with toolchange

Marius Stanciu 7 лет назад
Родитель
Сommit
4441e40042

+ 1 - 0
FlatCAMObj.py

@@ -1678,6 +1678,7 @@ class FlatCAMExcellon(FlatCAMObj, Excellon):
                                                    drillz=self.options['drillz'],
                                                    drillz=self.options['drillz'],
                                                    toolchange=self.options["toolchange"],
                                                    toolchange=self.options["toolchange"],
                                                    toolchangez=self.options["toolchangez"],
                                                    toolchangez=self.options["toolchangez"],
+                                                   toolchangexy=self.options["toolchangexy"],
                                                    startz=self.options["startz"],
                                                    startz=self.options["startz"],
                                                    endz=self.options["endz"],
                                                    endz=self.options["endz"],
                                                    excellon_optimization_type=self.options["optimization_type"])
                                                    excellon_optimization_type=self.options["optimization_type"])

+ 1 - 0
README.md

@@ -20,6 +20,7 @@ CAD program, and create G-Code for Isolation routing.
 - fixed unit conversion functions in case the toolchange_xy parameter is None
 - fixed unit conversion functions in case the toolchange_xy parameter is None
 - more fixes in camlib.CNCJob regarding usage of toolchange (in case it is None)
 - more fixes in camlib.CNCJob regarding usage of toolchange (in case it is None)
 - fixed postprocessor files to work with toolchange_xy parameter value = None (no values in Edit - Preferences fields)
 - fixed postprocessor files to work with toolchange_xy parameter value = None (no values in Edit - Preferences fields)
+- fixed Tcl commands CncJob and DrillCncJob to work with toolchange
 
 
 29.01.2019
 29.01.2019
 
 

+ 5 - 2
camlib.py

@@ -5167,12 +5167,15 @@ class CNCjob(Geometry):
         self.pp_geometry = self.app.postprocessors[self.pp_geometry_name]
         self.pp_geometry = self.app.postprocessors[self.pp_geometry_name]
         p = self.pp_geometry
         p = self.pp_geometry
 
 
+        self.oldx = 0.0
+        self.oldy = 0.0
+
         self.gcode = self.doformat(p.start_code)
         self.gcode = self.doformat(p.start_code)
 
 
         self.gcode += self.doformat(p.feedrate_code)        # sets the feed rate
         self.gcode += self.doformat(p.feedrate_code)        # sets the feed rate
 
 
-        self.gcode += self.doformat(p.lift_code, x=0, y=0)  # Move (up) to travel height
-        self.gcode += self.doformat(p.startz_code, x=0, y=0)
+        self.gcode += self.doformat(p.lift_code, x=self.oldx , y=self.oldy )  # Move (up) to travel height
+        self.gcode += self.doformat(p.startz_code, x=self.oldx , y=self.oldy )
 
 
         if toolchange:
         if toolchange:
             # if "line_xyz" in self.pp_geometry_name:
             # if "line_xyz" in self.pp_geometry_name:

+ 32 - 9
postprocessors/default.py

@@ -88,22 +88,47 @@ class default(FlatCAMPostProc):
                 if i[0] == p.tool:
                 if i[0] == p.tool:
                     no_drills = i[2]
                     no_drills = i[2]
 
 
-            gcode = """G00 Z{toolchangez}
+            if toolchangexy is not None:
+                gcode = """G00 Z{toolchangez}
+G00 X{toolchangex} Y{toolchangey}                
 T{tool}
 T{tool}
 M5
 M5
 M6
 M6
 (MSG, Change to Tool Dia = {toolC}, Total drills for tool T{tool} = {t_drills})
 (MSG, Change to Tool Dia = {toolC}, Total drills for tool T{tool} = {t_drills})
-M0""".format(toolchangez=self.coordinate_format%(p.coords_decimals, toolchangez),
+M0""".format(toolchangex=self.coordinate_format % (p.coords_decimals, toolchangex),
+             toolchangey=self.coordinate_format % (p.coords_decimals, toolchangey),
+             toolchangez=self.coordinate_format % (p.coords_decimals, toolchangez),
+             tool=int(p.tool),
+             t_drills=no_drills,
+             toolC=toolC_formatted)
+            else:
+                gcode = """G00 Z{toolchangez}
+T{tool}
+M5
+M6
+(MSG, Change to Tool Dia = {toolC}, Total drills for tool T{tool} = {t_drills})
+M0""".format(toolchangez=self.coordinate_format % (p.coords_decimals, toolchangez),
              tool=int(p.tool),
              tool=int(p.tool),
              t_drills=no_drills,
              t_drills=no_drills,
              toolC=toolC_formatted)
              toolC=toolC_formatted)
 
 
-            if toolchangexy is not None:
-                gcode += ('\n' + 'G00 X{toolchangex} Y{toolchangey}'.format(toolchangex=toolchangex,
-                                                                            toolchangey=toolchangey))
             return gcode
             return gcode
+
         else:
         else:
-            gcode = """G00 Z{toolchangez}
+            if toolchangexy is not None:
+                gcode = """G00 Z{toolchangez}
+G00 X{toolchangex} Y{toolchangey}
+T{tool}
+M5
+M6    
+(MSG, Change to Tool Dia = {toolC})
+M0""".format(toolchangex=self.coordinate_format % (p.coords_decimals, toolchangex),
+             toolchangey=self.coordinate_format % (p.coords_decimals, toolchangey),
+             toolchangez=self.coordinate_format % (p.coords_decimals, toolchangez),
+             tool=int(p.tool),
+             toolC=toolC_formatted)
+            else:
+                gcode = """G00 Z{toolchangez}
 T{tool}
 T{tool}
 M5
 M5
 M6    
 M6    
@@ -111,9 +136,7 @@ M6
 M0""".format(toolchangez=self.coordinate_format%(p.coords_decimals, toolchangez),
 M0""".format(toolchangez=self.coordinate_format%(p.coords_decimals, toolchangez),
              tool=int(p.tool),
              tool=int(p.tool),
              toolC=toolC_formatted)
              toolC=toolC_formatted)
-            if toolchangexy is not None:
-                gcode += ('\n' + 'G00 X{toolchangex} Y{toolchangey}'.format(toolchangex=toolchangex,
-                                                                            toolchangey=toolchangey))
+
             return gcode
             return gcode
 
 
     def up_to_zero_code(self, p):
     def up_to_zero_code(self, p):

+ 47 - 24
postprocessors/grbl_11.py

@@ -72,6 +72,8 @@ class grbl_11(FlatCAMPostProc):
             toolchangex = toolchangexy[0]
             toolchangex = toolchangexy[0]
             toolchangey = toolchangexy[1]
             toolchangey = toolchangexy[1]
 
 
+        no_drills = 1
+
         if int(p.tool) == 1 and p.startz is not None:
         if int(p.tool) == 1 and p.startz is not None:
             toolchangez = p.startz
             toolchangez = p.startz
 
 
@@ -80,39 +82,60 @@ class grbl_11(FlatCAMPostProc):
         else:
         else:
             toolC_formatted = format(p.toolC, '.4f')
             toolC_formatted = format(p.toolC, '.4f')
 
 
-        no_drills = 1
-
         if str(p['options']['type']) == 'Excellon':
         if str(p['options']['type']) == 'Excellon':
             for i in p['options']['Tools_in_use']:
             for i in p['options']['Tools_in_use']:
                 if i[0] == p.tool:
                 if i[0] == p.tool:
                     no_drills = i[2]
                     no_drills = i[2]
 
 
-            gcode = """G00 Z{toolchangez}
-        T{tool}
-        M5
-        M6
-        (MSG, Change to Tool Dia = {toolC}, Total drills for tool T{tool} = {t_drills})
-        M0""".format(toolchangez=self.coordinate_format % (p.coords_decimals, toolchangez),
-                     tool=int(p.tool),
-                     t_drills=no_drills,
-                     toolC=toolC_formatted)
-
             if toolchangexy is not None:
             if toolchangexy is not None:
-                gcode += ('\n' + 'G00 X{toolchangex} Y{toolchangey}'.format(toolchangex=toolchangex,
-                                                                            toolchangey=toolchangey))
+                gcode = """G00 Z{toolchangez}
+G00 X{toolchangex} Y{toolchangey}                
+T{tool}
+M5
+M6
+(MSG, Change to Tool Dia = {toolC}, Total drills for tool T{tool} = {t_drills})
+M0""".format(toolchangex=self.coordinate_format % (p.coords_decimals, toolchangex),
+             toolchangey=self.coordinate_format % (p.coords_decimals, toolchangey),
+             toolchangez=self.coordinate_format % (p.coords_decimals, toolchangez),
+             tool=int(p.tool),
+             t_drills=no_drills,
+             toolC=toolC_formatted)
+            else:
+                gcode = """G00 Z{toolchangez}
+T{tool}
+M5
+M6
+(MSG, Change to Tool Dia = {toolC}, Total drills for tool T{tool} = {t_drills})
+M0""".format(toolchangez=self.coordinate_format % (p.coords_decimals, toolchangez),
+             tool=int(p.tool),
+             t_drills=no_drills,
+             toolC=toolC_formatted)
+
             return gcode
             return gcode
+
         else:
         else:
-            gcode = """G00 Z{toolchangez}
-        T{tool}
-        M5
-        M6    
-        (MSG, Change to Tool Dia = {toolC})
-        M0""".format(toolchangez=self.coordinate_format % (p.coords_decimals, toolchangez),
-                     tool=int(p.tool),
-                     toolC=toolC_formatted)
             if toolchangexy is not None:
             if toolchangexy is not None:
-                gcode += ('\n' + 'G00 X{toolchangex} Y{toolchangey}'.format(toolchangex=toolchangex,
-                                                                            toolchangey=toolchangey))
+                gcode = """G00 Z{toolchangez}
+G00 X{toolchangex} Y{toolchangey}
+T{tool}
+M5
+M6    
+(MSG, Change to Tool Dia = {toolC})
+M0""".format(toolchangex=self.coordinate_format % (p.coords_decimals, toolchangex),
+             toolchangey=self.coordinate_format % (p.coords_decimals, toolchangey),
+             toolchangez=self.coordinate_format % (p.coords_decimals, toolchangez),
+             tool=int(p.tool),
+             toolC=toolC_formatted)
+            else:
+                gcode = """G00 Z{toolchangez}
+T{tool}
+M5
+M6    
+(MSG, Change to Tool Dia = {toolC})
+M0""".format(toolchangez=self.coordinate_format%(p.coords_decimals, toolchangez),
+             tool=int(p.tool),
+             toolC=toolC_formatted)
+
             return gcode
             return gcode
 
 
     def up_to_zero_code(self, p):
     def up_to_zero_code(self, p):

+ 6 - 2
postprocessors/line_xyz.py

@@ -80,8 +80,12 @@ class line_xyz(FlatCAMPostProc):
             toolchangex = toolchangexy[0]
             toolchangex = toolchangexy[0]
             toolchangey = toolchangexy[1]
             toolchangey = toolchangexy[1]
         else:
         else:
-            toolchangex = p.x
-            toolchangey = p.y
+            if str(p['options']['type']) == 'Excellon':
+                toolchangex = p.oldx
+                toolchangey = p.oldy
+            else:
+                toolchangex = p.x
+                toolchangey = p.y
 
 
         no_drills = 1
         no_drills = 1
 
 

+ 46 - 8
postprocessors/manual_toolchange.py

@@ -64,14 +64,15 @@ class manual_toolchange(FlatCAMPostProc):
 
 
     def toolchange_code(self, p):
     def toolchange_code(self, p):
         toolchangez = p.toolchangez
         toolchangez = p.toolchangez
-        toolchangexy = p['toolchange_xy']
+        toolchangexy = p.toolchange_xy
+        gcode = ''
 
 
         if toolchangexy is not None:
         if toolchangexy is not None:
             toolchangex = toolchangexy[0]
             toolchangex = toolchangexy[0]
             toolchangey = toolchangexy[1]
             toolchangey = toolchangexy[1]
-        else:
-            toolchangex = p.oldx
-            toolchangey = p.oldy
+        # else:
+        #     toolchangex = p.oldx
+        #     toolchangey = p.oldy
 
 
         no_drills = 1
         no_drills = 1
 
 
@@ -87,10 +88,12 @@ class manual_toolchange(FlatCAMPostProc):
             for i in p['options']['Tools_in_use']:
             for i in p['options']['Tools_in_use']:
                 if i[0] == p.tool:
                 if i[0] == p.tool:
                     no_drills = i[2]
                     no_drills = i[2]
-            return """G00 Z{toolchangez}
+
+            if toolchangexy is not None:
+                gcode =  """G00 Z{toolchangez}
 T{tool}
 T{tool}
-M5
-G00 X{toolchangex} Y{toolchangey}    
+M5   
+G00 X{toolchangex} Y{toolchangey} 
 (MSG, Change to Tool Dia = {toolC}, Total drills for current tool = {t_drills})
 (MSG, Change to Tool Dia = {toolC}, Total drills for current tool = {t_drills})
 M0
 M0
 G01 Z0
 G01 Z0
@@ -103,8 +106,28 @@ M0
            tool=int(p.tool),
            tool=int(p.tool),
            t_drills=no_drills,
            t_drills=no_drills,
            toolC=toolC_formatted)
            toolC=toolC_formatted)
+
+            else:
+                gcode =  """G00 Z{toolchangez}
+T{tool}
+M5  
+(MSG, Change to Tool Dia = {toolC}, Total drills for current tool = {t_drills})
+M0
+G01 Z0
+M0
+G00 Z{toolchangez}
+M0
+""".format(
+           toolchangez=self.coordinate_format%(p.coords_decimals, toolchangez),
+           tool=int(p.tool),
+           t_drills=no_drills,
+           toolC=toolC_formatted)
+
+            return gcode
+
         else:
         else:
-            return """G00 Z{toolchangez}
+            if toolchangexy is not None:
+                gcode =  """G00 Z{toolchangez}
 T{tool}
 T{tool}
 M5
 M5
 G00 X{toolchangex}Y{toolchangey}    
 G00 X{toolchangex}Y{toolchangey}    
@@ -119,6 +142,21 @@ M0
            toolchangez=self.coordinate_format%(p.coords_decimals, toolchangez),
            toolchangez=self.coordinate_format%(p.coords_decimals, toolchangez),
            tool=int(p.tool),
            tool=int(p.tool),
            toolC=toolC_formatted)
            toolC=toolC_formatted)
+            else:
+                                gcode =  """G00 Z{toolchangez}
+T{tool}
+M5  
+(MSG, Change to Tool Dia = {toolC})
+M0
+G01 Z0
+M0
+G00 Z{toolchangez}
+M0
+""".format(toolchangez=self.coordinate_format%(p.coords_decimals, toolchangez),
+           tool=int(p.tool),
+           toolC=toolC_formatted)
+
+            return gcode
 
 
     def up_to_zero_code(self, p):
     def up_to_zero_code(self, p):
         return 'G01 Z0'
         return 'G01 Z0'

+ 55 - 11
postprocessors/marlin.py

@@ -66,6 +66,13 @@ class marlin(FlatCAMPostProc):
 
 
     def toolchange_code(self, p):
     def toolchange_code(self, p):
         toolchangez = p.toolchangez
         toolchangez = p.toolchangez
+        toolchangexy = p.toolchange_xy
+        gcode = ''
+
+        if toolchangexy is not None:
+            toolchangex = toolchangexy[0]
+            toolchangey = toolchangexy[1]
+
         no_drills = 1
         no_drills = 1
 
 
         if int(p.tool) == 1 and p.startz is not None:
         if int(p.tool) == 1 and p.startz is not None:
@@ -80,20 +87,57 @@ class marlin(FlatCAMPostProc):
             for i in p['options']['Tools_in_use']:
             for i in p['options']['Tools_in_use']:
                 if i[0] == p.tool:
                 if i[0] == p.tool:
                     no_drills = i[2]
                     no_drills = i[2]
-            return """G0 Z{toolchangez}
+
+            if toolchangexy is not None:
+                gcode = """G0 Z{toolchangez}
+G0 X{toolchangex} Y{toolchangey}                
+T{tool}
+M5
+M6
+(MSG, Change to Tool Dia = {toolC}, Total drills for tool T{tool} = {t_drills})
+M0""".format(toolchangex=self.coordinate_format % (p.coords_decimals, toolchangex),
+             toolchangey=self.coordinate_format % (p.coords_decimals, toolchangey),
+             toolchangez=self.coordinate_format % (p.coords_decimals, toolchangez),
+             tool=int(p.tool),
+             t_drills=no_drills,
+             toolC=toolC_formatted)
+            else:
+                gcode = """G0 Z{toolchangez}
+T{tool}
 M5
 M5
-M0 Change to Tool Dia = {toolC}, Total drills for current tool = {t_drills}
-""".format(toolchangez=self.coordinate_format%(p.coords_decimals, toolchangez),
-           tool=int(p.tool),
-           t_drills=no_drills,
-           toolC=toolC_formatted)
+M6
+(MSG, Change to Tool Dia = {toolC}, Total drills for tool T{tool} = {t_drills})
+M0""".format(toolchangez=self.coordinate_format % (p.coords_decimals, toolchangez),
+             tool=int(p.tool),
+             t_drills=no_drills,
+             toolC=toolC_formatted)
+
+            return gcode
+
         else:
         else:
-            return """G0 Z{toolchangez}
+            if toolchangexy is not None:
+                gcode = """G0 Z{toolchangez}
+G0 X{toolchangex} Y{toolchangey}
+T{tool}
 M5
 M5
-M0 Change to Tool Dia = {toolC}
-""".format(toolchangez=self.coordinate_format%(p.coords_decimals, toolchangez),
-           tool=int(p.tool),
-           toolC=toolC_formatted)
+M6    
+(MSG, Change to Tool Dia = {toolC})
+M0""".format(toolchangex=self.coordinate_format % (p.coords_decimals, toolchangex),
+             toolchangey=self.coordinate_format % (p.coords_decimals, toolchangey),
+             toolchangez=self.coordinate_format % (p.coords_decimals, toolchangez),
+             tool=int(p.tool),
+             toolC=toolC_formatted)
+            else:
+                gcode = """G0 Z{toolchangez}
+T{tool}
+M5
+M6    
+(MSG, Change to Tool Dia = {toolC})
+M0""".format(toolchangez=self.coordinate_format%(p.coords_decimals, toolchangez),
+             tool=int(p.tool),
+             toolC=toolC_formatted)
+
+            return gcode
 
 
     def up_to_zero_code(self, p):
     def up_to_zero_code(self, p):
         return 'G1 Z0' + " " + self.feedrate_code(p)
         return 'G1 Z0' + " " + self.feedrate_code(p)

+ 7 - 0
tclCommands/TclCommandCncjob.py

@@ -55,6 +55,9 @@ class TclCommandCncjob(TclCommandSignaled):
             ('multidepth', 'Use or not multidepth cnccut. (True or False)'),
             ('multidepth', 'Use or not multidepth cnccut. (True or False)'),
             ('depthperpass', 'Height of one layer for multidepth.'),
             ('depthperpass', 'Height of one layer for multidepth.'),
             ('extracut', 'Use or not an extra cnccut over the first point in path,in the job end (example: True)'),
             ('extracut', 'Use or not an extra cnccut over the first point in path,in the job end (example: True)'),
+            ('toolchange', 'Enable tool changes (example: True).'),
+            ('toolchangez', 'Z distance for toolchange (example: 30.0).'),
+            ('toolchangexy', 'X, Y coordonates for toolchange in format (x, y) (example: (2.0, 3.1) ).'),
             ('endz', 'Height where the last move will park.'),
             ('endz', 'Height where the last move will park.'),
             ('outname', 'Name of the resulting Geometry object.'),
             ('outname', 'Name of the resulting Geometry object.'),
             ('ppname_g', 'Name of the Geometry postprocessor. No quotes, case sensitive')
             ('ppname_g', 'Name of the Geometry postprocessor. No quotes, case sensitive')
@@ -96,6 +99,10 @@ class TclCommandCncjob(TclCommandSignaled):
         args["endz"]= args["endz"] if "endz" in args else obj.options["endz"]
         args["endz"]= args["endz"] if "endz" in args else obj.options["endz"]
         args["ppname_g"] = args["ppname_g"] if "ppname_g" in args else obj.options["ppname_g"]
         args["ppname_g"] = args["ppname_g"] if "ppname_g" in args else obj.options["ppname_g"]
 
 
+        args["toolchange"] = True if "toolchange" in args and args["toolchange"] == 1 else False
+        args["toolchangez"] = args["toolchangez"] if "toolchangez" in args else obj.options["toolchangez"]
+        args["toolchangexy"] = args["toolchangexy"] if "toolchangexy" in args else obj.options["toolchangexy"]
+
         del args['name']
         del args['name']
 
 
         # HACK !!! Should be solved elsewhere!!!
         # HACK !!! Should be solved elsewhere!!!

+ 5 - 1
tclCommands/TclCommandDrillcncjob.py

@@ -47,6 +47,7 @@ class TclCommandDrillcncjob(TclCommandSignaled):
             ('spindlespeed', 'Speed of the spindle in rpm (example: 4000).'),
             ('spindlespeed', 'Speed of the spindle in rpm (example: 4000).'),
             ('toolchange', 'Enable tool changes (example: True).'),
             ('toolchange', 'Enable tool changes (example: True).'),
             ('toolchangez', 'Z distance for toolchange (example: 30.0).'),
             ('toolchangez', 'Z distance for toolchange (example: 30.0).'),
+            ('toolchangexy', 'X, Y coordonates for toolchange in format (x, y) (example: (2.0, 3.1) ).'),
             ('endz', 'Z distance at job end (example: 30.0).'),
             ('endz', 'Z distance at job end (example: 30.0).'),
             ('ppname_e', 'This is the Excellon postprocessor name: case_sensitive, no_quotes'),
             ('ppname_e', 'This is the Excellon postprocessor name: case_sensitive, no_quotes'),
             ('outname', 'Name of the resulting Geometry object.'),
             ('outname', 'Name of the resulting Geometry object.'),
@@ -93,13 +94,16 @@ class TclCommandDrillcncjob(TclCommandSignaled):
 
 
             toolchange = True if "toolchange" in args and args["toolchange"] == 1 else False
             toolchange = True if "toolchange" in args and args["toolchange"] == 1 else False
             toolchangez = args["toolchangez"] if "toolchangez" in args else obj.options["toolchangez"]
             toolchangez = args["toolchangez"] if "toolchangez" in args else obj.options["toolchangez"]
+            toolchangexy = args["toolchangexy"] if "toolchangexy" in args else obj.options["toolchangexy"]
 
 
             endz = args["endz"] if "endz" in args else obj.options["endz"]
             endz = args["endz"] if "endz" in args else obj.options["endz"]
 
 
             tools = args["tools"] if "tools" in args else 'all'
             tools = args["tools"] if "tools" in args else 'all'
             opt_type = args["opt_type"] if "opt_type" in args else 'B'
             opt_type = args["opt_type"] if "opt_type" in args else 'B'
 
 
-            job_obj.generate_from_excellon_by_tool(obj, tools, drillz=drillz, toolchangez=toolchangez, endz=endz,
+            job_obj.generate_from_excellon_by_tool(obj, tools, drillz=drillz, toolchangez=toolchangez,
+                                                   toolchangexy=toolchangexy,
+                                                   endz=endz,
                                                    toolchange=toolchange, excellon_optimization_type=opt_type)
                                                    toolchange=toolchange, excellon_optimization_type=opt_type)
             job_obj.gcode_parse()
             job_obj.gcode_parse()
             job_obj.create_geometry()
             job_obj.create_geometry()