Kaynağa Gözat

Use planner.leveling_active for all leveling systems

Scott Lahteine 7 yıl önce
ebeveyn
işleme
3e3911fb81

+ 2
- 2
Marlin/src/core/utility.cpp Dosyayı Görüntüle

@@ -333,7 +333,7 @@ void safe_delay(millis_t ms) {
333 333
       #elif ENABLED(AUTO_BED_LEVELING_UBL)
334 334
         SERIAL_ECHOPGM("UBL");
335 335
       #endif
336
-      if (LEVELING_IS_ACTIVE()) {
336
+      if (planner.leveling_active) {
337 337
         SERIAL_ECHOLNPGM(" (enabled)");
338 338
         #if ABL_PLANAR
339 339
           const float diff[XYZ] = {
@@ -364,7 +364,7 @@ void safe_delay(millis_t ms) {
364 364
     #elif ENABLED(MESH_BED_LEVELING)
365 365
 
366 366
       SERIAL_ECHOPGM("Mesh Bed Leveling");
367
-      if (LEVELING_IS_ACTIVE()) {
367
+      if (planner.leveling_active) {
368 368
         float lz = current_position[Z_AXIS];
369 369
         planner.apply_leveling(current_position[X_AXIS], current_position[Y_AXIS], lz);
370 370
         SERIAL_ECHOLNPGM(" (enabled)");

+ 11
- 13
Marlin/src/feature/bedlevel/bedlevel.cpp Dosyayı Görüntüle

@@ -44,7 +44,7 @@
44 44
 bool leveling_is_valid() {
45 45
   return
46 46
     #if ENABLED(MESH_BED_LEVELING)
47
-      mbl.has_mesh()
47
+      mbl.has_mesh
48 48
     #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
49 49
       !!bilinear_grid_spacing[X_AXIS]
50 50
     #elif ENABLED(AUTO_BED_LEVELING_UBL)
@@ -70,7 +70,7 @@ void set_bed_leveling_enabled(const bool enable/*=true*/) {
70 70
     constexpr bool can_change = true;
71 71
   #endif
72 72
 
73
-  if (can_change && enable != LEVELING_IS_ACTIVE()) {
73
+  if (can_change && enable != planner.leveling_active) {
74 74
 
75 75
     #if ENABLED(MESH_BED_LEVELING)
76 76
 
@@ -78,23 +78,23 @@ void set_bed_leveling_enabled(const bool enable/*=true*/) {
78 78
         planner.apply_leveling(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS]);
79 79
 
80 80
       const bool enabling = enable && leveling_is_valid();
81
-      mbl.set_active(enabling);
81
+      planner.leveling_active = enabling;
82 82
       if (enabling) planner.unapply_leveling(current_position);
83 83
 
84 84
     #elif ENABLED(AUTO_BED_LEVELING_UBL)
85 85
       #if PLANNER_LEVELING
86
-        if (ubl.state.active) {                       // leveling from on to off
86
+        if (planner.leveling_active) {                   // leveling from on to off
87 87
           // change unleveled current_position to physical current_position without moving steppers.
88 88
           planner.apply_leveling(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS]);
89
-          ubl.state.active = false;                   // disable only AFTER calling apply_leveling
89
+          planner.leveling_active = false;                   // disable only AFTER calling apply_leveling
90 90
         }
91 91
         else {                                        // leveling from off to on
92
-          ubl.state.active = true;                    // enable BEFORE calling unapply_leveling, otherwise ignored
92
+          planner.leveling_active = true;                    // enable BEFORE calling unapply_leveling, otherwise ignored
93 93
           // change physical current_position to unleveled current_position without moving steppers.
94 94
           planner.unapply_leveling(current_position);
95 95
         }
96 96
       #else
97
-        ubl.state.active = enable;                    // just flip the bit, current_position will be wrong until next move.
97
+        planner.leveling_active = enable;                    // just flip the bit, current_position will be wrong until next move.
98 98
       #endif
99 99
 
100 100
     #else // OLDSCHOOL_ABL
@@ -106,7 +106,7 @@ void set_bed_leveling_enabled(const bool enable/*=true*/) {
106 106
       #endif
107 107
 
108 108
       // Enable or disable leveling compensation in the planner
109
-      planner.abl_enabled = enable;
109
+      planner.leveling_active = enable;
110 110
 
111 111
       if (!enable)
112 112
         // When disabling just get the current position from the steppers.
@@ -131,15 +131,13 @@ void set_bed_leveling_enabled(const bool enable/*=true*/) {
131 131
 
132 132
   void set_z_fade_height(const float zfh) {
133 133
 
134
-    const bool level_active = LEVELING_IS_ACTIVE();
134
+    const bool level_active = planner.leveling_active;
135 135
 
136 136
     #if ENABLED(AUTO_BED_LEVELING_UBL)
137 137
       if (level_active) set_bed_leveling_enabled(false);  // turn off before changing fade height for proper apply/unapply leveling to maintain current_position
138 138
     #endif
139 139
 
140
-    planner.z_fade_height = zfh;
141
-    planner.inverse_z_fade_height = RECIPROCAL(zfh);
142
-    planner.force_fade_recalc();
140
+    planner.set_z_fade_height(zfh);
143 141
 
144 142
     if (level_active) {
145 143
       #if ENABLED(AUTO_BED_LEVELING_UBL)
@@ -166,7 +164,7 @@ void reset_bed_level() {
166 164
   #if ENABLED(MESH_BED_LEVELING)
167 165
     if (leveling_is_valid()) {
168 166
       mbl.reset();
169
-      mbl.set_has_mesh(false);
167
+      mbl.has_mesh = false;
170 168
     }
171 169
   #else
172 170
     #if ENABLED(DEBUG_LEVELING_FEATURE)

+ 0
- 10
Marlin/src/feature/bedlevel/bedlevel.h Dosyayı Görüntüle

@@ -43,16 +43,6 @@ bool leveling_is_valid();
43 43
 void set_bed_leveling_enabled(const bool enable=true);
44 44
 void reset_bed_level();
45 45
 
46
-#if ENABLED(MESH_BED_LEVELING)
47
-  #define LEVELING_IS_ACTIVE() (mbl.active())
48
-#elif ENABLED(AUTO_BED_LEVELING_UBL)
49
-  #define LEVELING_IS_ACTIVE() (ubl.state.active)
50
-#elif HAS_ABL
51
-  #define LEVELING_IS_ACTIVE() (planner.abl_enabled)
52
-#else
53
-  #define LEVELING_IS_ACTIVE() (false)
54
-#endif
55
-
56 46
 #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
57 47
   void set_z_fade_height(const float zfh);
58 48
 #endif

+ 2
- 2
Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp Dosyayı Görüntüle

@@ -31,7 +31,7 @@
31 31
 
32 32
   mesh_bed_leveling mbl;
33 33
 
34
-  uint8_t mesh_bed_leveling::status;
34
+  bool mesh_bed_leveling::has_mesh;
35 35
 
36 36
   float mesh_bed_leveling::z_offset,
37 37
         mesh_bed_leveling::z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y],
@@ -47,7 +47,7 @@
47 47
   }
48 48
 
49 49
   void mesh_bed_leveling::reset() {
50
-    status = MBL_STATUS_NONE;
50
+    has_mesh = false;
51 51
     z_offset = 0;
52 52
     ZERO(z_values);
53 53
   }

+ 1
- 12
Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.h Dosyayı Görüntüle

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

+ 2
- 2
Marlin/src/feature/bedlevel/ubl/ubl.cpp Dosyayı Görüntüle

@@ -51,7 +51,7 @@
51 51
   void unified_bed_leveling::report_state() {
52 52
     echo_name();
53 53
     SERIAL_PROTOCOLPGM(" System v" UBL_VERSION " ");
54
-    if (!state.active) SERIAL_PROTOCOLPGM("in");
54
+    if (!planner.leveling_active) SERIAL_PROTOCOLPGM("in");
55 55
     SERIAL_PROTOCOLLNPGM("active.");
56 56
     safe_delay(50);
57 57
   }
@@ -93,7 +93,7 @@
93 93
     set_bed_leveling_enabled(false);
94 94
     state.storage_slot = -1;
95 95
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
96
-      planner.z_fade_height = 10.0;
96
+      planner.set_z_fade_height(10.0);
97 97
     #endif
98 98
     ZERO(z_values);
99 99
     last_specified_z = -999.9;

+ 1
- 1
Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp Dosyayı Görüntüle

@@ -1170,7 +1170,7 @@
1170 1170
 
1171 1171
       return;
1172 1172
     }
1173
-    ubl_state_at_invocation = state.active;
1173
+    ubl_state_at_invocation = planner.leveling_active;
1174 1174
     set_bed_leveling_enabled(false);
1175 1175
   }
1176 1176
 

+ 10
- 22
Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp Dosyayı Görüntüle

@@ -257,9 +257,8 @@
257 257
          */
258 258
         const float x = inf_m_flag ? start[X_AXIS] : (next_mesh_line_y - c) / m;
259 259
 
260
-        float z0 = z_correction_for_x_on_horizontal_mesh_line(x, current_xi, current_yi);
261
-
262
-        z0 *= planner.fade_scaling_factor_for_z(end[Z_AXIS]);
260
+        float z0 = z_correction_for_x_on_horizontal_mesh_line(x, current_xi, current_yi)
261
+                   * planner.fade_scaling_factor_for_z(end[Z_AXIS]);
263 262
 
264 263
         /**
265 264
          * If part of the Mesh is undefined, it will show up as NAN
@@ -322,9 +321,8 @@
322 321
         const float next_mesh_line_x = LOGICAL_X_POSITION(mesh_index_to_xpos(current_xi)),
323 322
                     y = m * next_mesh_line_x + c;   // Calculate Y at the next X mesh line
324 323
 
325
-        float z0 = z_correction_for_y_on_vertical_mesh_line(y, current_xi, current_yi);
326
-
327
-        z0 *= planner.fade_scaling_factor_for_z(end[Z_AXIS]);
324
+        float z0 = z_correction_for_y_on_vertical_mesh_line(y, current_xi, current_yi)
325
+                   * planner.fade_scaling_factor_for_z(end[Z_AXIS]);
328 326
 
329 327
         /**
330 328
          * If part of the Mesh is undefined, it will show up as NAN
@@ -395,9 +393,8 @@
395 393
 
396 394
       if (left_flag == (x > next_mesh_line_x)) { // Check if we hit the Y line first
397 395
         // Yes!  Crossing a Y Mesh Line next
398
-        float z0 = z_correction_for_x_on_horizontal_mesh_line(x, current_xi - left_flag, current_yi + dyi);
399
-
400
-        z0 *= planner.fade_scaling_factor_for_z(end[Z_AXIS]);
396
+        float z0 = z_correction_for_x_on_horizontal_mesh_line(x, current_xi - left_flag, current_yi + dyi)
397
+                   * planner.fade_scaling_factor_for_z(end[Z_AXIS]);
401 398
 
402 399
         /**
403 400
          * If part of the Mesh is undefined, it will show up as NAN
@@ -423,9 +420,8 @@
423 420
       }
424 421
       else {
425 422
         // Yes!  Crossing a X Mesh Line next
426
-        float z0 = z_correction_for_y_on_vertical_mesh_line(y, current_xi + dxi, current_yi - down_flag);
427
-
428
-        z0 *= planner.fade_scaling_factor_for_z(end[Z_AXIS]);
423
+        float z0 = z_correction_for_y_on_vertical_mesh_line(y, current_xi + dxi, current_yi - down_flag)
424
+                   * planner.fade_scaling_factor_for_z(end[Z_AXIS]);
429 425
 
430 426
         /**
431 427
          * If part of the Mesh is undefined, it will show up as NAN
@@ -580,17 +576,9 @@
580 576
             seg_rz = RAW_Z_POSITION(current_position[Z_AXIS]),
581 577
             seg_le = current_position[E_AXIS];
582 578
 
583
-      const bool above_fade_height = (
584
-        #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
585
-          planner.z_fade_height != 0 && planner.z_fade_height < RAW_Z_POSITION(ltarget[Z_AXIS])
586
-        #else
587
-          false
588
-        #endif
589
-      );
590
-
591 579
       // Only compute leveling per segment if ubl active and target below z_fade_height.
592 580
 
593
-      if (!state.active || above_fade_height) {   // no mesh leveling
581
+      if (!planner.leveling_active || !planner.leveling_active_at_z(ltarget[Z_AXIS])) {   // no mesh leveling
594 582
 
595 583
         do {
596 584
 
@@ -648,7 +636,7 @@
648 636
               z_x0y1 = z_values[cell_xi  ][cell_yi+1],  // z at lower right corner
649 637
               z_x1y1 = z_values[cell_xi+1][cell_yi+1];  // z at upper right corner
650 638
 
651
-        if (isnan(z_x0y0)) z_x0y0 = 0;              // ideally activating state.active (G29 A)
639
+        if (isnan(z_x0y0)) z_x0y0 = 0;              // ideally activating planner.leveling_active (G29 A)
652 640
         if (isnan(z_x1y0)) z_x1y0 = 0;              //   should refuse if any invalid mesh points
653 641
         if (isnan(z_x0y1)) z_x0y1 = 0;              //   in order to avoid isnan tests per cell,
654 642
         if (isnan(z_x1y1)) z_x1y1 = 0;              //   thus guessing zero for undefined points

+ 2
- 3
Marlin/src/gcode/bedlevel/M420.cpp Dosyayı Görüntüle

@@ -105,14 +105,13 @@ void GcodeSuite::M420() {
105 105
   }
106 106
 
107 107
   const bool to_enable = parser.boolval('S');
108
-  if (parser.seen('S'))
109
-    set_bed_leveling_enabled(to_enable);
108
+  if (parser.seen('S')) set_bed_leveling_enabled(to_enable);
110 109
 
111 110
   #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
112 111
     if (parser.seen('Z')) set_z_fade_height(parser.value_linear_units());
113 112
   #endif
114 113
 
115
-  const bool new_status = LEVELING_IS_ACTIVE();
114
+  const bool new_status = planner.leveling_active;
116 115
 
117 116
   if (to_enable && !new_status) {
118 117
     SERIAL_ERROR_START();

+ 12
- 12
Marlin/src/gcode/bedlevel/abl/G29.cpp Dosyayı Görüntüle

@@ -247,7 +247,7 @@ void GcodeSuite::G29() {
247 247
       abl_probe_index = -1;
248 248
     #endif
249 249
 
250
-    abl_should_enable = LEVELING_IS_ACTIVE();
250
+    abl_should_enable = planner.leveling_active;
251 251
 
252 252
     #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
253 253
 
@@ -388,7 +388,7 @@ void GcodeSuite::G29() {
388 388
     stepper.synchronize();
389 389
 
390 390
     // Disable auto bed leveling during G29
391
-    planner.abl_enabled = false;
391
+    planner.leveling_active = false;
392 392
 
393 393
     if (!dryrun) {
394 394
       // Re-orient the current position without leveling
@@ -402,7 +402,7 @@ void GcodeSuite::G29() {
402 402
     #if HAS_BED_PROBE
403 403
       // Deploy the probe. Probe will raise if needed.
404 404
       if (DEPLOY_PROBE()) {
405
-        planner.abl_enabled = abl_should_enable;
405
+        planner.leveling_active = abl_should_enable;
406 406
         return;
407 407
       }
408 408
     #endif
@@ -421,7 +421,7 @@ void GcodeSuite::G29() {
421 421
       ) {
422 422
         if (dryrun) {
423 423
           // Before reset bed level, re-enable to correct the position
424
-          planner.abl_enabled = abl_should_enable;
424
+          planner.leveling_active = abl_should_enable;
425 425
         }
426 426
         // Reset grid to 0.0 or "not probed". (Also disables ABL)
427 427
         reset_bed_level();
@@ -466,7 +466,7 @@ void GcodeSuite::G29() {
466 466
       #if HAS_SOFTWARE_ENDSTOPS
467 467
         soft_endstops_enabled = enable_soft_endstops;
468 468
       #endif
469
-      planner.abl_enabled = abl_should_enable;
469
+      planner.leveling_active = abl_should_enable;
470 470
       g29_in_progress = false;
471 471
       #if ENABLED(LCD_BED_LEVELING)
472 472
         lcd_wait_for_move = false;
@@ -669,7 +669,7 @@ void GcodeSuite::G29() {
669 669
           measured_z = faux ? 0.001 * random(-100, 101) : probe_pt(xProbe, yProbe, stow_probe_after_each, verbose_level);
670 670
 
671 671
           if (isnan(measured_z)) {
672
-            planner.abl_enabled = abl_should_enable;
672
+            planner.leveling_active = abl_should_enable;
673 673
             break;
674 674
           }
675 675
 
@@ -705,7 +705,7 @@ void GcodeSuite::G29() {
705 705
         yProbe = LOGICAL_Y_POSITION(points[i].y);
706 706
         measured_z = faux ? 0.001 * random(-100, 101) : probe_pt(xProbe, yProbe, stow_probe_after_each, verbose_level);
707 707
         if (isnan(measured_z)) {
708
-          planner.abl_enabled = abl_should_enable;
708
+          planner.leveling_active = abl_should_enable;
709 709
           break;
710 710
         }
711 711
         points[i].z = measured_z;
@@ -728,7 +728,7 @@ void GcodeSuite::G29() {
728 728
 
729 729
     // Raise to _Z_CLEARANCE_DEPLOY_PROBE. Stow the probe.
730 730
     if (STOW_PROBE()) {
731
-      planner.abl_enabled = abl_should_enable;
731
+      planner.leveling_active = abl_should_enable;
732 732
       measured_z = NAN;
733 733
     }
734 734
   }
@@ -896,9 +896,9 @@ void GcodeSuite::G29() {
896 896
         float converted[XYZ];
897 897
         COPY(converted, current_position);
898 898
 
899
-        planner.abl_enabled = true;
899
+        planner.leveling_active = true;
900 900
         planner.unapply_leveling(converted); // use conversion machinery
901
-        planner.abl_enabled = false;
901
+        planner.leveling_active = false;
902 902
 
903 903
         // Use the last measured distance to the bed, if possible
904 904
         if ( NEAR(current_position[X_AXIS], xProbe - (X_PROBE_OFFSET_FROM_EXTRUDER))
@@ -950,7 +950,7 @@ void GcodeSuite::G29() {
950 950
     #endif
951 951
 
952 952
     // Auto Bed Leveling is complete! Enable if possible.
953
-    planner.abl_enabled = dryrun ? abl_should_enable : true;
953
+    planner.leveling_active = dryrun ? abl_should_enable : true;
954 954
   } // !isnan(measured_z)
955 955
 
956 956
   // Restore state after probing
@@ -964,7 +964,7 @@ void GcodeSuite::G29() {
964 964
 
965 965
   KEEPALIVE_STATE(IN_HANDLER);
966 966
 
967
-  if (LEVELING_IS_ACTIVE())
967
+  if (planner.leveling_active)
968 968
     SYNC_PLAN_POSITION_KINEMATIC();
969 969
 }
970 970
 

+ 2
- 2
Marlin/src/gcode/bedlevel/mbl/G29.cpp Dosyayı Görüntüle

@@ -42,7 +42,7 @@
42 42
 void echo_not_entered() { SERIAL_PROTOCOLLNPGM(" not entered."); }
43 43
 
44 44
 void mesh_probing_done() {
45
-  mbl.set_has_mesh(true);
45
+  mbl.has_mesh = true;
46 46
   gcode.home_all_axes();
47 47
   set_bed_leveling_enabled(true);
48 48
   #if ENABLED(MESH_G28_REST_ORIGIN)
@@ -92,7 +92,7 @@ void GcodeSuite::G29() {
92 92
   switch (state) {
93 93
     case MeshReport:
94 94
       if (leveling_is_valid()) {
95
-        SERIAL_PROTOCOLLNPAIR("State: ", LEVELING_IS_ACTIVE() ? MSG_ON : MSG_OFF);
95
+        SERIAL_PROTOCOLLNPAIR("State: ", planner.leveling_active ? MSG_ON : MSG_OFF);
96 96
         mbl_mesh_report();
97 97
       }
98 98
       else

+ 1
- 1
Marlin/src/gcode/calibrate/G28.cpp Dosyayı Görüntüle

@@ -157,7 +157,7 @@ void GcodeSuite::G28(const bool always_home_all) {
157 157
   // Disable the leveling matrix before homing
158 158
   #if HAS_LEVELING
159 159
     #if ENABLED(AUTO_BED_LEVELING_UBL)
160
-      const bool ubl_state_at_entry = LEVELING_IS_ACTIVE();
160
+      const bool ubl_state_at_entry = planner.leveling_active;
161 161
     #endif
162 162
     set_bed_leveling_enabled(false);
163 163
   #endif

+ 1
- 1
Marlin/src/gcode/calibrate/M48.cpp Dosyayı Görüntüle

@@ -119,7 +119,7 @@ void GcodeSuite::M48() {
119 119
   // Disable bed level correction in M48 because we want the raw data when we probe
120 120
 
121 121
   #if HAS_LEVELING
122
-    const bool was_enabled = LEVELING_IS_ACTIVE();
122
+    const bool was_enabled = planner.leveling_active;
123 123
     set_bed_leveling_enabled(false);
124 124
   #endif
125 125
 

+ 4
- 4
Marlin/src/lcd/ultralcd.cpp Dosyayı Görüntüle

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

+ 1
- 1
Marlin/src/lcd/ultralcd_impl_HD44780.h Dosyayı Görüntüle

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

+ 17
- 13
Marlin/src/module/configuration_store.cpp Dosyayı Görüntüle

@@ -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:                           2 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
@@ -202,6 +202,10 @@ MarlinSettings settings;
202 202
   #include "../feature/fwretract.h"
203 203
 #endif
204 204
 
205
+#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
206
+  float new_z_fade_height;
207
+#endif
208
+
205 209
 /**
206 210
  * Post-process after Retrieve or Reset
207 211
  */
@@ -231,7 +235,7 @@ void MarlinSettings::postprocess() {
231 235
   #endif
232 236
 
233 237
   #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
234
-    set_z_fade_height(planner.z_fade_height);
238
+    set_z_fade_height(new_z_fade_height);
235 239
   #endif
236 240
 
237 241
   #if HAS_BED_PROBE
@@ -329,7 +333,7 @@ void MarlinSettings::postprocess() {
329 333
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
330 334
       const float zfh = planner.z_fade_height;
331 335
     #else
332
-      const float zfh = 10.0;
336
+      const float zfh = 0.0;
333 337
     #endif
334 338
     EEPROM_WRITE(zfh);
335 339
 
@@ -343,7 +347,7 @@ void MarlinSettings::postprocess() {
343 347
         sizeof(mbl.z_values) == GRID_MAX_POINTS * sizeof(mbl.z_values[0][0]),
344 348
         "MBL Z array is the wrong size."
345 349
       );
346
-      const bool leveling_is_on = TEST(mbl.status, MBL_STATUS_HAS_MESH_BIT);
350
+      const bool leveling_is_on = mbl.has_mesh;
347 351
       const uint8_t mesh_num_x = GRID_MAX_POINTS_X, mesh_num_y = GRID_MAX_POINTS_Y;
348 352
       EEPROM_WRITE(leveling_is_on);
349 353
       EEPROM_WRITE(mbl.z_offset);
@@ -406,7 +410,7 @@ void MarlinSettings::postprocess() {
406 410
     #endif // AUTO_BED_LEVELING_BILINEAR
407 411
 
408 412
     #if ENABLED(AUTO_BED_LEVELING_UBL)
409
-      EEPROM_WRITE(ubl.state.active);
413
+      EEPROM_WRITE(planner.leveling_active);
410 414
       EEPROM_WRITE(ubl.state.storage_slot);
411 415
     #else
412 416
       const bool ubl_active = false;
@@ -720,7 +724,7 @@ void MarlinSettings::postprocess() {
720 724
       //
721 725
 
722 726
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
723
-        EEPROM_READ(planner.z_fade_height);
727
+        EEPROM_READ(new_z_fade_height);
724 728
       #else
725 729
         EEPROM_READ(dummy);
726 730
       #endif
@@ -737,7 +741,7 @@ void MarlinSettings::postprocess() {
737 741
       EEPROM_READ(mesh_num_y);
738 742
 
739 743
       #if ENABLED(MESH_BED_LEVELING)
740
-        mbl.status = leveling_is_on ? _BV(MBL_STATUS_HAS_MESH_BIT) : 0;
744
+        mbl.has_mesh = leveling_is_on;
741 745
         mbl.z_offset = dummy;
742 746
         if (mesh_num_x == GRID_MAX_POINTS_X && mesh_num_y == GRID_MAX_POINTS_Y) {
743 747
           // EEPROM data fits the current mesh
@@ -793,7 +797,7 @@ void MarlinSettings::postprocess() {
793 797
         }
794 798
 
795 799
       #if ENABLED(AUTO_BED_LEVELING_UBL)
796
-        EEPROM_READ(ubl.state.active);
800
+        EEPROM_READ(planner.leveling_active);
797 801
         EEPROM_READ(ubl.state.storage_slot);
798 802
       #else
799 803
         uint8_t dummyui8;
@@ -1156,7 +1160,7 @@ void MarlinSettings::reset() {
1156 1160
   planner.max_jerk[E_AXIS] = DEFAULT_EJERK;
1157 1161
 
1158 1162
   #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1159
-    planner.z_fade_height = 0.0;
1163
+    new_z_fade_height = 0.0;
1160 1164
   #endif
1161 1165
 
1162 1166
   #if HAS_HOME_OFFSET
@@ -1556,9 +1560,9 @@ void MarlinSettings::reset() {
1556 1560
         SERIAL_ECHOLNPGM(":");
1557 1561
       }
1558 1562
       CONFIG_ECHO_START;
1559
-      SERIAL_ECHOPAIR("  M420 S", LEVELING_IS_ACTIVE() ? 1 : 0);
1563
+      SERIAL_ECHOPAIR("  M420 S", planner.leveling_active ? 1 : 0);
1560 1564
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1561
-        SERIAL_ECHOPAIR(" Z", planner.z_fade_height);
1565
+        SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(planner.z_fade_height));
1562 1566
       #endif
1563 1567
       SERIAL_EOL();
1564 1568
 
@@ -1578,7 +1582,7 @@ void MarlinSettings::reset() {
1578 1582
         SERIAL_ECHOLNPGM("Auto Bed Leveling:");
1579 1583
       }
1580 1584
       CONFIG_ECHO_START;
1581
-      SERIAL_ECHOPAIR("  M420 S", LEVELING_IS_ACTIVE() ? 1 : 0);
1585
+      SERIAL_ECHOPAIR("  M420 S", planner.leveling_active ? 1 : 0);
1582 1586
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1583 1587
         SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(planner.z_fade_height));
1584 1588
       #endif

+ 22
- 31
Marlin/src/module/motion.cpp Dosyayı Görüntüle

@@ -490,14 +490,14 @@ float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS },
490 490
   #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
491 491
     #if ENABLED(DELTA)
492 492
       #define ADJUST_DELTA(V) \
493
-        if (LEVELING_IS_ACTIVE()) { \
493
+        if (planner.leveling_active) { \
494 494
           const float zadj = bilinear_z_offset(V); \
495 495
           delta[A_AXIS] += zadj; \
496 496
           delta[B_AXIS] += zadj; \
497 497
           delta[C_AXIS] += zadj; \
498 498
         }
499 499
     #else
500
-      #define ADJUST_DELTA(V) if (LEVELING_IS_ACTIVE()) { delta[Z_AXIS] += bilinear_z_offset(V); }
500
+      #define ADJUST_DELTA(V) if (planner.leveling_active) { delta[Z_AXIS] += bilinear_z_offset(V); }
501 501
     #endif
502 502
   #else
503 503
     #define ADJUST_DELTA(V) NOOP
@@ -630,41 +630,30 @@ float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS },
630 630
 
631 631
   /**
632 632
    * Prepare a linear move in a Cartesian setup.
633
-   * If Mesh Bed Leveling is enabled, perform a mesh move.
633
+   * Bed Leveling will be applied to the move if enabled.
634 634
    *
635
-   * Returns true if the caller didn't update current_position.
635
+   * Returns true if current_position[] was set to destination[]
636 636
    */
637 637
   inline bool prepare_move_to_destination_cartesian() {
638
-    #if ENABLED(AUTO_BED_LEVELING_UBL)
638
+    if (current_position[X_AXIS] != destination[X_AXIS] || current_position[Y_AXIS] != destination[Y_AXIS]) {
639 639
       const float fr_scaled = MMS_SCALED(feedrate_mm_s);
640
-      if (ubl.state.active) { // direct use of ubl.state.active for speed
641
-        ubl.line_to_destination_cartesian(fr_scaled, active_extruder);
642
-        return true;
643
-      }
644
-      else
645
-        line_to_destination(fr_scaled);
646
-    #else
647
-      // Do not use feedrate_percentage for E or Z only moves
648
-      if (current_position[X_AXIS] == destination[X_AXIS] && current_position[Y_AXIS] == destination[Y_AXIS])
649
-        line_to_destination();
650
-      else {
651
-        const float fr_scaled = MMS_SCALED(feedrate_mm_s);
652
-        #if ENABLED(MESH_BED_LEVELING)
653
-          if (mbl.active()) { // direct used of mbl.active() for speed
640
+      #if HAS_MESH
641
+        if (planner.leveling_active) {
642
+          #if ENABLED(AUTO_BED_LEVELING_UBL)
643
+            ubl.line_to_destination_cartesian(fr_scaled, active_extruder);
644
+          #elif ENABLED(MESH_BED_LEVELING)
654 645
             mesh_line_to_destination(fr_scaled);
655
-            return true;
656
-          }
657
-          else
658
-        #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
659
-          if (planner.abl_enabled) { // direct use of abl_enabled for speed
646
+          #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
660 647
             bilinear_line_to_destination(fr_scaled);
661
-            return true;
662
-          }
663
-          else
664
-        #endif
665
-            line_to_destination(fr_scaled);
666
-      }
667
-    #endif
648
+          #endif
649
+          return true;
650
+        }
651
+      #endif // HAS_MESH
652
+      line_to_destination(fr_scaled);
653
+    }
654
+    else
655
+      line_to_destination();
656
+
668 657
     return false;
669 658
   }
670 659
 
@@ -699,6 +688,8 @@ float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS },
699 688
 
700 689
   /**
701 690
    * Prepare a linear move in a dual X axis setup
691
+   *
692
+   * Return true if current_position[] was set to destination[]
702 693
    */
703 694
   inline bool prepare_move_to_destination_dualx() {
704 695
     if (active_extruder_parked) {

+ 30
- 37
Marlin/src/module/planner.cpp Dosyayı Görüntüle

@@ -122,8 +122,8 @@ float Planner::min_feedrate_mm_s,
122 122
       Planner::max_jerk[XYZE],       // The largest speed change requiring no acceleration
123 123
       Planner::min_travel_feedrate_mm_s;
124 124
 
125
-#if OLDSCHOOL_ABL
126
-  bool Planner::abl_enabled = false; // Flag that auto bed leveling is enabled
125
+#if HAS_LEVELING
126
+  bool Planner::leveling_active = false; // Flag that auto bed leveling is enabled
127 127
   #if ABL_PLANAR
128 128
     matrix_3x3 Planner::bed_level_matrix; // Transform to compensate for bed level
129 129
   #endif
@@ -556,7 +556,7 @@ void Planner::calculate_volumetric_multipliers() {
556 556
    */
557 557
   void Planner::apply_leveling(float &lx, float &ly, float &lz) {
558 558
 
559
-    if (!LEVELING_IS_ACTIVE()) return;
559
+    if (!planner.leveling_active) return;
560 560
 
561 561
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
562 562
       const float fade_scaling_factor = fade_scaling_factor_for_z(lz);
@@ -601,48 +601,41 @@ void Planner::calculate_volumetric_multipliers() {
601 601
 
602 602
   void Planner::unapply_leveling(float logical[XYZ]) {
603 603
 
604
-    #if ENABLED(AUTO_BED_LEVELING_UBL)
605
-
606
-      if (ubl.state.active) {
607
-
608
-        const float z_physical = RAW_Z_POSITION(logical[Z_AXIS]),
609
-                    z_correct = ubl.get_z_correction(logical[X_AXIS], logical[Y_AXIS]),
610
-                    z_virtual = z_physical - z_correct;
611
-              float z_logical = LOGICAL_Z_POSITION(z_virtual);
612
-
613
-        #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
614
-
615
-          // for P=physical_z, L=logical_z, M=mesh_z, H=fade_height,
616
-          // Given P=L+M(1-L/H) (faded mesh correction formula for L<H)
617
-          //  then L=P-M(1-L/H)
618
-          //    so L=P-M+ML/H
619
-          //    so L-ML/H=P-M
620
-          //    so L(1-M/H)=P-M
621
-          //    so L=(P-M)/(1-M/H) for L<H
604
+    if (!planner.leveling_active) return;
622 605
 
623
-          if (planner.z_fade_height) {
624
-            if (z_logical >= planner.z_fade_height)
625
-              z_logical = LOGICAL_Z_POSITION(z_physical);
626
-            else
627
-              z_logical /= 1.0 - z_correct * planner.inverse_z_fade_height;
628
-          }
606
+    #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
607
+      if (z_fade_height && RAW_Z_POSITION(logical[Z_AXIS]) >= z_fade_height) return;
608
+    #endif
629 609
 
630
-        #endif // ENABLE_LEVELING_FADE_HEIGHT
610
+    #if ENABLED(AUTO_BED_LEVELING_UBL)
631 611
 
632
-        logical[Z_AXIS] = z_logical;
633
-      }
612
+      const float z_physical = RAW_Z_POSITION(logical[Z_AXIS]),
613
+                  z_correct = ubl.get_z_correction(logical[X_AXIS], logical[Y_AXIS]),
614
+                  z_virtual = z_physical - z_correct;
615
+            float z_logical = LOGICAL_Z_POSITION(z_virtual);
634 616
 
635
-      return; // don't fall thru to other ENABLE_LEVELING_FADE_HEIGHT logic
617
+      #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
636 618
 
637
-    #endif
619
+        // for P=physical_z, L=logical_z, M=mesh_z, H=fade_height,
620
+        // Given P=L+M(1-L/H) (faded mesh correction formula for L<H)
621
+        //  then L=P-M(1-L/H)
622
+        //    so L=P-M+ML/H
623
+        //    so L-ML/H=P-M
624
+        //    so L(1-M/H)=P-M
625
+        //    so L=(P-M)/(1-M/H) for L<H
626
+
627
+        if (planner.z_fade_height) {
628
+          if (z_logical >= planner.z_fade_height)
629
+            z_logical = LOGICAL_Z_POSITION(z_physical);
630
+          else
631
+            z_logical /= 1.0 - z_correct * planner.inverse_z_fade_height;
632
+        }
638 633
 
639
-    if (!LEVELING_IS_ACTIVE()) return;
634
+      #endif // ENABLE_LEVELING_FADE_HEIGHT
640 635
 
641
-    #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
642
-      if (z_fade_height && RAW_Z_POSITION(logical[Z_AXIS]) >= z_fade_height) return;
643
-    #endif
636
+      logical[Z_AXIS] = z_logical;
644 637
 
645
-    #if ENABLED(MESH_BED_LEVELING)
638
+    #elif ENABLED(MESH_BED_LEVELING)
646 639
 
647 640
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
648 641
         const float c = mbl.get_z(RAW_X_POSITION(logical[X_AXIS]), RAW_Y_POSITION(logical[Y_AXIS]), 1.0);

+ 17
- 6
Marlin/src/module/planner.h Dosyayı Görüntüle

@@ -164,15 +164,14 @@ class Planner {
164 164
                  max_jerk[XYZE],       // The largest speed change requiring no acceleration
165 165
                  min_travel_feedrate_mm_s;
166 166
 
167
-    #if OLDSCHOOL_ABL
168
-      static bool abl_enabled;              // Flag that bed leveling is enabled
167
+    #if HAS_LEVELING
168
+      static bool leveling_active;              // Flag that bed leveling is enabled
169 169
       #if ABL_PLANAR
170 170
         static matrix_3x3 bed_level_matrix; // Transform to compensate for bed level
171 171
       #endif
172
-    #endif
173
-
174
-    #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
175
-      static float z_fade_height, inverse_z_fade_height;
172
+      #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
173
+        static float z_fade_height, inverse_z_fade_height;
174
+      #endif
176 175
     #endif
177 176
 
178 177
     #if ENABLED(LIN_ADVANCE)
@@ -292,6 +291,16 @@ class Planner {
292 291
 
293 292
       FORCE_INLINE static void force_fade_recalc() { last_raw_lz = -999.999; }
294 293
 
294
+      FORCE_INLINE static void set_z_fade_height(const float &zfh) {
295
+        z_fade_height = zfh > 0 ? zfh : 0;
296
+        inverse_z_fade_height = RECIPROCAL(z_fade_height);
297
+        force_fade_recalc();
298
+      }
299
+
300
+      FORCE_INLINE static bool leveling_active_at_z(const float &lz) {
301
+        return !z_fade_height || RAW_Z_POSITION(lz) < z_fade_height;
302
+      }
303
+
295 304
     #else
296 305
 
297 306
       FORCE_INLINE static float fade_scaling_factor_for_z(const float &lz) {
@@ -299,6 +308,8 @@ class Planner {
299 308
         return 1.0;
300 309
       }
301 310
 
311
+      FORCE_INLINE static bool leveling_active_at_z(const float &lz) { return true; }
312
+
302 313
     #endif
303 314
 
304 315
     #if PLANNER_LEVELING

+ 1
- 1
Marlin/src/module/probe.cpp Dosyayı Görüntüle

@@ -679,7 +679,7 @@ void refresh_zprobe_zoffset(const bool no_babystep/*=false*/) {
679 679
     #endif
680 680
 
681 681
     #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
682
-      if (!no_babystep && LEVELING_IS_ACTIVE())
682
+      if (!no_babystep && planner.leveling_active)
683 683
         thermalManager.babystep_axis(Z_AXIS, -LROUND(diff * planner.axis_steps_per_mm[Z_AXIS]));
684 684
     #else
685 685
       UNUSED(no_babystep);

+ 1
- 1
Marlin/src/module/tool_change.cpp Dosyayı Görüntüle

@@ -464,7 +464,7 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
464 464
 
465 465
             #if ENABLED(MESH_BED_LEVELING)
466 466
 
467
-              if (LEVELING_IS_ACTIVE()) {
467
+              if (planner.leveling_active) {
468 468
                 #if ENABLED(DEBUG_LEVELING_FEATURE)
469 469
                   if (DEBUGGING(LEVELING)) SERIAL_ECHOPAIR("Z before MBL: ", current_position[Z_AXIS]);
470 470
                 #endif

Loading…
İptal
Kaydet