Browse Source

Cleanups to UBL_DELTA

Scott Lahteine 8 years ago
parent
commit
0696dda470

+ 3
- 7
Marlin/Conditionals_post.h View File

@@ -731,15 +731,12 @@
731 731
    * Set granular options based on the specific type of leveling
732 732
    */
733 733
 
734
-  #if ENABLED(AUTO_BED_LEVELING_UBL) && ENABLED(DELTA)
735
-    #define UBL_DELTA
736
-  #endif
737
-
734
+  #define UBL_DELTA  (ENABLED(AUTO_BED_LEVELING_UBL) && ENABLED(DELTA))
738 735
   #define ABL_PLANAR (ENABLED(AUTO_BED_LEVELING_LINEAR) || ENABLED(AUTO_BED_LEVELING_3POINT))
739 736
   #define ABL_GRID   (ENABLED(AUTO_BED_LEVELING_LINEAR) || ENABLED(AUTO_BED_LEVELING_BILINEAR))
740 737
   #define HAS_ABL    (ABL_PLANAR || ABL_GRID || ENABLED(AUTO_BED_LEVELING_UBL))
741 738
   #define HAS_LEVELING          (HAS_ABL || ENABLED(MESH_BED_LEVELING))
742
-  #define PLANNER_LEVELING      (ABL_PLANAR || ABL_GRID || ENABLED(MESH_BED_LEVELING) || ENABLED(UBL_DELTA))
739
+  #define PLANNER_LEVELING      (ABL_PLANAR || ABL_GRID || ENABLED(MESH_BED_LEVELING) || UBL_DELTA)
743 740
   #define HAS_PROBING_PROCEDURE (HAS_ABL || ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST))
744 741
   #if HAS_PROBING_PROCEDURE
745 742
     #define PROBE_BED_WIDTH abs(RIGHT_PROBE_BED_POSITION - (LEFT_PROBE_BED_POSITION))
@@ -823,8 +820,7 @@
823 820
   /**
824 821
    * DELTA_SEGMENT_MIN_LENGTH for UBL_DELTA
825 822
    */
826
-
827
-  #if ENABLED(UBL_DELTA)
823
+  #if UBL_DELTA
828 824
     #ifndef DELTA_SEGMENT_MIN_LENGTH
829 825
       #if IS_SCARA
830 826
         #define DELTA_SEGMENT_MIN_LENGTH 0.25 // SCARA minimum segment size is 0.25mm

+ 4
- 9
Marlin/G26_Mesh_Validation_Tool.cpp View File

@@ -278,8 +278,7 @@
278 278
 
279 279
         // If this mesh location is outside the printable_radius, skip it.
280 280
 
281
-        if ( ! position_is_reachable_raw_xy( circle_x, circle_y ))
282
-          continue;
281
+        if (!position_is_reachable_raw_xy(circle_x, circle_y)) continue;
283 282
 
284 283
         xi = location.x_index;  // Just to shrink the next few lines and make them easier to understand
285 284
         yi = location.y_index;
@@ -329,9 +328,7 @@
329 328
                 ye = circle_y + sin_table[tmp_div_30 + 1];
330 329
           #if IS_KINEMATIC
331 330
             // Check to make sure this segment is entirely on the bed, skip if not.
332
-            if (( ! position_is_reachable_raw_xy( x , y  )) ||
333
-                ( ! position_is_reachable_raw_xy( xe, ye )))
334
-              continue;
331
+            if (!position_is_reachable_raw_xy(x, y) || !position_is_reachable_raw_xy(xe, ye)) continue;
335 332
           #else                                              // not, we need to skip
336 333
             x  = constrain(x, X_MIN_POS + 1, X_MAX_POS - 1); // This keeps us from bumping the endstops
337 334
             y  = constrain(y, Y_MIN_POS + 1, Y_MAX_POS - 1);
@@ -459,8 +456,7 @@
459 456
               sy = ey = constrain(pgm_read_float(&ubl.mesh_index_to_ypos[j]), Y_MIN_POS + 1, Y_MAX_POS - 1);
460 457
               ex = constrain(ex, X_MIN_POS + 1, X_MAX_POS - 1);
461 458
 
