Przeglądaj źródła

Merge pull request #8865 from thinkyhead/bf2_more_scara_scaling

[2.0.x] SCARA Feedrate Scaling for G2/G3 - using HYPOT
Scott Lahteine 7 lat temu
rodzic
commit
869c89d83f
No account linked to committer's email address

+ 1
- 1
Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp Wyświetl plik

427
 
427
 
428
     #if ENABLED(DELTA)  // apply delta inverse_kinematics
428
     #if ENABLED(DELTA)  // apply delta inverse_kinematics
429
 
429
 
430
-      DELTA_RAW_IK();
430
+      DELTA_IK(raw);
431
       planner.buffer_segment(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], in_raw[E_AXIS], fr, active_extruder);
431
       planner.buffer_segment(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], in_raw[E_AXIS], fr, active_extruder);
432
 
432
 
433
     #elif IS_SCARA  // apply scara inverse_kinematics (should be changed to save raw->logical->raw)
433
     #elif IS_SCARA  // apply scara inverse_kinematics (should be changed to save raw->logical->raw)

+ 42
- 13
Marlin/src/gcode/motion/G2_G3.cpp Wyświetl plik

29
 #include "../../module/planner.h"
29
 #include "../../module/planner.h"
30
 #include "../../module/temperature.h"
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
 #if N_ARC_CORRECTION < 1
38
 #if N_ARC_CORRECTION < 1
33
   #undef N_ARC_CORRECTION
39
   #undef N_ARC_CORRECTION
34
   #define N_ARC_CORRECTION 1
40
   #define N_ARC_CORRECTION 1
113
    * This is important when there are successive arc motions.
119
    * This is important when there are successive arc motions.
114
    */
120
    */
115
   // Vector rotation matrix values
121
   // Vector rotation matrix values
116
-  float arc_target[XYZE];
122
+  float raw[XYZE];
117
   const float theta_per_segment = angular_travel / segments,
123
   const float theta_per_segment = angular_travel / segments,
118
               linear_per_segment = linear_travel / segments,
124
               linear_per_segment = linear_travel / segments,
119
               extruder_per_segment = extruder_travel / segments,
125
               extruder_per_segment = extruder_travel / segments,
121
               cos_T = 1 - 0.5 * sq(theta_per_segment); // Small angle approximation
127
               cos_T = 1 - 0.5 * sq(theta_per_segment); // Small angle approximation
122
 
128
 
123
   // Initialize the linear axis
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
   // Initialize the extruder axis
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
   const float fr_mm_s = MMS_SCALED(feedrate_mm_s);
135
   const float fr_mm_s = MMS_SCALED(feedrate_mm_s);
130
 
136
 
134
     int8_t arc_recalc_count = N_ARC_CORRECTION;
140
     int8_t arc_recalc_count = N_ARC_CORRECTION;
135
   #endif
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
   for (uint16_t i = 1; i < segments; i++) { // Iterate (segments-1) times
151
   for (uint16_t i = 1; i < segments; i++) { // Iterate (segments-1) times
138
 
152
 
139
     thermalManager.manage_heater();
153
     thermalManager.manage_heater();
165
       r_Q = -offset[0] * sin_Ti - offset[1] * cos_Ti;
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
   // Ensure last segment arrives at target location.
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
   // As far as the parser is concerned, the position is now == target. In reality the
211
   // As far as the parser is concerned, the position is now == target. In reality the
183
   // motion control system might still be processing the action and the real tool position
212
   // motion control system might still be processing the action and the real tool position

+ 1
- 1
Marlin/src/module/delta.cpp Wyświetl plik

121
   }while(0)
121
   }while(0)
122
 
122
 
123
 void inverse_kinematics(const float raw[XYZ]) {
123
 void inverse_kinematics(const float raw[XYZ]) {
124
-  DELTA_RAW_IK();
124
+  DELTA_IK(raw);
125
   // DELTA_DEBUG();
125
   // DELTA_DEBUG();
126
 }
126
 }
127
 
127
 

+ 9
- 9
Marlin/src/module/delta.h Wyświetl plik

