Browse Source

Merge pull request #8729 from thinkyhead/bf1_sort_out_leveling

[1.1.x] UBL - Skew and Dual X Carriage
Scott Lahteine 6 years ago
parent
commit
17b05c150c
No account linked to committer's email address

+ 4
- 3
.travis.yml View File

@@ -103,9 +103,10 @@ script:
103 103
   - opt_enable_adv CUSTOM_USER_MENUS I2C_POSITION_ENCODERS BABYSTEPPING NANODLP_Z_SYNC
104 104
   - build_marlin
105 105
   #
106
-  # And with a Sled Z Probe
106
+  # Add a Sled Z Probe, use UBL Cartesian moves
107 107
   #
108
-  - opt_enable Z_PROBE_SLED
108
+  - opt_enable Z_PROBE_SLED SKEW_CORRECTION SKEW_CORRECTION_FOR_Z SKEW_CORRECTION_GCODE
109
+  - opt_disable SEGMENT_LEVELED_MOVES
109 110
   - opt_enable_adv BABYSTEP_ZPROBE_OFFSET DOUBLECLICK_FOR_Z_BABYSTEPPING
110 111
   - build_marlin
111 112
   #
@@ -141,7 +142,7 @@ script:
141 142
   - opt_enable ULTIMAKERCONTROLLER SDSUPPORT
142 143
   - opt_enable PRINTCOUNTER NOZZLE_PARK_FEATURE NOZZLE_CLEAN_FEATURE PCA9632 USE_XMAX_PLUG
143 144
   - opt_enable_adv BEZIER_CURVE_SUPPORT EXPERIMENTAL_I2CBUS
144
-  - opt_enable_adv ADVANCED_PAUSE_FEATURE PARK_HEAD_ON_PAUSE LCD_INFO_MENU
145
+  - opt_enable_adv ADVANCED_PAUSE_FEATURE PARK_HEAD_ON_PAUSE LCD_INFO_MENU M114_DETAIL
145 146
   - opt_set_adv PWM_MOTOR_CURRENT {1300,1300,1250}
146 147
   - opt_set_adv I2C_SLAVE_ADDRESS 63
147 148
   - build_marlin

+ 9
- 9
Marlin/Conditionals_post.h View File

@@ -933,15 +933,15 @@
933 933
   /**
934 934
    * Set granular options based on the specific type of leveling
935 935
    */
936
-  #define UBL_DELTA  (ENABLED(AUTO_BED_LEVELING_UBL) && (ENABLED(DELTA) || ENABLED(SEGMENT_LEVELED_MOVES)))
937
-  #define ABL_PLANAR (ENABLED(AUTO_BED_LEVELING_LINEAR) || ENABLED(AUTO_BED_LEVELING_3POINT))
938
-  #define ABL_GRID   (ENABLED(AUTO_BED_LEVELING_LINEAR) || ENABLED(AUTO_BED_LEVELING_BILINEAR))
939
-  #define OLDSCHOOL_ABL         (ABL_PLANAR || ABL_GRID)
940
-  #define HAS_ABL               (OLDSCHOOL_ABL || ENABLED(AUTO_BED_LEVELING_UBL))
941
-  #define HAS_LEVELING          (HAS_ABL || ENABLED(MESH_BED_LEVELING))
942
-  #define HAS_AUTOLEVEL         (HAS_ABL && DISABLED(PROBE_MANUALLY))
943
-  #define HAS_MESH              (ENABLED(AUTO_BED_LEVELING_BILINEAR) || ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(MESH_BED_LEVELING))
944
-  #define PLANNER_LEVELING      (OLDSCHOOL_ABL || ENABLED(MESH_BED_LEVELING) || UBL_DELTA || ENABLED(SKEW_CORRECTION))
936
+  #define UBL_SEGMENTED  (ENABLED(AUTO_BED_LEVELING_UBL) && (ENABLED(DELTA) || ENABLED(SEGMENT_LEVELED_MOVES)))
937
+  #define ABL_PLANAR     (ENABLED(AUTO_BED_LEVELING_LINEAR) || ENABLED(AUTO_BED_LEVELING_3POINT))
938
+  #define ABL_GRID       (ENABLED(AUTO_BED_LEVELING_LINEAR) || ENABLED(AUTO_BED_LEVELING_BILINEAR))
939
+  #define OLDSCHOOL_ABL  (ABL_PLANAR || ABL_GRID)
940
+  #define HAS_ABL        (OLDSCHOOL_ABL || ENABLED(AUTO_BED_LEVELING_UBL))
941
+  #define HAS_LEVELING   (HAS_ABL || ENABLED(MESH_BED_LEVELING))
942
+  #define HAS_AUTOLEVEL  (HAS_ABL && DISABLED(PROBE_MANUALLY))
943
+  #define HAS_MESH       (ENABLED(AUTO_BED_LEVELING_BILINEAR) || ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(MESH_BED_LEVELING))
944
+  #define PLANNER_LEVELING      (OLDSCHOOL_ABL || ENABLED(MESH_BED_LEVELING) || UBL_SEGMENTED || ENABLED(SKEW_CORRECTION))
945 945
   #define HAS_PROBING_PROCEDURE (HAS_ABL || ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST))
946 946
   #if HAS_PROBING_PROCEDURE
947 947
     #define PROBE_BED_WIDTH abs(RIGHT_PROBE_BED_POSITION - (LEFT_PROBE_BED_POSITION))

+ 1
- 2
Marlin/G26_Mesh_Validation_Tool.cpp View File

@@ -137,7 +137,6 @@
137 137
   #if ENABLED(ULTRA_LCD)
138 138
     extern char lcd_status_message[];
139 139
   #endif
140
-  extern float destination[XYZE];
141 140
   void set_destination_from_current();
142 141
   void prepare_move_to_destination();
143 142
   inline void sync_plan_position_e() { planner.set_e_position_mm(current_position[E_AXIS]); }
@@ -189,7 +188,7 @@
189 188
   void G26_line_to_destination(const float &feed_rate) {
190 189
     const float save_feedrate = feedrate_mm_s;
191 190
     feedrate_mm_s = feed_rate;      // use specified feed rate
192
-    prepare_move_to_destination();  // will ultimately call ubl.line_to_destination_cartesian or ubl.prepare_linear_move_to for UBL_DELTA
191
+    prepare_move_to_destination();  // will ultimately call ubl.line_to_destination_cartesian or ubl.prepare_linear_move_to for UBL_SEGMENTED
193 192
     feedrate_mm_s = save_feedrate;  // restore global feed rate
194 193
   }
195 194
 

+ 1
- 1
Marlin/Marlin.h View File

@@ -223,7 +223,7 @@ extern volatile bool wait_for_heatup;
223 223
   extern volatile bool wait_for_user;
224 224
 #endif
225 225
 
226
-extern float current_position[NUM_AXIS];
226
+extern float current_position[XYZE], destination[XYZE];
227 227
 
228 228
 // Workspace offsets
229 229
 #if HAS_WORKSPACE_OFFSET

+ 30
- 24
Marlin/Marlin_main.cpp View File

