Browse Source

Apply SCARA_FEEDRATE_SCALING to G2/G3

Scott Lahteine 6 years ago
parent
commit
c694608450
2 changed files with 52 additions and 32 deletions
  1. 42
    13
      Marlin/src/gcode/motion/G2_G3.cpp
  2. 10
    19
      Marlin/src/module/motion.cpp

+ 42
- 13
Marlin/src/gcode/motion/G2_G3.cpp View File

@@ -29,6 +29,12 @@
29 29
 #include "../../module/planner.h"
30 30
 #include "../../module/temperature.h"
31 31
 
32
+#if ENABLED(DELTA)
33
+  #include "../../module/delta.h"
34
+#elif ENABLED(SCARA)
35
+  #include "../../module/scara.h"
36
+#endif
37
+
32 38
 #if N_ARC_CORRECTION < 1
33 39
   #undef N_ARC_CORRECTION
34 40
   #define N_ARC_CORRECTION 1
@@ -113,7 +119,7 @@ void plan_arc(
113 119
    * This is important when there are successive arc motions.
114 120
    */
115 121
   // Vector rotation matrix values
116
-  float arc_target[XYZE];
122
+  float raw[XYZE];
117 123
   const float theta_per_segment = angular_travel / segments,
118 124
               linear_per_segment = linear_travel / segments,
119 125
               extruder_per_segment = extruder_travel / segments,
@@ -121,10 +127,10 @@ void plan_arc(
121 127
               cos_T = 1 - 0.5 * sq(theta_per_segment); // Small angle approximation
122 128
 
123 129
   // Initialize the linear axis
124
-  arc_target[l_axis] = current_position[l_axis];
130
+  raw[l_axis] = current_position[l_axis];
125 131
 
126 132
   // Initialize the extruder axis
127
-  arc_target[E_AXIS] = current_position[E_AXIS];
133
+  raw[E_AXIS] = current_position[E_AXIS];
128 134
 
129 135
   const float fr_mm_s = MMS_SCALED(feedrate_mm_s);
130 136
 
@@ -134,6 +140,14 @@ void plan_arc(
134 140
     int8_t arc_recalc_count = N_ARC_CORRECTION;
135 141
   #endif
136 142
 
143
+  #if ENABLED(SCARA_FEEDRATE_SCALING)
144
+    // SCARA needs to scale the feed rate from mm/s to degrees/s
145
+    const float inv_segment_length = 1.0 / (MM_PER_ARC_SEGMENT),
146
+                inverse_secs = inv_segment_length * fr_mm_s;
147
+    float oldA = stepper.get_axis_position_degrees(A_AXIS),
148
+          oldB = stepper.get_axis_position_degrees(B_AXIS);
149
+  #endif
150
+
137 151
   for (uint16_t i = 1; i < segments; i++) { // Iterate (segments-1) times
138 152
 
139 153
     thermalManager.manage_heater();
@@ -165,19 +179,34 @@ void plan_arc(
165 179
       r_Q = -offset[0] * sin_Ti - offset[1] * cos_Ti;
166 180
     }
167 181
 
168
-    // Update arc_target location
169
-    arc_target[p_axis] = center_P + r_P;
170
-    arc_target[q_axis] = center_Q + r_Q;
171
-    arc_target[l_axis] += linear_per_segment;
172
-    arc_target[E_AXIS] += extruder_per_segment;
173
-
174
-    clamp_to_software_endstops(arc_target);
175
-
176
-    planner.buffer_line_kinematic(arc_target, fr_mm_s, active_extruder);
182
+    // Update raw location
183
+    raw[p_axis] = center_P + r_P;
184
+    raw[q_axis] = center_Q + r_Q;
185
+    raw[l_axis] += linear_per_segment;
186
+    raw[E_AXIS] += extruder_per_segment;
187
+
188
+    clamp_to_software_endstops(raw);
189
+
190
+    #if ENABLED(SCARA_FEEDRATE_SCALING)
191
+      // For SCARA scale the feed rate from mm/s to degrees/s.
192
+      // i.e., Complete the angular vector in the given time.
193
+      inverse_kinematics(raw);
194
+      ADJUST_DELTA(raw);
195
+      planner.buffer_segment(delta[A_AXIS], delta[B_AXIS], raw[Z_AXIS], raw[E_AXIS], HYPOT(delta[A_AXIS] - oldA, delta[B_AXIS] - oldB) * inverse_secs, active_extruder);
196
+      oldA = delta[A_AXIS]; oldB = delta[B_AXIS];
197
+    #else
198
+      planner.buffer_line_kinematic(raw, fr_mm_s, active_extruder);
199
+    #endif
177 200
   }
178 201
 
179 202
   // Ensure last segment arrives at target location.
180
-  planner.buffer_line_kinematic(cart, fr_mm_s, active_extruder);
203
+  #if ENABLED(SCARA_FEEDRATE_SCALING)
204
+    inverse_kinematics(cart);
205
+    ADJUST_DELTA(cart);
206
+    planner.buffer_segment(delta[A_AXIS], delta[B_AXIS], cart[Z_AXIS], cart[E_AXIS], HYPOT(delta[A_AXIS] - oldA, delta[B_AXIS] - oldB) * inverse_secs, active_extruder);
207
+  #else
208
+    planner.buffer_line_kinematic(cart, fr_mm_s, active_extruder);
209
+  #endif
181 210
 
182 211
   // As far as the parser is concerned, the position is now == target. In reality the
183 212
   // motion control system might still be processing the action and the real tool position

+ 10
- 19
Marlin/src/module/motion.cpp View File

@@ -587,7 +587,7 @@ float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS },
587 587
     // SERIAL_ECHOPAIR(" seconds=", seconds);
588 588
     // SERIAL_ECHOLNPAIR(" segments=", segments);
589 589
 
590
-    #if IS_SCARA && ENABLED(SCARA_FEEDRATE_SCALING)
590
+    #if ENABLED(SCARA_FEEDRATE_SCALING)
591 591
       // SCARA needs to scale the feed rate from mm/s to degrees/s
592 592
       const float inv_segment_length = min(10.0, float(segments) / cartesian_mm), // 1/mm/segs
593 593
                   inverse_secs = inv_segment_length * _feedrate_mm_s;
@@ -611,38 +611,29 @@ float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS },
611 611
       }