462
-              if (( position_is_reachable_raw_xy( sx, sy )) &&
463
-                  ( position_is_reachable_raw_xy( ex, ey ))) {
459
+              if (position_is_reachable_raw_xy(sx, sy) && position_is_reachable_raw_xy(ex, ey)) {
464 460
 
465 461
                 if (ubl.g26_debug_flag) {
466 462
                   SERIAL_ECHOPAIR(" Connecting with horizontal line (sx=", sx);
@@ -494,8 +490,7 @@
494 490
                 sy = constrain(sy, Y_MIN_POS + 1, Y_MAX_POS - 1);
495 491
                 ey = constrain(ey, Y_MIN_POS + 1, Y_MAX_POS - 1);
496 492
 
497
-                if (( position_is_reachable_raw_xy( sx, sy )) &&
498
-                    ( position_is_reachable_raw_xy( ex, ey ))) {
493
+                if (position_is_reachable_raw_xy(sx, sy) && position_is_reachable_raw_xy(ex, ey)) {
499 494
 
500 495
                   if (ubl.g26_debug_flag) {
501 496
                     SERIAL_ECHOPAIR(" Connecting with vertical line (sx=", sx);

+ 23
- 20
Marlin/Marlin_main.cpp View File

@@ -2427,9 +2427,12 @@ static void clean_up_after_endstop_or_probe_move() {
2427 2427
 
2428 2428
     #elif ENABLED(AUTO_BED_LEVELING_UBL)
2429 2429
 
2430
-      #if ENABLED(UBL_DELTA)
2431
-        if (( ubl.state.active ) && ( ! enable )) {   // leveling from on to off
2432
-          planner.unapply_leveling(current_position);
2430
+      #if PLANNER_LEVELING
2431
+        if (ubl.state.active != enable) {
2432
+          if (!enable)   // leveling from on to off
2433
+            planner.apply_leveling(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS]);
2434
+          else
2435
+            planner.unapply_leveling(current_position);
2433 2436
         }
2434 2437
       #endif
2435 2438
 
@@ -11104,7 +11107,7 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
11104 11107
 
11105 11108
 #endif // AUTO_BED_LEVELING_BILINEAR
11106 11109
 
11107
-#if IS_KINEMATIC && DISABLED(UBL_DELTA)
11110
+#if IS_KINEMATIC && !UBL_DELTA
11108 11111
 
11109 11112
   /**
11110 11113
    * Prepare a linear move in a DELTA or SCARA setup.
@@ -11124,7 +11127,7 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
11124 11127
     }
11125 11128
 
11126 11129
     // Fail if attempting move outside printable radius
11127
-    if ( ! position_is_reachable_xy( ltarget[X_AXIS], ltarget[Y_AXIS] )) return true;
11130
+    if (!position_is_reachable_xy(ltarget[X_AXIS], ltarget[Y_AXIS])) return true;
11128 11131
 
11129 11132
     // Get the cartesian distances moved in XYZE
11130 11133
     float difference[XYZE];
@@ -11225,7 +11228,7 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
11225 11228
     return false;
11226 11229
   }
11227 11230
 
11228
-#else // !IS_KINEMATIC
11231
+#else // !IS_KINEMATIC || UBL_DELTA
11229 11232
 
11230 11233
   /**
11231 11234
    * Prepare a linear move in a Cartesian setup.
@@ -11263,7 +11266,7 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
11263 11266
     return false;
11264 11267
   }
11265 11268
 
11266
-#endif // !IS_KINEMATIC
11269
+#endif // !IS_KINEMATIC || UBL_DELTA
11267 11270
 
11268 11271
 #if ENABLED(DUAL_X_CARRIAGE)
11269 11272
 
@@ -11375,21 +11378,21 @@ void prepare_move_to_destination() {
11375 11378
 
11376 11379
   #endif
11377 11380
 
11378
-  #if IS_KINEMATIC
11379
-    #if ENABLED(UBL_DELTA)
11380
-      if (ubl_prepare_linear_move_to(destination,feedrate_mm_s)) return;
11381
-    #else
11382
-      if (prepare_kinematic_move_to(destination)) return;
11383
-    #endif
11384
-  #else
11385
-    #if ENABLED(DUAL_X_CARRIAGE)
11386
-      if (prepare_move_to_destination_dualx()) return;
11387
-    #elif ENABLED(UBL_DELTA) // will work for CARTESIAN too (smaller segments follow mesh more closely)
11388
-      if (ubl_prepare_linear_move_to(destination,feedrate_mm_s)) return;
11381
+  if (
11382
+    #if IS_KINEMATIC
11383
+      #if UBL_DELTA
11384
+        ubl_prepare_linear_move_to(destination, feedrate_mm_s)
11385
+      #else
11386
+        prepare_kinematic_move_to(destination)
11387
+      #endif
11388
+    #elif ENABLED(DUAL_X_CARRIAGE)
11389
+      prepare_move_to_destination_dualx()
11390
+    #elif UBL_DELTA // will work for CARTESIAN too (smaller segments follow mesh more closely)
11391
+      ubl_prepare_linear_move_to(destination, feedrate_mm_s)
11389 11392
     #else
11390
-      if (prepare_move_to_destination_cartesian()) return;
11393
+      prepare_move_to_destination_cartesian()
11391 11394
     #endif
11392
-  #endif
11395
+  ) return;
11393 11396
 
11394 11397
   set_current_to_destination();
11395 11398
 }

+ 8
- 21
Marlin/SanityCheck.h View File

@@ -248,11 +248,9 @@
248 248
 #if ENABLED(DELTA)
249 249
   #if DISABLED(USE_XMAX_PLUG) && DISABLED(USE_YMAX_PLUG) && DISABLED(USE_ZMAX_PLUG)
250 250
     #error "You probably want to use Max Endstops for DELTA!"
251
-  #endif
252
-  #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) && DISABLED(UBL_DELTA)
253
-    #error "ENABLE_LEVELING_FADE_HEIGHT for DELTA requires UBL_DELTA and AUTO_BED_LEVELING_UBL."
254
-  #endif
255
-  #if ABL_GRID
251
+  #elif ENABLED(ENABLE_LEVELING_FADE_HEIGHT) && DISABLED(AUTO_BED_LEVELING_BILINEAR) && !UBL_DELTA
252
+    #error "ENABLE_LEVELING_FADE_HEIGHT on DELTA requires AUTO_BED_LEVELING_BILINEAR or AUTO_BED_LEVELING_UBL."
253
+  #elif ABL_GRID
256 254
     #if (GRID_MAX_POINTS_X & 1) == 0 || (GRID_MAX_POINTS_Y & 1) == 0
257 255
       #error "DELTA requires GRID_MAX_POINTS_X and GRID_MAX_POINTS_Y to be odd numbers."
258 256
     #elif GRID_MAX_POINTS_X < 3
@@ -431,20 +429,11 @@ static_assert(1 >= 0
431 429
  * Unified Bed Leveling
432 430
  */
433 431
 #if ENABLED(AUTO_BED_LEVELING_UBL)
434
-  #if IS_KINEMATIC
435
-    #if ENABLED(DELTA)
436
-      #if DISABLED(UBL_DELTA)
437
-        #error "AUTO_BED_LEVELING_UBL requires UBL_DELTA for DELTA printers."
438
-      #endif
439
-    #else // SCARA
440
-      #error "AUTO_BED_LEVELING_UBL not supported for SCARA printers."
441
-    #endif
442
-  #endif
443
-  #if DISABLED(NEWPANEL)
432
+  #if IS_SCARA
433
+    #error "AUTO_BED_LEVELING_UBL does not yet support SCARA printers."
434
+  #elif DISABLED(NEWPANEL)
444 435
     #error "AUTO_BED_LEVELING_UBL requires an LCD controller."
445 436
   #endif
446
-#elif ENABLED(UBL_DELTA)
447
-  #error "UBL_DELTA requires AUTO_BED_LEVELING_UBL."
448 437
 #endif
449 438
 
450 439
 /**
@@ -603,10 +592,8 @@ static_assert(1 >= 0
603 592
   /**
604 593
    * Delta and SCARA have limited bed leveling options
605 594
    */
606
-  #if IS_KINEMATIC
607
-    #if DISABLED(AUTO_BED_LEVELING_BILINEAR) && DISABLED(UBL_DELTA)
608
-      #error "Only AUTO_BED_LEVELING_BILINEAR or AUTO_BED_LEVELING_UBL with UBL_DELTA support DELTA and SCARA bed leveling."
609
-    #endif
595
+  #if IS_SCARA && DISABLED(AUTO_BED_LEVELING_BILINEAR)
596
+    #error "Only AUTO_BED_LEVELING_BILINEAR currently supports SCARA bed leveling."
610 597
   #endif
611 598
 
612 599
   /**

+ 10
- 10
Marlin/planner.cpp View File

@@ -534,12 +534,12 @@ void Planner::check_axes_activity() {
534 534
    */
535 535
   void Planner::apply_leveling(float &lx, float &ly, float &lz) {
536 536
 
537
-    #if ENABLED(AUTO_BED_LEVELING_UBL) && ENABLED(UBL_DELTA)  // probably should also be enabled for UBL without UBL_DELTA
537
+    #if ENABLED(AUTO_BED_LEVELING_UBL) && UBL_DELTA  // probably should also be enabled for UBL without UBL_DELTA
538 538
       if (!ubl.state.active) return;
539 539
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
540 540
         // if z_fade_height enabled (nonzero) and raw_z above it, no leveling required
541 541
         if ((planner.z_fade_height) && (planner.z_fade_height <= RAW_Z_POSITION(lz))) return;
542
-        lz += ubl.state.z_offset + ( ubl.get_z_correction(lx,ly) * ubl.fade_scaling_factor_for_z(lz));
542
+        lz += ubl.state.z_offset + ubl.get_z_correction(lx,ly) * ubl.fade_scaling_factor_for_z(lz);
543 543
       #else // no fade
544 544
         lz += ubl.state.z_offset + ubl.get_z_correction(lx,ly);
545 545
       #endif // FADE
@@ -598,13 +598,13 @@ void Planner::check_axes_activity() {
598 598
 
599 599
   void Planner::unapply_leveling(float logical[XYZ]) {
600 600
 
601
-    #if ENABLED(AUTO_BED_LEVELING_UBL) && ENABLED(UBL_DELTA)
601
+    #if ENABLED(AUTO_BED_LEVELING_UBL) && UBL_DELTA
602 602
 
603
-      if ( ubl.state.active ) {
603
+      if (ubl.state.active) {
604 604
 
605
-        float z_leveled = RAW_Z_POSITION(logical[Z_AXIS]);
606
-        float z_ublmesh = ubl.get_z_correction(logical[X_AXIS],logical[Y_AXIS]);
607
-        float z_unlevel = z_leveled - ubl.state.z_offset - z_ublmesh;
605
+        const float z_leveled = RAW_Z_POSITION(logical[Z_AXIS]),
606
+                    z_ublmesh = ubl.get_z_correction(logical[X_AXIS], logical[Y_AXIS]);
607
+              float z_unlevel = z_leveled - ubl.state.z_offset - z_ublmesh;
608 608
 
609 609
         #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
610 610
 
@@ -616,9 +616,9 @@ void Planner::check_axes_activity() {
616 616
           //    so U(1-M/H)==L-O-M
617 617
           //    so U==(L-O-M)/(1-M/H) for U<H
618 618
 
619
-          if ( planner.z_fade_height ) {
620
-            float z_unfaded = z_unlevel / ( 1.0 - ( z_ublmesh * planner.inverse_z_fade_height ));
621
-            if ( z_unfaded < planner.z_fade_height )  // don't know until after compute
619
+          if (planner.z_fade_height) {
620
+            float z_unfaded = z_unlevel / (1.0 - z_ublmesh * planner.inverse_z_fade_height);
621
+            if (z_unfaded < planner.z_fade_height)  // don't know until after compute
622 622
               z_unlevel = z_unfaded;
623 623
           }
624 624
 

+ 68
- 81
Marlin/ubl_motion.cpp View File

@@ -474,20 +474,10 @@
474 474
     set_current_to_destination();
475 475
   }
476 476
 
477
-
478
-  #ifdef UBL_DELTA
479
-
480
-    #define COPY_XYZE( target, source ) { \
481
-                target[X_AXIS] = source[X_AXIS]; \
482
-                target[Y_AXIS] = source[Y_AXIS]; \
483
-                target[Z_AXIS] = source[Z_AXIS]; \
484
-                target[E_AXIS] = source[E_AXIS]; \
485
-            }
477
+  #if UBL_DELTA
486 478
 
487 479
     #if IS_SCARA // scale the feed rate from mm/s to degrees/s
488
-      static float scara_feed_factor;
489
-      static float scara_oldA;
490
-      static float scara_oldB;
480
+      static float scara_feed_factor, scara_oldA, scara_oldB;
491 481
     #endif
492 482
 
493 483
     // We don't want additional apply_leveling() performed by regular buffer_line or buffer_line_kinematic, 
@@ -501,18 +491,18 @@
501 491
         float feedrate = fr_mm_s;
502 492
 
503 493
         #if IS_SCARA // scale the feed rate from mm/s to degrees/s
504
-          float adiff = abs(delta[A_AXIS] - scara_oldA);
505
-          float bdiff = abs(delta[B_AXIS] - scara_oldB);
494
+          float adiff = abs(delta[A_AXIS] - scara_oldA),
495
+                bdiff = abs(delta[B_AXIS] - scara_oldB);
506 496
           scara_oldA = delta[A_AXIS];
507 497
           scara_oldB = delta[B_AXIS];
508 498
           feedrate = max(adiff, bdiff) * scara_feed_factor;
509 499
         #endif
510 500
 
511
-        planner._buffer_line( delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], ltarget[E_AXIS], feedrate, extruder );
501
+        planner._buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], ltarget[E_AXIS], feedrate, extruder);
512 502
 
513 503
       #else // cartesian
514 504
 
515
-        planner._buffer_line( ltarget[X_AXIS], ltarget[Y_AXIS], ltarget[Z_AXIS], ltarget[E_AXIS], fr_mm_s, extruder );
505
+        planner._buffer_line(ltarget[X_AXIS], ltarget[Y_AXIS], ltarget[Z_AXIS], ltarget[E_AXIS], fr_mm_s, extruder);
516 506
 
517 507
       #endif
518 508
     }
@@ -525,7 +515,7 @@
525 515
 
526 516
     static bool ubl_prepare_linear_move_to(const float ltarget[XYZE], const float &feedrate) {
527 517
 
528
-      if ( ! position_is_reachable_xy( ltarget[X_AXIS], ltarget[Y_AXIS] ))  // fail if moving outside reachable boundary
518
+      if (!position_is_reachable_xy(ltarget[X_AXIS], ltarget[Y_AXIS]))  // fail if moving outside reachable boundary
529 519
         return true; // did not move, so current_position still accurate
530 520
 
531 521
       const float difference[XYZE] = {    // cartesian distances moved in XYZE
@@ -533,21 +523,21 @@
533 523
                     ltarget[Y_AXIS] - current_position[Y_AXIS],
534 524
                     ltarget[Z_AXIS] - current_position[Z_AXIS],
535 525
                     ltarget[E_AXIS] - current_position[E_AXIS]
536
-                    };
526
+                  };
537 527
 
538
-      float cartesian_xy_mm = sqrtf( sq(difference[X_AXIS]) + sq(difference[Y_AXIS]) ); // total horizontal xy distance
528
+      const float cartesian_xy_mm = HYPOT(difference[X_AXIS], difference[Y_AXIS]);        // total horizontal xy distance
539 529
 
540 530
       #if IS_KINEMATIC
541
-        float    seconds  = cartesian_xy_mm / feedrate;                                   // seconds to move xy distance at requested rate
542
-        uint16_t segments = lroundf( delta_segments_per_second * seconds );               // preferred number of segments for distance @ feedrate
543
-        uint16_t seglimit = lroundf( cartesian_xy_mm * (1.0/(DELTA_SEGMENT_MIN_LENGTH))); // number of segments at minimum segment length
544
-        NOMORE( segments, seglimit );                                                     // limit to minimum segment length (fewer segments)
531
+        const float seconds = cartesian_xy_mm / feedrate;                                 // seconds to move xy distance at requested rate
532
+        uint16_t segments = lroundf(delta_segments_per_second * seconds),                // preferred number of segments for distance @ feedrate
533
+                 seglimit = lroundf(cartesian_xy_mm * (1.0 / (DELTA_SEGMENT_MIN_LENGTH))); // number of segments at minimum segment length
534
+        NOMORE(segments, seglimit);                                                     // limit to minimum segment length (fewer segments)
545 535
       #else
546
-        uint16_t segments = lroundf( cartesian_xy_mm * (1.0/(DELTA_SEGMENT_MIN_LENGTH))); // cartesian fixed segment length
536
+        uint16_t segments = lroundf(cartesian_xy_mm * (1.0 / (DELTA_SEGMENT_MIN_LENGTH))); // cartesian fixed segment length
547 537
       #endif
548 538
 
549
-      NOLESS( segments, 1 );                // must have at least one segment
550
-      float inv_segments = 1.0 / segments;  // divide once, multiply thereafter
539
+      NOLESS(segments, 1);                        // must have at least one segment
540
+      const float inv_segments = 1.0 / segments;  // divide once, multiply thereafter
551 541
 
552 542
       #if IS_SCARA // scale the feed rate from mm/s to degrees/s
553 543
         scara_feed_factor = cartesian_xy_mm * inv_segments * feedrate;
@@ -560,57 +550,53 @@
560 550
                     difference[Y_AXIS] * inv_segments,
561 551
                     difference[Z_AXIS] * inv_segments,
562 552
                     difference[E_AXIS] * inv_segments 
563
-                    };
553
+                  };
564 554
 
565 555
       // Note that E segment distance could vary slightly as z mesh height
566 556
       // changes for each segment, but small enough to ignore.
567 557
 
568
-      bool above_fade_height = false;
569
-      #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
570
-        if (( planner.z_fade_height != 0 ) && 
571
-            ( planner.z_fade_height < RAW_Z_POSITION(ltarget[Z_AXIS]) )) {
572
-          above_fade_height = true;
573
-          }
574
-      #endif
558
+      const bool above_fade_height = (
559
+        #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
560
+          planner.z_fade_height != 0 && planner.z_fade_height < RAW_Z_POSITION(ltarget[Z_AXIS])
561
+        #else
562
+          false
563
+        #endif
564
+      );
575 565
 
576 566
       // Only compute leveling per segment if ubl active and target below z_fade_height.
577 567
 
578
-      if (( ! ubl.state.active ) || ( above_fade_height )) {   // no mesh leveling
568
+      if (!ubl.state.active || above_fade_height) {   // no mesh leveling
579 569
 
580 570
         const float z_offset = ubl.state.active ? ubl.state.z_offset : 0.0;
581 571
 
582
-        float seg_dest[XYZE];                     // per-segment destination,
583
-        COPY_XYZE( seg_dest, current_position );  // starting from current position
572
+        float seg_dest[XYZE];              // per-segment destination,
573
+        COPY(seg_dest, current_position);  // starting from current position
584 574
 
585 575
         while (--segments) {
586 576
           LOOP_XYZE(i) seg_dest[i] += segment_distance[i];
587 577
           float ztemp = seg_dest[Z_AXIS];
588 578
           seg_dest[Z_AXIS] += z_offset;
589
-          ubl_buffer_line_segment( seg_dest, feedrate, active_extruder );
579
+          ubl_buffer_line_segment(seg_dest, feedrate, active_extruder);
590 580
           seg_dest[Z_AXIS] = ztemp;
591 581
         }
592 582
 
593 583
         // Since repeated adding segment_distance accumulates small errors, final move to exact destination.
594
-        COPY_XYZE( seg_dest, ltarget );
584
+        COPY(seg_dest, ltarget);
595 585
         seg_dest[Z_AXIS] += z_offset;
596
-        ubl_buffer_line_segment( seg_dest, feedrate, active_extruder );
586
+        ubl_buffer_line_segment(seg_dest, feedrate, active_extruder);
597 587
         return false; // moved but did not set_current_to_destination();
598 588
       }
599 589
 
600 590
       // Otherwise perform per-segment leveling
601 591
 
602
-      #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
603
-        float fade_scaling_factor = ubl.fade_scaling_factor_for_z(ltarget[Z_AXIS]);
604
-      #endif
605
-
606 592
       float seg_dest[XYZE];  // per-segment destination, initialize to first segment
607 593
       LOOP_XYZE(i) seg_dest[i] = current_position[i] + segment_distance[i];
608 594
 
609 595
       const float& dx_seg = segment_distance[X_AXIS];  // alias for clarity
610 596
       const float& dy_seg = segment_distance[Y_AXIS];
611 597
 
612
-      float rx = RAW_X_POSITION(seg_dest[X_AXIS]);  // assume raw vs logical coordinates shifted but not scaled.
613
-      float ry = RAW_Y_POSITION(seg_dest[Y_AXIS]);
598
+      float rx = RAW_X_POSITION(seg_dest[X_AXIS]),  // assume raw vs logical coordinates shifted but not scaled.
599
+            ry = RAW_Y_POSITION(seg_dest[Y_AXIS]);
614 600
 
615 601
       do {  // for each mesh cell encountered during the move
616 602
 
@@ -621,74 +607,75 @@
621 607
         // in top of loop and again re-find same adjacent cell and use it, just less efficient
622 608
         // for mesh inset area.
623 609
 
624
-        int8_t cell_xi = (rx - (UBL_MESH_MIN_X)) * (1.0 / (MESH_X_DIST));
625
-               cell_xi = constrain( cell_xi, 0, (GRID_MAX_POINTS_X) - 1 );
610
+        int8_t cell_xi = (rx - (UBL_MESH_MIN_X)) * (1.0 / (MESH_X_DIST)),
611
+               cell_yi = (ry - (UBL_MESH_MIN_Y)) * (1.0 / (MESH_X_DIST));
626 612
 
627
-        int8_t cell_yi = (ry - (UBL_MESH_MIN_Y)) * (1.0 / (MESH_X_DIST));
628
-               cell_yi = constrain( cell_yi, 0, (GRID_MAX_POINTS_Y) - 1 );
613
+        cell_xi = constrain(cell_xi, 0, (GRID_MAX_POINTS_X) - 1);
614
+        cell_yi = constrain(cell_yi, 0, (GRID_MAX_POINTS_Y) - 1);
629 615
 
630 616
         // float x0 = (UBL_MESH_MIN_X) + ((MESH_X_DIST) * cell_xi );         // lower left cell corner
631 617
         // float y0 = (UBL_MESH_MIN_Y) + ((MESH_Y_DIST) * cell_yi );         // lower left cell corner
632 618
         // float x1 = x0 + MESH_X_DIST;                                      // upper right cell corner
633 619
         // float y1 = y0 + MESH_Y_DIST;                                      // upper right cell corner
634 620
 
635
-        float x0 = pgm_read_float(&(ubl.mesh_index_to_xpos[cell_xi  ]));  // 64 byte table lookup avoids mul+add
636
-        float y0 = pgm_read_float(&(ubl.mesh_index_to_ypos[cell_yi  ]));  // 64 byte table lookup avoids mul+add
637
-        float x1 = pgm_read_float(&(ubl.mesh_index_to_xpos[cell_xi+1]));  // 64 byte table lookup avoids mul+add
638
-        float y1 = pgm_read_float(&(ubl.mesh_index_to_ypos[cell_yi+1]));  // 64 byte table lookup avoids mul+add
621
+        const float x0 = pgm_read_float(&(ubl.mesh_index_to_xpos[cell_xi  ])),  // 64 byte table lookup avoids mul+add
622
+                    y0 = pgm_read_float(&(ubl.mesh_index_to_ypos[cell_yi  ])),  // 64 byte table lookup avoids mul+add
623
+                    x1 = pgm_read_float(&(ubl.mesh_index_to_xpos[cell_xi+1])),  // 64 byte table lookup avoids mul+add
624
+                    y1 = pgm_read_float(&(ubl.mesh_index_to_ypos[cell_yi+1])),  // 64 byte table lookup avoids mul+add
625
+
626
+                    cx = rx - x0,   // cell-relative x
627
+                    cy = ry - y0;   // cell-relative y
639 628
 
640
-        float cx = rx - x0;   // cell-relative x
641
-        float cy = ry - y0;   // cell-relative y
629
+        float z_x0y0 = ubl.z_values[cell_xi  ][cell_yi  ],  // z at lower left corner
630
+              z_x1y0 = ubl.z_values[cell_xi+1][cell_yi  ],  // z at upper left corner
631
+              z_x0y1 = ubl.z_values[cell_xi  ][cell_yi+1],  // z at lower right corner
632
+              z_x1y1 = ubl.z_values[cell_xi+1][cell_yi+1];  // z at upper right corner
642 633
 
643
-        float z_x0y0 = ubl.z_values[cell_xi  ][cell_yi  ];  // z at lower left corner
644
-        float z_x1y0 = ubl.z_values[cell_xi+1][cell_yi  ];  // z at upper left corner
645
-        float z_x0y1 = ubl.z_values[cell_xi  ][cell_yi+1];  // z at lower right corner
646
-        float z_x1y1 = ubl.z_values[cell_xi+1][cell_yi+1];  // z at upper right corner
634
+        if (isnan(z_x0y0)) z_x0y0 = 0;              // ideally activating ubl.state.active (G29 A) 
635
+        if (isnan(z_x1y0)) z_x1y0 = 0;              //   should refuse if any invalid mesh points
636
+        if (isnan(z_x0y1)) z_x0y1 = 0;              //   in order to avoid isnan tests per cell,
637
+        if (isnan(z_x1y1)) z_x1y1 = 0;              //   thus guessing zero for undefined points
647 638
 
648
-        if ( isnan( z_x0y0 )) z_x0y0 = 0;     // ideally activating ubl.state.active (G29 A) 
649
-        if ( isnan( z_x1y0 )) z_x1y0 = 0;     //   should refuse if any invalid mesh points
650
-        if ( isnan( z_x0y1 )) z_x0y1 = 0;     //   in order to avoid isnan tests per cell,
651
-        if ( isnan( z_x1y1 )) z_x1y1 = 0;     //   thus guessing zero for undefined points
639
+        const float z_xmy0 = (z_x1y0 - z_x0y0) * (1.0 / (MESH_X_DIST)),   // z slope per x along y0 (lower left to lower right)
640
+                    z_xmy1 = (z_x1y1 - z_x0y1) * (1.0 / (MESH_X_DIST));   // z slope per x along y1 (upper left to upper right)
652 641
 
653
-        float z_xmy0 = (z_x1y0 - z_x0y0) * (1.0/MESH_X_DIST);   // z slope per x along y0 (lower left to lower right)
654
-        float z_xmy1 = (z_x1y1 - z_x0y1) * (1.0/MESH_X_DIST);   // z slope per x along y1 (upper left to upper right)
642
+              float z_cxy0 = z_x0y0 + z_xmy0 * cx;          // z height along y0 at cx
655 643
 
656
-        float z_cxy0 = z_x0y0 + z_xmy0 * cx;        // z height along y0 at cx
657
-        float z_cxy1 = z_x0y1 + z_xmy1 * cx;        // z height along y1 at cx
658
-        float z_cxyd = z_cxy1 - z_cxy0;             // z height difference along cx from y0 to y1
644
+        const float z_cxy1 = z_x0y1 + z_xmy1 * cx,          // z height along y1 at cx
645
+                    z_cxyd = z_cxy1 - z_cxy0;               // z height difference along cx from y0 to y1
659 646
 
660
-        float z_cxym = z_cxyd * (1.0/MESH_Y_DIST);  // z slope per y along cx from y0 to y1
661
-        float z_cxcy = z_cxy0 + z_cxym * cy;        // z height along cx at cy
647
+              float z_cxym = z_cxyd * (1.0 / (MESH_Y_DIST)),  // z slope per y along cx from y0 to y1
648
+                    z_cxcy = z_cxy0 + z_cxym * cy;          // z height along cx at cy
662 649
 
663 650
         // As subsequent segments step through this cell, the z_cxy0 intercept will change
664 651
         // and the z_cxym slope will change, both as a function of cx within the cell, and
665 652
         // each change by a constant for fixed segment lengths.
666 653
 
667
-        float z_sxy0 = z_xmy0 * dx_seg;                                   // per-segment adjustment to z_cxy0
668
-        float z_sxym = ( z_xmy1 - z_xmy0 ) * (1.0/MESH_Y_DIST) * dx_seg;  // per-segment adjustment to z_cxym
654
+        const float z_sxy0 = z_xmy0 * dx_seg,                                     // per-segment adjustment to z_cxy0
655
+                    z_sxym = (z_xmy1 - z_xmy0) * (1.0 / (MESH_Y_DIST)) * dx_seg;  // per-segment adjustment to z_cxym
669 656
 
670 657
         do {  // for all segments within this mesh cell
671 658
 
672 659
           z_cxcy += ubl.state.z_offset;
673 660
 
674
-          if ( --segments == 0 ) {          // this is last segment, use ltarget for exact
675
-            COPY_XYZE( seg_dest, ltarget );
661
+          if (--segments == 0) {          // this is last segment, use ltarget for exact
662
+            COPY(seg_dest, ltarget);
676 663
             seg_dest[Z_AXIS] += z_cxcy;
677
-            ubl_buffer_line_segment( seg_dest, feedrate, active_extruder );
664
+            ubl_buffer_line_segment(seg_dest, feedrate, active_extruder);
678 665
             return false;   // did not set_current_to_destination()
679 666
           }
680 667
 
681
-          float z_orig = seg_dest[Z_AXIS];    // remember the pre-leveled segment z value
682
-          seg_dest[Z_AXIS] = z_orig + z_cxcy; // adjust segment z height per mesh leveling
683
-          ubl_buffer_line_segment( seg_dest, feedrate, active_extruder );
684
-          seg_dest[Z_AXIS] = z_orig;          // restore pre-leveled z before incrementing
668
+          const float z_orig = seg_dest[Z_AXIS];  // remember the pre-leveled segment z value
669
+          seg_dest[Z_AXIS] = z_orig + z_cxcy;     // adjust segment z height per mesh leveling
670
+          ubl_buffer_line_segment(seg_dest, feedrate, active_extruder);
671
+          seg_dest[Z_AXIS] = z_orig;              // restore pre-leveled z before incrementing
685 672
 
686 673
           LOOP_XYZE(i) seg_dest[i] += segment_distance[i];  // adjust seg_dest for next segment
687 674
 
688 675
           cx += dx_seg;
689 676
           cy += dy_seg;
690 677
 
691
-          if ( !WITHIN(cx,0,MESH_X_DIST) || !WITHIN(cy,0,MESH_Y_DIST)) {  // done within this cell, break to next
678
+          if (!WITHIN(cx, 0, MESH_X_DIST) || !WITHIN(cy, 0, MESH_Y_DIST)) {  // done within this cell, break to next
692 679
             rx = RAW_X_POSITION(seg_dest[X_AXIS]);
693 680
             ry = RAW_Y_POSITION(seg_dest[Y_AXIS]);
694 681
             break;  

Loading…
Cancel
Save