Selaa lähdekoodia

Move fade_scaling_factor_for_z to Planner

Scott Lahteine 6 vuotta sitten
vanhempi
commit
88857e8028

+ 59
- 75
Marlin/Marlin_main.cpp Näytä tiedosto

@@ -544,14 +544,14 @@ static uint8_t target_extruder;
544 544
 #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
545 545
   #if ENABLED(DELTA)
546 546
     #define ADJUST_DELTA(V) \
547
-      if (planner.abl_enabled) { \
547
+      if (planner.leveling_active) { \
548 548
         const float zadj = bilinear_z_offset(V); \
549 549
         delta[A_AXIS] += zadj; \
550 550
         delta[B_AXIS] += zadj; \
551 551
         delta[C_AXIS] += zadj; \
552 552
       }
553 553
   #else
554
-    #define ADJUST_DELTA(V) if (planner.abl_enabled) { delta[Z_AXIS] += bilinear_z_offset(V); }
554
+    #define ADJUST_DELTA(V) if (planner.leveling_active) { delta[Z_AXIS] += bilinear_z_offset(V); }
555 555
   #endif
556 556
 #elif IS_KINEMATIC
557 557
   #define ADJUST_DELTA(V) NOOP
@@ -2460,7 +2460,7 @@ static void clean_up_after_endstop_or_probe_move() {
2460 2460
   bool leveling_is_valid() {
2461 2461
     return
2462 2462
       #if ENABLED(MESH_BED_LEVELING)
2463
-        mbl.has_mesh()
2463
+        mbl.has_mesh
2464 2464
       #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
2465 2465
         !!bilinear_grid_spacing[X_AXIS]
2466 2466
       #elif ENABLED(AUTO_BED_LEVELING_UBL)
@@ -2486,7 +2486,7 @@ static void clean_up_after_endstop_or_probe_move() {
2486 2486
       constexpr bool can_change = true;
2487 2487
     #endif
2488 2488
 
2489
-    if (can_change && enable != LEVELING_IS_ACTIVE()) {
2489
+    if (can_change && enable != planner.leveling_active) {
2490 2490
 
2491 2491
       #if ENABLED(MESH_BED_LEVELING)
2492 2492
 
@@ -2494,23 +2494,23 @@ static void clean_up_after_endstop_or_probe_move() {
2494 2494
           planner.apply_leveling(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS]);
2495 2495
 
2496 2496
         const bool enabling = enable && leveling_is_valid();
2497
-        mbl.set_active(enabling);
2497
+        planner.leveling_active = enabling;
2498 2498
         if (enabling) planner.unapply_leveling(current_position);
2499 2499
 
2500 2500
       #elif ENABLED(AUTO_BED_LEVELING_UBL)
2501 2501
         #if PLANNER_LEVELING
2502
-          if (ubl.state.active) {                       // leveling from on to off
2502
+          if (planner.leveling_active) {                       // leveling from on to off
2503 2503
             // change unleveled current_position to physical current_position without moving steppers.
2504 2504
             planner.apply_leveling(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS]);
2505
-            ubl.state.active = false;                   // disable only AFTER calling apply_leveling
2505
+            planner.leveling_active = false;                   // disable only AFTER calling apply_leveling
2506 2506
           }
2507 2507
           else {                                        // leveling from off to on
2508
-            ubl.state.active = true;                    // enable BEFORE calling unapply_leveling, otherwise ignored
2508
+            planner.leveling_active = true;                    // enable BEFORE calling unapply_leveling, otherwise ignored
2509 2509
             // change physical current_position to unleveled current_position without moving steppers.
2510 2510
             planner.unapply_leveling(current_position);
2511 2511
           }
2512 2512
         #else
2513
-          ubl.state.active = enable;                    // just flip the bit, current_position will be wrong until next move.
2513
+          planner.leveling_active = enable;                    // just flip the bit, current_position will be wrong until next move.
2514 2514
         #endif
2515 2515
 
2516 2516
       #else // ABL
@@ -2522,7 +2522,7 @@ static void clean_up_after_endstop_or_probe_move() {
2522 2522
         #endif
2523 2523
 
2524 2524
         // Enable or disable leveling compensation in the planner
2525
-        planner.abl_enabled = enable;
2525
+        planner.leveling_active = enable;
2526 2526
 
2527 2527
         if (!enable)
2528 2528
           // When disabling just get the current position from the steppers.
@@ -2547,23 +2547,18 @@ static void clean_up_after_endstop_or_probe_move() {
2547 2547
 
2548 2548
     void set_z_fade_height(const float zfh) {
2549 2549
 
2550
-      const bool level_active = LEVELING_IS_ACTIVE();
2550
+      const bool level_active = planner.leveling_active;
2551 2551
 
2552 2552
       #if ENABLED(AUTO_BED_LEVELING_UBL)
2553
+        if (level_active) set_bed_leveling_enabled(false);  // turn off before changing fade height for proper apply/unapply leveling to maintain current_position
2554
+      #endif
2553 2555
 
2554
-        if (level_active)
2555
-          set_bed_leveling_enabled(false);  // turn off before changing fade height for proper apply/unapply leveling to maintain current_position
2556
-        planner.z_fade_height = zfh;
2557
-        planner.inverse_z_fade_height = RECIPROCAL(zfh);
2558
-        if (level_active)
2559
-          set_bed_leveling_enabled(true);  // turn back on after changing fade height
2560
-
2561
-      #else
2562
-
2563
-        planner.z_fade_height = zfh;
2564
-        planner.inverse_z_fade_height = RECIPROCAL(zfh);
2556
+      planner.set_z_fade_height(zfh);
2565 2557
 
2566
-        if (level_active) {
2558
+      if (level_active) {
2559
+        #if ENABLED(AUTO_BED_LEVELING_UBL)
2560
+          set_bed_leveling_enabled(true);  // turn back on after changing fade height
2561
+        #else
2567 2562
           set_current_from_steppers_for_axis(
2568 2563
             #if ABL_PLANAR
2569 2564
               ALL_AXES
@@ -2571,8 +2566,8 @@ static void clean_up_after_endstop_or_probe_move() {
2571 2566
               Z_AXIS
2572 2567
             #endif
2573 2568
           );
2574
-        }
2575
-      #endif
2569
+        #endif
2570
+      }
2576 2571
     }
2577 2572
 
2578 2573
   #endif // LEVELING_FADE_HEIGHT
@@ -2585,7 +2580,7 @@ static void clean_up_after_endstop_or_probe_move() {
2585 2580
     #if ENABLED(MESH_BED_LEVELING)
2586 2581
       if (leveling_is_valid()) {
2587 2582
         mbl.reset();
2588
-        mbl.set_has_mesh(false);
2583
+        mbl.has_mesh = false;
2589 2584
       }
2590 2585
     #else
2591 2586
       #if ENABLED(DEBUG_LEVELING_FEATURE)
@@ -3759,7 +3754,7 @@ inline void gcode_G4() {
3759 3754
       #elif ENABLED(AUTO_BED_LEVELING_UBL)
3760 3755
         SERIAL_ECHOPGM("UBL");
3761 3756
       #endif
3762
-      if (LEVELING_IS_ACTIVE()) {
3757
+      if (planner.leveling_active) {
3763 3758
         SERIAL_ECHOLNPGM(" (enabled)");
3764 3759
         #if ABL_PLANAR
3765 3760
           const float diff[XYZ] = {
@@ -3790,7 +3785,7 @@ inline void gcode_G4() {
3790 3785
     #elif ENABLED(MESH_BED_LEVELING)
3791 3786
 
3792 3787
       SERIAL_ECHOPGM("Mesh Bed Leveling");
3793
-      if (LEVELING_IS_ACTIVE()) {
3788
+      if (planner.leveling_active) {
3794 3789
         float lz = current_position[Z_AXIS];
3795 3790
         planner.apply_leveling(current_position[X_AXIS], current_position[Y_AXIS], lz);
3796 3791
         SERIAL_ECHOLNPGM(" (enabled)");
@@ -3959,7 +3954,7 @@ inline void gcode_G28(const bool always_home_all) {
3959 3954
   // Disable the leveling matrix before homing
3960 3955
   #if HAS_LEVELING
3961 3956
     #if ENABLED(AUTO_BED_LEVELING_UBL)
3962
-      const bool ubl_state_at_entry = LEVELING_IS_ACTIVE();
3957
+      const bool ubl_state_at_entry = planner.leveling_active;
3963 3958
     #endif
3964 3959
     set_bed_leveling_enabled(false);
3965 3960
   #endif
@@ -4199,7 +4194,7 @@ void home_all_axes() { gcode_G28(true); }
4199 4194
   }
4200 4195
 
4201 4196
   void mesh_probing_done() {
4202
-    mbl.set_has_mesh(true);
4197
+    mbl.has_mesh = true;
4203 4198
     home_all_axes();
4204 4199
     set_bed_leveling_enabled(true);
4205 4200
     #if ENABLED(MESH_G28_REST_ORIGIN)
@@ -4249,7 +4244,7 @@ void home_all_axes() { gcode_G28(true); }
4249 4244
     switch (state) {
4250 4245
       case MeshReport:
4251 4246
         if (leveling_is_valid()) {
4252
-          SERIAL_PROTOCOLLNPAIR("State: ", LEVELING_IS_ACTIVE() ? MSG_ON : MSG_OFF);
4247
+          SERIAL_PROTOCOLLNPAIR("State: ", planner.leveling_active ? MSG_ON : MSG_OFF);
4253 4248
           mbl_mesh_report();
4254 4249
         }
4255 4250
         else
@@ -4568,7 +4563,7 @@ void home_all_axes() { gcode_G28(true); }
4568 4563
         abl_probe_index = -1;
4569 4564
       #endif
4570 4565
 
4571
-      abl_should_enable = LEVELING_IS_ACTIVE();
4566
+      abl_should_enable = planner.leveling_active;
4572 4567
 
4573 4568
       #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
4574 4569
 
@@ -4708,7 +4703,7 @@ void home_all_axes() { gcode_G28(true); }
4708 4703
       stepper.synchronize();
4709 4704
 
4710 4705
       // Disable auto bed leveling during G29
4711
-      planner.abl_enabled = false;
4706
+      planner.leveling_active = false;
4712 4707
 
4713 4708
       if (!dryrun) {
4714 4709
         // Re-orient the current position without leveling
@@ -4722,7 +4717,7 @@ void home_all_axes() { gcode_G28(true); }
4722 4717
       #if HAS_BED_PROBE
4723 4718
         // Deploy the probe. Probe will raise if needed.
4724 4719
         if (DEPLOY_PROBE()) {
4725
-          planner.abl_enabled = abl_should_enable;
4720
+          planner.leveling_active = abl_should_enable;
4726 4721
           return;
4727 4722
         }
4728 4723
       #endif
@@ -4741,7 +4736,7 @@ void home_all_axes() { gcode_G28(true); }
4741 4736
         ) {
4742 4737
           if (dryrun) {
4743 4738
             // Before reset bed level, re-enable to correct the position
4744
-            planner.abl_enabled = abl_should_enable;
4739
+            planner.leveling_active = abl_should_enable;
4745 4740
           }
4746 4741
           // Reset grid to 0.0 or "not probed". (Also disables ABL)
4747 4742
           reset_bed_level();
@@ -4786,7 +4781,7 @@ void home_all_axes() { gcode_G28(true); }
4786 4781
         #if HAS_SOFTWARE_ENDSTOPS
4787 4782
           soft_endstops_enabled = enable_soft_endstops;
4788 4783
         #endif
4789
-        planner.abl_enabled = abl_should_enable;
4784
+        planner.leveling_active = abl_should_enable;
4790 4785
         g29_in_progress = false;
4791 4786
         #if ENABLED(LCD_BED_LEVELING)
4792 4787
           lcd_wait_for_move = false;
@@ -4987,7 +4982,7 @@ void home_all_axes() { gcode_G28(true); }
4987 4982
             measured_z = faux ? 0.001 * random(-100, 101) : probe_pt(xProbe, yProbe, stow_probe_after_each, verbose_level);
4988 4983
 
4989 4984
             if (isnan(measured_z)) {
4990
-              planner.abl_enabled = abl_should_enable;
4985
+              planner.leveling_active = abl_should_enable;
4991 4986
               break;
4992 4987
             }
4993 4988
 
@@ -5023,7 +5018,7 @@ void home_all_axes() { gcode_G28(true); }
5023 5018
           yProbe = LOGICAL_Y_POSITION(points[i].y);
5024 5019
           measured_z = faux ? 0.001 * random(-100, 101) : probe_pt(xProbe, yProbe, stow_probe_after_each, verbose_level);
5025 5020
           if (isnan(measured_z)) {
5026
-            planner.abl_enabled = abl_should_enable;
5021
+            planner.leveling_active = abl_should_enable;
5027 5022
             break;
5028 5023
           }
5029 5024
           points[i].z = measured_z;
@@ -5046,7 +5041,7 @@ void home_all_axes() { gcode_G28(true); }
5046 5041
 
5047 5042
       // Raise to _Z_CLEARANCE_DEPLOY_PROBE. Stow the probe.
5048 5043
       if (STOW_PROBE()) {
5049
-        planner.abl_enabled = abl_should_enable;
5044
+        planner.leveling_active = abl_should_enable;
5050 5045
         measured_z = NAN;
5051 5046
       }
5052 5047
     }
@@ -5214,9 +5209,9 @@ void home_all_axes() { gcode_G28(true); }
5214 5209
           float converted[XYZ];
5215 5210
           COPY(converted, current_position);
5216 5211
 
5217
-          planner.abl_enabled = true;
5212
+          planner.leveling_active = true;
5218 5213
           planner.unapply_leveling(converted); // use conversion machinery
5219
-          planner.abl_enabled = false;
5214
+          planner.leveling_active = false;
5220 5215
 
5221 5216
           // Use the last measured distance to the bed, if possible
5222 5217
           if ( NEAR(current_position[X_AXIS], xProbe - (X_PROBE_OFFSET_FROM_EXTRUDER))
@@ -5268,7 +5263,7 @@ void home_all_axes() { gcode_G28(true); }
5268 5263
       #endif
5269 5264
 
5270 5265
       // Auto Bed Leveling is complete! Enable if possible.
5271
-      planner.abl_enabled = dryrun ? abl_should_enable : true;
5266
+      planner.leveling_active = dryrun ? abl_should_enable : true;
5272 5267
     } // !isnan(measured_z)
5273 5268
 
5274 5269
     // Restore state after probing
@@ -5282,7 +5277,7 @@ void home_all_axes() { gcode_G28(true); }
5282 5277
 
5283 5278
     KEEPALIVE_STATE(IN_HANDLER);
5284 5279
 
5285
-    if (planner.abl_enabled)
5280
+    if (planner.leveling_active)
5286 5281
       SYNC_PLAN_POSITION_KINEMATIC();
5287 5282
   }
5288 5283
 
@@ -7065,7 +7060,7 @@ inline void gcode_M42() {
7065 7060
     // Disable bed level correction in M48 because we want the raw data when we probe
7066 7061
 
7067 7062
     #if HAS_LEVELING
7068
-      const bool was_enabled = LEVELING_IS_ACTIVE();
7063
+      const bool was_enabled = planner.leveling_active;
7069 7064
       set_bed_leveling_enabled(false);
7070 7065
     #endif
7071 7066
 
@@ -9401,7 +9396,7 @@ void quickstop_stepper() {
9401 9396
       if (parser.seen('Z')) set_z_fade_height(parser.value_linear_units());
9402 9397
     #endif
9403 9398
 
9404
-    const bool new_status = LEVELING_IS_ACTIVE();
9399
+    const bool new_status = planner.leveling_active;
9405 9400
 
9406 9401
     if (to_enable && !new_status) {
9407 9402
       SERIAL_ERROR_START();
@@ -9632,7 +9627,7 @@ inline void gcode_M502() {
9632 9627
       #endif
9633 9628
 
9634 9629
       #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
9635
-        if (!no_babystep && LEVELING_IS_ACTIVE())
9630
+        if (!no_babystep && planner.leveling_active)
9636 9631
           thermalManager.babystep_axis(Z_AXIS, -LROUND(diff * planner.axis_steps_per_mm[Z_AXIS]));
9637 9632
       #else
9638 9633
         UNUSED(no_babystep);
@@ -10679,7 +10674,7 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
10679 10674
 
10680 10675
             #if ENABLED(MESH_BED_LEVELING)
10681 10676
 
10682
-              if (LEVELING_IS_ACTIVE()) {
10677
+              if (planner.leveling_active) {
10683 10678
                 #if ENABLED(DEBUG_LEVELING_FEATURE)
10684 10679
                   if (DEBUGGING(LEVELING)) SERIAL_ECHOPAIR("Z before MBL: ", current_position[Z_AXIS]);
10685 10680
                 #endif
@@ -12377,39 +12372,28 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
12377 12372
    * Prepare a linear move in a Cartesian setup.
12378 12373
    * If Mesh Bed Leveling is enabled, perform a mesh move.
12379 12374
    *
12380
-   * Returns true if the caller didn't update current_position.
12375
+   * Returns true if current_position[] was set to destination[]
12381 12376
    */
12382 12377
   inline bool prepare_move_to_destination_cartesian() {
12383
-    #if ENABLED(AUTO_BED_LEVELING_UBL)
12378
+    if (current_position[X_AXIS] != destination[X_AXIS] || current_position[Y_AXIS] != destination[Y_AXIS]) {
12384 12379
       const float fr_scaled = MMS_SCALED(feedrate_mm_s);
12385
-      if (ubl.state.active) { // direct use of ubl.state.active for speed
12386
-        ubl.line_to_destination_cartesian(fr_scaled, active_extruder);
12387
-        return true;
12388
-      }
12389
-      else
12390
-        line_to_destination(fr_scaled);
12391
-    #else
12392
-      // Do not use feedrate_percentage for E or Z only moves
12393
-      if (current_position[X_AXIS] == destination[X_AXIS] && current_position[Y_AXIS] == destination[Y_AXIS])
12394
-        line_to_destination();
12395
-      else {
12396
-        const float fr_scaled = MMS_SCALED(feedrate_mm_s);
12397
-        #if ENABLED(MESH_BED_LEVELING)
12398
-          if (mbl.active()) { // direct used of mbl.active() for speed
12380
+      #if HAS_LEVELING
12381
+        if (planner.leveling_active) {
12382
+          #if ENABLED(AUTO_BED_LEVELING_UBL)
12383
+            ubl.line_to_destination_cartesian(fr_scaled, active_extruder);
12384
+          #elif ENABLED(MESH_BED_LEVELING)
12399 12385
             mesh_line_to_destination(fr_scaled);
12400
-            return true;
12401
-          }
12402
-          else
12403
-        #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
12404
-          if (planner.abl_enabled) { // direct use of abl_enabled for speed
12386
+          #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
12405 12387
             bilinear_line_to_destination(fr_scaled);
12406
-            return true;
12407
-          }
12408
-          else
12409
-        #endif
12410
-            line_to_destination(fr_scaled);
12411
-      }
12412
-    #endif
12388
+          #endif
12389
+          return true;
12390
+        }
12391
+      #endif // HAS_LEVELING
12392
+      line_to_destination(fr_scaled);
12393
+    }
12394
+    else
12395
+      line_to_destination();
12396
+
12413 12397
     return false;
12414 12398
   }
12415 12399
 

+ 63
- 53
Marlin/configuration_store.cpp Näytä tiedosto

@@ -68,7 +68,7 @@
68 68
  *  219            z_fade_height                    (float)
69 69
  *
70 70
  * MESH_BED_LEVELING:                               43 bytes
71
- *  223  M420 S    from mbl.status                  (bool)
71
+ *  223  M420 S    planner.leveling_active          (bool)
72 72
  *  224            mbl.z_offset                     (float)
73 73
  *  228            GRID_MAX_POINTS_X                (uint8_t)
74 74
  *  229            GRID_MAX_POINTS_Y                (uint8_t)
@@ -88,7 +88,7 @@
88 88
  *  316            z_values[][]                     (float x9, up to float x256) +988
89 89
  *
90 90
  * AUTO_BED_LEVELING_UBL:                           6 bytes
91
- *  324  G29 A     ubl.state.active                 (bool)
91
+ *  324  G29 A     planner.leveling_active          (bool)
92 92
  *  325  G29 S     ubl.state.storage_slot           (int8_t)
93 93
  *
94 94
  * DELTA:                                           48 bytes
@@ -204,6 +204,10 @@ MarlinSettings settings;
204 204
   extern void refresh_bed_level();
205 205
 #endif
206 206
 
207
+#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
208
+  float new_z_fade_height;
209
+#endif
210
+
207 211
 /**
208 212
  * Post-process after Retrieve or Reset
209 213
  */
@@ -233,7 +237,7 @@ void MarlinSettings::postprocess() {
233 237
   #endif
234 238
 
235 239
   #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
236
-    set_z_fade_height(planner.z_fade_height);
240
+    set_z_fade_height(new_z_fade_height);
237 241
   #endif
238 242
 
239 243
   #if HAS_BED_PROBE
@@ -372,7 +376,7 @@ void MarlinSettings::postprocess() {
372 376
         sizeof(mbl.z_values) == GRID_MAX_POINTS * sizeof(mbl.z_values[0][0]),
373 377
         "MBL Z array is the wrong size."
374 378
       );
375
-      const bool leveling_is_on = TEST(mbl.status, MBL_STATUS_HAS_MESH_BIT);
379
+      const bool leveling_is_on = mbl.has_mesh;
376 380
       const uint8_t mesh_num_x = GRID_MAX_POINTS_X, mesh_num_y = GRID_MAX_POINTS_Y;
377 381
       EEPROM_WRITE(leveling_is_on);
378 382
       EEPROM_WRITE(mbl.z_offset);
@@ -435,7 +439,7 @@ void MarlinSettings::postprocess() {
435 439
     #endif // AUTO_BED_LEVELING_BILINEAR
436 440
 
437 441
     #if ENABLED(AUTO_BED_LEVELING_UBL)
438
-      EEPROM_WRITE(ubl.state.active);
442
+      EEPROM_WRITE(planner.leveling_active);
439 443
       EEPROM_WRITE(ubl.state.storage_slot);
440 444
     #else
441 445
       const bool ubl_active = false;
@@ -751,7 +755,7 @@ void MarlinSettings::postprocess() {
751 755
       //
752 756
 
753 757
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
754
-        EEPROM_READ(planner.z_fade_height);
758
+        EEPROM_READ(new_z_fade_height);
755 759
       #else
756 760
         EEPROM_READ(dummy);
757 761
       #endif
@@ -768,7 +772,7 @@ void MarlinSettings::postprocess() {
768 772
       EEPROM_READ(mesh_num_y);
769 773
 
770 774
       #if ENABLED(MESH_BED_LEVELING)
771
-        mbl.status = leveling_is_on ? _BV(MBL_STATUS_HAS_MESH_BIT) : 0;
775
+        mbl.has_mesh = leveling_is_on;
772 776
         mbl.z_offset = dummy;
773 777
         if (mesh_num_x == GRID_MAX_POINTS_X && mesh_num_y == GRID_MAX_POINTS_Y) {
774 778
           // EEPROM data fits the current mesh
@@ -824,7 +828,7 @@ void MarlinSettings::postprocess() {
824 828
         }
825 829
 
826 830
       #if ENABLED(AUTO_BED_LEVELING_UBL)
827
-        EEPROM_READ(ubl.state.active);
831
+        EEPROM_READ(planner.leveling_active);
828 832
         EEPROM_READ(ubl.state.storage_slot);
829 833
       #else
830 834
         uint8_t dummyui8;
@@ -1186,7 +1190,7 @@ void MarlinSettings::reset() {
1186 1190
   planner.max_jerk[E_AXIS] = DEFAULT_EJERK;
1187 1191
 
1188 1192
   #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1189
-    planner.z_fade_height = 0.0;
1193
+    new_z_fade_height = 10.0;
1190 1194
   #endif
1191 1195
 
1192 1196
   #if HAS_HOME_OFFSET
@@ -1563,65 +1567,71 @@ void MarlinSettings::reset() {
1563 1567
       }
1564 1568
     #endif
1565 1569
 
1566
-    #if ENABLED(MESH_BED_LEVELING)
1570
+    /**
1571
+     * Bed Leveling
1572
+     */
1573
+    #if HAS_LEVELING
1567 1574
 
1568
-      if (!forReplay) {
1575
+      #if ENABLED(MESH_BED_LEVELING)
1576
+
1577
+        if (!forReplay) {
1578
+          CONFIG_ECHO_START;
1579
+          SERIAL_ECHOLNPGM("Mesh Bed Leveling:");
1580
+        }
1569 1581
         CONFIG_ECHO_START;
1570
-        SERIAL_ECHOLNPGM("Mesh Bed Leveling:");
1571
-      }
1572
-      CONFIG_ECHO_START;
1573
-      SERIAL_ECHOPAIR("  M420 S", leveling_is_valid() ? 1 : 0);
1574
-      #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1575
-        SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(planner.z_fade_height));
1576
-      #endif
1577
-      SERIAL_EOL();
1578
-      for (uint8_t py = 0; py < GRID_MAX_POINTS_Y; py++) {
1579
-        for (uint8_t px = 0; px < GRID_MAX_POINTS_X; px++) {
1582
+
1583
+      #elif ENABLED(AUTO_BED_LEVELING_UBL)
1584
+
1585
+        if (!forReplay) {
1580 1586
           CONFIG_ECHO_START;
1581
-          SERIAL_ECHOPAIR("  G29 S3 X", (int)px + 1);
1582
-          SERIAL_ECHOPAIR(" Y", (int)py + 1);
1583
-          SERIAL_ECHOPGM(" Z");
1584
-          SERIAL_PROTOCOL_F(LINEAR_UNIT(mbl.z_values[px][py]), 5);
1585
-          SERIAL_EOL();
1587
+          ubl.echo_name();
1588
+          SERIAL_ECHOLNPGM(":");
1586 1589
         }
1587
-      }
1590
+        CONFIG_ECHO_START;
1588 1591
 
1589
-    #elif ENABLED(AUTO_BED_LEVELING_UBL)
1592
+      #elif HAS_ABL
1590 1593
 
1591
-      if (!forReplay) {
1594
+        if (!forReplay) {
1595
+          CONFIG_ECHO_START;
1596
+          SERIAL_ECHOLNPGM("Auto Bed Leveling:");
1597
+        }
1592 1598
         CONFIG_ECHO_START;
1593
-        ubl.echo_name();
1594
-        SERIAL_ECHOLNPGM(":");
1595
-      }
1599
+
1600
+      #endif
1601
+
1596 1602
       CONFIG_ECHO_START;
1597
-      SERIAL_ECHOPAIR("  M420 S", LEVELING_IS_ACTIVE() ? 1 : 0);
1603
+      SERIAL_ECHOPAIR("  M420 S", planner.leveling_active ? 1 : 0);
1598 1604
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1599
-        SERIAL_ECHOPAIR(" Z", planner.z_fade_height);
1605
+        SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(planner.z_fade_height));
1600 1606
       #endif
1601 1607
       SERIAL_EOL();
1602 1608
 
1603
-      if (!forReplay) {
1604
-        SERIAL_EOL();
1605
-        ubl.report_state();
1606
-        SERIAL_ECHOLNPAIR("\nActive Mesh Slot: ", ubl.state.storage_slot);
1607
-        SERIAL_ECHOPAIR("EEPROM can hold ", calc_num_meshes());
1608
-        SERIAL_ECHOLNPGM(" meshes.\n");
1609
-      }
1609
+      #if ENABLED(MESH_BED_LEVELING)
1610 1610
 
1611
-    #elif HAS_ABL
1611
+        for (uint8_t py = 0; py < GRID_MAX_POINTS_Y; py++) {
1612
+          for (uint8_t px = 0; px < GRID_MAX_POINTS_X; px++) {
1613
+            CONFIG_ECHO_START;
1614
+            SERIAL_ECHOPAIR("  G29 S3 X", (int)px + 1);
1615
+            SERIAL_ECHOPAIR(" Y", (int)py + 1);
1616
+            SERIAL_ECHOPGM(" Z");
1617
+            SERIAL_PROTOCOL_F(LINEAR_UNIT(mbl.z_values[px][py]), 5);
1618
+            SERIAL_EOL();
1619
+          }
1620
+        }
1621
+
1622
+      #elif ENABLED(AUTO_BED_LEVELING_UBL)
1623
+
1624
+        if (!forReplay) {
1625
+          SERIAL_EOL();
1626
+          ubl.report_state();
1627
+          SERIAL_ECHOLNPAIR("\nActive Mesh Slot: ", ubl.state.storage_slot);
1628
+          SERIAL_ECHOPAIR("EEPROM can hold ", calc_num_meshes());
1629
+          SERIAL_ECHOLNPGM(" meshes.\n");
1630
+        }
1612 1631
 
1613
-      if (!forReplay) {
1614
-        CONFIG_ECHO_START;
1615
-        SERIAL_ECHOLNPGM("Auto Bed Leveling:");
1616
-      }
1617
-      CONFIG_ECHO_START;
1618
-      SERIAL_ECHOPAIR("  M420 S", LEVELING_IS_ACTIVE() ? 1 : 0);
1619
-      #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1620
-        SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(planner.z_fade_height));
1621 1632
       #endif
1622
-      SERIAL_EOL();
1623 1633
 
1624
-    #endif
1634
+    #endif // HAS_LEVELING
1625 1635
 
1626 1636
     #if ENABLED(DELTA)
1627 1637
       if (!forReplay) {
@@ -1757,7 +1767,7 @@ void MarlinSettings::reset() {
1757 1767
     #endif // FWRETRACT
1758 1768
 
1759 1769
     /**
1760
-     * Auto Bed Leveling
1770
+     * Probe Offset
1761 1771
      */
1762 1772
     #if HAS_BED_PROBE
1763 1773
       if (!forReplay) {

+ 2
- 2
Marlin/mesh_bed_leveling.cpp Näytä tiedosto

@@ -26,7 +26,7 @@
26 26
 
27 27
   mesh_bed_leveling mbl;
28 28
 
29
-  uint8_t mesh_bed_leveling::status;
29
+  bool mesh_bed_leveling::has_mesh;
30 30
 
31 31
   float mesh_bed_leveling::z_offset,
32 32
         mesh_bed_leveling::z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y],
@@ -42,7 +42,7 @@
42 42
   }
43 43
 
44 44
   void mesh_bed_leveling::reset() {
45
-    status = MBL_STATUS_NONE;
45
+    has_mesh = false;
46 46
     z_offset = 0;
47 47
     ZERO(z_values);
48 48
   }

+ 1
- 12
Marlin/mesh_bed_leveling.h Näytä tiedosto

@@ -33,18 +33,12 @@
33 33
     MeshReset
34 34
   };
35 35
 
36
-  enum MBLStatus {
37
-    MBL_STATUS_NONE = 0,
38
-    MBL_STATUS_HAS_MESH_BIT = 0,
39
-    MBL_STATUS_ACTIVE_BIT = 1
40
-  };
41
-
42 36
   #define MESH_X_DIST ((MESH_MAX_X - (MESH_MIN_X)) / (GRID_MAX_POINTS_X - 1))
43 37
   #define MESH_Y_DIST ((MESH_MAX_Y - (MESH_MIN_Y)) / (GRID_MAX_POINTS_Y - 1))
44 38
 
45 39
   class mesh_bed_leveling {
46 40
   public:
47
-    static uint8_t status; // Has Mesh and Is Active bits
41
+    static bool has_mesh;
48 42
     static float z_offset,
49 43
                  z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y],
50 44
                  index_to_xpos[GRID_MAX_POINTS_X],
@@ -56,11 +50,6 @@
56 50
 
57 51
     static void set_z(const int8_t px, const int8_t py, const float &z) { z_values[px][py] = z; }
58 52
 
59
-    static bool active()                       { return TEST(status, MBL_STATUS_ACTIVE_BIT); }
60
-    static void set_active(const bool onOff)   { onOff ? SBI(status, MBL_STATUS_ACTIVE_BIT) : CBI(status, MBL_STATUS_ACTIVE_BIT); }
61
-    static bool has_mesh()                     { return TEST(status, MBL_STATUS_HAS_MESH_BIT); }
62
-    static void set_has_mesh(const bool onOff) { onOff ? SBI(status, MBL_STATUS_HAS_MESH_BIT) : CBI(status, MBL_STATUS_HAS_MESH_BIT); }
63
-
64 53
     static inline void zigzag(const int8_t index, int8_t &px, int8_t &py) {
65 54
       px = index % (GRID_MAX_POINTS_X);
66 55
       py = index / (GRID_MAX_POINTS_X);

+ 58
- 81
Marlin/planner.cpp Näytä tiedosto

@@ -104,17 +104,16 @@ float Planner::min_feedrate_mm_s,
104 104
       Planner::max_jerk[XYZE],       // The largest speed change requiring no acceleration
105 105
       Planner::min_travel_feedrate_mm_s;
106 106
 
107
-#if HAS_ABL
108
-  bool Planner::abl_enabled = false; // Flag that auto bed leveling is enabled
109
-#endif
110
-
111
-#if ABL_PLANAR
112
-  matrix_3x3 Planner::bed_level_matrix; // Transform to compensate for bed level
113
-#endif
114
-
115
-#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
116
-  float Planner::z_fade_height, // Initialized by settings.load()
117
-        Planner::inverse_z_fade_height;
107
+#if HAS_LEVELING
108
+  bool Planner::leveling_active = false; // Flag that auto bed leveling is enabled
109
+  #if ABL_PLANAR
110
+    matrix_3x3 Planner::bed_level_matrix; // Transform to compensate for bed level
111
+  #endif
112
+  #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
113
+    float Planner::z_fade_height,      // Initialized by settings.load()
114
+          Planner::inverse_z_fade_height,
115
+          Planner::last_raw_lz;
116
+  #endif
118 117
 #endif
119 118
 
120 119
 #if ENABLED(AUTOTEMP)
@@ -528,46 +527,31 @@ void Planner::check_axes_activity() {
528 527
    */
529 528
   void Planner::apply_leveling(float &lx, float &ly, float &lz) {
530 529
 
531
-    #if ENABLED(AUTO_BED_LEVELING_UBL)
532
-      if (!ubl.state.active) return;
533
-      #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
534
-        // if z_fade_height enabled (nonzero) and raw_z above it, no leveling required
535
-        if (planner.z_fade_height && planner.z_fade_height <= RAW_Z_POSITION(lz)) return;
536
-        lz += ubl.get_z_correction(lx, ly) * ubl.fade_scaling_factor_for_z(lz);
537
-      #else // no fade
538
-        lz += ubl.get_z_correction(lx, ly);
539
-      #endif // FADE
540
-    #endif // UBL
541
-
542
-    #if HAS_ABL
543
-      if (!abl_enabled) return;
544
-    #endif
530
+    if (!leveling_active) return;
545 531
 
546
-    #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) && DISABLED(AUTO_BED_LEVELING_UBL)
547
-      static float z_fade_factor = 1.0, last_raw_lz = -999.0;
548
-      if (z_fade_height) {
549
-        const float raw_lz = RAW_Z_POSITION(lz);
550
-        if (raw_lz >= z_fade_height) return;
551
-        if (last_raw_lz != raw_lz) {
552
-          last_raw_lz = raw_lz;
553
-          z_fade_factor = 1.0 - raw_lz * inverse_z_fade_height;
554
-        }
555
-      }
556
-      else
557
-        z_fade_factor = 1.0;
532
+    #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
533
+      const float fade_scaling_factor = fade_scaling_factor_for_z(lz);
534
+      if (!fade_scaling_factor) return;
535
+    #else
536
+      constexpr float fade_scaling_factor = 1.0;
558 537
     #endif
559 538
 
560
-    #if ENABLED(MESH_BED_LEVELING)
539
+    #if ENABLED(AUTO_BED_LEVELING_UBL)
561 540
 
562
-      if (mbl.active())
563
-        lz += mbl.get_z(RAW_X_POSITION(lx), RAW_Y_POSITION(ly)
564
-          #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
565
-            , z_fade_factor
566
-          #endif
567
-          );
541
+      lz += ubl.get_z_correction(lx, ly) * fade_scaling_factor;
542
+
543
+    #elif ENABLED(MESH_BED_LEVELING)
544
+
545
+      lz += mbl.get_z(RAW_X_POSITION(lx), RAW_Y_POSITION(ly)
546
+        #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
547
+          , fade_scaling_factor
548
+        #endif
549
+      );
568 550
 
569 551
     #elif ABL_PLANAR
570 552
 
553
+      UNUSED(fade_scaling_factor);
554
+
571 555
       float dx = RAW_X_POSITION(lx) - (X_TILT_FULCRUM),
572 556
             dy = RAW_Y_POSITION(ly) - (Y_TILT_FULCRUM),
573 557
             dz = RAW_Z_POSITION(lz);
@@ -581,63 +565,56 @@ void Planner::check_axes_activity() {
581 565
     #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
582 566
 
583 567
       float tmp[XYZ] = { lx, ly, 0 };
584
-      lz += bilinear_z_offset(tmp)
585
-        #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
586
-          * z_fade_factor
587
-        #endif
588
-      ;
568
+      lz += bilinear_z_offset(tmp) * fade_scaling_factor;
589 569
 
590 570
     #endif
591 571
   }
592 572
 
593 573
   void Planner::unapply_leveling(float logical[XYZ]) {
594 574
 
595
-    #if ENABLED(AUTO_BED_LEVELING_UBL)
575
+    #if HAS_LEVELING
576
+      if (!leveling_active) return;
577
+    #endif
596 578
 
597
-      if (ubl.state.active) {
579
+    #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
580
+      if (!leveling_active_at_z(logical[Z_AXIS])) return;
581
+    #endif
598 582
 
599
-        const float z_physical = RAW_Z_POSITION(logical[Z_AXIS]),
600
-                    z_correct = ubl.get_z_correction(logical[X_AXIS], logical[Y_AXIS]),
601
-                    z_virtual = z_physical - z_correct;
602
-              float z_logical = LOGICAL_Z_POSITION(z_virtual);
583
+    #if ENABLED(AUTO_BED_LEVELING_UBL)
603 584
 
604
-        #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
585
+      const float z_physical = RAW_Z_POSITION(logical[Z_AXIS]),
586
+                  z_correct = ubl.get_z_correction(logical[X_AXIS], logical[Y_AXIS]),
587
+                  z_virtual = z_physical - z_correct;
588
+            float z_logical = LOGICAL_Z_POSITION(z_virtual);
605 589
 
606
-          // for P=physical_z, L=logical_z, M=mesh_z, H=fade_height,
607
-          // Given P=L+M(1-L/H) (faded mesh correction formula for L<H)
608
-          //  then L=P-M(1-L/H)
609
-          //    so L=P-M+ML/H
610
-          //    so L-ML/H=P-M
611
-          //    so L(1-M/H)=P-M
612
-          //    so L=(P-M)/(1-M/H) for L<H
590
+      #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
613 591
 
614
-          if (planner.z_fade_height) {
615
-            if (z_logical >= planner.z_fade_height)
616
-              z_logical = LOGICAL_Z_POSITION(z_physical);
617
-            else
618
-              z_logical /= 1.0 - z_correct * planner.inverse_z_fade_height;
619
-          }
592
+        // for P=physical_z, L=logical_z, M=mesh_z, H=fade_height,
593
+        // Given P=L+M(1-L/H) (faded mesh correction formula for L<H)
594
+        //  then L=P-M(1-L/H)
595
+        //    so L=P-M+ML/H
596
+        //    so L-ML/H=P-M
597
+        //    so L(1-M/H)=P-M
598
+        //    so L=(P-M)/(1-M/H) for L<H
599
+
600
+        if (planner.z_fade_height) {
601
+          if (z_logical >= planner.z_fade_height)
602
+            z_logical = LOGICAL_Z_POSITION(z_physical);
603
+          else
604
+            z_logical /= 1.0 - z_correct * planner.inverse_z_fade_height;
605
+        }
620 606
 
621
-        #endif // ENABLE_LEVELING_FADE_HEIGHT
607
+      #endif // ENABLE_LEVELING_FADE_HEIGHT
622 608
 
623
-        logical[Z_AXIS] = z_logical;
624
-      }
609
+      logical[Z_AXIS] = z_logical;
625 610
 
626 611
       return; // don't fall thru to other ENABLE_LEVELING_FADE_HEIGHT logic
627 612
 
628 613
     #endif
629 614
 
630
-    #if HAS_ABL
631
-      if (!abl_enabled) return;
632
-    #endif
633
-
634
-    #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
635
-      if (z_fade_height && RAW_Z_POSITION(logical[Z_AXIS]) >= z_fade_height) return;
636
-    #endif
637
-
638 615
     #if ENABLED(MESH_BED_LEVELING)
639 616
 
640
-      if (mbl.active()) {
617
+      if (leveling_active) {
641 618
         #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
642 619
           const float c = mbl.get_z(RAW_X_POSITION(logical[X_AXIS]), RAW_Y_POSITION(logical[Y_AXIS]), 1.0);
643 620
           logical[Z_AXIS] = (z_fade_height * (RAW_Z_POSITION(logical[Z_AXIS]) - c)) / (z_fade_height - c);

+ 55
- 16
Marlin/planner.h Näytä tiedosto

@@ -154,15 +154,14 @@ class Planner {
154 154
                  max_jerk[XYZE],       // The largest speed change requiring no acceleration
155 155
                  min_travel_feedrate_mm_s;
156 156
 
157
-    #if HAS_ABL
158
-      static bool abl_enabled;              // Flag that bed leveling is enabled
157
+    #if HAS_LEVELING
158
+      static bool leveling_active;          // Flag that bed leveling is enabled
159 159
       #if ABL_PLANAR
160 160
         static matrix_3x3 bed_level_matrix; // Transform to compensate for bed level
161 161
       #endif
162
-    #endif
163
-
164
-    #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
165
-      static float z_fade_height, inverse_z_fade_height;
162
+      #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
163
+        static float z_fade_height, inverse_z_fade_height;
164
+      #endif
166 165
     #endif
167 166
 
168 167
     #if ENABLED(LIN_ADVANCE)
@@ -192,6 +191,10 @@ class Planner {
192 191
      */
193 192
     static uint32_t cutoff_long;
194 193
 
194
+    #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
195
+      static float last_raw_lz;
196
+    #endif
197
+
195 198
     #if ENABLED(DISABLE_INACTIVE_EXTRUDER)
196 199
       /**
197 200
        * Counters to manage disabling inactive extruders
@@ -243,6 +246,52 @@ class Planner {
243 246
 
244 247
     static bool is_full() { return (block_buffer_tail == BLOCK_MOD(block_buffer_head + 1)); }
245 248
 
249
+    #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
250
+
251
+      /**
252
+       * Get the Z leveling fade factor based on the given Z height,
253
+       * re-calculating only when needed.
254
+       *
255
+       *  Returns 1.0 if planner.z_fade_height is 0.0.
256
+       *  Returns 0.0 if Z is past the specified 'Fade Height'.
257
+       */
258
+      inline static float fade_scaling_factor_for_z(const float &lz) {
259
+        static float z_fade_factor = 1.0;
260
+        if (z_fade_height) {
261
+          const float raw_lz = RAW_Z_POSITION(lz);
262
+          if (raw_lz >= z_fade_height) return 0.0;
263
+          if (last_raw_lz != raw_lz) {
264
+            last_raw_lz = raw_lz;
265
+            z_fade_factor = 1.0 - raw_lz * inverse_z_fade_height;
266
+          }
267
+          return z_fade_factor;
268
+        }
269
+        return 1.0;
270
+      }
271
+
272
+      FORCE_INLINE static void force_fade_recalc() { last_raw_lz = -999.999; }
273
+
274
+      FORCE_INLINE static void set_z_fade_height(const float &zfh) {
275
+        z_fade_height = zfh > 0 ? zfh : 0;
276
+        inverse_z_fade_height = RECIPROCAL(z_fade_height);
277
+        force_fade_recalc();
278
+      }
279
+
280
+      FORCE_INLINE static bool leveling_active_at_z(const float &lz) {
281
+        return !z_fade_height || RAW_Z_POSITION(lz) < z_fade_height;
282
+      }
283
+
284
+    #else
285
+
286
+      FORCE_INLINE static float fade_scaling_factor_for_z(const float &lz) {
287
+        UNUSED(lz);
288
+        return 1.0;
289
+      }
290
+
291
+      FORCE_INLINE static bool leveling_active_at_z(const float &lz) { return true; }
292
+
293
+    #endif
294
+
246 295
     #if PLANNER_LEVELING
247 296
 
248 297
       #define ARG_X float lx
@@ -468,16 +517,6 @@ class Planner {
468 517
 
469 518
 #define PLANNER_XY_FEEDRATE() (min(planner.max_feedrate_mm_s[X_AXIS], planner.max_feedrate_mm_s[Y_AXIS]))
470 519
 
471
-#if ENABLED(MESH_BED_LEVELING)
472
-  #define LEVELING_IS_ACTIVE() (mesh_bed_leveling::active())
473
-#elif ENABLED(AUTO_BED_LEVELING_UBL)
474
-  #define LEVELING_IS_ACTIVE() (unified_bed_leveling::state.active)
475
-#elif HAS_ABL
476
-  #define LEVELING_IS_ACTIVE() (Planner::abl_enabled)
477
-#else
478
-  #define LEVELING_IS_ACTIVE() (false)
479
-#endif
480
-
481 520
 extern Planner planner;
482 521
 
483 522
 #endif // PLANNER_H

+ 4
- 7
Marlin/ubl.cpp Näytä tiedosto

@@ -28,8 +28,7 @@
28 28
   #include "ubl.h"
29 29
   #include "hex_print_routines.h"
30 30
   #include "temperature.h"
31
-
32
-  extern Planner planner;
31
+  #include "planner.h"
33 32
 
34 33
   /**
35 34
    * These support functions allow the use of large bit arrays of flags that take very
@@ -48,7 +47,7 @@
48 47
   void unified_bed_leveling::report_state() {
49 48
     echo_name();
50 49
     SERIAL_PROTOCOLPGM(" System v" UBL_VERSION " ");
51
-    if (!state.active) SERIAL_PROTOCOLPGM("in");
50
+    if (!planner.leveling_active) SERIAL_PROTOCOLPGM("in");
52 51
     SERIAL_PROTOCOLLNPGM("active.");
53 52
     safe_delay(50);
54 53
   }
@@ -64,8 +63,7 @@
64 63
 
65 64
   ubl_state unified_bed_leveling::state;
66 65
 
67
-  float unified_bed_leveling::z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y],
68
-        unified_bed_leveling::last_specified_z;
66
+  float unified_bed_leveling::z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
69 67
 
70 68
   // 15 is the maximum nubmer of grid points supported + 1 safety margin for now,
71 69
   // until determinism prevails
@@ -86,10 +84,9 @@
86 84
     set_bed_leveling_enabled(false);
87 85
     state.storage_slot = -1;
88 86
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
89
-      planner.z_fade_height = 10.0;
87
+      planner.set_z_fade_height(10.0);
90 88
     #endif
91 89
     ZERO(z_values);
92
-    last_specified_z = -999.9;
93 90
   }
94 91
 
95 92
   void unified_bed_leveling::invalidate() {

+ 0
- 27
Marlin/ubl.h Näytä tiedosto

@@ -84,8 +84,6 @@
84 84
   class unified_bed_leveling {
85 85
     private:
86 86
 
87
-      static float last_specified_z;
88
-
89 87
       static int    g29_verbose_level,
90 88
                     g29_phase_value,
91 89
                     g29_repetition_cnt,
@@ -361,31 +359,6 @@
361 359
         return z0;
362 360
       }
363 361
 
364
-      /**
365
-       * This function sets the Z leveling fade factor based on the given Z height,
366
-       * only re-calculating when necessary.
367
-       *
368
-       *  Returns 1.0 if planner.z_fade_height is 0.0.
369
-       *  Returns 0.0 if Z is past the specified 'Fade Height'.
370
-       */
371
-      #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
372
-        static inline float fade_scaling_factor_for_z(const float &lz) {
373
-          if (planner.z_fade_height == 0.0) return 1.0;
374
-          static float fade_scaling_factor = 1.0;
375
-          const float rz = RAW_Z_POSITION(lz);
376
-          if (last_specified_z != rz) {
377
-            last_specified_z = rz;
378
-            fade_scaling_factor =
379
-              rz < planner.z_fade_height
380
-                ? 1.0 - (rz * planner.inverse_z_fade_height)
381
-                : 0.0;
382
-          }
383
-          return fade_scaling_factor;
384
-        }
385
-      #else
386
-        FORCE_INLINE static float fade_scaling_factor_for_z(const float &lz) { return 1.0; }
387
-      #endif
388
-
389 362
       FORCE_INLINE static float mesh_index_to_xpos(const uint8_t i) {
390 363
         return i < GRID_MAX_POINTS_X ? pgm_read_float(&_mesh_index_to_xpos[i]) : UBL_MESH_MIN_X + i * (MESH_X_DIST);
391 364
       }

+ 1
- 1
Marlin/ubl_G29.cpp Näytä tiedosto

@@ -1165,7 +1165,7 @@
1165 1165
 
1166 1166
       return;
1167 1167
     }
1168
-    ubl_state_at_invocation = state.active;
1168
+    ubl_state_at_invocation = planner.leveling_active;
1169 1169
     set_bed_leveling_enabled(false);
1170 1170
   }
1171 1171
 

+ 15
- 21
Marlin/ubl_motion.cpp Näytä tiedosto

@@ -186,7 +186,7 @@
186 186
       // are going to apply the Y-Distance into the cell to interpolate the final Z correction.
187 187
 
188 188
       const float yratio = (RAW_Y_POSITION(end[Y_AXIS]) - mesh_index_to_ypos(cell_dest_yi)) * (1.0 / (MESH_Y_DIST));
189
-      float z0 = cell_dest_yi < GRID_MAX_POINTS_Y - 1 ? (z1 + (z2 - z1) * yratio) * fade_scaling_factor_for_z(end[Z_AXIS]) : 0.0;
189
+      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;
190 190
 
191 191
       /**
192 192
        * If part of the Mesh is undefined, it will show up as NAN
@@ -270,9 +270,8 @@
270 270
          */
271 271
         const float x = inf_m_flag ? start[X_AXIS] : (next_mesh_line_y - c) / m;
272 272
 
273
-        float z0 = z_correction_for_x_on_horizontal_mesh_line(x, current_xi, current_yi);
274
-
275
-        z0 *= fade_scaling_factor_for_z(end[Z_AXIS]);
273
+        float z0 = z_correction_for_x_on_horizontal_mesh_line(x, current_xi, current_yi)
274
+                   * planner.fade_scaling_factor_for_z(end[Z_AXIS]);
276 275
 
277 276
         /**
278 277
          * If part of the Mesh is undefined, it will show up as NAN
@@ -335,9 +334,8 @@
335 334
         const float next_mesh_line_x = LOGICAL_X_POSITION(mesh_index_to_xpos(current_xi)),
336 335
                     y = m * next_mesh_line_x + c;   // Calculate Y at the next X mesh line
337 336
 
338
-        float z0 = z_correction_for_y_on_vertical_mesh_line(y, current_xi, current_yi);
339
-
340
-        z0 *= fade_scaling_factor_for_z(end[Z_AXIS]);
337
+        float z0 = z_correction_for_y_on_vertical_mesh_line(y, current_xi, current_yi)
338
+                   * planner.fade_scaling_factor_for_z(end[Z_AXIS]);
341 339
 
342 340
         /**
343 341
          * If part of the Mesh is undefined, it will show up as NAN
@@ -408,9 +406,8 @@
408 406
 
409 407
       if (left_flag == (x > next_mesh_line_x)) { // Check if we hit the Y line first
410 408
         // Yes!  Crossing a Y Mesh Line next
411
-        float z0 = z_correction_for_x_on_horizontal_mesh_line(x, current_xi - left_flag, current_yi + dyi);
412
-
413
-        z0 *= fade_scaling_factor_for_z(end[Z_AXIS]);
409
+        float z0 = z_correction_for_x_on_horizontal_mesh_line(x, current_xi - left_flag, current_yi + dyi)
410
+                   * planner.fade_scaling_factor_for_z(end[Z_AXIS]);
414 411
 
415 412
         /**
416 413
          * If part of the Mesh is undefined, it will show up as NAN
@@ -436,9 +433,8 @@
436 433
       }
437 434
       else {
438 435
         // Yes!  Crossing a X Mesh Line next
439
-        float z0 = z_correction_for_y_on_vertical_mesh_line(y, current_xi + dxi, current_yi - down_flag);
440
-
441
-        z0 *= fade_scaling_factor_for_z(end[Z_AXIS]);
436
+        float z0 = z_correction_for_y_on_vertical_mesh_line(y, current_xi + dxi, current_yi - down_flag)
437
+                   * planner.fade_scaling_factor_for_z(end[Z_AXIS]);
442 438
 
443 439
         /**
444 440
          * If part of the Mesh is undefined, it will show up as NAN
@@ -603,7 +599,7 @@
603 599
 
604 600
       // Only compute leveling per segment if ubl active and target below z_fade_height.
605 601
 
606
-      if (!state.active || above_fade_height) {   // no mesh leveling
602
+      if (!planner.leveling_active || !planner.leveling_active_at_z(ltarget[Z_AXIS])) {   // no mesh leveling
607 603
 
608 604
         do {
609 605
 
@@ -629,7 +625,9 @@
629 625
       // Otherwise perform per-segment leveling
630 626
 
631 627
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
632
-        const float fade_scaling_factor = fade_scaling_factor_for_z(ltarget[Z_AXIS]);
628
+        const float fade_scaling_factor = planner.fade_scaling_factor_for_z(ltarget[Z_AXIS]);
629
+      #else
630
+        constexpr float fade_scaling_factor = 1.0;
633 631
       #endif
634 632
 
635 633
       // increment to first segment destination
@@ -661,7 +659,7 @@
661 659
               z_x0y1 = z_values[cell_xi  ][cell_yi+1],  // z at lower right corner
662 660
               z_x1y1 = z_values[cell_xi+1][cell_yi+1];  // z at upper right corner
663 661
 
664
-        if (isnan(z_x0y0)) z_x0y0 = 0;              // ideally activating state.active (G29 A)
662
+        if (isnan(z_x0y0)) z_x0y0 = 0;              // ideally activating planner.leveling_active (G29 A)
665 663
         if (isnan(z_x1y0)) z_x1y0 = 0;              //   should refuse if any invalid mesh points
666 664
         if (isnan(z_x0y1)) z_x0y1 = 0;              //   in order to avoid isnan tests per cell,
667 665
         if (isnan(z_x1y1)) z_x1y1 = 0;              //   thus guessing zero for undefined points
@@ -690,11 +688,7 @@
690 688
 
691 689
         for(;;) {  // for all segments within this mesh cell
692 690
 
693
-          float z_cxcy = z_cxy0 + z_cxym * cy;      // interpolated mesh z height along cx at cy
694
-
695
-          #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
696
-            z_cxcy *= fade_scaling_factor;          // apply fade factor to interpolated mesh height
697
-          #endif
691
+          float z_cxcy = (z_cxy0 + z_cxym * cy) * fade_scaling_factor; // interpolated mesh z height along cx at cy, scaled for fade
698 692
 
699 693
           if (--segments == 0) {                    // if this is last segment, use ltarget for exact
700 694
             seg_rx = RAW_X_POSITION(ltarget[X_AXIS]);

+ 3
- 4
Marlin/ultralcd.cpp Näytä tiedosto

@@ -1089,7 +1089,7 @@ void kill_screen(const char* lcd_msg) {
1089 1089
           const float new_zoffset = zprobe_zoffset + planner.steps_to_mm[Z_AXIS] * babystep_increment;
1090 1090
           if (WITHIN(new_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) {
1091 1091
 
1092
-            if (planner.abl_enabled)
1092
+            if (planner.leveling_active)
1093 1093
               thermalManager.babystep_axis(Z_AXIS, babystep_increment);
1094 1094
 
1095 1095
             zprobe_zoffset = new_zoffset;
@@ -1791,7 +1791,7 @@ void kill_screen(const char* lcd_msg) {
1791 1791
 
1792 1792
             _lcd_after_probing();
1793 1793
 
1794
-            mbl.set_has_mesh(true);
1794
+            mbl.has_mesh = true;
1795 1795
             mesh_probing_done();
1796 1796
 
1797 1797
           #endif
@@ -1937,12 +1937,11 @@ void kill_screen(const char* lcd_msg) {
1937 1937
       if (!(axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS]))
1938 1938
         MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
1939 1939
       else if (leveling_is_valid()) {
1940
-        _level_state = LEVELING_IS_ACTIVE();
1940
+        _level_state = planner.leveling_active;
1941 1941
         MENU_ITEM_EDIT_CALLBACK(bool, MSG_BED_LEVELING, &_level_state, _lcd_toggle_bed_leveling);
1942 1942
       }
1943 1943
 
1944 1944
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1945
-        set_z_fade_height(planner.z_fade_height);
1946 1945
         MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_Z_FADE_HEIGHT, &planner.z_fade_height, 0.0, 100.0, _lcd_set_z_fade_height);
1947 1946
       #endif
1948 1947
 

+ 1
- 1
Marlin/ultralcd_impl_HD44780.h Näytä tiedosto

@@ -792,7 +792,7 @@ static void lcd_implementation_status_screen() {
792 792
     lcd.print(ftostr52sp(FIXFLOAT(current_position[Z_AXIS])));
793 793
 
794 794
     #if HAS_LEVELING
795
-      lcd.write(LEVELING_IS_ACTIVE() || blink ? '_' : ' ');
795
+      lcd.write(planner.leveling_active || blink ? '_' : ' ');
796 796
     #endif
797 797
 
798 798
   #endif // LCD_HEIGHT > 2

Loading…
Peruuta
Tallenna