76
 #endif
76
 #endif
77
 
77
 
78
 // Macro to obtain the Z position of an individual tower
78
 // Macro to obtain the Z position of an individual tower
79
-#define DELTA_Z(T) raw[Z_AXIS] + _SQRT(     \
80
-  delta_diagonal_rod_2_tower[T] - HYPOT2(   \
81
-      delta_tower[T][X_AXIS] - raw[X_AXIS], \
82
-      delta_tower[T][Y_AXIS] - raw[Y_AXIS]  \
83
-    )                                       \
79
+#define DELTA_Z(V,T) V[Z_AXIS] + _SQRT(   \
80
+  delta_diagonal_rod_2_tower[T] - HYPOT2( \
81
+      delta_tower[T][X_AXIS] - V[X_AXIS], \
82
+      delta_tower[T][Y_AXIS] - V[Y_AXIS]  \
83
+    )                                     \
84
   )
84
   )
85
 
85
 
86
-#define DELTA_RAW_IK() do {        \
87
-  delta[A_AXIS] = DELTA_Z(A_AXIS); \
88
-  delta[B_AXIS] = DELTA_Z(B_AXIS); \
89
-  delta[C_AXIS] = DELTA_Z(C_AXIS); \
86
+#define DELTA_IK(V) do {        \
87
+  delta[A_AXIS] = DELTA_Z(V, A_AXIS); \
88
+  delta[B_AXIS] = DELTA_Z(V, B_AXIS); \
89
+  delta[C_AXIS] = DELTA_Z(V, C_AXIS); \
90
 }while(0)
90
 }while(0)
91
 
91
 
92
 void inverse_kinematics(const float raw[XYZ]);
92
 void inverse_kinematics(const float raw[XYZ]);

+ 11
- 20
Marlin/src/module/motion.cpp Wyświetl plik

587
     // SERIAL_ECHOPAIR(" seconds=", seconds);
587
     // SERIAL_ECHOPAIR(" seconds=", seconds);
588
     // SERIAL_ECHOLNPAIR(" segments=", segments);
588
     // SERIAL_ECHOLNPAIR(" segments=", segments);
589
 
589
 
590
-    #if IS_SCARA && ENABLED(SCARA_FEEDRATE_SCALING)
590
+    #if ENABLED(SCARA_FEEDRATE_SCALING)
591
       // SCARA needs to scale the feed rate from mm/s to degrees/s
591
       // SCARA needs to scale the feed rate from mm/s to degrees/s
592
       const float inv_segment_length = min(10.0, float(segments) / cartesian_mm), // 1/mm/segs
592
       const float inv_segment_length = min(10.0, float(segments) / cartesian_mm), // 1/mm/segs
593
                   inverse_secs = inv_segment_length * _feedrate_mm_s;
593
                   inverse_secs = inv_segment_length * _feedrate_mm_s;
611
       }
611
       }
612
 
612
 
613
       LOOP_XYZE(i) raw[i] += segment_distance[i];
613
       LOOP_XYZE(i) raw[i] += segment_distance[i];
614
+
614
       #if ENABLED(DELTA)
615
       #if ENABLED(DELTA)
615
-        DELTA_RAW_IK(); // Delta can inline its kinematics
616
+        DELTA_IK(raw); // Delta can inline its kinematics
616
       #else
617
       #else
617
         inverse_kinematics(raw);
618
         inverse_kinematics(raw);
618
       #endif
619
       #endif
619
-
620
       ADJUST_DELTA(raw); // Adjust Z if bed leveling is enabled
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
         // For SCARA scale the feed rate from mm/s to degrees/s
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
       #else
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
       #endif
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
       inverse_kinematics(rtarget);
634
       inverse_kinematics(rtarget);
642
       ADJUST_DELTA(rtarget);
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
     #else
637
     #else
647
       planner.buffer_line_kinematic(rtarget, _feedrate_mm_s, active_extruder);
638
       planner.buffer_line_kinematic(rtarget, _feedrate_mm_s, active_extruder);
648
     #endif
639
     #endif

Ładowanie…
Anuluj
Zapisz