瀏覽代碼

Optimize prepare_kinematic_move_to

Scott Lahteine 9 年之前
父節點
當前提交
8e31640229
共有 1 個文件被更改,包括 41 次插入10 次删除
  1. 41
    10
      Marlin/Marlin_main.cpp

+ 41
- 10
Marlin/Marlin_main.cpp 查看文件

@@ -8043,28 +8043,59 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
8043 8043
    * small incremental moves for DELTA or SCARA.
8044 8044
    */
8045 8045
   inline bool prepare_kinematic_move_to(float logical[NUM_AXIS]) {
8046
+
8047
+    // Get the top feedrate of the move in the XY plane
8048
+    float _feedrate_mm_s = MMS_SCALED(feedrate_mm_s);
8049
+
8050
+    // If the move is only in Z don't split up the move.
8051
+    // This shortcut cannot be used if planar bed leveling
8052
+    // is in use, but is fine with mesh-based bed leveling
8053
+    if (logical[X_AXIS] == current_position[X_AXIS] && logical[Y_AXIS] == current_position[Y_AXIS]) {
8054
+      inverse_kinematics(logical);
8055
+      planner.buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], logical[E_AXIS], _feedrate_mm_s, active_extruder);
8056
+      return true;
8057
+    }
8058
+
8059
+    // Get the distance moved in XYZ
8046 8060
     float difference[NUM_AXIS];
8047 8061
     LOOP_XYZE(i) difference[i] = logical[i] - current_position[i];
8048 8062
 
8049 8063
     float cartesian_mm = sqrt(sq(difference[X_AXIS]) + sq(difference[Y_AXIS]) + sq(difference[Z_AXIS]));
8050 8064
     if (UNEAR_ZERO(cartesian_mm)) cartesian_mm = abs(difference[E_AXIS]);
8051 8065
     if (UNEAR_ZERO(cartesian_mm)) return false;
8052
-    float _feedrate_mm_s = MMS_SCALED(feedrate_mm_s);
8066
+
8067
+    // Minimum number of seconds to move the given distance
8053 8068
     float seconds = cartesian_mm / _feedrate_mm_s;
8054
-    int steps = max(1, int(delta_segments_per_second * seconds));
8055
-    float inv_steps = 1.0/steps;
8056 8069
 
8057
-    // SERIAL_ECHOPAIR("mm=", cartesian_mm);
8058
-    // SERIAL_ECHOPAIR(" seconds=", seconds);
8059
-    // SERIAL_ECHOLNPAIR(" steps=", steps);
8070
+    // The number of segments-per-second times the duration
8071
+    // gives the number of segments we should produce
8072
+    uint16_t segments = delta_segments_per_second * seconds;
8060 8073
 
8061
-    for (int s = 1; s <= steps; s++) {
8074
+    #if IS_SCARA
8075
+      NOMORE(segments, cartesian_mm * 2);
8076
+    #endif
8062 8077
 
8063
-      float fraction = float(s) * inv_steps;
8078
+    NOLESS(segments, 1);
8079
+
8080
+    // Each segment produces this much of the move
8081
+    float inv_segments = 1.0 / segments,
8082
+          segment_distance[XYZE] = {
8083
+            difference[X_AXIS] * inv_segments,
8084
+            difference[Y_AXIS] * inv_segments,
8085
+            difference[Z_AXIS] * inv_segments,
8086
+            difference[E_AXIS] * inv_segments
8087
+          };
8088
+
8089
+    // SERIAL_ECHOPAIR("mm=", cartesian_mm);
8090
+    // SERIAL_ECHOPAIR(" seconds=", seconds);
8091
+    // SERIAL_ECHOLNPAIR(" segments=", segments);
8064 8092
 
8065
-      LOOP_XYZE(i)
8066
-        logical[i] = current_position[i] + difference[i] * fraction;
8093
+    // Set the target to the current position to start
8094
+    LOOP_XYZE(i) logical[i] = current_position[i];
8067 8095
 
8096
+    // Send all the segments to the planner
8097
+    for (uint16_t s = 0; s < segments; s++) {
8098
+      LOOP_XYZE(i) logical[i] += segment_distance[i];
8068 8099
       inverse_kinematics(logical);
8069 8100
 
8070 8101
       //DEBUG_POS("prepare_kinematic_move_to", logical);

Loading…
取消
儲存