Преглед изворни кода

Use planner.leveling_active for all leveling systems

Scott Lahteine пре 7 година
родитељ
комит
3e3911fb81

+ 2
- 2
Marlin/src/core/utility.cpp Прегледај датотеку

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

+ 11
- 13
Marlin/src/feature/bedlevel/bedlevel.cpp Прегледај датотеку

44
 bool leveling_is_valid() {
44
 bool leveling_is_valid() {
45
   return
45
   return
46
     #if ENABLED(MESH_BED_LEVELING)
46
     #if ENABLED(MESH_BED_LEVELING)
47
-      mbl.has_mesh()
47
+      mbl.has_mesh
48
     #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
48
     #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
49
       !!bilinear_grid_spacing[X_AXIS]
49
       !!bilinear_grid_spacing[X_AXIS]
50
     #elif ENABLED(AUTO_BED_LEVELING_UBL)
50
     #elif ENABLED(AUTO_BED_LEVELING_UBL)
70
     constexpr bool can_change = true;
70
     constexpr bool can_change = true;
71
   #endif
71
   #endif
72
 
72
 
73
-  if (can_change && enable != LEVELING_IS_ACTIVE()) {
73
+  if (can_change && enable != planner.leveling_active) {
74
 
74
 
75
     #if ENABLED(MESH_BED_LEVELING)
75
     #if ENABLED(MESH_BED_LEVELING)
76
 
76
 
78
         planner.apply_leveling(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS]);
78
         planner.apply_leveling(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS]);
79
 
79
 
80
       const bool enabling = enable && leveling_is_valid();
80
       const bool enabling = enable && leveling_is_valid();
81
-      mbl.set_active(enabling);
81
+      planner.leveling_active = enabling;
82
       if (enabling) planner.unapply_leveling(current_position);
82
       if (enabling) planner.unapply_leveling(current_position);
83
 
83
 
84
     #elif ENABLED(AUTO_BED_LEVELING_UBL)
84
     #elif ENABLED(AUTO_BED_LEVELING_UBL)
85
       #if PLANNER_LEVELING
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
           // change unleveled current_position to physical current_position without moving steppers.
87
           // change unleveled current_position to physical current_position without moving steppers.
88
           planner.apply_leveling(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS]);
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
         else {                                        // leveling from off to on
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
           // change physical current_position to unleveled current_position without moving steppers.
93
           // change physical current_position to unleveled current_position without moving steppers.
94
           planner.unapply_leveling(current_position);
94
           planner.unapply_leveling(current_position);
95
         }
95
         }
96
       #else
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
       #endif
98
       #endif
99
 
99
 
100
     #else // OLDSCHOOL_ABL
100
     #else // OLDSCHOOL_ABL
106
       #endif
106
       #endif
107
 
107
 
108
       // Enable or disable leveling compensation in the planner
108
       // Enable or disable leveling compensation in the planner
109
-      planner.abl_enabled = enable;
109
+      planner.leveling_active = enable;
110
 
110
 
111
       if (!enable)
111
       if (!enable)
112
         // When disabling just get the current position from the steppers.
112
         // When disabling just get the current position from the steppers.
131
 
131
 
