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

- fixed error when creating CNCJob due of having the annotations disabled from preferences but the plot2() function from camlib.CNCJob class still performed operations who yielded TypeError exceptions

Marius Stanciu 6 лет назад
Родитель
Сommit
9205dd61f8
5 измененных файлов с 90 добавлено и 25 удалено
  1. 1 1
      FlatCAMApp.py
  2. 8 8
      FlatCAMObj.py
  3. 2 0
      README.md
  4. 73 10
      camlib.py
  5. 6 6
      flatcamGUI/ObjectUI.py

+ 1 - 1
FlatCAMApp.py

@@ -824,7 +824,7 @@ class App(QtCore.QObject):
             "excellon_toolchangexy": "0.0, 0.0",
             "excellon_startz": None,
             "excellon_endz": 0.5,
-            "excellon_feedrate_rapid": 3.14961,
+            "excellon_feedrate_rapid": 31.4961,
             "excellon_z_pdepth": -0.02,
             "excellon_feedrate_probe": 3.14961,
             "excellon_f_plunge": False,

+ 8 - 8
FlatCAMObj.py

@@ -5521,11 +5521,11 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob):
                 self.ui.t_time_entry.setDisabled(True)
                 # if time is more than 1 then we have minutes, else we have seconds
                 if self.routing_time > 1:
-                    self.ui.t_time_entry.set_value('%.4f' % float(self.routing_time))
+                    self.ui.t_time_entry.set_value('%.4f' % math.ceil(float(self.routing_time)))
                     self.ui.units_time_label.setText('min')
                 else:
                     time_r = self.routing_time * 60
-                    self.ui.t_time_entry.set_value('%.4f' % float(time_r))
+                    self.ui.t_time_entry.set_value('%.4f' % math.ceil(float(time_r)))
                     self.ui.units_time_label.setText('sec')
                 self.ui.units_time_label.setDisabled(True)
         except AttributeError:
@@ -5985,6 +5985,12 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob):
 
         visible = visible if visible else self.options['plot']
 
+        if self.ui.annotation_cb.get_value() and self.ui.plot_cb.get_value():
+            self.text_col.enabled = True
+        else:
+            self.text_col.enabled = False
+        self.annotation.redraw()
+
         try:
             if self.multitool is False:  # single tool usage
                 self.plot2(tooldia=float(self.options["tooldia"]), obj=self, visible=visible, kind=kind)
@@ -5999,12 +6005,6 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob):
             self.shapes.clear(update=True)
             self.annotation.clear(update=True)
 
-        if self.ui.annotation_cb.get_value() and self.ui.plot_cb.get_value():
-            self.text_col.enabled = True
-        else:
-            self.text_col.enabled = False
-        self.annotation.redraw()
-
     def on_annotation_change(self):
         if self.ui.annotation_cb.get_value():
             self.text_col.enabled = True

+ 2 - 0
README.md

@@ -13,6 +13,8 @@ CAD program, and create G-Code for Isolation routing.
 
 - added estimated time of routing for the CNCJob and added travelled distance parameter for geometry, too
 - fixed error when creating CNCJob due of having the annotations disabled from preferences but the plot2() function from camlib.CNCJob class still performed operations who yielded TypeError exceptions
+- coded a more accurate way to estimate the job time in CNCJob, taking into consideration if there is a usage of multi depth which generate more passes
+- another fix (final one) for the Exception generated by the annotations set not to show in Preferences
 
 17.08.2019
 

+ 73 - 10
camlib.py

@@ -5290,7 +5290,10 @@ class CNCjob(Geometry):
             self.oldx = 0.0
             self.oldy = 0.0
 
-        measured_distance = 0
+        measured_distance = 0.0
+        measured_down_distance = 0.0
+        measured_up_to_zero_distance = 0.0
+        measured_lift_distance = 0.0
 
         current_platform = platform.architecture()[0]
         if current_platform == '64bit':
@@ -5387,8 +5390,16 @@ class CNCjob(Geometry):
 
                                 gcode += self.doformat(p.rapid_code, x=locx, y=locy)
                                 gcode += self.doformat(p.down_code, x=locx, y=locy)