@@ -706,7 +706,7 @@ FORCE_INLINE signed char pgm_read_any(const signed char *p) { return pgm_read_by
706 706
 
707 707
 #define XYZ_CONSTS_FROM_CONFIG(type, array, CONFIG) \
708 708
   static const PROGMEM type array##_P[XYZ] = { X_##CONFIG, Y_##CONFIG, Z_##CONFIG }; \
709
-  static inline type array(AxisEnum axis) { return pgm_read_any(&array##_P[axis]); } \
709
+  static inline type array(const AxisEnum axis) { return pgm_read_any(&array##_P[axis]); } \
710 710
   typedef void __void_##CONFIG##__
711 711
 
712 712
 XYZ_CONSTS_FROM_CONFIG(float, base_min_pos,   MIN_POS);
@@ -733,11 +733,11 @@ void get_cartesian_from_steppers();
733 733
 void set_current_from_steppers_for_axis(const AxisEnum axis);
734 734
 
735 735
 #if ENABLED(ARC_SUPPORT)
736
-  void plan_arc(float target[XYZE], float* offset, uint8_t clockwise);
736
+  void plan_arc(const float (&cart)[XYZE], const float (&offset)[2], const bool clockwise);
737 737
 #endif
738 738
 
739 739
 #if ENABLED(BEZIER_CURVE_SUPPORT)
740
-  void plan_cubic_move(const float offset[4]);
740
+  void plan_cubic_move(const float (&offset)[4]);
741 741
 #endif
742 742
 
743 743
 void tool_change(const uint8_t tmp_extruder, const float fr_mm_s=0.0, bool no_move=false);
@@ -1550,7 +1550,7 @@ inline void set_destination_from_current() { COPY(destination, current_position)
1550 1550
 
1551 1551
     refresh_cmd_timeout();
1552 1552
 
1553
-    #if UBL_DELTA
1553
+    #if UBL_SEGMENTED
1554 1554
       // ubl segmented line will do z-only moves in single segment
1555 1555
       ubl.prepare_segmented_line_to(destination, MMS_SCALED(fr_mm_s ? fr_mm_s : feedrate_mm_s));
1556 1556
     #else
@@ -1808,7 +1808,7 @@ static void clean_up_after_endstop_or_probe_move() {
1808 1808
 
1809 1809
 #elif ENABLED(Z_PROBE_ALLEN_KEY)
1810 1810
 
1811
-  FORCE_INLINE void do_blocking_move_to(const float raw[XYZ], const float &fr_mm_s) {
1811
+  FORCE_INLINE void do_blocking_move_to(const float (&raw)[XYZ], const float &fr_mm_s) {
1812 1812
     do_blocking_move_to(raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS], fr_mm_s);
1813 1813
   }
1814 1814
 
@@ -8326,7 +8326,7 @@ void report_current_position() {
8326 8326
 
8327 8327
 #ifdef M114_DETAIL
8328 8328
 
8329
-  void report_xyze(const float pos[XYZE], const uint8_t n = 4, const uint8_t precision = 3) {
8329
+  void report_xyze(const float pos[], const uint8_t n = 4, const uint8_t precision = 3) {
8330 8330
     char str[12];
8331 8331
     for (uint8_t i = 0; i < n; i++) {
8332 8332
       SERIAL_CHAR(' ');
@@ -8337,7 +8337,7 @@ void report_current_position() {
8337 8337
     SERIAL_EOL();
8338 8338
   }
8339 8339
 
8340
-  inline void report_xyz(const float pos[XYZ]) { report_xyze(pos, 3); }
8340
+  inline void report_xyz(const float pos[]) { report_xyze(pos, 3); }
8341 8341
 
8342 8342
   void report_current_position_detail() {
8343 8343
 
@@ -12647,7 +12647,7 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
12647 12647
 #endif // AUTO_BED_LEVELING_BILINEAR
12648 12648
 #endif // IS_CARTESIAN
12649 12649
 
12650
-#if !UBL_DELTA
12650
+#if !UBL_SEGMENTED
12651 12651
 #if IS_KINEMATIC
12652 12652
 
12653 12653
   /**
@@ -12659,7 +12659,7 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
12659 12659
    * For Unified Bed Leveling (Delta or Segmented Cartesian)
12660 12660
    * the ubl.prepare_segmented_line_to method replaces this.
12661 12661
    */
12662
-  inline bool prepare_kinematic_move_to(float rtarget[XYZE]) {
12662
+  inline bool prepare_kinematic_move_to(const float (&rtarget)[XYZE]) {
12663 12663
 
12664 12664
     // Get the top feedrate of the move in the XY plane
12665 12665
     const float _feedrate_mm_s = MMS_SCALED(feedrate_mm_s);
@@ -12819,7 +12819,7 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
12819 12819
   }
12820 12820
 
12821 12821
 #endif // !IS_KINEMATIC
12822
-#endif // !UBL_DELTA
12822
+#endif // !UBL_SEGMENTED
12823 12823
 
12824 12824
 #if ENABLED(DUAL_X_CARRIAGE)
12825 12825
 
@@ -12895,7 +12895,13 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
12895 12895
           break;
12896 12896
       }
12897 12897
     }
12898
-    return prepare_move_to_destination_cartesian();
12898
+    return (
12899
+      #if UBL_SEGMENTED
12900
+        ubl.prepare_segmented_line_to(destination, MMS_SCALED(feedrate_mm_s))
12901
+      #else
12902
+        prepare_move_to_destination_cartesian()
12903
+      #endif
12904
+    );
12899 12905
   }
12900 12906
 
12901 12907
 #endif // DUAL_X_CARRIAGE
@@ -12937,12 +12943,12 @@ void prepare_move_to_destination() {
12937 12943
   #endif
12938 12944
 
12939 12945
   if (
12940
-    #if UBL_DELTA // Also works for CARTESIAN (smaller segments follow mesh more closely)
12946
+    #if ENABLED(DUAL_X_CARRIAGE)
12947
+      prepare_move_to_destination_dualx()
12948
+    #elif UBL_SEGMENTED
12941 12949
       ubl.prepare_segmented_line_to(destination, MMS_SCALED(feedrate_mm_s))
12942 12950
     #elif IS_KINEMATIC
12943 12951
       prepare_kinematic_move_to(destination)
12944
-    #elif ENABLED(DUAL_X_CARRIAGE)
12945
-      prepare_move_to_destination_dualx()
12946 12952
     #else
12947 12953
       prepare_move_to_destination_cartesian()
12948 12954
     #endif
@@ -12968,9 +12974,9 @@ void prepare_move_to_destination() {
12968 12974
    * options for G2/G3 arc generation. In future these options may be GCode tunable.
12969 12975
    */
12970 12976
   void plan_arc(
12971
-    float raw[XYZE],     // Destination position
12972
-    float *offset,       // Center of rotation relative to current_position
12973
-    uint8_t clockwise    // Clockwise?
12977
+    const float (&cart)[XYZE], // Destination position
12978
+    const float (&offset)[2], // Center of rotation relative to current_position
12979
+    const bool clockwise      // Clockwise?
12974 12980
   ) {
12975 12981
     #if ENABLED(CNC_WORKSPACE_PLANES)
12976 12982
       AxisEnum p_axis, q_axis, l_axis;
@@ -12990,10 +12996,10 @@ void prepare_move_to_destination() {
12990 12996
     const float radius = HYPOT(r_P, r_Q),
12991 12997
                 center_P = current_position[p_axis] - r_P,
12992 12998
                 center_Q = current_position[q_axis] - r_Q,
12993
-                rt_X = raw[p_axis] - center_P,
12994
-                rt_Y = raw[q_axis] - center_Q,
12995
-                linear_travel = raw[l_axis] - current_position[l_axis],
12996
-                extruder_travel = raw[E_AXIS] - current_position[E_AXIS];
12999
+                rt_X = cart[p_axis] - center_P,
13000
+                rt_Y = cart[q_axis] - center_Q,
13001
+                linear_travel = cart[l_axis] - current_position[l_axis],
13002
+                extruder_travel = cart[E_AXIS] - current_position[E_AXIS];
12997 13003
 
12998 13004
     // CCW angle of rotation between position and target from the circle center. Only one atan2() trig computation required.
12999 13005
     float angular_travel = ATAN2(r_P * rt_Y - r_Q * rt_X, r_P * rt_X + r_Q * rt_Y);
@@ -13001,7 +13007,7 @@ void prepare_move_to_destination() {
13001 13007
     if (clockwise) angular_travel -= RADIANS(360);
13002 13008
 
13003 13009
     // Make a circle if the angular rotation is 0 and the target is current position
13004
-    if (angular_travel == 0 && current_position[p_axis] == raw[p_axis] && current_position[q_axis] == raw[q_axis])
13010
+    if (angular_travel == 0 && current_position[p_axis] == cart[p_axis] && current_position[q_axis] == cart[q_axis])
13005 13011
       angular_travel = RADIANS(360);
13006 13012
 
13007 13013
     const float mm_of_travel = HYPOT(angular_travel * radius, FABS(linear_travel));
@@ -13101,7 +13107,7 @@ void prepare_move_to_destination() {
13101 13107
     }
13102 13108
 
13103 13109
     // Ensure last segment arrives at target location.
13104
-    planner.buffer_line_kinematic(raw, fr_mm_s, active_extruder);
13110
+    planner.buffer_line_kinematic(cart, fr_mm_s, active_extruder);
13105 13111
 
13106 13112
     // As far as the parser is concerned, the position is now == target. In reality the
13107 13113
     // motion control system might still be processing the action and the real tool position
@@ -13113,7 +13119,7 @@ void prepare_move_to_destination() {
13113 13119
 
13114 13120
 #if ENABLED(BEZIER_CURVE_SUPPORT)
13115 13121
 
13116
-  void plan_cubic_move(const float offset[4]) {
13122
+  void plan_cubic_move(const float (&offset)[4]) {
13117 13123
     cubic_b_spline(current_position, destination, offset, MMS_SCALED(feedrate_mm_s), active_extruder);
13118 13124
 
13119 13125
     // As far as the parser is concerned, the position is now == destination. In reality the

+ 1
- 4
Marlin/SanityCheck.h View File

@@ -590,7 +590,7 @@ static_assert(1 >= 0
590 590
     #error "Delta probably shouldn't use Z_MIN_PROBE_ENDSTOP. Comment out this line to continue."
591 591
   #elif DISABLED(USE_XMAX_PLUG) && DISABLED(USE_YMAX_PLUG) && DISABLED(USE_ZMAX_PLUG)
592 592
     #error "You probably want to use Max Endstops for DELTA!"
593
-  #elif ENABLED(ENABLE_LEVELING_FADE_HEIGHT) && DISABLED(AUTO_BED_LEVELING_BILINEAR) && !UBL_DELTA
593
+  #elif ENABLED(ENABLE_LEVELING_FADE_HEIGHT) && DISABLED(AUTO_BED_LEVELING_BILINEAR) && !UBL_SEGMENTED
594 594
     #error "ENABLE_LEVELING_FADE_HEIGHT on DELTA requires AUTO_BED_LEVELING_BILINEAR or AUTO_BED_LEVELING_UBL."
595 595
   #elif ENABLED(DELTA_AUTO_CALIBRATION) && !(HAS_BED_PROBE || ENABLED(ULTIPANEL))
596 596
     #error "DELTA_AUTO_CALIBRATION requires either a probe or an LCD Controller."
@@ -1539,9 +1539,6 @@ static_assert(COUNT(sanity_arr_3) <= XYZE_N, "DEFAULT_MAX_ACCELERATION has too m
1539 1539
 #endif
1540 1540
 
1541 1541
 #if ENABLED(SKEW_CORRECTION)
1542
-  #if ENABLED(AUTO_BED_LEVELING_UBL) && !ENABLED(SEGMENT_LEVELED_MOVES)
1543
-    #error "SKEW_CORRECTION with AUTO_BED_LEVELING_UBL requires SEGMENT_LEVELED_MOVES."
1544
-  #endif
1545 1542
   #if !defined(XY_SKEW_FACTOR) && !(defined(XY_DIAG_AC) && defined(XY_DIAG_BD) && defined(XY_SIDE_AD))
1546 1543
     #error "SKEW_CORRECTION requires XY_SKEW_FACTOR or XY_DIAG_AC, XY_DIAG_BD, XY_SIDE_AD."
1547 1544
   #endif

+ 14
- 28
Marlin/planner.cpp View File

@@ -569,14 +569,7 @@ void Planner::calculate_volumetric_multipliers() {
569 569
   void Planner::apply_leveling(float &rx, float &ry, float &rz) {
570 570
 
571 571
     #if ENABLED(SKEW_CORRECTION)
572
-      if (WITHIN(rx, X_MIN_POS + 1, X_MAX_POS) && WITHIN(ry, Y_MIN_POS + 1, Y_MAX_POS)) {
573
-        const float tempry = ry - (rz * planner.yz_skew_factor),
574
-                    temprx = rx - (ry * planner.xy_skew_factor) - (rz * (planner.xz_skew_factor - (planner.xy_skew_factor * planner.yz_skew_factor)));
575
-        if (WITHIN(temprx, X_MIN_POS, X_MAX_POS) && WITHIN(tempry, Y_MIN_POS, Y_MAX_POS)) {
576
-          rx = temprx;
577
-          ry = tempry;
578
-        }
579
-      }
572
+      skew(rx, ry, rz);
580 573
     #endif
581 574
 
582 575
     if (!leveling_active) return;
@@ -605,7 +598,7 @@ void Planner::calculate_volumetric_multipliers() {
605 598
       #endif
606 599
 
607 600
       rz += (
608
-        #if ENABLED(AUTO_BED_LEVELING_UBL) // UBL_DELTA
601
+        #if ENABLED(AUTO_BED_LEVELING_UBL)
609 602
           ubl.get_z_correction(rx, ry) * fade_scaling_factor
610 603
         #elif ENABLED(MESH_BED_LEVELING)
611 604
           mbl.get_z(rx, ry
@@ -667,14 +660,7 @@ void Planner::calculate_volumetric_multipliers() {
667 660
     }
668 661
 
669 662
     #if ENABLED(SKEW_CORRECTION)
670
-      if (WITHIN(raw[X_AXIS], X_MIN_POS, X_MAX_POS) && WITHIN(raw[Y_AXIS], Y_MIN_POS, Y_MAX_POS)) {
671
-        const float temprx = raw[X_AXIS] + raw[Y_AXIS] * planner.xy_skew_factor + raw[Z_AXIS] * planner.xz_skew_factor,
672
-                    tempry = raw[Y_AXIS] + raw[Z_AXIS] * planner.yz_skew_factor;
673
-        if (WITHIN(temprx, X_MIN_POS, X_MAX_POS) && WITHIN(tempry, Y_MIN_POS, Y_MAX_POS)) {
674
-          raw[X_AXIS] = temprx;
675
-          raw[Y_AXIS] = tempry;
676
-        }
677
-      }
663
+      unskew(raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS]);
678 664
     #endif
679 665
   }
680 666
 
@@ -1354,7 +1340,7 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE], float fr_mm_s, const
1354 1340
 } // _buffer_steps()
1355 1341
 
1356 1342
 /**
1357
- * Planner::_buffer_line
1343
+ * Planner::buffer_segment
1358 1344
  *
1359 1345
  * Add a new linear movement to the buffer in axis units.
1360 1346
  *
@@ -1364,7 +1350,7 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE], float fr_mm_s, const
1364 1350
  *  fr_mm_s   - (target) speed of the move
1365 1351
  *  extruder  - target extruder
1366 1352
  */
1367
-void Planner::_buffer_line(const float &a, const float &b, const float &c, const float &e, const float &fr_mm_s, const uint8_t extruder) {
1353
+void Planner::buffer_segment(const float &a, const float &b, const float &c, const float &e, const float &fr_mm_s, const uint8_t extruder) {
1368 1354
   // When changing extruders recalculate steps corresponding to the E position
1369 1355
   #if ENABLED(DISTINCT_E_FACTORS)
1370 1356
     if (last_extruder != extruder && axis_steps_per_mm[E_AXIS_N] != axis_steps_per_mm[E_AXIS + last_extruder]) {
@@ -1383,7 +1369,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1383 1369
   };
1384 1370
 
1385 1371
   /* <-- add a slash to enable
1386
-    SERIAL_ECHOPAIR("  _buffer_line FR:", fr_mm_s);
1372
+    SERIAL_ECHOPAIR("  buffer_segment FR:", fr_mm_s);
1387 1373
     #if IS_KINEMATIC
1388 1374
       SERIAL_ECHOPAIR(" A:", a);
1389 1375
       SERIAL_ECHOPAIR(" (", position[A_AXIS]);
@@ -1430,7 +1416,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1430 1416
 
1431 1417
   stepper.wake_up();
1432 1418
 
1433
-} // _buffer_line()
1419
+} // buffer_segment()
1434 1420
 
1435 1421
 /**
1436 1422
  * Directly set the planner XYZ position (and stepper positions)
@@ -1455,18 +1441,18 @@ void Planner::_set_position_mm(const float &a, const float &b, const float &c, c
1455 1441
   ZERO(previous_speed);
1456 1442
 }
1457 1443
 
1458
-void Planner::set_position_mm_kinematic(const float position[NUM_AXIS]) {
1444
+void Planner::set_position_mm_kinematic(const float (&cart)[XYZE]) {
1459 1445
   #if PLANNER_LEVELING
1460
-    float lpos[XYZ] = { position[X_AXIS], position[Y_AXIS], position[Z_AXIS] };
1461
-    apply_leveling(lpos);
1446
+    float raw[XYZ] = { cart[X_AXIS], cart[Y_AXIS], cart[Z_AXIS] };
1447
+    apply_leveling(raw);
1462 1448
   #else
1463
-    const float * const lpos = position;
1449
+    const float (&raw)[XYZE] = cart;
1464 1450
   #endif
1465 1451
   #if IS_KINEMATIC
1466
-    inverse_kinematics(lpos);
1467
-    _set_position_mm(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], position[E_AXIS]);
1452
+    inverse_kinematics(raw);
1453
+    _set_position_mm(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], cart[E_AXIS]);
1468 1454
   #else
1469
-    _set_position_mm(lpos[X_AXIS], lpos[Y_AXIS], lpos[Z_AXIS], position[E_AXIS]);
1455
+    _set_position_mm(raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS], cart[E_AXIS]);
1470 1456
   #endif
1471 1457
 }
1472 1458
 

+ 34
- 10
Marlin/planner.h View File

@@ -142,7 +142,7 @@ class Planner {
142 142
      *            head!=tail : blocks are in the buffer
143 143
      *   head==(tail-1)%size : the buffer is full
144 144
      *
145
-     *  Writer of head is Planner::_buffer_line().
145
+     *  Writer of head is Planner::buffer_segment().
146 146
      *  Reader of tail is Stepper::isr(). Always consider tail busy / read-only
147 147
      */
148 148
     static block_t block_buffer[BLOCK_BUFFER_SIZE];
@@ -341,6 +341,30 @@ class Planner {
341 341
 
342 342
     #endif
343 343
 
344
+    #if ENABLED(SKEW_CORRECTION)
345
+
346
+      FORCE_INLINE static void skew(float &cx, float &cy, const float &cz) {
347
+        if (WITHIN(cx, X_MIN_POS + 1, X_MAX_POS) && WITHIN(cy, Y_MIN_POS + 1, Y_MAX_POS)) {
348
+          const float sx = cx - (cy * xy_skew_factor) - (cz * (xz_skew_factor - (xy_skew_factor * yz_skew_factor))),
349
+                      sy = cy - (cz * yz_skew_factor);
350
+          if (WITHIN(sx, X_MIN_POS, X_MAX_POS) && WITHIN(sy, Y_MIN_POS, Y_MAX_POS)) {
351
+            cx = sx; cy = sy;
352
+          }
353
+        }
354
+      }
355
+
356
+      FORCE_INLINE static void unskew(float &cx, float &cy, const float &cz) {
357
+        if (WITHIN(cx, X_MIN_POS, X_MAX_POS) && WITHIN(cy, Y_MIN_POS, Y_MAX_POS)) {
358
+          const float sx = cx + cy * xy_skew_factor + cz * xz_skew_factor,
359
+                      sy = cy + cz * yz_skew_factor;
360
+          if (WITHIN(sx, X_MIN_POS, X_MAX_POS) && WITHIN(sy, Y_MIN_POS, Y_MAX_POS)) {
361
+            cx = sx; cy = sy;
362
+          }
363
+        }
364
+      }
365
+
366
+    #endif // SKEW_CORRECTION
367
+
344 368
     #if PLANNER_LEVELING
345 369
 
346 370
       #define ARG_X float rx
@@ -352,7 +376,7 @@ class Planner {
352 376
        * as it will be given to the planner and steppers.
353 377
        */
354 378
       static void apply_leveling(float &rx, float &ry, float &rz);
355
-      static void apply_leveling(float raw[XYZ]) { apply_leveling(raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS]); }
379
+      static void apply_leveling(float (&raw)[XYZ]) { apply_leveling(raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS]); }
356 380
       static void unapply_leveling(float raw[XYZ]);
357 381
 
358 382
     #else
@@ -375,7 +399,7 @@ class Planner {
375 399
     static void _buffer_steps(const int32_t (&target)[XYZE], float fr_mm_s, const uint8_t extruder);
376 400
 
377 401
     /**
378
-     * Planner::_buffer_line
402
+     * Planner::buffer_segment
379 403
      *
380 404
      * Add a new linear movement to the buffer in axis units.
381 405
      *
@@ -385,7 +409,7 @@ class Planner {
385 409
      *  fr_mm_s   - (target) speed of the move
386 410
      *  extruder  - target extruder
387 411
      */
388
-    static void _buffer_line(const float &a, const float &b, const float &c, const float &e, const float &fr_mm_s, const uint8_t extruder);
412
+    static void buffer_segment(const float &a, const float &b, const float &c, const float &e, const float &fr_mm_s, const uint8_t extruder);
389 413
 
390 414
     static void _set_position_mm(const float &a, const float &b, const float &c, const float &e);
391 415
 
@@ -405,7 +429,7 @@ class Planner {
405 429
       #if PLANNER_LEVELING && IS_CARTESIAN
406 430
         apply_leveling(rx, ry, rz);
407 431
       #endif
408
-      _buffer_line(rx, ry, rz, e, fr_mm_s, extruder);
432
+      buffer_segment(rx, ry, rz, e, fr_mm_s, extruder);
409 433
     }
410 434
 
411 435
     /**
@@ -417,18 +441,18 @@ class Planner {
417 441
      *  fr_mm_s  - (target) speed of the move (mm/s)
418 442
      *  extruder - target extruder
419 443
      */
420
-    FORCE_INLINE static void buffer_line_kinematic(const float cart[XYZE], const float &fr_mm_s, const uint8_t extruder) {
444
+    FORCE_INLINE static void buffer_line_kinematic(const float (&cart)[XYZE], const float &fr_mm_s, const uint8_t extruder) {
421 445
       #if PLANNER_LEVELING
422 446
         float raw[XYZ] = { cart[X_AXIS], cart[Y_AXIS], cart[Z_AXIS] };
423 447
         apply_leveling(raw);
424 448
       #else
425
-        const float * const raw = cart;
449
+        const float (&raw)[XYZE] = cart;
426 450
       #endif
427 451
       #if IS_KINEMATIC
428 452
         inverse_kinematics(raw);
429
-        _buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], cart[E_AXIS], fr_mm_s, extruder);
453
+        buffer_segment(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], cart[E_AXIS], fr_mm_s, extruder);
430 454
       #else
431
-        _buffer_line(raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS], cart[E_AXIS], fr_mm_s, extruder);
455
+        buffer_segment(raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS], cart[E_AXIS], fr_mm_s, extruder);
432 456
       #endif
433 457
     }
434 458
 
@@ -447,7 +471,7 @@ class Planner {
447 471
       #endif
448 472
       _set_position_mm(rx, ry, rz, e);
449 473
     }
450
-    static void set_position_mm_kinematic(const float position[NUM_AXIS]);
474
+    static void set_position_mm_kinematic(const float (&cart)[XYZE]);
451 475
     static void set_position_mm(const AxisEnum axis, const float &v);
452 476
     FORCE_INLINE static void set_z_position_mm(const float &z) { set_position_mm(Z_AXIS, z); }
453 477
     FORCE_INLINE static void set_e_position_mm(const float &e) { set_position_mm(AxisEnum(E_AXIS), e); }

+ 2
- 2
Marlin/stepper.cpp View File

@@ -1198,7 +1198,7 @@ void Stepper::set_e_position(const long &e) {
1198 1198
 /**
1199 1199
  * Get a stepper's position in steps.
1200 1200
  */
1201
-long Stepper::position(AxisEnum axis) {
1201
+long Stepper::position(const AxisEnum axis) {
1202 1202
   CRITICAL_SECTION_START;
1203 1203
   const long count_pos = count_position[axis];
1204 1204
   CRITICAL_SECTION_END;
@@ -1209,7 +1209,7 @@ long Stepper::position(AxisEnum axis) {
1209 1209
  * Get an axis position according to stepper position(s)
1210 1210
  * For CORE machines apply translation from ABC to XYZ.
1211 1211
  */
1212
-float Stepper::get_axis_position_mm(AxisEnum axis) {
1212
+float Stepper::get_axis_position_mm(const AxisEnum axis) {
1213 1213
   float axis_steps;
1214 1214
   #if IS_CORE
1215 1215
     // Requesting one of the "core" axes?

+ 6
- 6
Marlin/stepper.h View File

@@ -209,7 +209,7 @@ class Stepper {
209 209
     //
210 210
     // Get the position of a stepper, in steps
211 211
     //
212
-    static long position(AxisEnum axis);
212
+    static long position(const AxisEnum axis);
213 213
 
214 214
     //
215 215
     // Report the positions of the steppers, in steps
@@ -219,13 +219,13 @@ class Stepper {
219 219
     //
220 220
     // Get the position (mm) of an axis based on stepper position(s)
221 221
     //
222
-    static float get_axis_position_mm(AxisEnum axis);
222
+    static float get_axis_position_mm(const AxisEnum axis);
223 223
 
224 224
     //
225 225
     // SCARA AB axes are in degrees, not mm
226 226
     //
227 227
     #if IS_SCARA
228
-      FORCE_INLINE static float get_axis_position_degrees(AxisEnum axis) { return get_axis_position_mm(axis); }
228
+      FORCE_INLINE static float get_axis_position_degrees(const AxisEnum axis) { return get_axis_position_mm(axis); }
229 229
     #endif
230 230
 
231 231
     //
@@ -247,7 +247,7 @@ class Stepper {
247 247
     //
248 248
     // The direction of a single motor
249 249
     //
250
-    FORCE_INLINE static bool motor_direction(AxisEnum axis) { return TEST(last_direction_bits, axis); }
250
+    FORCE_INLINE static bool motor_direction(const AxisEnum axis) { return TEST(last_direction_bits, axis); }
251 251
 
252 252
     #if HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM
253 253
       static void digitalPotWrite(const int16_t address, const int16_t value);
@@ -287,12 +287,12 @@ class Stepper {
287 287
     //
288 288
     // Handle a triggered endstop
289 289
     //
290
-    static void endstop_triggered(AxisEnum axis);
290
+    static void endstop_triggered(const AxisEnum axis);
291 291
 
292 292
     //
293 293
     // Triggered position of an axis in mm (not core-savvy)
294 294
     //
295
-    FORCE_INLINE static float triggered_position_mm(AxisEnum axis) {
295
+    FORCE_INLINE static float triggered_position_mm(const AxisEnum axis) {
296 296
       return endstops_trigsteps[axis] * planner.steps_to_mm[axis];
297 297
     }
298 298
 

+ 1
- 1
Marlin/stepper_dac.cpp View File

@@ -94,7 +94,7 @@
94 94
   static float dac_perc(int8_t n) { return 100.0 * mcp4728_getValue(dac_order[n]) * (1.0 / (DAC_STEPPER_MAX)); }
95 95
   static float dac_amps(int8_t n) { return mcp4728_getDrvPct(dac_order[n]) * (DAC_STEPPER_MAX) * 0.125 * (1.0 / (DAC_STEPPER_SENSE)); }
96 96
 
97
-  uint8_t dac_current_get_percent(AxisEnum axis) { return mcp4728_getDrvPct(dac_order[axis]); }
97
+  uint8_t dac_current_get_percent(const AxisEnum axis) { return mcp4728_getDrvPct(dac_order[axis]); }
98 98
   void dac_current_set_percents(const uint8_t pct[XYZE]) {
99 99
     LOOP_XYZE(i) dac_channel_pct[i] = pct[dac_order[i]];
100 100
     mcp4728_setDrvPct(dac_channel_pct);

+ 1
- 1
Marlin/stepper_dac.h View File

@@ -51,7 +51,7 @@ void dac_current_percent(uint8_t channel, float val);
51 51
 void dac_current_raw(uint8_t channel, uint16_t val);
52 52
 void dac_print_values();
53 53
 void dac_commit_eeprom();
54
-uint8_t dac_current_get_percent(AxisEnum axis);
54
+uint8_t dac_current_get_percent(const AxisEnum axis);
55 55
 void dac_current_set_percents(const uint8_t pct[XYZE]);
56 56
 
57 57
 #endif // STEPPER_DAC_H

+ 54
- 1
Marlin/ubl.cpp View File

@@ -51,6 +51,59 @@
51 51
     safe_delay(10);
52 52
   }
53 53
 
54
+  #if ENABLED(UBL_DEVEL_DEBUGGING)
55
+
56
+    static void debug_echo_axis(const AxisEnum axis) {
57
+      if (current_position[axis] == destination[axis])
58
+        SERIAL_ECHOPGM("-------------");
59
+      else
60
+        SERIAL_ECHO_F(destination[X_AXIS], 6);
61
+    }
62
+
63
+    void debug_current_and_destination(const char *title) {
64
+
65
+      // if the title message starts with a '!' it is so important, we are going to
66
+      // ignore the status of the g26_debug_flag
67
+      if (*title != '!' && !g26_debug_flag) return;
68
+
69
+      const float de = destination[E_AXIS] - current_position[E_AXIS];
70
+
71
+      if (de == 0.0) return; // Printing moves only
72
+
73
+      const float dx = destination[X_AXIS] - current_position[X_AXIS],
74
+                  dy = destination[Y_AXIS] - current_position[Y_AXIS],
75
+                  xy_dist = HYPOT(dx, dy);
76
+
77
+      if (xy_dist == 0.0) return;
78
+
79
+      SERIAL_ECHOPGM("   fpmm=");
80
+      const float fpmm = de / xy_dist;
81
+      SERIAL_ECHO_F(fpmm, 6);
82
+
83
+      SERIAL_ECHOPGM("    current=( ");
84
+      SERIAL_ECHO_F(current_position[X_AXIS], 6);
85
+      SERIAL_ECHOPGM(", ");
86
+      SERIAL_ECHO_F(current_position[Y_AXIS], 6);
87
+      SERIAL_ECHOPGM(", ");
88
+      SERIAL_ECHO_F(current_position[Z_AXIS], 6);
89
+      SERIAL_ECHOPGM(", ");
90
+      SERIAL_ECHO_F(current_position[E_AXIS], 6);
91
+      SERIAL_ECHOPGM(" )   destination=( ");
92
+      debug_echo_axis(X_AXIS);
93
+      SERIAL_ECHOPGM(", ");
94
+      debug_echo_axis(Y_AXIS);
95
+      SERIAL_ECHOPGM(", ");
96
+      debug_echo_axis(Z_AXIS);
97
+      SERIAL_ECHOPGM(", ");
98
+      debug_echo_axis(E_AXIS);
99
+      SERIAL_ECHOPGM(" )   ");
100
+      SERIAL_ECHO(title);
101
+      SERIAL_EOL();
102
+
103
+    }
104
+
105
+  #endif // UBL_DEVEL_DEBUGGING
106
+
54 107
   int8_t unified_bed_leveling::storage_slot;
55 108
 
56 109
   float unified_bed_leveling::z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
@@ -174,7 +227,7 @@
174 227
     uint8_t error_flag = 0;
175 228
 
176 229
     if (settings.calc_num_meshes() < 1) {
177
-      SERIAL_PROTOCOLLNPGM("?Insufficient EEPROM storage for a mesh of this size.");
230
+      SERIAL_PROTOCOLLNPGM("?Mesh too big for EEPROM.");
178 231
       error_flag++;
179 232
     }
180 233
 

+ 26
- 16
Marlin/ubl.h View File

@@ -26,6 +26,9 @@
26 26
 #include "MarlinConfig.h"
27 27
 
28 28
 #if ENABLED(AUTO_BED_LEVELING_UBL)
29
+
30
+  //#define UBL_DEVEL_DEBUGGING
31
+
29 32
   #include "Marlin.h"
30 33
   #include "planner.h"
31 34
   #include "math.h"
@@ -41,7 +44,11 @@
41 44
 
42 45
   // ubl_motion.cpp
43 46
 
44
-  void debug_current_and_destination(const char * const title);
47
+  #if ENABLED(UBL_DEVEL_DEBUGGING)
48
+    void debug_current_and_destination(const char * const title);
49
+  #else
50
+    FORCE_INLINE void debug_current_and_destination(const char * const title) { UNUSED(title); }
51
+  #endif
45 52
 
46 53
   // ubl_G29.cpp
47 54
 
@@ -319,21 +326,24 @@
319 326
         return i < GRID_MAX_POINTS_Y ? pgm_read_float(&_mesh_index_to_ypos[i]) : MESH_MIN_Y + i * (MESH_Y_DIST);
320 327
       }
321 328
 
322
-      static bool prepare_segmented_line_to(const float rtarget[XYZE], const float &feedrate);
323
-      static void line_to_destination_cartesian(const float &fr, uint8_t e);
324
-
325
-    #define _CMPZ(a,b) (z_values[a][b] == z_values[a][b+1])
326
-    #define CMPZ(a) (_CMPZ(a, 0) && _CMPZ(a, 1))
327
-    #define ZZER(a) (z_values[a][0] == 0)
328
-
329
-    FORCE_INLINE bool mesh_is_valid() {
330
-      return !(
331
-        (    CMPZ(0) && CMPZ(1) && CMPZ(2) // adjacent z values all equal?
332
-          && ZZER(0) && ZZER(1) && ZZER(2) // all zero at the edge?
333
-        )
334
-        || isnan(z_values[0][0])
335
-      );
336
-    }
329
+      #if UBL_SEGMENTED
330
+        static bool prepare_segmented_line_to(const float (&rtarget)[XYZE], const float &feedrate);
331
+      #else
332
+        static void line_to_destination_cartesian(const float &fr, const uint8_t e);
333
+      #endif
334
+
335
+      #define _CMPZ(a,b) (z_values[a][b] == z_values[a][b+1])
336
+      #define CMPZ(a) (_CMPZ(a, 0) && _CMPZ(a, 1))
337
+      #define ZZER(a) (z_values[a][0] == 0)
338
+
339
+      FORCE_INLINE bool mesh_is_valid() {
340
+        return !(
341
+          (    CMPZ(0) && CMPZ(1) && CMPZ(2) // adjacent z values all equal?
342
+            && ZZER(0) && ZZER(1) && ZZER(2) // all zero at the edge?
343
+          )
344
+          || isnan(z_values[0][0])
345
+        );
346
+      }
337 347
   }; // class unified_bed_leveling
338 348
 
339 349
   extern unified_bed_leveling ubl;

+ 4
- 6
Marlin/ubl_G29.cpp View File

@@ -24,8 +24,6 @@
24 24
 
25 25
 #if ENABLED(AUTO_BED_LEVELING_UBL)
26 26
 
27
-  //#define UBL_DEVEL_DEBUGGING
28
-
29 27
   #include "ubl.h"
30 28
   #include "Marlin.h"
31 29
   #include "hex_print_routines.h"
@@ -1165,12 +1163,12 @@
1165 1163
 
1166 1164
   static uint8_t ubl_state_at_invocation = 0;
1167 1165
 
1168
-  #ifdef UBL_DEVEL_DEBUGGING
1166
+  #if ENABLED(UBL_DEVEL_DEBUGGING)
1169 1167
     static uint8_t ubl_state_recursion_chk = 0;
1170 1168
   #endif
1171 1169
 
1172 1170
   void unified_bed_leveling::save_ubl_active_state_and_disable() {
1173
-    #ifdef UBL_DEVEL_DEBUGGING
1171
+    #if ENABLED(UBL_DEVEL_DEBUGGING)
1174 1172
       ubl_state_recursion_chk++;
1175 1173
       if (ubl_state_recursion_chk != 1) {
1176 1174
         SERIAL_ECHOLNPGM("save_ubl_active_state_and_disabled() called multiple times in a row.");
@@ -1186,7 +1184,7 @@
1186 1184
   }
1187 1185
 
1188 1186
   void unified_bed_leveling::restore_ubl_active_state_and_leave() {
1189
-    #ifdef UBL_DEVEL_DEBUGGING
1187
+    #if ENABLED(UBL_DEVEL_DEBUGGING)
1190 1188
       if (--ubl_state_recursion_chk) {
1191 1189
         SERIAL_ECHOLNPGM("restore_ubl_active_state_and_leave() called too many times.");
1192 1190
         #if ENABLED(NEWPANEL)
@@ -1267,7 +1265,7 @@
1267 1265
     SERIAL_EOL();
1268 1266
     safe_delay(50);
1269 1267
 
1270
-    #ifdef UBL_DEVEL_DEBUGGING
1268
+    #if ENABLED(UBL_DEVEL_DEBUGGING)
1271 1269
       SERIAL_PROTOCOLLNPAIR("ubl_state_at_invocation :", ubl_state_at_invocation);
1272 1270
       SERIAL_EOL();
1273 1271
       SERIAL_PROTOCOLLNPAIR("ubl_state_recursion_chk :", ubl_state_recursion_chk);

+ 319
- 366
Marlin/ubl_motion.cpp View File

@@ -30,250 +30,326 @@
30 30
   #include <avr/io.h>
31 31
   #include <math.h>
32 32
 
33
-  extern float destination[XYZE];
34
-
35 33
   #if AVR_AT90USB1286_FAMILY  // Teensyduino & Printrboard IDE extensions have compile errors without this
36 34
     inline void set_current_from_destination() { COPY(current_position, destination); }
37 35
   #else
38 36
     extern void set_current_from_destination();
39 37
   #endif
40 38
 
41
-  static void debug_echo_axis(const AxisEnum axis) {
42
-    if (current_position[axis] == destination[axis])
43
-      SERIAL_ECHOPGM("-------------");
44
-    else
45
-      SERIAL_ECHO_F(destination[X_AXIS], 6);
46
-  }
47
-
48
-  void debug_current_and_destination(const char *title) {
49
-
50
-    // if the title message starts with a '!' it is so important, we are going to
51
-    // ignore the status of the g26_debug_flag
52
-    if (*title != '!' && !g26_debug_flag) return;
53
-
54
-    const float de = destination[E_AXIS] - current_position[E_AXIS];
55
-
56
-    if (de == 0.0) return; // Printing moves only
57
-
58
-    const float dx = destination[X_AXIS] - current_position[X_AXIS],
59
-                dy = destination[Y_AXIS] - current_position[Y_AXIS],
60
-                xy_dist = HYPOT(dx, dy);
61
-
62
-    if (xy_dist == 0.0) return;
63
-
64
-    SERIAL_ECHOPGM("   fpmm=");
65
-    const float fpmm = de / xy_dist;
66
-    SERIAL_ECHO_F(fpmm, 6);
67
-
68
-    SERIAL_ECHOPGM("    current=( ");
69
-    SERIAL_ECHO_F(current_position[X_AXIS], 6);
70
-    SERIAL_ECHOPGM(", ");
71
-    SERIAL_ECHO_F(current_position[Y_AXIS], 6);
72
-    SERIAL_ECHOPGM(", ");
73
-    SERIAL_ECHO_F(current_position[Z_AXIS], 6);
74
-    SERIAL_ECHOPGM(", ");
75
-    SERIAL_ECHO_F(current_position[E_AXIS], 6);
76
-    SERIAL_ECHOPGM(" )   destination=( ");
77
-    debug_echo_axis(X_AXIS);
78
-    SERIAL_ECHOPGM(", ");
79
-    debug_echo_axis(Y_AXIS);
80
-    SERIAL_ECHOPGM(", ");
81
-    debug_echo_axis(Z_AXIS);
82
-    SERIAL_ECHOPGM(", ");
83
-    debug_echo_axis(E_AXIS);
84
-    SERIAL_ECHOPGM(" )   ");
85
-    SERIAL_ECHO(title);
86
-    SERIAL_EOL();
87
-
88
-  }
89
-
90
-  void unified_bed_leveling::line_to_destination_cartesian(const float &feed_rate, uint8_t extruder) {
91
-    /**
92
-     * Much of the nozzle movement will be within the same cell. So we will do as little computation
93
-     * as possible to determine if this is the case. If this move is within the same cell, we will
94
-     * just do the required Z-Height correction, call the Planner's buffer_line() routine, and leave
95
-     */
96
-    const float start[XYZE] = {
97
-                  current_position[X_AXIS],
98
-                  current_position[Y_AXIS],
99
-                  current_position[Z_AXIS],
100
-                  current_position[E_AXIS]
101
-                },
102
-                end[XYZE] = {
103
-                  destination[X_AXIS],
104
-                  destination[Y_AXIS],
105
-                  destination[Z_AXIS],
106
-                  destination[E_AXIS]
107
-                };
108
-
109
-    const int cell_start_xi = get_cell_index_x(start[X_AXIS]),
110
-              cell_start_yi = get_cell_index_y(start[Y_AXIS]),
111
-              cell_dest_xi  = get_cell_index_x(end[X_AXIS]),
112
-              cell_dest_yi  = get_cell_index_y(end[Y_AXIS]);
113
-
114
-    if (g26_debug_flag) {
115
-      SERIAL_ECHOPAIR(" ubl.line_to_destination(xe=", end[X_AXIS]);
116
-      SERIAL_ECHOPAIR(", ye=", end[Y_AXIS]);
117
-      SERIAL_ECHOPAIR(", ze=", end[Z_AXIS]);
118
-      SERIAL_ECHOPAIR(", ee=", end[E_AXIS]);
119
-      SERIAL_CHAR(')');
120
-      SERIAL_EOL();
121
-      debug_current_and_destination(PSTR("Start of ubl.line_to_destination()"));
122
-    }
39
+  #if !UBL_SEGMENTED
123 40
 
124
-    if (cell_start_xi == cell_dest_xi && cell_start_yi == cell_dest_yi) { // if the whole move is within the same cell,
41
+    void unified_bed_leveling::line_to_destination_cartesian(const float &feed_rate, const uint8_t extruder) {
125 42
       /**
126
-       * we don't need to break up the move
127
-       *
128
-       * If we are moving off the print bed, we are going to allow the move at this level.
129
-       * But we detect it and isolate it. For now, we just pass along the request.
43
+       * Much of the nozzle movement will be within the same cell. So we will do as little computation
44
+       * as possible to determine if this is the case. If this move is within the same cell, we will
45
+       * just do the required Z-Height correction, call the Planner's buffer_line() routine, and leave
130 46
        */
47
+      #if ENABLED(SKEW_CORRECTION)
48
+        // For skew correction just adjust the destination point and we're done
49
+        float start[XYZE] = { current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS] },
50
+              end[XYZE] = { destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS] };
51
+        planner.skew(start[X_AXIS], start[Y_AXIS], start[Z_AXIS]);
52
+        planner.skew(end[X_AXIS], end[Y_AXIS], end[Z_AXIS]);
53
+      #else
54
+        const float (&start)[XYZE] = current_position,
55
+                      (&end)[XYZE] = destination;
56
+      #endif
131 57
 
132
-      if (!WITHIN(cell_dest_xi, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(cell_dest_yi, 0, GRID_MAX_POINTS_Y - 1)) {
58
+      const int cell_start_xi = get_cell_index_x(start[X_AXIS]),
59
+                cell_start_yi = get_cell_index_y(start[Y_AXIS]),
60
+                cell_dest_xi  = get_cell_index_x(end[X_AXIS]),
61
+                cell_dest_yi  = get_cell_index_y(end[Y_AXIS]);
62
+
63
+      if (g26_debug_flag) {
64
+        SERIAL_ECHOPAIR(" ubl.line_to_destination_cartesian(xe=", destination[X_AXIS]);
65
+        SERIAL_ECHOPAIR(", ye=", destination[Y_AXIS]);
66
+        SERIAL_ECHOPAIR(", ze=", destination[Z_AXIS]);
67
+        SERIAL_ECHOPAIR(", ee=", destination[E_AXIS]);
68
+        SERIAL_CHAR(')');
69
+        SERIAL_EOL();
70
+        debug_current_and_destination(PSTR("Start of ubl.line_to_destination_cartesian()"));
71
+      }
133 72
 
134
-        // Note: There is no Z Correction in this case. We are off the grid and don't know what
135
-        // a reasonable correction would be.
73
+      if (cell_start_xi == cell_dest_xi && cell_start_yi == cell_dest_yi) { // if the whole move is within the same cell,
74
+        /**
75
+         * we don't need to break up the move
76
+         *
77
+         * If we are moving off the print bed, we are going to allow the move at this level.
78
+         * But we detect it and isolate it. For now, we just pass along the request.
79
+         */
136 80
 
137
-        planner._buffer_line(end[X_AXIS], end[Y_AXIS], end[Z_AXIS], end[E_AXIS], feed_rate, extruder);
138
-        set_current_from_destination();
81
+        if (!WITHIN(cell_dest_xi, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(cell_dest_yi, 0, GRID_MAX_POINTS_Y - 1)) {
82
+
83
+          // Note: There is no Z Correction in this case. We are off the grid and don't know what
84
+          // a reasonable correction would be.
85
+
86
+          planner.buffer_segment(end[X_AXIS], end[Y_AXIS], end[Z_AXIS], end[E_AXIS], feed_rate, extruder);
87
+          set_current_from_destination();
88
+
89
+          if (g26_debug_flag)
90
+            debug_current_and_destination(PSTR("out of bounds in ubl.line_to_destination_cartesian()"));
91
+
92
+          return;
93
+        }
94
+
95
+        FINAL_MOVE:
96
+
97
+        /**
98
+         * Optimize some floating point operations here. We could call float get_z_correction(float x0, float y0) to
99
+         * generate the correction for us. But we can lighten the load on the CPU by doing a modified version of the function.
100
+         * We are going to only calculate the amount we are from the first mesh line towards the second mesh line once.
101
+         * We will use this fraction in both of the original two Z Height calculations for the bi-linear interpolation. And,
102
+         * instead of doing a generic divide of the distance, we know the distance is MESH_X_DIST so we can use the preprocessor
103
+         * to create a 1-over number for us. That will allow us to do a floating point multiply instead of a floating point divide.
104
+         */
105
+
106
+        const float xratio = (end[X_AXIS] - mesh_index_to_xpos(cell_dest_xi)) * (1.0 / (MESH_X_DIST));
107
+
108
+        float z1 = z_values[cell_dest_xi    ][cell_dest_yi    ] + xratio *
109
+                  (z_values[cell_dest_xi + 1][cell_dest_yi    ] - z_values[cell_dest_xi][cell_dest_yi    ]),
110
+              z2 = z_values[cell_dest_xi    ][cell_dest_yi + 1] + xratio *
111
+                  (z_values[cell_dest_xi + 1][cell_dest_yi + 1] - z_values[cell_dest_xi][cell_dest_yi + 1]);
112
+
113
+        if (cell_dest_xi >= GRID_MAX_POINTS_X - 1) z1 = z2 = 0.0;
114
+
115
+        // we are done with the fractional X distance into the cell. Now with the two Z-Heights we have calculated, we
116
+        // are going to apply the Y-Distance into the cell to interpolate the final Z correction.
117
+
118
+        const float yratio = (end[Y_AXIS] - mesh_index_to_ypos(cell_dest_yi)) * (1.0 / (MESH_Y_DIST));
119
+        float z0 = cell_dest_yi < GRID_MAX_POINTS_Y - 1 ? (z1 + (z2 - z1) * yratio) * planner.fade_scaling_factor_for_z(end[Z_AXIS]) : 0.0;
120
+
121
+        /**
122
+         * If part of the Mesh is undefined, it will show up as NAN
123
+         * in z_values[][] and propagate through the
124
+         * calculations. If our correction is NAN, we throw it out
125
+         * because part of the Mesh is undefined and we don't have the
126
+         * information we need to complete the height correction.
127
+         */
128
+        if (isnan(z0)) z0 = 0.0;
129
+
130
+        planner.buffer_segment(end[X_AXIS], end[Y_AXIS], end[Z_AXIS] + z0, end[E_AXIS], feed_rate, extruder);
139 131
 
140 132
         if (g26_debug_flag)
141
-          debug_current_and_destination(PSTR("out of bounds in ubl.line_to_destination()"));
133
+          debug_current_and_destination(PSTR("FINAL_MOVE in ubl.line_to_destination_cartesian()"));
142 134
 
135
+        set_current_from_destination();
143 136
         return;
144 137
       }
145 138
 
146
-      FINAL_MOVE:
139
+      /**
140
+       * If we get here, we are processing a move that crosses at least one Mesh Line. We will check
141
+       * for the simple case of just crossing X or just crossing Y Mesh Lines after we get all the details
142
+       * of the move figured out. We can process the easy case of just crossing an X or Y Mesh Line with less
143
+       * computation and in fact most lines are of this nature. We will check for that in the following
144
+       * blocks of code:
145
+       */
146
+
147
+      const float dx = end[X_AXIS] - start[X_AXIS],
148
+                  dy = end[Y_AXIS] - start[Y_AXIS];
149
+
150
+      const int left_flag = dx < 0.0 ? 1 : 0,
151
+                down_flag = dy < 0.0 ? 1 : 0;
152
+
153
+      const float adx = left_flag ? -dx : dx,
154
+                  ady = down_flag ? -dy : dy;
155
+
156
+      const int dxi = cell_start_xi == cell_dest_xi ? 0 : left_flag ? -1 : 1,
157
+                dyi = cell_start_yi == cell_dest_yi ? 0 : down_flag ? -1 : 1;
147 158
 
148 159
       /**
149
-       * Optimize some floating point operations here. We could call float get_z_correction(float x0, float y0) to
150
-       * generate the correction for us. But we can lighten the load on the CPU by doing a modified version of the function.
151
-       * We are going to only calculate the amount we are from the first mesh line towards the second mesh line once.
152
-       * We will use this fraction in both of the original two Z Height calculations for the bi-linear interpolation. And,
153
-       * instead of doing a generic divide of the distance, we know the distance is MESH_X_DIST so we can use the preprocessor
154
-       * to create a 1-over number for us. That will allow us to do a floating point multiply instead of a floating point divide.
160
+       * Compute the scaling factor for the extruder for each partial move.
161
+       * We need to watch out for zero length moves because it will cause us to
162
+       * have an infinate scaling factor. We are stuck doing a floating point
163
+       * divide to get our scaling factor, but after that, we just multiply by this
164
+       * number. We also pick our scaling factor based on whether the X or Y
165
+       * component is larger. We use the biggest of the two to preserve precision.
155 166
        */
156 167
 
157
-      const float xratio = (end[X_AXIS] - mesh_index_to_xpos(cell_dest_xi)) * (1.0 / (MESH_X_DIST));
168
+      const bool use_x_dist = adx > ady;
158 169
 
159
-      float z1 = z_values[cell_dest_xi    ][cell_dest_yi    ] + xratio *
160
-                (z_values[cell_dest_xi + 1][cell_dest_yi    ] - z_values[cell_dest_xi][cell_dest_yi    ]),
161
-            z2 = z_values[cell_dest_xi    ][cell_dest_yi + 1] + xratio *
162
-                (z_values[cell_dest_xi + 1][cell_dest_yi + 1] - z_values[cell_dest_xi][cell_dest_yi + 1]);
170
+      float on_axis_distance = use_x_dist ? dx : dy,
171
+            e_position = end[E_AXIS] - start[E_AXIS],
172
+            z_position = end[Z_AXIS] - start[Z_AXIS];
163 173
 
164
-      if (cell_dest_xi >= GRID_MAX_POINTS_X - 1) z1 = z2 = 0.0;
174
+      const float e_normalized_dist = e_position / on_axis_distance,
175
+                  z_normalized_dist = z_position / on_axis_distance;
165 176
 
166
-      // we are done with the fractional X distance into the cell. Now with the two Z-Heights we have calculated, we
167
-      // are going to apply the Y-Distance into the cell to interpolate the final Z correction.
177
+      int current_xi = cell_start_xi,
178
+          current_yi = cell_start_yi;
168 179
 
169
-      const float yratio = (end[Y_AXIS] - mesh_index_to_ypos(cell_dest_yi)) * (1.0 / (MESH_Y_DIST));
170
-      float z0 = cell_dest_yi < GRID_MAX_POINTS_Y - 1 ? (z1 + (z2 - z1) * yratio) * planner.fade_scaling_factor_for_z(end[Z_AXIS]) : 0.0;
180
+      const float m = dy / dx,
181
+                  c = start[Y_AXIS] - m * start[X_AXIS];
171 182
 
183
+      const bool inf_normalized_flag = (isinf(e_normalized_dist) != 0),
184
+                 inf_m_flag = (isinf(m) != 0);
172 185
       /**
173
-       * If part of the Mesh is undefined, it will show up as NAN
174
-       * in z_values[][] and propagate through the
175
-       * calculations. If our correction is NAN, we throw it out
176
-       * because part of the Mesh is undefined and we don't have the
177
-       * information we need to complete the height correction.
186
+       * This block handles vertical lines. These are lines that stay within the same
187
+       * X Cell column. They do not need to be perfectly vertical. They just can
188
+       * not cross into another X Cell column.
178 189
        */
179
-      if (isnan(z0)) z0 = 0.0;
180
-
181
-      planner._buffer_line(end[X_AXIS], end[Y_AXIS], end[Z_AXIS] + z0, end[E_AXIS], feed_rate, extruder);
190
+      if (dxi == 0) {       // Check for a vertical line
191
+        current_yi += down_flag;  // Line is heading down, we just want to go to the bottom
192
+        while (current_yi != cell_dest_yi + down_flag) {
193
+          current_yi += dyi;
194
+          const float next_mesh_line_y = mesh_index_to_ypos(current_yi);
195
+
196
+          /**
197
+           * if the slope of the line is infinite, we won't do the calculations
198
+           * else, we know the next X is the same so we can recover and continue!
199
+           * Calculate X at the next Y mesh line
200
+           */
201
+          const float rx = inf_m_flag ? start[X_AXIS] : (next_mesh_line_y - c) / m;
202
+
203
+          float z0 = z_correction_for_x_on_horizontal_mesh_line(rx, current_xi, current_yi)
204
+                     * planner.fade_scaling_factor_for_z(end[Z_AXIS]);
205
+
206
+          /**
207
+           * If part of the Mesh is undefined, it will show up as NAN
208
+           * in z_values[][] and propagate through the
209
+           * calculations. If our correction is NAN, we throw it out
210
+           * because part of the Mesh is undefined and we don't have the
211
+           * information we need to complete the height correction.
212
+           */
213
+          if (isnan(z0)) z0 = 0.0;
214
+
215
+          const float ry = mesh_index_to_ypos(current_yi);
216
+
217
+          /**
218
+           * Without this check, it is possible for the algorithm to generate a zero length move in the case
219
+           * where the line is heading down and it is starting right on a Mesh Line boundary. For how often that
220
+           * happens, it might be best to remove the check and always 'schedule' the move because
221
+           * the planner.buffer_segment() routine will filter it if that happens.
222
+           */
223
+          if (ry != start[Y_AXIS]) {
224
+            if (!inf_normalized_flag) {
225
+              on_axis_distance = use_x_dist ? rx - start[X_AXIS] : ry - start[Y_AXIS];
226
+              e_position = start[E_AXIS] + on_axis_distance * e_normalized_dist;
227
+              z_position = start[Z_AXIS] + on_axis_distance * z_normalized_dist;
228
+            }
229
+            else {
230
+              e_position = end[E_AXIS];
231
+              z_position = end[Z_AXIS];
232
+            }
182 233
 
183
-      if (g26_debug_flag)
184
-        debug_current_and_destination(PSTR("FINAL_MOVE in ubl.line_to_destination()"));
234
+            planner.buffer_segment(rx, ry, z_position + z0, e_position, feed_rate, extruder);
235
+          } //else printf("FIRST MOVE PRUNED  ");
236
+        }
185 237
 
186
-      set_current_from_destination();
187
-      return;
188
-    }
238
+        if (g26_debug_flag)
239
+          debug_current_and_destination(PSTR("vertical move done in ubl.line_to_destination_cartesian()"));
189 240
 
190
-    /**
191
-     * If we get here, we are processing a move that crosses at least one Mesh Line. We will check
192
-     * for the simple case of just crossing X or just crossing Y Mesh Lines after we get all the details
193
-     * of the move figured out. We can process the easy case of just crossing an X or Y Mesh Line with less
194
-     * computation and in fact most lines are of this nature. We will check for that in the following
195
-     * blocks of code:
196
-     */
241
+        //
242
+        // Check if we are at the final destination. Usually, we won't be, but if it is on a Y Mesh Line, we are done.
243
+        //
244
+        if (current_position[X_AXIS] != end[X_AXIS] || current_position[Y_AXIS] != end[Y_AXIS])
245
+          goto FINAL_MOVE;
197 246
 
198
-    const float dx = end[X_AXIS] - start[X_AXIS],
199
-                dy = end[Y_AXIS] - start[Y_AXIS];
247
+        set_current_from_destination();
248
+        return;
249
+      }
200 250
 
201
-    const int left_flag = dx < 0.0 ? 1 : 0,
202
-              down_flag = dy < 0.0 ? 1 : 0;
251
+      /**
252
+       *
253
+       * This block handles horizontal lines. These are lines that stay within the same
254
+       * Y Cell row. They do not need to be perfectly horizontal. They just can
255
+       * not cross into another Y Cell row.
256
+       *
257
+       */
203 258
 
204
-    const float adx = left_flag ? -dx : dx,
205
-                ady = down_flag ? -dy : dy;
259
+      if (dyi == 0) {             // Check for a horizontal line
260
+        current_xi += left_flag;  // Line is heading left, we just want to go to the left
261
+                                  // edge of this cell for the first move.
262
+        while (current_xi != cell_dest_xi + left_flag) {
263
+          current_xi += dxi;
264
+          const float next_mesh_line_x = mesh_index_to_xpos(current_xi),
265
+                      ry = m * next_mesh_line_x + c;   // Calculate Y at the next X mesh line
266
+
267
+          float z0 = z_correction_for_y_on_vertical_mesh_line(ry, current_xi, current_yi)
268
+                     * planner.fade_scaling_factor_for_z(end[Z_AXIS]);
269
+
270
+          /**
271
+           * If part of the Mesh is undefined, it will show up as NAN
272
+           * in z_values[][] and propagate through the
273
+           * calculations. If our correction is NAN, we throw it out
274
+           * because part of the Mesh is undefined and we don't have the
275
+           * information we need to complete the height correction.
276
+           */
277
+          if (isnan(z0)) z0 = 0.0;
278
+
279
+          const float rx = mesh_index_to_xpos(current_xi);
280
+
281
+          /**
282
+           * Without this check, it is possible for the algorithm to generate a zero length move in the case
283
+           * where the line is heading left and it is starting right on a Mesh Line boundary. For how often
284
+           * that happens, it might be best to remove the check and always 'schedule' the move because
285
+           * the planner.buffer_segment() routine will filter it if that happens.
286
+           */
287
+          if (rx != start[X_AXIS]) {
288
+            if (!inf_normalized_flag) {
289
+              on_axis_distance = use_x_dist ? rx - start[X_AXIS] : ry - start[Y_AXIS];
290
+              e_position = start[E_AXIS] + on_axis_distance * e_normalized_dist;  // is based on X or Y because this is a horizontal move
291
+              z_position = start[Z_AXIS] + on_axis_distance * z_normalized_dist;
292
+            }
293
+            else {
294
+              e_position = end[E_AXIS];
295
+              z_position = end[Z_AXIS];
296
+            }
206 297
 
207
-    const int dxi = cell_start_xi == cell_dest_xi ? 0 : left_flag ? -1 : 1,
208
-              dyi = cell_start_yi == cell_dest_yi ? 0 : down_flag ? -1 : 1;
298
+            planner.buffer_segment(rx, ry, z_position + z0, e_position, feed_rate, extruder);
299
+          } //else printf("FIRST MOVE PRUNED  ");
300
+        }
209 301
 
210
-    /**
211
-     * Compute the scaling factor for the extruder for each partial move.
212
-     * We need to watch out for zero length moves because it will cause us to
213
-     * have an infinate scaling factor. We are stuck doing a floating point
214
-     * divide to get our scaling factor, but after that, we just multiply by this
215
-     * number. We also pick our scaling factor based on whether the X or Y
216
-     * component is larger. We use the biggest of the two to preserve precision.
217
-     */
302
+        if (g26_debug_flag)
303
+          debug_current_and_destination(PSTR("horizontal move done in ubl.line_to_destination_cartesian()"));
218 304
 
219
-    const bool use_x_dist = adx > ady;
305
+        if (current_position[X_AXIS] != end[X_AXIS] || current_position[Y_AXIS] != end[Y_AXIS])
306
+          goto FINAL_MOVE;
220 307
 
221
-    float on_axis_distance = use_x_dist ? dx : dy,
222
-          e_position = end[E_AXIS] - start[E_AXIS],
223
-          z_position = end[Z_AXIS] - start[Z_AXIS];
308
+        set_current_from_destination();
309
+        return;
310
+      }
224 311
 
225
-    const float e_normalized_dist = e_position / on_axis_distance,
226
-                z_normalized_dist = z_position / on_axis_distance;
312
+      /**
313
+       *
314
+       * This block handles the generic case of a line crossing both X and Y Mesh lines.
315
+       *
316
+       */
227 317
 
228
-    int current_xi = cell_start_xi,
229
-        current_yi = cell_start_yi;
318
+      int xi_cnt = cell_start_xi - cell_dest_xi,
319
+          yi_cnt = cell_start_yi - cell_dest_yi;
230 320
 
231
-    const float m = dy / dx,
232
-                c = start[Y_AXIS] - m * start[X_AXIS];
321
+      if (xi_cnt < 0) xi_cnt = -xi_cnt;
322
+      if (yi_cnt < 0) yi_cnt = -yi_cnt;
233 323
 
234
-    const bool inf_normalized_flag = (isinf(e_normalized_dist) != 0),
235
-               inf_m_flag = (isinf(m) != 0);
236
-    /**
237
-     * This block handles vertical lines. These are lines that stay within the same
238
-     * X Cell column. They do not need to be perfectly vertical. They just can
239
-     * not cross into another X Cell column.
240
-     */
241
-    if (dxi == 0) {       // Check for a vertical line
242
-      current_yi += down_flag;  // Line is heading down, we just want to go to the bottom
243
-      while (current_yi != cell_dest_yi + down_flag) {
244
-        current_yi += dyi;
245
-        const float next_mesh_line_y = mesh_index_to_ypos(current_yi);
324
+      current_xi += left_flag;
325
+      current_yi += down_flag;
246 326
 
247
-        /**
248
-         * if the slope of the line is infinite, we won't do the calculations
249
-         * else, we know the next X is the same so we can recover and continue!
250
-         * Calculate X at the next Y mesh line
251
-         */
252
-        const float rx = inf_m_flag ? start[X_AXIS] : (next_mesh_line_y - c) / m;
327
+      while (xi_cnt > 0 || yi_cnt > 0) {
253 328
 
254
-        float z0 = z_correction_for_x_on_horizontal_mesh_line(rx, current_xi, current_yi)
255
-                   * planner.fade_scaling_factor_for_z(end[Z_AXIS]);
329
+        const float next_mesh_line_x = mesh_index_to_xpos(current_xi + dxi),
330
+                    next_mesh_line_y = mesh_index_to_ypos(current_yi + dyi),
331
+                    ry = m * next_mesh_line_x + c,   // Calculate Y at the next X mesh line
332
+                    rx = (next_mesh_line_y - c) / m; // Calculate X at the next Y mesh line
333
+                                                     // (No need to worry about m being zero.
334
+                                                     //  If that was the case, it was already detected
335
+                                                     //  as a vertical line move above.)
256 336
 
257
-        /**
258
-         * If part of the Mesh is undefined, it will show up as NAN
259
-         * in z_values[][] and propagate through the
260
-         * calculations. If our correction is NAN, we throw it out
261
-         * because part of the Mesh is undefined and we don't have the
262
-         * information we need to complete the height correction.
263
-         */
264
-        if (isnan(z0)) z0 = 0.0;
337
+        if (left_flag == (rx > next_mesh_line_x)) { // Check if we hit the Y line first
338
+          // Yes!  Crossing a Y Mesh Line next
339
+          float z0 = z_correction_for_x_on_horizontal_mesh_line(rx, current_xi - left_flag, current_yi + dyi)
340
+                     * planner.fade_scaling_factor_for_z(end[Z_AXIS]);
265 341
 
266
-        const float ry = mesh_index_to_ypos(current_yi);
342
+          /**
343
+           * If part of the Mesh is undefined, it will show up as NAN
344
+           * in z_values[][] and propagate through the
345
+           * calculations. If our correction is NAN, we throw it out
346
+           * because part of the Mesh is undefined and we don't have the
347
+           * information we need to complete the height correction.
348
+           */
349
+          if (isnan(z0)) z0 = 0.0;
267 350
 
268
-        /**
269
-         * Without this check, it is possible for the algorithm to generate a zero length move in the case
270
-         * where the line is heading down and it is starting right on a Mesh Line boundary. For how often that
271
-         * happens, it might be best to remove the check and always 'schedule' the move because
272
-         * the planner._buffer_line() routine will filter it if that happens.
273
-         */
274
-        if (ry != start[Y_AXIS]) {
275 351
           if (!inf_normalized_flag) {
276
-            on_axis_distance = use_x_dist ? rx - start[X_AXIS] : ry - start[Y_AXIS];
352
+            on_axis_distance = use_x_dist ? rx - start[X_AXIS] : next_mesh_line_y - start[Y_AXIS];
277 353
             e_position = start[E_AXIS] + on_axis_distance * e_normalized_dist;
278 354
             z_position = start[Z_AXIS] + on_axis_distance * z_normalized_dist;
279 355
           }
@@ -281,64 +357,27 @@
281 357
             e_position = end[E_AXIS];
282 358
             z_position = end[Z_AXIS];
283 359
           }
360
+          planner.buffer_segment(rx, next_mesh_line_y, z_position + z0, e_position, feed_rate, extruder);
361
+          current_yi += dyi;
362
+          yi_cnt--;
363
+        }
364
+        else {
365
+          // Yes!  Crossing a X Mesh Line next
366
+          float z0 = z_correction_for_y_on_vertical_mesh_line(ry, current_xi + dxi, current_yi - down_flag)
367
+                     * planner.fade_scaling_factor_for_z(end[Z_AXIS]);
368
+
369
+          /**
370
+           * If part of the Mesh is undefined, it will show up as NAN
371
+           * in z_values[][] and propagate through the
372
+           * calculations. If our correction is NAN, we throw it out
373
+           * because part of the Mesh is undefined and we don't have the
374
+           * information we need to complete the height correction.
375
+           */
376
+          if (isnan(z0)) z0 = 0.0;
284 377
 
285
-          planner._buffer_line(rx, ry, z_position + z0, e_position, feed_rate, extruder);
286
-        } //else printf("FIRST MOVE PRUNED  ");
287
-      }
288
-
289
-      if (g26_debug_flag)
290
-        debug_current_and_destination(PSTR("vertical move done in ubl.line_to_destination()"));
291
-
292
-      //
293
-      // Check if we are at the final destination. Usually, we won't be, but if it is on a Y Mesh Line, we are done.
294
-      //
295
-      if (current_position[X_AXIS] != end[X_AXIS] || current_position[Y_AXIS] != end[Y_AXIS])
296
-        goto FINAL_MOVE;
297
-
298
-      set_current_from_destination();
299
-      return;
300
-    }
301
-
302
-    /**
303
-     *
304
-     * This block handles horizontal lines. These are lines that stay within the same
305
-     * Y Cell row. They do not need to be perfectly horizontal. They just can
306
-     * not cross into another Y Cell row.
307
-     *
308
-     */
309
-
310
-    if (dyi == 0) {             // Check for a horizontal line
311
-      current_xi += left_flag;  // Line is heading left, we just want to go to the left
312
-                                // edge of this cell for the first move.
313
-      while (current_xi != cell_dest_xi + left_flag) {
314
-        current_xi += dxi;
315
-        const float next_mesh_line_x = mesh_index_to_xpos(current_xi),
316
-                    ry = m * next_mesh_line_x + c;   // Calculate Y at the next X mesh line
317
-
318
-        float z0 = z_correction_for_y_on_vertical_mesh_line(ry, current_xi, current_yi)
319
-                   * planner.fade_scaling_factor_for_z(end[Z_AXIS]);
320
-
321
-        /**
322
-         * If part of the Mesh is undefined, it will show up as NAN
323
-         * in z_values[][] and propagate through the
324
-         * calculations. If our correction is NAN, we throw it out
325
-         * because part of the Mesh is undefined and we don't have the
326
-         * information we need to complete the height correction.
327
-         */
328
-        if (isnan(z0)) z0 = 0.0;
329
-
330
-        const float rx = mesh_index_to_xpos(current_xi);
331
-
332
-        /**
333
-         * Without this check, it is possible for the algorithm to generate a zero length move in the case
334
-         * where the line is heading left and it is starting right on a Mesh Line boundary. For how often
335
-         * that happens, it might be best to remove the check and always 'schedule' the move because
336
-         * the planner._buffer_line() routine will filter it if that happens.
337
-         */
338
-        if (rx != start[X_AXIS]) {
339 378
           if (!inf_normalized_flag) {
340
-            on_axis_distance = use_x_dist ? rx - start[X_AXIS] : ry - start[Y_AXIS];
341
-            e_position = start[E_AXIS] + on_axis_distance * e_normalized_dist;  // is based on X or Y because this is a horizontal move
379
+            on_axis_distance = use_x_dist ? next_mesh_line_x - start[X_AXIS] : ry - start[Y_AXIS];
380
+            e_position = start[E_AXIS] + on_axis_distance * e_normalized_dist;
342 381
             z_position = start[Z_AXIS] + on_axis_distance * z_normalized_dist;
343 382
           }
344 383
           else {
@@ -346,136 +385,38 @@
346 385
             z_position = end[Z_AXIS];
347 386
           }
348 387
 
349
-          planner._buffer_line(rx, ry, z_position + z0, e_position, feed_rate, extruder);
350
-        } //else printf("FIRST MOVE PRUNED  ");
388
+          planner.buffer_segment(next_mesh_line_x, ry, z_position + z0, e_position, feed_rate, extruder);
389
+          current_xi += dxi;
390
+          xi_cnt--;
391
+        }
392
+
393
+        if (xi_cnt < 0 || yi_cnt < 0) break; // we've gone too far, so exit the loop and move on to FINAL_MOVE
351 394
       }
352 395
 
353 396
       if (g26_debug_flag)
354
-        debug_current_and_destination(PSTR("horizontal move done in ubl.line_to_destination()"));
397
+        debug_current_and_destination(PSTR("generic move done in ubl.line_to_destination_cartesian()"));
355 398
 
356 399
       if (current_position[X_AXIS] != end[X_AXIS] || current_position[Y_AXIS] != end[Y_AXIS])
357 400
         goto FINAL_MOVE;
358 401
 
359 402
       set_current_from_destination();
360
-      return;
361
-    }
362
-
363
-    /**
364
-     *
365
-     * This block handles the generic case of a line crossing both X and Y Mesh lines.
366
-     *
367
-     */
368
-
369
-    int xi_cnt = cell_start_xi - cell_dest_xi,
370
-        yi_cnt = cell_start_yi - cell_dest_yi;
371
-
372
-    if (xi_cnt < 0) xi_cnt = -xi_cnt;
373
-    if (yi_cnt < 0) yi_cnt = -yi_cnt;
374
-
375
-    current_xi += left_flag;
376
-    current_yi += down_flag;
377
-
378
-    while (xi_cnt > 0 || yi_cnt > 0) {
379
-
380
-      const float next_mesh_line_x = mesh_index_to_xpos(current_xi + dxi),
381
-                  next_mesh_line_y = mesh_index_to_ypos(current_yi + dyi),
382
-                  ry = m * next_mesh_line_x + c,   // Calculate Y at the next X mesh line
383
-                  rx = (next_mesh_line_y - c) / m; // Calculate X at the next Y mesh line
384
-                                                   // (No need to worry about m being zero.
385
-                                                   //  If that was the case, it was already detected
386
-                                                   //  as a vertical line move above.)
387
-
388
-      if (left_flag == (rx > next_mesh_line_x)) { // Check if we hit the Y line first
389
-        // Yes!  Crossing a Y Mesh Line next
390
-        float z0 = z_correction_for_x_on_horizontal_mesh_line(rx, current_xi - left_flag, current_yi + dyi)
391
-                   * planner.fade_scaling_factor_for_z(end[Z_AXIS]);
392
-
393
-        /**
394
-         * If part of the Mesh is undefined, it will show up as NAN
395
-         * in z_values[][] and propagate through the
396
-         * calculations. If our correction is NAN, we throw it out
397
-         * because part of the Mesh is undefined and we don't have the
398
-         * information we need to complete the height correction.
399
-         */
400
-        if (isnan(z0)) z0 = 0.0;
401
-
402
-        if (!inf_normalized_flag) {
403
-          on_axis_distance = use_x_dist ? rx - start[X_AXIS] : next_mesh_line_y - start[Y_AXIS];
404
-          e_position = start[E_AXIS] + on_axis_distance * e_normalized_dist;
405
-          z_position = start[Z_AXIS] + on_axis_distance * z_normalized_dist;
406
-        }
407
-        else {
408
-          e_position = end[E_AXIS];
409
-          z_position = end[Z_AXIS];
410
-        }
411
-        planner._buffer_line(rx, next_mesh_line_y, z_position + z0, e_position, feed_rate, extruder);
412
-        current_yi += dyi;
413
-        yi_cnt--;
414
-      }
415
-      else {
416
-        // Yes!  Crossing a X Mesh Line next
417
-        float z0 = z_correction_for_y_on_vertical_mesh_line(ry, current_xi + dxi, current_yi - down_flag)
418
-                   * planner.fade_scaling_factor_for_z(end[Z_AXIS]);
419
-
420
-        /**
421
-         * If part of the Mesh is undefined, it will show up as NAN
422
-         * in z_values[][] and propagate through the
423
-         * calculations. If our correction is NAN, we throw it out
424
-         * because part of the Mesh is undefined and we don't have the
425
-         * information we need to complete the height correction.
426
-         */
427
-        if (isnan(z0)) z0 = 0.0;
428
-
429
-        if (!inf_normalized_flag) {
430
-          on_axis_distance = use_x_dist ? next_mesh_line_x - start[X_AXIS] : ry - start[Y_AXIS];
431
-          e_position = start[E_AXIS] + on_axis_distance * e_normalized_dist;
432
-          z_position = start[Z_AXIS] + on_axis_distance * z_normalized_dist;
433
-        }
434
-        else {
435
-          e_position = end[E_AXIS];
436
-          z_position = end[Z_AXIS];
437
-        }
438
-
439
-        planner._buffer_line(next_mesh_line_x, ry, z_position + z0, e_position, feed_rate, extruder);
440
-        current_xi += dxi;
441
-        xi_cnt--;
442
-      }
443
-
444
-      if (xi_cnt < 0 || yi_cnt < 0) break; // we've gone too far, so exit the loop and move on to FINAL_MOVE
445 403
     }
446 404
 
447
-    if (g26_debug_flag)
448
-      debug_current_and_destination(PSTR("generic move done in ubl.line_to_destination()"));
449
-
450
-    if (current_position[X_AXIS] != end[X_AXIS] || current_position[Y_AXIS] != end[Y_AXIS])
451
-      goto FINAL_MOVE;
452
-
453
-    set_current_from_destination();
454
-  }
455
-
456
-  #if UBL_DELTA
457
-
458
-    // macro to inline copy exactly 4 floats, don't rely on sizeof operator
459
-    #define COPY_XYZE( target, source ) { \
460
-                target[X_AXIS] = source[X_AXIS]; \
461
-                target[Y_AXIS] = source[Y_AXIS]; \
462
-                target[Z_AXIS] = source[Z_AXIS]; \
463
-                target[E_AXIS] = source[E_AXIS]; \
464
-            }
405
+  #else // UBL_SEGMENTED
465 406
 
466 407
     #if IS_SCARA // scale the feed rate from mm/s to degrees/s
467 408
       static float scara_feed_factor, scara_oldA, scara_oldB;
468 409
     #endif
469 410
 
470 411
     // We don't want additional apply_leveling() performed by regular buffer_line or buffer_line_kinematic,
471
-    // so we call _buffer_line directly here.  Per-segmented leveling and kinematics performed first.
412
+    // so we call buffer_segment directly here.  Per-segmented leveling and kinematics performed first.
472 413
 
473
-    inline void _O2 ubl_buffer_segment_raw(const float raw[XYZE], const float &fr) {
414
+    inline void _O2 ubl_buffer_segment_raw(const float (&raw)[XYZE], const float &fr) {
474 415
 
475 416
       #if ENABLED(DELTA)  // apply delta inverse_kinematics
476 417
 
477 418
         DELTA_RAW_IK();
478
-        planner._buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], raw[E_AXIS], fr, active_extruder);
419
+        planner.buffer_segment(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], raw[E_AXIS], fr, active_extruder);
479 420
 
480 421
       #elif IS_SCARA  // apply scara inverse_kinematics (should be changed to save raw->logical->raw)
481 422
 
@@ -488,11 +429,11 @@
488 429
         scara_oldB = delta[B_AXIS];
489 430
         float s_feedrate = max(adiff, bdiff) * scara_feed_factor;
490 431
 
491
-        planner._buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], raw[E_AXIS], s_feedrate, active_extruder);
432
+        planner.buffer_segment(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], raw[E_AXIS], s_feedrate, active_extruder);
492 433
 
493 434
       #else // CARTESIAN
494 435
 
495
-        planner._buffer_line(raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS], raw[E_AXIS], fr, active_extruder);
436
+        planner.buffer_segment(raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS], raw[E_AXIS], fr, active_extruder);
496 437
 
497 438
       #endif
498 439
     }
@@ -511,15 +452,23 @@
511 452
 
512 453
     /**
513 454
      * Prepare a segmented linear move for DELTA/SCARA/CARTESIAN with UBL and FADE semantics.
514
-     * This calls planner._buffer_line multiple times for small incremental moves.
455
+     * This calls planner.buffer_segment multiple times for small incremental moves.
515 456
      * Returns true if did NOT move, false if moved (requires current_position update).
516 457
      */
517 458
 
518
-    bool _O2 unified_bed_leveling::prepare_segmented_line_to(const float rtarget[XYZE], const float &feedrate) {
459
+    bool _O2 unified_bed_leveling::prepare_segmented_line_to(const float (&in_target)[XYZE], const float &feedrate) {
519 460
 
520
-      if (!position_is_reachable(rtarget[X_AXIS], rtarget[Y_AXIS]))  // fail if moving outside reachable boundary
461
+      if (!position_is_reachable(in_target[X_AXIS], in_target[Y_AXIS]))  // fail if moving outside reachable boundary
521 462
         return true; // did not move, so current_position still accurate
522 463
 
464
+      #if ENABLED(SKEW_CORRECTION)
465
+        // For skew correction just adjust the destination point and we're done
466
+        float rtarget[XYZE] = { in_target[X_AXIS], in_target[Y_AXIS], in_target[Z_AXIS], in_target[E_AXIS] };
467
+        planner.skew(rtarget[X_AXIS], rtarget[Y_AXIS], rtarget[Z_AXIS]);
468
+      #else
469
+        const float (&rtarget)[XYZE] = in_target;
470
+      #endif
471
+
523 472
       const float total[XYZE] = {
524 473
         rtarget[X_AXIS] - current_position[X_AXIS],
525 474
         rtarget[Y_AXIS] - current_position[Y_AXIS],
@@ -564,6 +513,10 @@
564 513
         current_position[E_AXIS]
565 514
       };
566 515
 
516
+      #if ENABLED(SKEW_CORRECTION)
517
+        planner.skew(raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS]);
518
+      #endif
519
+
567 520
       // Only compute leveling per segment if ubl active and target below z_fade_height.
568 521
       if (!planner.leveling_active || !planner.leveling_active_at_z(rtarget[Z_AXIS])) {   // no mesh leveling
569 522
         while (--segments) {
@@ -670,6 +623,6 @@
670 623
       } // cell loop
671 624
     }
672 625
 
673
-  #endif // UBL_DELTA
626
+  #endif // UBL_SEGMENTED
674 627
 
675 628
 #endif // AUTO_BED_LEVELING_UBL

+ 0
- 1
Marlin/ultralcd.cpp View File

@@ -2755,7 +2755,6 @@ void kill_screen(const char* lcd_msg) {
2755 2755
 
2756 2756
   #if IS_KINEMATIC
2757 2757
     extern float feedrate_mm_s;
2758
-    extern float destination[XYZE];
2759 2758
     void set_destination_from_current();
2760 2759
     void prepare_move_to_destination();
2761 2760
   #endif

Loading…
Cancel
Save