612 612
 
613 613
       LOOP_XYZE(i) raw[i] += segment_distance[i];
614
+
614 615
       #if ENABLED(DELTA)
615 616
         DELTA_RAW_IK(); // Delta can inline its kinematics
616 617
       #else
617 618
         inverse_kinematics(raw);
618 619
       #endif
619
-
620 620
       ADJUST_DELTA(raw); // Adjust Z if bed leveling is enabled
621 621
 
622
-      #if IS_SCARA && ENABLED(SCARA_FEEDRATE_SCALING)
622
+      #if ENABLED(SCARA_FEEDRATE_SCALING)
623 623
         // For SCARA scale the feed rate from mm/s to degrees/s
624
-        // Use ratio between the length of the move and the larger angle change
625
-        const float adiff = abs(delta[A_AXIS] - oldA),
626
-                    bdiff = abs(delta[B_AXIS] - oldB);
627
-        planner.buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], raw[E_AXIS], max(adiff, bdiff) * inverse_secs, active_extruder);
628
-        oldA = delta[A_AXIS];
629
-        oldB = delta[B_AXIS];
624
+        // i.e., Complete the angular vector in the given time.
625
+        planner.buffer_segment(delta[A_AXIS], delta[B_AXIS], raw[Z_AXIS], raw[E_AXIS], HYPOT(delta[A_AXIS] - oldA, delta[B_AXIS] - oldB) * inverse_secs, active_extruder);
626
+        oldA = delta[A_AXIS]; oldB = delta[B_AXIS];
630 627
       #else
631
-        planner.buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], raw[E_AXIS], _feedrate_mm_s, active_extruder);
628
+        planner.buffer_line(delta[A_AXIS], delta[B_AXIS], raw[Z_AXIS], raw[E_AXIS], _feedrate_mm_s, active_extruder);
632 629
       #endif
633 630
     }
634 631
 
635
-    // Since segment_distance is only approximate,
636
-    // the final move must be to the exact destination.
637
-
638
-    #if IS_SCARA && ENABLED(SCARA_FEEDRATE_SCALING)
639
-      // For SCARA scale the feed rate from mm/s to degrees/s
640
-      // With segments > 1 length is 1 segment, otherwise total length
632
+    // Ensure last segment arrives at target location.
633
+    #if ENABLED(SCARA_FEEDRATE_SCALING)
641 634
       inverse_kinematics(rtarget);
642 635
       ADJUST_DELTA(rtarget);
643
-      const float adiff = abs(delta[A_AXIS] - oldA),
644
-                  bdiff = abs(delta[B_AXIS] - oldB);
645
-      planner.buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], raw[E_AXIS], max(adiff, bdiff) * inverse_secs, active_extruder);
636
+      planner.buffer_segment(delta[A_AXIS], delta[B_AXIS], rtarget[Z_AXIS], rtarget[E_AXIS], HYPOT(delta[A_AXIS] - oldA, delta[B_AXIS] - oldB) * inverse_secs, active_extruder);
646 637
     #else
647 638
       planner.buffer_line_kinematic(rtarget, _feedrate_mm_s, active_extruder);
648 639
     #endif

Loading…
Cancel
Save