+
+                                measured_down_distance += abs(self.z_cut) + abs(self.z_move)
+
                                 if self.f_retract is False:
                                     gcode += self.doformat(p.up_to_zero_code, x=locx, y=locy)
+                                    measured_up_to_zero_distance += abs(self.z_cut)
+                                    measured_lift_distance += abs(self.z_move)
+                                else:
+                                    measured_lift_distance += abs(self.z_cut) + abs(self.z_move)
+
                                 gcode += self.doformat(p.lift_code, x=locx, y=locy)
                                 measured_distance += abs(distance_euclidian(locx, locy, self.oldx, self.oldy))
                                 self.oldx = locx
@@ -5482,10 +5493,19 @@ class CNCjob(Geometry):
                             for k in node_list:
                                 locx = locations[k][0]
                                 locy = locations[k][1]
+
                                 gcode += self.doformat(p.rapid_code, x=locx, y=locy)
                                 gcode += self.doformat(p.down_code, x=locx, y=locy)
+
+                                measured_down_distance += abs(self.z_cut) + abs(self.z_move)
+
                                 if self.f_retract is False:
                                     gcode += self.doformat(p.up_to_zero_code, x=locx, y=locy)
+                                    measured_up_to_zero_distance += abs(self.z_cut)
+                                    measured_lift_distance += abs(self.z_move)
+                                else:
+                                    measured_lift_distance += abs(self.z_cut) + abs(self.z_move)
+
                                 gcode += self.doformat(p.lift_code, x=locx, y=locy)
                                 measured_distance += abs(distance_euclidian(locx, locy, self.oldx, self.oldy))
                                 self.oldx = locx
@@ -5542,8 +5562,16 @@ class CNCjob(Geometry):
                         for point in self.optimized_travelling_salesman(altPoints):
                             gcode += self.doformat(p.rapid_code, x=point[0], y=point[1])
                             gcode += self.doformat(p.down_code, x=point[0], y=point[1])
+
+                            measured_down_distance += abs(self.z_cut) + abs(self.z_move)
+
                             if self.f_retract is False:
                                 gcode += self.doformat(p.up_to_zero_code, x=point[0], y=point[1])
+                                measured_up_to_zero_distance += abs(self.z_cut)
+                                measured_lift_distance += abs(self.z_move)
+                            else:
+                                measured_lift_distance += abs(self.z_cut) + abs(self.z_move)
+
                             gcode += self.doformat(p.lift_code, x=point[0], y=point[1])
                             measured_distance += abs(distance_euclidian(point[0], point[1], self.oldx, self.oldy))
                             self.oldx = point[0]
@@ -5562,7 +5590,15 @@ class CNCjob(Geometry):
         log.debug("The total travel distance including travel to end position is: %s" %
                   str(measured_distance) + '\n')
         self.travel_distance = measured_distance
-        # self.routing_time = measured_distance / self.z_feedrate
+
+        # I use the value of self.feedrate_rapid for the feadrate in case of the measure_lift_distance and for
+        # traveled_time because it is not always possible to determine the feedrate that the CNC machine uses
+        # for G0 move (the fastest speed available to the CNC router). Although self.feedrate_rapids is used only with
+        # Marlin postprocessor and derivatives.
+        self.routing_time = (measured_down_distance + measured_up_to_zero_distance) / self.feedrate
+        lift_time = measured_lift_distance / self.feedrate_rapid
+        traveled_time = measured_distance / self.feedrate_rapid
+        self.routing_time += lift_time + traveled_time
 
         self.gcode = gcode
         return 'OK'
@@ -5766,16 +5802,28 @@ class CNCjob(Geometry):
 
                 # ---------- Single depth/pass --------
                 if not multidepth:
+                    # calculate the cut distance
+                    total_cut = total_cut + geo.length
+
                     self.gcode += self.create_gcode_single_pass(geo, extracut, tolerance)
 
                 # --------- Multi-pass ---------
                 else:
