Browse Source

Merge pull request #6149 from thinkyhead/rc_scara_feedrate

Convert feedrate on SCARA from mm/s to deg/s
Scott Lahteine 7 years ago
parent
commit
592300922c
1 changed files with 46 additions and 13 deletions
  1. 46
    13
      Marlin/Marlin_main.cpp

+ 46
- 13
Marlin/Marlin_main.cpp View File

@@ -9793,34 +9793,43 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
9793 9793
     // gives the number of segments
9794 9794
     uint16_t segments = delta_segments_per_second * seconds;
9795 9795
 
9796
-    // For SCARA minimum segment size is 0.5mm
9796
+    // For SCARA minimum segment size is 0.25mm
9797 9797
     #if IS_SCARA
9798
-      NOMORE(segments, cartesian_mm * 2);
9798
+      NOMORE(segments, cartesian_mm * 4);
9799 9799
     #endif
9800 9800
 
9801 9801
     // At least one segment is required
9802 9802
     NOLESS(segments, 1);
9803 9803
 
9804 9804
     // The approximate length of each segment
9805
-    float segment_distance[XYZE] = {
9806
-            difference[X_AXIS] / segments,
9807
-            difference[Y_AXIS] / segments,
9808
-            difference[Z_AXIS] / segments,
9809
-            difference[E_AXIS] / segments
9810
-          };
9805
+    const float inv_segments = 1.0 / float(segments),
9806
+                segment_distance[XYZE] = {
9807
+                  difference[X_AXIS] * inv_segments,
9808
+                  difference[Y_AXIS] * inv_segments,
9809
+                  difference[Z_AXIS] * inv_segments,
9810
+                  difference[E_AXIS] * inv_segments
9811
+                };
9811 9812
 
9812 9813
     // SERIAL_ECHOPAIR("mm=", cartesian_mm);
9813 9814
     // SERIAL_ECHOPAIR(" seconds=", seconds);
9814 9815
     // SERIAL_ECHOLNPAIR(" segments=", segments);
9815 9816
 
9816
-    // Drop one segment so the last move is to the exact target.
9817
-    // If there's only 1 segment, loops will be skipped entirely.
9818
-    --segments;
9817
+    #if IS_SCARA
9818
+      // SCARA needs to scale the feed rate from mm/s to degrees/s
9819
+      const float inv_segment_length = min(10.0, float(segments) / cartesian_mm), // 1/mm/segs
9820
+                  feed_factor = inv_segment_length * _feedrate_mm_s;
9821
+      float oldA = stepper.get_axis_position_degrees(A_AXIS),
9822
+            oldB = stepper.get_axis_position_degrees(B_AXIS);
9823
+    #endif
9819 9824
 
9820 9825
     // Get the logical current position as starting point
9821 9826
     float logical[XYZE];
9822 9827
     COPY(logical, current_position);
9823 9828
 
9829
+    // Drop one segment so the last move is to the exact target.
9830
+    // If there's only 1 segment, loops will be skipped entirely.
9831
+    --segments;
9832
+
9824 9833
     // Calculate and execute the segments
9825 9834
     for (uint16_t s = segments + 1; --s;) {
9826 9835
       LOOP_XYZE(i) logical[i] += segment_distance[i];
@@ -9829,13 +9838,37 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
9829 9838
       #else
9830 9839
         inverse_kinematics(logical);
9831 9840
       #endif
9841
+
9832 9842
       ADJUST_DELTA(logical); // Adjust Z if bed leveling is enabled
9833
-      planner.buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], logical[E_AXIS], _feedrate_mm_s, active_extruder);
9843
+
9844
+      #if IS_SCARA
9845
+        // For SCARA scale the feed rate from mm/s to degrees/s
9846
+        // Use ratio between the length of the move and the larger angle change
9847
+        const float adiff = abs(delta[A_AXIS] - oldA),
9848
+                    bdiff = abs(delta[B_AXIS] - oldB);
9849
+        planner.buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], logical[E_AXIS], max(adiff, bdiff) * feed_factor, active_extruder);
9850
+        oldA = delta[A_AXIS];
9851
+        oldB = delta[B_AXIS];
9852
+      #else
9853
+        planner.buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], logical[E_AXIS], _feedrate_mm_s, active_extruder);
9854
+      #endif
9834 9855
     }
9835 9856
 
9836 9857
     // Since segment_distance is only approximate,
9837 9858
     // the final move must be to the exact destination.
9838
-    planner.buffer_line_kinematic(ltarget, _feedrate_mm_s, active_extruder);
9859
+
9860
+    #if IS_SCARA
9861
+      // For SCARA scale the feed rate from mm/s to degrees/s
9862
+      // With segments > 1 length is 1 segment, otherwise total length
9863
+      inverse_kinematics(ltarget);
9864
+      ADJUST_DELTA(logical);
9865
+      const float adiff = abs(delta[A_AXIS] - oldA),
9866
+                  bdiff = abs(delta[B_AXIS] - oldB);
9867
+      planner.buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], logical[E_AXIS], max(adiff, bdiff) * feed_factor, active_extruder);
9868
+    #else
9869
+      planner.buffer_line_kinematic(ltarget, _feedrate_mm_s, active_extruder);
9870
+    #endif
9871
+
9839 9872
     return true;
9840 9873
   }
9841 9874
 

Loading…
Cancel
Save