132
   void set_z_fade_height(const float zfh) {
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
     #if ENABLED(AUTO_BED_LEVELING_UBL)
136
     #if ENABLED(AUTO_BED_LEVELING_UBL)
137
       if (level_active) set_bed_leveling_enabled(false);  // turn off before changing fade height for proper apply/unapply leveling to maintain current_position
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
     #endif
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
     if (level_active) {
142
     if (level_active) {
145
       #if ENABLED(AUTO_BED_LEVELING_UBL)
143
       #if ENABLED(AUTO_BED_LEVELING_UBL)
166
   #if ENABLED(MESH_BED_LEVELING)
164
   #if ENABLED(MESH_BED_LEVELING)
167
     if (leveling_is_valid()) {
165
     if (leveling_is_valid()) {
168
       mbl.reset();
166
       mbl.reset();
169
-      mbl.set_has_mesh(false);
167
+      mbl.has_mesh = false;
170
     }
168
     }
171
   #else
169
   #else
172
     #if ENABLED(DEBUG_LEVELING_FEATURE)
170
     #if ENABLED(DEBUG_LEVELING_FEATURE)

+ 0
- 10
Marlin/src/feature/bedlevel/bedlevel.h Прегледај датотеку

43
 void set_bed_leveling_enabled(const bool enable=true);
43
 void set_bed_leveling_enabled(const bool enable=true);
44
 void reset_bed_level();
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
 #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
46
 #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
57
   void set_z_fade_height(const float zfh);
47
   void set_z_fade_height(const float zfh);
58
 #endif
48
 #endif

+ 2
- 2
Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp Прегледај датотеку

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

+ 1
- 12
Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.h Прегледај датотеку

34
   MeshReset
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
 #define MESH_X_DIST ((MESH_MAX_X - (MESH_MIN_X)) / (GRID_MAX_POINTS_X - 1))
37
 #define MESH_X_DIST ((MESH_MAX_X - (MESH_MIN_X)) / (GRID_MAX_POINTS_X - 1))
44
 #define MESH_Y_DIST ((MESH_MAX_Y - (MESH_MIN_Y)) / (GRID_MAX_POINTS_Y - 1))
38
 #define MESH_Y_DIST ((MESH_MAX_Y - (MESH_MIN_Y)) / (GRID_MAX_POINTS_Y - 1))
45
 
39
 
46
 class mesh_bed_leveling {
40
 class mesh_bed_leveling {
47
 public:
41
 public:
48
-  static uint8_t status; // Has Mesh and Is Active bits
42
+  static bool has_mesh;
49
   static float z_offset,
43
   static float z_offset,
50
                z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y],
44
                z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y],
51
                index_to_xpos[GRID_MAX_POINTS_X],
45
                index_to_xpos[GRID_MAX_POINTS_X],
57
 
51
 
58
   static void set_z(const int8_t px, const int8_t py, const float &z) { z_values[px][py] = z; }
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
   static inline void zigzag(const int8_t index, int8_t &px, int8_t &py) {
54
   static inline void zigzag(const int8_t index, int8_t &px, int8_t &py) {
66
     px = index % (GRID_MAX_POINTS_X);
55
     px = index % (GRID_MAX_POINTS_X);
67
     py = index / (GRID_MAX_POINTS_X);
56
     py = index / (GRID_MAX_POINTS_X);

+ 2
- 2
Marlin/src/feature/bedlevel/ubl/ubl.cpp Прегледај датотеку

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

+ 1
- 1
Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp Прегледај датотеку

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

+ 10
- 22
Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp Прегледај датотеку

257
          */
257
          */
258
         const float x = inf_m_flag ? start[X_AXIS] : (next_mesh_line_y - c) / m;
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
          * If part of the Mesh is undefined, it will show up as NAN
264
          * If part of the Mesh is undefined, it will show up as NAN
322
         const float next_mesh_line_x = LOGICAL_X_POSITION(mesh_index_to_xpos(current_xi)),
321
         const float next_mesh_line_x = LOGICAL_X_POSITION(mesh_index_to_xpos(current_xi)),
323
                     y = m * next_mesh_line_x + c;   // Calculate Y at the next X mesh line
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
          * If part of the Mesh is undefined, it will show up as NAN
328
          * If part of the Mesh is undefined, it will show up as NAN
395
 
393
 
396
       if (left_flag == (x > next_mesh_line_x)) { // Check if we hit the Y line first
394
       if (left_flag == (x > next_mesh_line_x)) { // Check if we hit the Y line first
397
         // Yes!  Crossing a Y Mesh Line next
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
          * If part of the Mesh is undefined, it will show up as NAN
400
          * If part of the Mesh is undefined, it will show up as NAN
423
       }
420
       }
424
       else {
421
       else {
425
         // Yes!  Crossing a X Mesh Line next
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
          * If part of the Mesh is undefined, it will show up as NAN
427
          * If part of the Mesh is undefined, it will show up as NAN
580
             seg_rz = RAW_Z_POSITION(current_position[Z_AXIS]),
576
             seg_rz = RAW_Z_POSITION(current_position[Z_AXIS]),
581
             seg_le = current_position[E_AXIS];
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
       // Only compute leveling per segment if ubl active and target below z_fade_height.
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
         do {
583
         do {
596
 
584
 
648
               z_x0y1 = z_values[cell_xi  ][cell_yi+1],  // z at lower right corner
636
               z_x0y1 = z_values[cell_xi  ][cell_yi+1],  // z at lower right corner
649
               z_x1y1 = z_values[cell_xi+1][cell_yi+1];  // z at upper right corner
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
         if (isnan(z_x1y0)) z_x1y0 = 0;              //   should refuse if any invalid mesh points
640
         if (isnan(z_x1y0)) z_x1y0 = 0;              //   should refuse if any invalid mesh points
653
         if (isnan(z_x0y1)) z_x0y1 = 0;              //   in order to avoid isnan tests per cell,
641
         if (isnan(z_x0y1)) z_x0y1 = 0;              //   in order to avoid isnan tests per cell,
654
         if (isnan(z_x1y1)) z_x1y1 = 0;              //   thus guessing zero for undefined points
642
         if (isnan(z_x1y1)) z_x1y1 = 0;              //   thus guessing zero for undefined points

+ 2
- 3
Marlin/src/gcode/bedlevel/M420.cpp Прегледај датотеку

105
   }
105
   }
106
 
106
 
107
   const bool to_enable = parser.boolval('S');
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
   #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
110
   #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
112
     if (parser.seen('Z')) set_z_fade_height(parser.value_linear_units());
111
     if (parser.seen('Z')) set_z_fade_height(parser.value_linear_units());
113
   #endif
112
   #endif
114
 
113
 
115
-  const bool new_status = LEVELING_IS_ACTIVE();
114
+  const bool new_status = planner.leveling_active;
116
 
115
 
117
   if (to_enable && !new_status) {
116
   if (to_enable && !new_status) {
118
     SERIAL_ERROR_START();
117
     SERIAL_ERROR_START();

+ 12
- 12
Marlin/src/gcode/bedlevel/abl/G29.cpp Прегледај датотеку

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

+ 2
- 2
Marlin/src/gcode/bedlevel/mbl/G29.cpp Прегледај датотеку

42
 void echo_not_entered() { SERIAL_PROTOCOLLNPGM(" not entered."); }
42
 void echo_not_entered() { SERIAL_PROTOCOLLNPGM(" not entered."); }
43
 
43
 
44
 void mesh_probing_done() {
44
 void mesh_probing_done() {
45
-  mbl.set_has_mesh(true);
45
+  mbl.has_mesh = true;
46
   gcode.home_all_axes();
46
   gcode.home_all_axes();
47
   set_bed_leveling_enabled(true);
47
   set_bed_leveling_enabled(true);
48
   #if ENABLED(MESH_G28_REST_ORIGIN)
48
   #if ENABLED(MESH_G28_REST_ORIGIN)
92
   switch (state) {
92
   switch (state) {
93
     case MeshReport:
93
     case MeshReport:
94
       if (leveling_is_valid()) {
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
         mbl_mesh_report();
96
         mbl_mesh_report();
97
       }
97
       }
98
       else
98
       else

+ 1
- 1
Marlin/src/gcode/calibrate/G28.cpp Прегледај датотеку

157
   // Disable the leveling matrix before homing
157
   // Disable the leveling matrix before homing
158
   #if HAS_LEVELING
158
   #if HAS_LEVELING
159
     #if ENABLED(AUTO_BED_LEVELING_UBL)
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
     #endif
161
     #endif
162
     set_bed_leveling_enabled(false);
162
     set_bed_leveling_enabled(false);
163
   #endif
163
   #endif

+ 1
- 1
Marlin/src/gcode/calibrate/M48.cpp Прегледај датотеку

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

+ 4
- 4
Marlin/src/lcd/ultralcd.cpp Прегледај датотеку

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

+ 1
- 1
Marlin/src/lcd/ultralcd_impl_HD44780.h Прегледај датотеку

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

+ 17
- 13
Marlin/src/module/configuration_store.cpp Прегледај датотеку

68
  *  219            z_fade_height                    (float)
68
  *  219            z_fade_height                    (float)
69
  *
69
  *
70
  * MESH_BED_LEVELING:                               43 bytes
70
  * MESH_BED_LEVELING:                               43 bytes
71
- *  223  M420 S    from mbl.status                  (bool)
71
+ *  223  M420 S    planner.leveling_active         (bool)
72
  *  224            mbl.z_offset                     (float)
72
  *  224            mbl.z_offset                     (float)
73
  *  228            GRID_MAX_POINTS_X                (uint8_t)
73
  *  228            GRID_MAX_POINTS_X                (uint8_t)
74
  *  229            GRID_MAX_POINTS_Y                (uint8_t)
74
  *  229            GRID_MAX_POINTS_Y                (uint8_t)
88
  *  316            z_values[][]                     (float x9, up to float x256) +988
88
  *  316            z_values[][]                     (float x9, up to float x256) +988
89
  *
89
  *
90
  * AUTO_BED_LEVELING_UBL:                           2 bytes
90
  * AUTO_BED_LEVELING_UBL:                           2 bytes
91
- *  324  G29 A     ubl.state.active                 (bool)
91
+ *  324  G29 A     planner.leveling_active          (bool)
92
  *  325  G29 S     ubl.state.storage_slot           (int8_t)
92
  *  325  G29 S     ubl.state.storage_slot           (int8_t)
93
  *
93
  *
94
  * DELTA:                                           48 bytes
94
  * DELTA:                                           48 bytes
202
   #include "../feature/fwretract.h"
202
   #include "../feature/fwretract.h"
203
 #endif
203
 #endif
204
 
204
 
205
+#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
206
+  float new_z_fade_height;
207
+#endif
208
+
205
 /**
209
 /**
206
  * Post-process after Retrieve or Reset
210
  * Post-process after Retrieve or Reset
207
  */
211
  */
231
   #endif
235
   #endif
232
 
236
 
233
   #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
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
   #endif
239
   #endif
236
 
240
 
237
   #if HAS_BED_PROBE
241
   #if HAS_BED_PROBE
329
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
333
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
330
       const float zfh = planner.z_fade_height;
334
       const float zfh = planner.z_fade_height;
331
     #else
335
     #else
332
-      const float zfh = 10.0;
336
+      const float zfh = 0.0;
333
     #endif
337
     #endif
334
     EEPROM_WRITE(zfh);
338
     EEPROM_WRITE(zfh);
335
 
339
 
343
         sizeof(mbl.z_values) == GRID_MAX_POINTS * sizeof(mbl.z_values[0][0]),
347
         sizeof(mbl.z_values) == GRID_MAX_POINTS * sizeof(mbl.z_values[0][0]),
344
         "MBL Z array is the wrong size."
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
       const uint8_t mesh_num_x = GRID_MAX_POINTS_X, mesh_num_y = GRID_MAX_POINTS_Y;
351
       const uint8_t mesh_num_x = GRID_MAX_POINTS_X, mesh_num_y = GRID_MAX_POINTS_Y;
348
       EEPROM_WRITE(leveling_is_on);
352
       EEPROM_WRITE(leveling_is_on);
349
       EEPROM_WRITE(mbl.z_offset);
353
       EEPROM_WRITE(mbl.z_offset);
406
     #endif // AUTO_BED_LEVELING_BILINEAR
410
     #endif // AUTO_BED_LEVELING_BILINEAR
407
 
411
 
408
     #if ENABLED(AUTO_BED_LEVELING_UBL)
412
     #if ENABLED(AUTO_BED_LEVELING_UBL)
409
-      EEPROM_WRITE(ubl.state.active);
413
+      EEPROM_WRITE(planner.leveling_active);
410
       EEPROM_WRITE(ubl.state.storage_slot);
414
       EEPROM_WRITE(ubl.state.storage_slot);
411
     #else
415
     #else
412
       const bool ubl_active = false;
416
       const bool ubl_active = false;
720
       //
724
       //
721
 
725
 
722
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
726
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
723
-        EEPROM_READ(planner.z_fade_height);
727
+        EEPROM_READ(new_z_fade_height);
724
       #else
728
       #else
725
         EEPROM_READ(dummy);
729
         EEPROM_READ(dummy);
726
       #endif
730
       #endif
737
       EEPROM_READ(mesh_num_y);
741
       EEPROM_READ(mesh_num_y);
738
 
742
 
739
       #if ENABLED(MESH_BED_LEVELING)
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
         mbl.z_offset = dummy;
745
         mbl.z_offset = dummy;
742
         if (mesh_num_x == GRID_MAX_POINTS_X && mesh_num_y == GRID_MAX_POINTS_Y) {
746
         if (mesh_num_x == GRID_MAX_POINTS_X && mesh_num_y == GRID_MAX_POINTS_Y) {
743
           // EEPROM data fits the current mesh
747
           // EEPROM data fits the current mesh
793
         }
797
         }
794
 
798
 
795
       #if ENABLED(AUTO_BED_LEVELING_UBL)
799
       #if ENABLED(AUTO_BED_LEVELING_UBL)
796
-        EEPROM_READ(ubl.state.active);
800
+        EEPROM_READ(planner.leveling_active);
797
         EEPROM_READ(ubl.state.storage_slot);
801
         EEPROM_READ(ubl.state.storage_slot);
798
       #else
802
       #else
799
         uint8_t dummyui8;
803
         uint8_t dummyui8;
1156
   planner.max_jerk[E_AXIS] = DEFAULT_EJERK;
1160
   planner.max_jerk[E_AXIS] = DEFAULT_EJERK;
1157
 
1161
 
1158
   #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1162
   #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1159
-    planner.z_fade_height = 0.0;
1163
+    new_z_fade_height = 0.0;
1160
   #endif
1164
   #endif
1161
 
1165
 
1162
   #if HAS_HOME_OFFSET
1166
   #if HAS_HOME_OFFSET
1556
         SERIAL_ECHOLNPGM(":");
1560
         SERIAL_ECHOLNPGM(":");
1557
       }
1561
       }
1558
       CONFIG_ECHO_START;
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
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
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
       #endif
1566
       #endif
1563
       SERIAL_EOL();
1567
       SERIAL_EOL();
1564
 
1568
 
1578
         SERIAL_ECHOLNPGM("Auto Bed Leveling:");
1582
         SERIAL_ECHOLNPGM("Auto Bed Leveling:");
1579
       }
1583
       }
1580
       CONFIG_ECHO_START;
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
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1586
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1583
         SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(planner.z_fade_height));
1587
         SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(planner.z_fade_height));
1584
       #endif
1588
       #endif

+ 22
- 31
Marlin/src/module/motion.cpp Прегледај датотеку

490
   #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
490
   #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
491
     #if ENABLED(DELTA)
491
     #if ENABLED(DELTA)
492
       #define ADJUST_DELTA(V) \
492
       #define ADJUST_DELTA(V) \
493
-        if (LEVELING_IS_ACTIVE()) { \
493
+        if (planner.leveling_active) { \
494
           const float zadj = bilinear_z_offset(V); \
494
           const float zadj = bilinear_z_offset(V); \
495
           delta[A_AXIS] += zadj; \
495
           delta[A_AXIS] += zadj; \
496
           delta[B_AXIS] += zadj; \
496
           delta[B_AXIS] += zadj; \
497
           delta[C_AXIS] += zadj; \
497
           delta[C_AXIS] += zadj; \
498
         }
498
         }
499
     #else
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
     #endif
501
     #endif
502
   #else
502
   #else
503
     #define ADJUST_DELTA(V) NOOP
503
     #define ADJUST_DELTA(V) NOOP
630
 
630
 
631
   /**
631
   /**
632
    * Prepare a linear move in a Cartesian setup.
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
   inline bool prepare_move_to_destination_cartesian() {
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
       const float fr_scaled = MMS_SCALED(feedrate_mm_s);
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
             mesh_line_to_destination(fr_scaled);
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
             bilinear_line_to_destination(fr_scaled);
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
     return false;
657
     return false;
669
   }
658
   }
670
 
659
 
699
 
688
 
700
   /**
689
   /**
701
    * Prepare a linear move in a dual X axis setup
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
   inline bool prepare_move_to_destination_dualx() {
694
   inline bool prepare_move_to_destination_dualx() {
704
     if (active_extruder_parked) {
695
     if (active_extruder_parked) {

+ 30
- 37
Marlin/src/module/planner.cpp Прегледај датотеку

122
       Planner::max_jerk[XYZE],       // The largest speed change requiring no acceleration
122
       Planner::max_jerk[XYZE],       // The largest speed change requiring no acceleration
123
       Planner::min_travel_feedrate_mm_s;
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
   #if ABL_PLANAR
127
   #if ABL_PLANAR
128
     matrix_3x3 Planner::bed_level_matrix; // Transform to compensate for bed level
128
     matrix_3x3 Planner::bed_level_matrix; // Transform to compensate for bed level
129
   #endif
129
   #endif
556
    */
556
    */
557
   void Planner::apply_leveling(float &lx, float &ly, float &lz) {
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
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
561
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
562
       const float fade_scaling_factor = fade_scaling_factor_for_z(lz);
562
       const float fade_scaling_factor = fade_scaling_factor_for_z(lz);
601
 
601
 
602
   void Planner::unapply_leveling(float logical[XYZ]) {
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
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
640
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
648
         const float c = mbl.get_z(RAW_X_POSITION(logical[X_AXIS]), RAW_Y_POSITION(logical[Y_AXIS]), 1.0);
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 Прегледај датотеку

164
                  max_jerk[XYZE],       // The largest speed change requiring no acceleration
164
                  max_jerk[XYZE],       // The largest speed change requiring no acceleration
165
                  min_travel_feedrate_mm_s;
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
       #if ABL_PLANAR
169
       #if ABL_PLANAR
170
         static matrix_3x3 bed_level_matrix; // Transform to compensate for bed level
170
         static matrix_3x3 bed_level_matrix; // Transform to compensate for bed level
171
       #endif
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
     #endif
175
     #endif
177
 
176
 
178
     #if ENABLED(LIN_ADVANCE)
177
     #if ENABLED(LIN_ADVANCE)
292
 
291
 
293
       FORCE_INLINE static void force_fade_recalc() { last_raw_lz = -999.999; }
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
     #else
304
     #else
296
 
305
 
297
       FORCE_INLINE static float fade_scaling_factor_for_z(const float &lz) {
306
       FORCE_INLINE static float fade_scaling_factor_for_z(const float &lz) {
299
         return 1.0;
308
         return 1.0;
300
       }
309
       }
301
 
310
 
311
+      FORCE_INLINE static bool leveling_active_at_z(const float &lz) { return true; }
312
+
302
     #endif
313
     #endif
303
 
314
 
304
     #if PLANNER_LEVELING
315
     #if PLANNER_LEVELING

+ 1
- 1
Marlin/src/module/probe.cpp Прегледај датотеку

679
     #endif
679
     #endif
680
 
680
 
681
     #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
681
     #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
682
-      if (!no_babystep && LEVELING_IS_ACTIVE())
682
+      if (!no_babystep && planner.leveling_active)
683
         thermalManager.babystep_axis(Z_AXIS, -LROUND(diff * planner.axis_steps_per_mm[Z_AXIS]));
683
         thermalManager.babystep_axis(Z_AXIS, -LROUND(diff * planner.axis_steps_per_mm[Z_AXIS]));
684
     #else
684
     #else
685
       UNUSED(no_babystep);
685
       UNUSED(no_babystep);

+ 1
- 1
Marlin/src/module/tool_change.cpp Прегледај датотеку

464
 
464
 
465
             #if ENABLED(MESH_BED_LEVELING)
465
             #if ENABLED(MESH_BED_LEVELING)
466
 
466
 
467
-              if (LEVELING_IS_ACTIVE()) {
467
+              if (planner.leveling_active) {
468
                 #if ENABLED(DEBUG_LEVELING_FEATURE)
468
                 #if ENABLED(DEBUG_LEVELING_FEATURE)
469
                   if (DEBUGGING(LEVELING)) SERIAL_ECHOPAIR("Z before MBL: ", current_position[Z_AXIS]);
469
                   if (DEBUGGING(LEVELING)) SERIAL_ECHOPAIR("Z before MBL: ", current_position[Z_AXIS]);
470
                 #endif
470
                 #endif

Loading…
Откажи
Сачувај