+                    # calculate the cut distance
+                    # due of the number of cuts (multi depth) it has to multiplied by the number of cuts
+                    nr_cuts = 0
+                    depth = abs(self.z_cut)
+                    while depth > 0:
+                        nr_cuts += 1
+                        depth -= float(self.z_depthpercut)
+
+                    total_cut += (geo.length * nr_cuts)
+
                     self.gcode += self.create_gcode_multi_pass(geo, extracut, tolerance,
                                                                postproc=p, current_point=current_pt)
 
                 # calculate the total distance
                 total_travel = total_travel + abs(distance(pt1=current_pt, pt2=pt))
-                total_cut = total_cut + geo.length
                 current_pt = geo.coords[-1]
 
                 pt, geo = storage.nearest(current_pt) # Next
@@ -5784,8 +5832,10 @@ class CNCjob(Geometry):
 
         log.debug("Finishing G-Code... %s paths traced." % path_count)
 
-        self.travel_distance = total_travel + total_cut
-        self.routing_time = total_cut / self.feedrate
+        # add move to end position
+        total_travel += abs(distance_euclidian(current_pt[0], current_pt[1], 0, 0))
+        self.travel_distance += total_travel + total_cut
+        self.routing_time += total_cut / self.feedrate
 
         # Finish
         self.gcode += self.doformat(p.spindle_stop_code)
@@ -6039,16 +6089,27 @@ class CNCjob(Geometry):
 
                 # ---------- Single depth/pass --------
                 if not multidepth:
+                    # calculate the cut distance
+                    total_cut += geo.length
                     self.gcode += self.create_gcode_single_pass(geo, extracut, tolerance)
 
                 # --------- Multi-pass ---------
                 else:
+                    # calculate the cut distance
+                    # due of the number of cuts (multi depth) it has to multiplied by the number of cuts
+                    nr_cuts = 0
+                    depth = abs(self.z_cut)
+                    while depth > 0:
+                        nr_cuts += 1
+                        depth -= float(self.z_depthpercut)
+
+                    total_cut += (geo.length * nr_cuts)
+
                     self.gcode += self.create_gcode_multi_pass(geo, extracut, tolerance,
                                                                postproc=p, current_point=current_pt)
 
-                # calculate the total distance
-                total_travel = total_travel + abs(distance(pt1=current_pt, pt2=pt))
-                total_cut = total_cut + geo.length
+                # calculate the travel distance
+                total_travel += abs(distance(pt1=current_pt, pt2=pt))
                 current_pt = geo.coords[-1]
 
                 pt, geo = storage.nearest(current_pt) # Next
@@ -6057,8 +6118,10 @@ class CNCjob(Geometry):
 
         log.debug("Finishing G-Code... %s paths traced." % path_count)
 
-        self.travel_distance = total_travel + total_cut
-        self.routing_time = total_cut / self.feedrate
+        # add move to end position
+        total_travel += abs(distance_euclidian(current_pt[0], current_pt[1], 0, 0))
+        self.travel_distance += total_travel + total_cut
+        self.routing_time += total_cut / self.feedrate
 
         # Finish
         self.gcode += self.doformat(p.spindle_stop_code)

+ 6 - 6
flatcamGUI/ObjectUI.py

@@ -1403,15 +1403,15 @@ class CNCObjectUI(ObjectUI):
         )
         self.units_label = QtWidgets.QLabel()
 
-        self.t_time_label = QtWidgets.QLabel(_("<b>Estimated time.:</b>"))
-        self.t_distance_label.setToolTip(
-            _("This is the estimated time to do the routing.\n"
-              "In current units.")
+        self.t_time_label = QtWidgets.QLabel(_("<b>Estimated time:</b>"))
+        self.t_time_label.setToolTip(
+            _("This is the estimated time to do the routing/drilling,\n"
+              "without the time spent in ToolChange events.")
         )
         self.t_time_entry = FCEntry()
         self.t_time_entry.setToolTip(
-            _("This is the estimated time to do the routing.\n"
-              "In current units.")
+            _("This is the estimated time to do the routing/drilling,\n"
+              "without the time spent in ToolChange events.")
         )
         self.units_time_label = QtWidgets.QLabel()