Просмотр исходного кода

Merge pull request #7966 from thinkyhead/bf2_ubl_remove_z_offset

[2.0.x] Unify Z fade factor
Scott Lahteine 7 лет назад
Родитель
Сommit
85b2e7e764

+ 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)");

+ 19
- 36
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)
55
   ;
55
   ;
56
 }
56
 }
57
 
57
 
58
-bool leveling_is_active() {
59
-  return
60
-    #if ENABLED(MESH_BED_LEVELING)
61
-      mbl.active()
62
-    #elif ENABLED(AUTO_BED_LEVELING_UBL)
63
-      ubl.state.active
64
-    #else // OLDSCHOOL_ABL
65
-      planner.abl_enabled
66
-    #endif
67
-  ;
68
-}
69
-
70
 /**
58
 /**
71
  * Turn bed leveling on or off, fixing the current
59
  * Turn bed leveling on or off, fixing the current
72
  * position as-needed.
60
  * position as-needed.
82
     constexpr bool can_change = true;
70
     constexpr bool can_change = true;
83
   #endif
71
   #endif
84
 
72
 
85
-  if (can_change && enable != leveling_is_active()) {
73
+  if (can_change && enable != planner.leveling_active) {
86
 
74
 
87
     #if ENABLED(MESH_BED_LEVELING)
75
     #if ENABLED(MESH_BED_LEVELING)
88
 
76
 
90
         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]);
91
 
79
 
92
       const bool enabling = enable && leveling_is_valid();
80
       const bool enabling = enable && leveling_is_valid();
93
-      mbl.set_active(enabling);
81
+      planner.leveling_active = enabling;
94
       if (enabling) planner.unapply_leveling(current_position);
82
       if (enabling) planner.unapply_leveling(current_position);
95
 
83
 
96
     #elif ENABLED(AUTO_BED_LEVELING_UBL)
84
     #elif ENABLED(AUTO_BED_LEVELING_UBL)
97
       #if PLANNER_LEVELING
85
       #if PLANNER_LEVELING
98
-        if (ubl.state.active) {                       // leveling from on to off
86
+        if (planner.leveling_active) {                   // leveling from on to off
99
           // change unleveled current_position to physical current_position without moving steppers.
87
           // change unleveled current_position to physical current_position without moving steppers.
100
           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]);
101
-          ubl.state.active = false;                   // disable only AFTER calling apply_leveling
89
+          planner.leveling_active = false;                   // disable only AFTER calling apply_leveling
102
         }
90
         }
103
         else {                                        // leveling from off to on
91
         else {                                        // leveling from off to on
104
-          ubl.state.active = true;                    // enable BEFORE calling unapply_leveling, otherwise ignored
92
+          planner.leveling_active = true;                    // enable BEFORE calling unapply_leveling, otherwise ignored
105
           // change physical current_position to unleveled current_position without moving steppers.
93
           // change physical current_position to unleveled current_position without moving steppers.
106
           planner.unapply_leveling(current_position);
94
           planner.unapply_leveling(current_position);
107
         }
95
         }
108
       #else
96
       #else
109
-        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.
110
       #endif
98
       #endif
111
 
99
 
112
     #else // OLDSCHOOL_ABL
100
     #else // OLDSCHOOL_ABL
118
       #endif
106
       #endif
119
 
107
 
120
       // Enable or disable leveling compensation in the planner
108
       // Enable or disable leveling compensation in the planner
121
-      planner.abl_enabled = enable;
109
+      planner.leveling_active = enable;
122
 
110
 
123
       if (!enable)
111
       if (!enable)
124
         // When disabling just get the current position from the steppers.
112
         // When disabling just get the current position from the steppers.
143
 
131
 
144
   void set_z_fade_height(const float zfh) {
132
   void set_z_fade_height(const float zfh) {
145
 
133
 
146
-    const bool level_active = leveling_is_active();
134
+    const bool level_active = planner.leveling_active;
147
 
135
 
148
     #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
138
+    #endif
149
 
139
 
150
-      if (level_active)
151
-        set_bed_leveling_enabled(false);  // turn off before changing fade height for proper apply/unapply leveling to maintain current_position
152
-      planner.z_fade_height = zfh;
153
-      planner.inverse_z_fade_height = RECIPROCAL(zfh);
154
-      if (level_active)
155
-        set_bed_leveling_enabled(true);  // turn back on after changing fade height
156
-
157
-    #else
158
-
159
-      planner.z_fade_height = zfh;
160
-      planner.inverse_z_fade_height = RECIPROCAL(zfh);
140
+    planner.set_z_fade_height(zfh);
161
 
141
 
162
-      if (level_active) {
142
+    if (level_active) {
143
+      #if ENABLED(AUTO_BED_LEVELING_UBL)
144
+        set_bed_leveling_enabled(true);  // turn back on after changing fade height
145
+      #else
163
         set_current_from_steppers_for_axis(
146
         set_current_from_steppers_for_axis(
164
           #if ABL_PLANAR
147
           #if ABL_PLANAR
165
             ALL_AXES
148
             ALL_AXES
167
             Z_AXIS
150
             Z_AXIS
168
           #endif
151
           #endif
169
         );
152
         );
170
-      }
171
-    #endif
153
+      #endif
154
+    }
172
   }
155
   }
173
 
156
 
174
 #endif // ENABLE_LEVELING_FADE_HEIGHT
157
 #endif // ENABLE_LEVELING_FADE_HEIGHT
181
   #if ENABLED(MESH_BED_LEVELING)
164
   #if ENABLED(MESH_BED_LEVELING)
182
     if (leveling_is_valid()) {
165
     if (leveling_is_valid()) {
183
       mbl.reset();
166
       mbl.reset();
184
-      mbl.set_has_mesh(false);
167
+      mbl.has_mesh = false;
185
     }
168
     }
186
   #else
169
   #else
187
     #if ENABLED(DEBUG_LEVELING_FEATURE)
170
     #if ENABLED(DEBUG_LEVELING_FEATURE)

+ 0
- 1
Marlin/src/feature/bedlevel/bedlevel.h Просмотреть файл

40
 #endif
40
 #endif
41
 
41
 
42
 bool leveling_is_valid();
42
 bool leveling_is_valid();
43
-bool leveling_is_active();
44
 void set_bed_leveling_enabled(const bool enable=true);
43
 void set_bed_leveling_enabled(const bool enable=true);
45
 void reset_bed_level();
44
 void reset_bed_level();
46
 
45
 

+ 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);

+ 5
- 7
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
   }
65
     safe_delay(10);
65
     safe_delay(10);
66
   }
66
   }
67
 
67
 
68
-  ubl_state unified_bed_leveling::state;
68
+  int8_t unified_bed_leveling::storage_slot;
69
 
69
 
70
-  float unified_bed_leveling::z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y],
71
-        unified_bed_leveling::last_specified_z;
70
+  float unified_bed_leveling::z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
72
 
71
 
73
   // 15 is the maximum nubmer of grid points supported + 1 safety margin for now,
72
   // 15 is the maximum nubmer of grid points supported + 1 safety margin for now,
74
   // until determinism prevails
73
   // until determinism prevails
91
 
90
 
92
   void unified_bed_leveling::reset() {
91
   void unified_bed_leveling::reset() {
93
     set_bed_leveling_enabled(false);
92
     set_bed_leveling_enabled(false);
94
-    state.storage_slot = -1;
93
+    storage_slot = -1;
95
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
94
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
96
-      planner.z_fade_height = 10.0;
95
+      planner.set_z_fade_height(10.0);
97
     #endif
96
     #endif
98
     ZERO(z_values);
97
     ZERO(z_values);
99
-    last_specified_z = -999.9;
100
   }
98
   }
101
 
99
 
102
   void unified_bed_leveling::invalidate() {
100
   void unified_bed_leveling::invalidate() {

+ 1
- 33
Marlin/src/feature/bedlevel/ubl/ubl.h Просмотреть файл

70
 #define MESH_X_DIST (float(UBL_MESH_MAX_X - (UBL_MESH_MIN_X)) / float(GRID_MAX_POINTS_X - 1))
70
 #define MESH_X_DIST (float(UBL_MESH_MAX_X - (UBL_MESH_MIN_X)) / float(GRID_MAX_POINTS_X - 1))
71
 #define MESH_Y_DIST (float(UBL_MESH_MAX_Y - (UBL_MESH_MIN_Y)) / float(GRID_MAX_POINTS_Y - 1))
71
 #define MESH_Y_DIST (float(UBL_MESH_MAX_Y - (UBL_MESH_MIN_Y)) / float(GRID_MAX_POINTS_Y - 1))
72
 
72
 
73
-typedef struct {
74
-  bool active = false;
75
-  int8_t storage_slot = -1;
76
-} ubl_state;
77
-
78
 class unified_bed_leveling {
73
 class unified_bed_leveling {
79
   private:
74
   private:
80
 
75
 
81
-    static float last_specified_z;
82
-
83
     static int    g29_verbose_level,
76
     static int    g29_verbose_level,
84
                   g29_phase_value,
77
                   g29_phase_value,
85
                   g29_repetition_cnt,
78
                   g29_repetition_cnt,
161
       static void G26();
154
       static void G26();
162
     #endif
155
     #endif
163
 
156
 
164
-    static ubl_state state;
157
+    static int8_t storage_slot;
165
 
158
 
166
     static float z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
159
     static float z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
167
 
160
 
367
       return z0;
360
       return z0;
368
     }
361
     }
369
 
362
 
370
-    /**
371
-     * This function sets the Z leveling fade factor based on the given Z height,
372
-     * only re-calculating when necessary.
373
-     *
374
-     *  Returns 1.0 if planner.z_fade_height is 0.0.
375
-     *  Returns 0.0 if Z is past the specified 'Fade Height'.
376
-     */
377
-    #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
378
-      static inline float fade_scaling_factor_for_z(const float &lz) {
379
-        if (planner.z_fade_height == 0.0) return 1.0;
380
-        static float fade_scaling_factor = 1.0;
381
-        const float rz = RAW_Z_POSITION(lz);
382
-        if (last_specified_z != rz) {
383
-          last_specified_z = rz;
384
-          fade_scaling_factor =
385
-            rz < planner.z_fade_height
386
-              ? 1.0 - (rz * planner.inverse_z_fade_height)
387
-              : 0.0;
388
-        }
389
-        return fade_scaling_factor;
390
-      }
391
-    #else
392
-      FORCE_INLINE static float fade_scaling_factor_for_z(const float &lz) { return 1.0; }
393
-    #endif
394
-
395
     FORCE_INLINE static float mesh_index_to_xpos(const uint8_t i) {
363
     FORCE_INLINE static float mesh_index_to_xpos(const uint8_t i) {
396
       return i < GRID_MAX_POINTS_X ? pgm_read_float(&_mesh_index_to_xpos[i]) : UBL_MESH_MIN_X + i * (MESH_X_DIST);
364
       return i < GRID_MAX_POINTS_X ? pgm_read_float(&_mesh_index_to_xpos[i]) : UBL_MESH_MIN_X + i * (MESH_X_DIST);
397
     }
365
     }

+ 9
- 9
Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp Просмотреть файл

424
     #endif // HAS_BED_PROBE
424
     #endif // HAS_BED_PROBE
425
 
425
 
426
     if (parser.seen('P')) {
426
     if (parser.seen('P')) {
427
-      if (WITHIN(g29_phase_value, 0, 1) && state.storage_slot == -1) {
428
-        state.storage_slot = 0;
427
+      if (WITHIN(g29_phase_value, 0, 1) && storage_slot == -1) {
428
+        storage_slot = 0;
429
         SERIAL_PROTOCOLLNPGM("Default storage slot 0 selected.");
429
         SERIAL_PROTOCOLLNPGM("Default storage slot 0 selected.");
430
       }
430
       }
431
 
431
 
604
     //
604
     //
605
 
605
 
606
     if (parser.seen('L')) {     // Load Current Mesh Data
606
     if (parser.seen('L')) {     // Load Current Mesh Data
607
-      g29_storage_slot = parser.has_value() ? parser.value_int() : state.storage_slot;
607
+      g29_storage_slot = parser.has_value() ? parser.value_int() : storage_slot;
608
 
608
 
609
       int16_t a = settings.calc_num_meshes();
609
       int16_t a = settings.calc_num_meshes();
610
 
610
 
620
       }
620
       }
621
 
621
 
622
       settings.load_mesh(g29_storage_slot);
622
       settings.load_mesh(g29_storage_slot);
623
-      state.storage_slot = g29_storage_slot;
623
+      storage_slot = g29_storage_slot;
624
 
624
 
625
       SERIAL_PROTOCOLLNPGM("Done.");
625
       SERIAL_PROTOCOLLNPGM("Done.");
626
     }
626
     }
630
     //
630
     //
631
 
631
 
632
     if (parser.seen('S')) {     // Store (or Save) Current Mesh Data
632
     if (parser.seen('S')) {     // Store (or Save) Current Mesh Data
633
-      g29_storage_slot = parser.has_value() ? parser.value_int() : state.storage_slot;
633
+      g29_storage_slot = parser.has_value() ? parser.value_int() : storage_slot;
634
 
634
 
635
       if (g29_storage_slot == -1) {                     // Special case, we are going to 'Export' the mesh to the
635
       if (g29_storage_slot == -1) {                     // Special case, we are going to 'Export' the mesh to the
636
         SERIAL_ECHOLNPGM("G29 I 999");              // host in a form it can be reconstructed on a different machine
636
         SERIAL_ECHOLNPGM("G29 I 999");              // host in a form it can be reconstructed on a different machine
662
       }
662
       }
663
 
663
 
664
       settings.store_mesh(g29_storage_slot);
664
       settings.store_mesh(g29_storage_slot);
665
-      state.storage_slot = g29_storage_slot;
665
+      storage_slot = g29_storage_slot;
666
 
666
 
667
       SERIAL_PROTOCOLLNPGM("Done.");
667
       SERIAL_PROTOCOLLNPGM("Done.");
668
     }
668
     }
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
 
1195
   void unified_bed_leveling::g29_what_command() {
1195
   void unified_bed_leveling::g29_what_command() {
1196
     report_state();
1196
     report_state();
1197
 
1197
 
1198
-    if (state.storage_slot == -1)
1198
+    if (storage_slot == -1)
1199
       SERIAL_PROTOCOLPGM("No Mesh Loaded.");
1199
       SERIAL_PROTOCOLPGM("No Mesh Loaded.");
1200
     else {
1200
     else {
1201
-      SERIAL_PROTOCOLPAIR("Mesh ", state.storage_slot);
1201
+      SERIAL_PROTOCOLPAIR("Mesh ", storage_slot);
1202
       SERIAL_PROTOCOLPGM(" Loaded.");
1202
       SERIAL_PROTOCOLPGM(" Loaded.");
1203
     }
1203
     }
1204
     SERIAL_EOL();
1204
     SERIAL_EOL();

+ 12
- 24
Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp Просмотреть файл

173
       // are going to apply the Y-Distance into the cell to interpolate the final Z correction.
173
       // are going to apply the Y-Distance into the cell to interpolate the final Z correction.
174
 
174
 
175
       const float yratio = (RAW_Y_POSITION(end[Y_AXIS]) - mesh_index_to_ypos(cell_dest_yi)) * (1.0 / (MESH_Y_DIST));
175
       const float yratio = (RAW_Y_POSITION(end[Y_AXIS]) - mesh_index_to_ypos(cell_dest_yi)) * (1.0 / (MESH_Y_DIST));
176
-      float z0 = cell_dest_yi < GRID_MAX_POINTS_Y - 1 ? (z1 + (z2 - z1) * yratio) * fade_scaling_factor_for_z(end[Z_AXIS]) : 0.0;
176
+      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;
177
 
177
 
178
       /**
178
       /**
179
        * If part of the Mesh is undefined, it will show up as NAN
179
        * If part of the Mesh is undefined, it will show up as NAN
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 *= 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 *= 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 *= 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 *= 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
 
616
       // Otherwise perform per-segment leveling
604
       // Otherwise perform per-segment leveling
617
 
605
 
618
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
606
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
619
-        const float fade_scaling_factor = fade_scaling_factor_for_z(ltarget[Z_AXIS]);
607
+        const float fade_scaling_factor = planner.fade_scaling_factor_for_z(ltarget[Z_AXIS]);
620
       #endif
608
       #endif
621
 
609
 
622
       // increment to first segment destination
610
       // increment to first segment destination
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

+ 5
- 6
Marlin/src/gcode/bedlevel/M420.cpp Просмотреть файл

51
     if (parser.seen('L')) {
51
     if (parser.seen('L')) {
52
 
52
 
53
       #if ENABLED(EEPROM_SETTINGS)
53
       #if ENABLED(EEPROM_SETTINGS)
54
-        const int8_t storage_slot = parser.has_value() ? parser.value_int() : ubl.state.storage_slot;
54
+        const int8_t storage_slot = parser.has_value() ? parser.value_int() : ubl.storage_slot;
55
         const int16_t a = settings.calc_num_meshes();
55
         const int16_t a = settings.calc_num_meshes();
56
 
56
 
57
         if (!a) {
57
         if (!a) {
66
         }
66
         }
67
 
67
 
68
         settings.load_mesh(storage_slot);
68
         settings.load_mesh(storage_slot);
69
-        ubl.state.storage_slot = storage_slot;
69
+        ubl.storage_slot = storage_slot;
70
 
70
 
71
       #else
71
       #else
72
 
72
 
80
     if (parser.seen('L') || parser.seen('V')) {
80
     if (parser.seen('L') || parser.seen('V')) {
81
       ubl.display_map(0);  // Currently only supports one map type
81
       ubl.display_map(0);  // Currently only supports one map type
82
       SERIAL_ECHOLNPAIR("ubl.mesh_is_valid = ", ubl.mesh_is_valid());
82
       SERIAL_ECHOLNPAIR("ubl.mesh_is_valid = ", ubl.mesh_is_valid());
83
-      SERIAL_ECHOLNPAIR("ubl.state.storage_slot = ", ubl.state.storage_slot);
83
+      SERIAL_ECHOLNPAIR("ubl.storage_slot = ", ubl.storage_slot);
84
     }
84
     }
85
 
85
 
86
   #endif // AUTO_BED_LEVELING_UBL
86
   #endif // AUTO_BED_LEVELING_UBL
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();

+ 14
- 14
Marlin/src/gcode/bedlevel/abl/G29.cpp Просмотреть файл

137
     const uint8_t old_debug_flags = marlin_debug_flags;
137
     const uint8_t old_debug_flags = marlin_debug_flags;
138
     if (query) marlin_debug_flags |= DEBUG_LEVELING;
138
     if (query) marlin_debug_flags |= DEBUG_LEVELING;
139
     if (DEBUGGING(LEVELING)) {
139
     if (DEBUGGING(LEVELING)) {
140
-      DEBUG_POS(">>> gcode_G29", current_position);
140
+      DEBUG_POS(">>> G29", current_position);
141
       log_machine_info();
141
       log_machine_info();
142
     }
142
     }
143
     marlin_debug_flags = old_debug_flags;
143
     marlin_debug_flags = old_debug_flags;
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
957
   if (!faux) clean_up_after_endstop_or_probe_move();
957
   if (!faux) clean_up_after_endstop_or_probe_move();
958
 
958
 
959
   #if ENABLED(DEBUG_LEVELING_FEATURE)
959
   #if ENABLED(DEBUG_LEVELING_FEATURE)
960
-    if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("<<< gcode_G29");
960
+    if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("<<< G29");
961
   #endif
961
   #endif
962
 
962
 
963
   report_current_position();
963
   report_current_position();
964
 
964
 
965
   KEEPALIVE_STATE(IN_HANDLER);
965
   KEEPALIVE_STATE(IN_HANDLER);
966
 
966
 
967
-  if (planner.abl_enabled)
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

+ 5
- 1
Marlin/src/gcode/calibrate/M48.cpp Просмотреть файл

32
   #include "../../feature/bedlevel/bedlevel.h"
32
   #include "../../feature/bedlevel/bedlevel.h"
33
 #endif
33
 #endif
34
 
34
 
35
+#if HAS_LEVELING
36
+  #include "../../module/planner.h"
37
+#endif
38
+
35
 /**
39
 /**
36
  * M48: Z probe repeatability measurement function.
40
  * M48: Z probe repeatability measurement function.
37
  *
41
  *
115
   // 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
116
 
120
 
117
   #if HAS_LEVELING
121
   #if HAS_LEVELING
118
-    const bool was_enabled = leveling_is_active();
122
+    const bool was_enabled = planner.leveling_active;
119
     set_bed_leveling_enabled(false);
123
     set_bed_leveling_enabled(false);
120
   #endif
124
   #endif
121
 
125
 

+ 2
- 2
Marlin/src/gcode/control/T.cpp Просмотреть файл

37
 
37
 
38
   #if ENABLED(DEBUG_LEVELING_FEATURE)
38
   #if ENABLED(DEBUG_LEVELING_FEATURE)
39
     if (DEBUGGING(LEVELING)) {
39
     if (DEBUGGING(LEVELING)) {
40
-      SERIAL_ECHOPAIR(">>> gcode_T(", tmp_extruder);
40
+      SERIAL_ECHOPAIR(">>> T(", tmp_extruder);
41
       SERIAL_CHAR(')');
41
       SERIAL_CHAR(')');
42
       SERIAL_EOL();
42
       SERIAL_EOL();
43
       DEBUG_POS("BEFORE", current_position);
43
       DEBUG_POS("BEFORE", current_position);
61
   #if ENABLED(DEBUG_LEVELING_FEATURE)
61
   #if ENABLED(DEBUG_LEVELING_FEATURE)
62
     if (DEBUGGING(LEVELING)) {
62
     if (DEBUGGING(LEVELING)) {
63
       DEBUG_POS("AFTER", current_position);
63
       DEBUG_POS("AFTER", current_position);
64
-      SERIAL_ECHOLNPGM("<<< gcode_T");
64
+      SERIAL_ECHOLNPGM("<<< T()");
65
     }
65
     }
66
   #endif
66
   #endif
67
 }
67
 }

+ 6
- 6
Marlin/src/inc/Conditionals_post.h Просмотреть файл

820
   #define UBL_DELTA  (ENABLED(AUTO_BED_LEVELING_UBL) && (ENABLED(DELTA) || ENABLED(UBL_GRANULAR_SEGMENTATION_FOR_CARTESIAN)))
820
   #define UBL_DELTA  (ENABLED(AUTO_BED_LEVELING_UBL) && (ENABLED(DELTA) || ENABLED(UBL_GRANULAR_SEGMENTATION_FOR_CARTESIAN)))
821
   #define ABL_PLANAR (ENABLED(AUTO_BED_LEVELING_LINEAR) || ENABLED(AUTO_BED_LEVELING_3POINT))
821
   #define ABL_PLANAR (ENABLED(AUTO_BED_LEVELING_LINEAR) || ENABLED(AUTO_BED_LEVELING_3POINT))
822
   #define ABL_GRID   (ENABLED(AUTO_BED_LEVELING_LINEAR) || ENABLED(AUTO_BED_LEVELING_BILINEAR))
822
   #define ABL_GRID   (ENABLED(AUTO_BED_LEVELING_LINEAR) || ENABLED(AUTO_BED_LEVELING_BILINEAR))
823
-  #define HAS_ABL    (ABL_PLANAR || ABL_GRID || ENABLED(AUTO_BED_LEVELING_UBL))
824
-  #define HAS_LEVELING  (HAS_ABL || ENABLED(MESH_BED_LEVELING))
825
-  #define HAS_AUTOLEVEL (HAS_ABL && DISABLED(PROBE_MANUALLY))
826
-  #define OLDSCHOOL_ABL (HAS_ABL && DISABLED(AUTO_BED_LEVELING_UBL))
827
-  #define HAS_MESH   (ENABLED(AUTO_BED_LEVELING_BILINEAR) || ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(MESH_BED_LEVELING))
828
-  #define PLANNER_LEVELING      (ABL_PLANAR || ABL_GRID || ENABLED(MESH_BED_LEVELING) || UBL_DELTA)
823
+  #define OLDSCHOOL_ABL         (ABL_PLANAR || ABL_GRID)
824
+  #define HAS_ABL               (OLDSCHOOL_ABL || ENABLED(AUTO_BED_LEVELING_UBL))
825
+  #define HAS_LEVELING          (HAS_ABL || ENABLED(MESH_BED_LEVELING))
826
+  #define HAS_AUTOLEVEL         (HAS_ABL && DISABLED(PROBE_MANUALLY))
827
+  #define HAS_MESH              (ENABLED(AUTO_BED_LEVELING_BILINEAR) || ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(MESH_BED_LEVELING))
828
+  #define PLANNER_LEVELING      (OLDSCHOOL_ABL || ENABLED(MESH_BED_LEVELING) || UBL_DELTA)
829
   #define HAS_PROBING_PROCEDURE (HAS_ABL || ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST))
829
   #define HAS_PROBING_PROCEDURE (HAS_ABL || ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST))
830
   #if HAS_PROBING_PROCEDURE
830
   #if HAS_PROBING_PROCEDURE
831
     #define PROBE_BED_WIDTH abs(RIGHT_PROBE_BED_POSITION - (LEFT_PROBE_BED_POSITION))
831
     #define PROBE_BED_WIDTH abs(RIGHT_PROBE_BED_POSITION - (LEFT_PROBE_BED_POSITION))

+ 1
- 1
Marlin/src/inc/SanityCheck.h Просмотреть файл

651
   /**
651
   /**
652
    * Require some kind of probe for bed leveling and probe testing
652
    * Require some kind of probe for bed leveling and probe testing
653
    */
653
    */
654
-  #if HAS_ABL && DISABLED(AUTO_BED_LEVELING_UBL)
654
+  #if OLDSCHOOL_ABL
655
     #error "Auto Bed Leveling requires one of these: PROBE_MANUALLY, FIX_MOUNTED_PROBE, BLTOUCH, SOLENOID_PROBE, Z_PROBE_ALLEN_KEY, Z_PROBE_SLED, or a Z Servo."
655
     #error "Auto Bed Leveling requires one of these: PROBE_MANUALLY, FIX_MOUNTED_PROBE, BLTOUCH, SOLENOID_PROBE, Z_PROBE_ALLEN_KEY, Z_PROBE_SLED, or a Z Servo."
656
   #endif
656
   #endif
657
 
657
 

+ 25
- 10
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
1906
       enqueue_and_echo_commands_P(PSTR("G28"));
1906
       enqueue_and_echo_commands_P(PSTR("G28"));
1907
     }
1907
     }
1908
 
1908
 
1909
-    static bool _level_state;
1910
-    void _lcd_toggle_bed_leveling() { set_bed_leveling_enabled(_level_state); }
1909
+    static bool new_level_state;
1910
+    void _lcd_toggle_bed_leveling() { set_bed_leveling_enabled(new_level_state); }
1911
 
1911
 
1912
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1912
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1913
-      void _lcd_set_z_fade_height() { set_z_fade_height(planner.z_fade_height); }
1913
+      static float new_z_fade_height;
1914
+      void _lcd_set_z_fade_height() { set_z_fade_height(new_z_fade_height); }
1914
     #endif
1915
     #endif
1915
 
1916
 
1916
     /**
1917
     /**
1934
       if (!(axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS]))
1935
       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"));
1936
         MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
1936
       else if (leveling_is_valid()) {
1937
       else if (leveling_is_valid()) {
1937
-        _level_state = leveling_is_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, &new_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);
1943
-        MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_Z_FADE_HEIGHT, &planner.z_fade_height, 0.0, 100.0, _lcd_set_z_fade_height);
1942
+        MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_Z_FADE_HEIGHT, &new_z_fade_height, 0.0, 100.0, _lcd_set_z_fade_height);
1944
       #endif
1943
       #endif
1945
 
1944
 
1946
       //
1945
       //
1971
       END_MENU();
1970
       END_MENU();
1972
     }
1971
     }
1973
 
1972
 
1973
+    void _lcd_goto_bed_leveling() {
1974
+      currentScreen = lcd_bed_leveling;
1975
+      #if ENABLED(LCD_BED_LEVELING)
1976
+        new_level_state = planner.leveling_active;
1977
+      #endif
1978
+      #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1979
+        new_z_fade_height = planner.z_fade_height;
1980
+      #endif
1981
+    }
1982
+
1974
   #elif ENABLED(AUTO_BED_LEVELING_UBL)
1983
   #elif ENABLED(AUTO_BED_LEVELING_UBL)
1975
 
1984
 
1976
     void _lcd_ubl_level_bed();
1985
     void _lcd_ubl_level_bed();
2541
       #if ENABLED(PROBE_MANUALLY)
2550
       #if ENABLED(PROBE_MANUALLY)
2542
         if (!g29_in_progress)
2551
         if (!g29_in_progress)
2543
       #endif
2552
       #endif
2544
-      MENU_ITEM(submenu, MSG_BED_LEVELING, lcd_bed_leveling);
2553
+          MENU_ITEM(submenu, MSG_BED_LEVELING,
2554
+            #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
2555
+              _lcd_goto_bed_leveling
2556
+            #else
2557
+              lcd_bed_leveling
2558
+            #endif
2559
+          );
2545
     #else
2560
     #else
2546
       #if PLANNER_LEVELING
2561
       #if PLANNER_LEVELING
2547
         MENU_ITEM(gcode, MSG_BED_LEVELING, PSTR("G28\nG29"));
2562
         MENU_ITEM(gcode, MSG_BED_LEVELING, PSTR("G28\nG29"));

+ 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

+ 26
- 22
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)
92
- *  325  G29 S     ubl.state.storage_slot           (int8_t)
91
+ *  324  G29 A     planner.leveling_active          (bool)
92
+ *  325  G29 S     ubl.storage_slot                 (int8_t)
93
  *
93
  *
94
  * DELTA:                                           48 bytes
94
  * DELTA:                                           48 bytes
95
  *  344  M666 XYZ  delta_endstop_adj                (float x3)
95
  *  344  M666 XYZ  delta_endstop_adj                (float x3)
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);
410
-      EEPROM_WRITE(ubl.state.storage_slot);
413
+      EEPROM_WRITE(planner.leveling_active);
414
+      EEPROM_WRITE(ubl.storage_slot);
411
     #else
415
     #else
412
       const bool ubl_active = false;
416
       const bool ubl_active = false;
413
       const int8_t storage_slot = -1;
417
       const int8_t storage_slot = -1;
630
     }
634
     }
631
 
635
 
632
     #if ENABLED(UBL_SAVE_ACTIVE_ON_M500)
636
     #if ENABLED(UBL_SAVE_ACTIVE_ON_M500)
633
-      if (ubl.state.storage_slot >= 0)
634
-        store_mesh(ubl.state.storage_slot);
637
+      if (ubl.storage_slot >= 0)
638
+        store_mesh(ubl.storage_slot);
635
     #endif
639
     #endif
636
     EEPROM_FINISH();
640
     EEPROM_FINISH();
637
     return !eeprom_error;
641
     return !eeprom_error;
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);
797
-        EEPROM_READ(ubl.state.storage_slot);
800
+        EEPROM_READ(planner.leveling_active);
801
+        EEPROM_READ(ubl.storage_slot);
798
       #else
802
       #else
799
         uint8_t dummyui8;
803
         uint8_t dummyui8;
800
         EEPROM_READ(dummyb);
804
         EEPROM_READ(dummyb);
1011
           ubl.reset();
1015
           ubl.reset();
1012
         }
1016
         }
1013
 
1017
 
1014
-        if (ubl.state.storage_slot >= 0) {
1015
-          load_mesh(ubl.state.storage_slot);
1018
+        if (ubl.storage_slot >= 0) {
1019
+          load_mesh(ubl.storage_slot);
1016
           #if ENABLED(EEPROM_CHITCHAT)
1020
           #if ENABLED(EEPROM_CHITCHAT)
1017
-            SERIAL_ECHOPAIR("Mesh ", ubl.state.storage_slot);
1021
+            SERIAL_ECHOPAIR("Mesh ", ubl.storage_slot);
1018
             SERIAL_ECHOLNPGM(" loaded from storage.");
1022
             SERIAL_ECHOLNPGM(" loaded from storage.");
1019
           #endif
1023
           #endif
1020
         }
1024
         }
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
 
1566
         SERIAL_EOL();
1570
         SERIAL_EOL();
1567
         ubl.report_state();
1571
         ubl.report_state();
1568
 
1572
 
1569
-        SERIAL_ECHOLNPAIR("\nActive Mesh Slot: ", ubl.state.storage_slot);
1573
+        SERIAL_ECHOLNPAIR("\nActive Mesh Slot: ", ubl.storage_slot);
1570
         SERIAL_ECHOPAIR("EEPROM can hold ", calc_num_meshes());
1574
         SERIAL_ECHOPAIR("EEPROM can hold ", calc_num_meshes());
1571
         SERIAL_ECHOLNPGM(" meshes.\n");
1575
         SERIAL_ECHOLNPGM(" meshes.\n");
1572
       }
1576
       }
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 (planner.abl_enabled) { \
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 (planner.abl_enabled) { 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) {

+ 56
- 85
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
131
 
131
 
132
 #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
132
 #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
133
   float Planner::z_fade_height, // Initialized by settings.load()
133
   float Planner::z_fade_height, // Initialized by settings.load()
134
-        Planner::inverse_z_fade_height;
134
+        Planner::inverse_z_fade_height,
135
+        Planner::last_raw_lz;
135
 #endif
136
 #endif
136
 
137
 
137
 #if ENABLED(AUTOTEMP)
138
 #if ENABLED(AUTOTEMP)
555
    */
556
    */
556
   void Planner::apply_leveling(float &lx, float &ly, float &lz) {
557
   void Planner::apply_leveling(float &lx, float &ly, float &lz) {
557
 
558
 
558
-    #if ENABLED(AUTO_BED_LEVELING_UBL)
559
-      if (!ubl.state.active) return;
560
-      #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
561
-        // if z_fade_height enabled (nonzero) and raw_z above it, no leveling required
562
-        if (planner.z_fade_height && planner.z_fade_height <= RAW_Z_POSITION(lz)) return;
563
-        lz += ubl.get_z_correction(lx, ly) * ubl.fade_scaling_factor_for_z(lz);
564
-      #else // no fade
565
-        lz += ubl.get_z_correction(lx, ly);
566
-      #endif // FADE
567
-    #endif // UBL
568
-
569
-    #if OLDSCHOOL_ABL
570
-      if (!abl_enabled) return;
571
-    #endif
559
+    if (!planner.leveling_active) return;
572
 
560
 
573
-    #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) && DISABLED(AUTO_BED_LEVELING_UBL)
574
-      static float z_fade_factor = 1.0, last_raw_lz = -999.0;
575
-      if (z_fade_height) {
576
-        const float raw_lz = RAW_Z_POSITION(lz);
577
-        if (raw_lz >= z_fade_height) return;
578
-        if (last_raw_lz != raw_lz) {
579
-          last_raw_lz = raw_lz;
580
-          z_fade_factor = 1.0 - raw_lz * inverse_z_fade_height;
581
-        }
582
-      }
583
-      else
584
-        z_fade_factor = 1.0;
561
+    #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
562
+      const float fade_scaling_factor = fade_scaling_factor_for_z(lz);
563
+      if (!fade_scaling_factor) return;
564
+    #else
565
+      constexpr float fade_scaling_factor = 1.0;
585
     #endif
566
     #endif
586
 
567
 
587
-    #if ENABLED(MESH_BED_LEVELING)
568
+    #if ENABLED(AUTO_BED_LEVELING_UBL)
588
 
569
 
589
-      if (mbl.active())
590
-        lz += mbl.get_z(RAW_X_POSITION(lx), RAW_Y_POSITION(ly)
591
-          #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
592
-            , z_fade_factor
593
-          #endif
594
-          );
570
+      lz += ubl.get_z_correction(lx, ly) * fade_scaling_factor;
571
+
572
+    #elif ENABLED(MESH_BED_LEVELING)
573
+
574
+      lz += mbl.get_z(RAW_X_POSITION(lx), RAW_Y_POSITION(ly)
575
+        #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
576
+          , fade_scaling_factor
577
+        #endif
578
+      );
595
 
579
 
596
     #elif ABL_PLANAR
580
     #elif ABL_PLANAR
597
 
581
 
582
+      UNUSED(fade_scaling_factor);
583
+
598
       float dx = RAW_X_POSITION(lx) - (X_TILT_FULCRUM),
584
       float dx = RAW_X_POSITION(lx) - (X_TILT_FULCRUM),
599
             dy = RAW_Y_POSITION(ly) - (Y_TILT_FULCRUM),
585
             dy = RAW_Y_POSITION(ly) - (Y_TILT_FULCRUM),
600
             dz = RAW_Z_POSITION(lz);
586
             dz = RAW_Z_POSITION(lz);
608
     #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
594
     #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
609
 
595
 
610
       float tmp[XYZ] = { lx, ly, 0 };
596
       float tmp[XYZ] = { lx, ly, 0 };
611
-      lz += bilinear_z_offset(tmp)
612
-        #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
613
-          * z_fade_factor
614
-        #endif
615
-      ;
597
+      lz += bilinear_z_offset(tmp) * fade_scaling_factor;
616
 
598
 
617
     #endif
599
     #endif
618
   }
600
   }
619
 
601
 
620
   void Planner::unapply_leveling(float logical[XYZ]) {
602
   void Planner::unapply_leveling(float logical[XYZ]) {
621
 
603
 
622
-    #if ENABLED(AUTO_BED_LEVELING_UBL)
623
-
624
-      if (ubl.state.active) {
604
+    if (!planner.leveling_active) return;
625
 
605
 
626
-        const float z_physical = RAW_Z_POSITION(logical[Z_AXIS]),
627
-                    z_correct = ubl.get_z_correction(logical[X_AXIS], logical[Y_AXIS]),
628
-                    z_virtual = z_physical - z_correct;
629
-              float z_logical = LOGICAL_Z_POSITION(z_virtual);
630
-
631
-        #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
606
+    #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
607
+      if (z_fade_height && RAW_Z_POSITION(logical[Z_AXIS]) >= z_fade_height) return;
608
+    #endif
632
 
609
 
633
-          // for P=physical_z, L=logical_z, M=mesh_z, H=fade_height,
634
-          // Given P=L+M(1-L/H) (faded mesh correction formula for L<H)
635
-          //  then L=P-M(1-L/H)
636
-          //    so L=P-M+ML/H
637
-          //    so L-ML/H=P-M
638
-          //    so L(1-M/H)=P-M
639
-          //    so L=(P-M)/(1-M/H) for L<H
610
+    #if ENABLED(AUTO_BED_LEVELING_UBL)
640
 
611
 
641
-          if (planner.z_fade_height) {
642
-            if (z_logical >= planner.z_fade_height)
643
-              z_logical = LOGICAL_Z_POSITION(z_physical);
644
-            else
645
-              z_logical /= 1.0 - z_correct * planner.inverse_z_fade_height;
646
-          }
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);
647
 
616
 
648
-        #endif // ENABLE_LEVELING_FADE_HEIGHT
617
+      #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
649
 
618
 
650
-        logical[Z_AXIS] = z_logical;
651
-      }
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
+        }
652
 
633
 
653
-      return; // don't fall thru to other ENABLE_LEVELING_FADE_HEIGHT logic
634
+      #endif // ENABLE_LEVELING_FADE_HEIGHT
654
 
635
 
655
-    #endif
636
+      logical[Z_AXIS] = z_logical;
656
 
637
 
657
-    #if OLDSCHOOL_ABL
658
-      if (!abl_enabled) return;
659
-    #endif
638
+    #elif ENABLED(MESH_BED_LEVELING)
660
 
639
 
661
-    #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
662
-      if (z_fade_height && RAW_Z_POSITION(logical[Z_AXIS]) >= z_fade_height) return;
663
-    #endif
664
-
665
-    #if ENABLED(MESH_BED_LEVELING)
666
-
667
-      if (mbl.active()) {
668
-        #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
669
-          const float c = mbl.get_z(RAW_X_POSITION(logical[X_AXIS]), RAW_Y_POSITION(logical[Y_AXIS]), 1.0);
670
-          logical[Z_AXIS] = (z_fade_height * (RAW_Z_POSITION(logical[Z_AXIS]) - c)) / (z_fade_height - c);
671
-        #else
672
-          logical[Z_AXIS] -= mbl.get_z(RAW_X_POSITION(logical[X_AXIS]), RAW_Y_POSITION(logical[Y_AXIS]));
673
-        #endif
674
-      }
640
+      #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
641
+        const float c = mbl.get_z(RAW_X_POSITION(logical[X_AXIS]), RAW_Y_POSITION(logical[Y_AXIS]), 1.0);
642
+        logical[Z_AXIS] = (z_fade_height * (RAW_Z_POSITION(logical[Z_AXIS]) - c)) / (z_fade_height - c);
643
+      #else
644
+        logical[Z_AXIS] -= mbl.get_z(RAW_X_POSITION(logical[X_AXIS]), RAW_Y_POSITION(logical[Y_AXIS]));
645
+      #endif
675
 
646
 
676
     #elif ABL_PLANAR
647
     #elif ABL_PLANAR
677
 
648
 

+ 55
- 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)
202
      */
201
      */
203
     static uint32_t cutoff_long;
202
     static uint32_t cutoff_long;
204
 
203
 
204
+    #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
205
+      static float last_raw_lz;
206
+    #endif
207
+
205
     #if ENABLED(DISABLE_INACTIVE_EXTRUDER)
208
     #if ENABLED(DISABLE_INACTIVE_EXTRUDER)
206
       /**
209
       /**
207
        * Counters to manage disabling inactive extruders
210
        * Counters to manage disabling inactive extruders
263
         if (!filament_size[i]) filament_size[i] = DEFAULT_NOMINAL_FILAMENT_DIA;
266
         if (!filament_size[i]) filament_size[i] = DEFAULT_NOMINAL_FILAMENT_DIA;
264
     }
267
     }
265
 
268
 
269
+    #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
270
+
271
+      /**
272
+       * Get the Z leveling fade factor based on the given Z height,
273
+       * re-calculating only when needed.
274
+       *
275
+       *  Returns 1.0 if planner.z_fade_height is 0.0.
276
+       *  Returns 0.0 if Z is past the specified 'Fade Height'.
277
+       */
278
+      inline static float fade_scaling_factor_for_z(const float &lz) {
279
+        static float z_fade_factor = 1.0;
280
+        if (z_fade_height) {
281
+          const float raw_lz = RAW_Z_POSITION(lz);
282
+          if (raw_lz >= z_fade_height) return 0.0;
283
+          if (last_raw_lz != raw_lz) {
284
+            last_raw_lz = raw_lz;
285
+            z_fade_factor = 1.0 - raw_lz * inverse_z_fade_height;
286
+          }
287
+          return z_fade_factor;
288
+        }
289
+        return 1.0;
290
+      }
291
+
292
+      FORCE_INLINE static void force_fade_recalc() { last_raw_lz = -999.999; }
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
+
304
+    #else
305
+
306
+      FORCE_INLINE static float fade_scaling_factor_for_z(const float &lz) {
307
+        UNUSED(lz);
308
+        return 1.0;
309
+      }
310
+
311
+      FORCE_INLINE static bool leveling_active_at_z(const float &lz) { return true; }
312
+
313
+    #endif
314
+
266
     #if PLANNER_LEVELING
315
     #if PLANNER_LEVELING
267
 
316
 
268
       #define ARG_X float lx
317
       #define ARG_X float lx

+ 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);

+ 2
- 1
Marlin/src/module/temperature.cpp Просмотреть файл

2059
   } // temp_count >= OVERSAMPLENR
2059
   } // temp_count >= OVERSAMPLENR
2060
 
2060
 
2061
   // Go to the next state, up to SensorsReady
2061
   // Go to the next state, up to SensorsReady
2062
-  adc_sensor_state = (ADCSensorState)((int(adc_sensor_state) + 1) % int(StartupDelay));
2062
+  adc_sensor_state = (ADCSensorState)(int(adc_sensor_state) + 1);
2063
+  if (adc_sensor_state > SensorsReady) adc_sensor_state = (ADCSensorState)0;
2063
 
2064
 
2064
   #if ENABLED(BABYSTEPPING)
2065
   #if ENABLED(BABYSTEPPING)
2065
     LOOP_XYZ(axis) {
2066
     LOOP_XYZ(axis) {

+ 8
- 8
Marlin/src/module/tool_change.cpp Просмотреть файл

295
                                     + (tmp_extruder == 0 ? -(PARKING_EXTRUDER_GRAB_DISTANCE) : PARKING_EXTRUDER_GRAB_DISTANCE);
295
                                     + (tmp_extruder == 0 ? -(PARKING_EXTRUDER_GRAB_DISTANCE) : PARKING_EXTRUDER_GRAB_DISTANCE);
296
               /**
296
               /**
297
                *  Steps:
297
                *  Steps:
298
-               *    1. raise Z-Axis to have enough clearance
299
-               *    2. move to park poition of old extruder
300
-               *    3. disengage magnetc field, wait for delay
301
-               *    4. move near new extruder
302
-               *    5. engage magnetic field for new extruder
303
-               *    6. move to parking incl. offset of new extruder
304
-               *    7. lower Z-Axis
298
+               *    1. Raise Z-Axis to give enough clearance
299
+               *    2. Move to park position of old extruder
300
+               *    3. Disengage magnetic field, wait for delay
301
+               *    4. Move near new extruder
302
+               *    5. Engage magnetic field for new extruder
303
+               *    6. Move to parking incl. offset of new extruder
304
+               *    7. Lower Z-Axis
305
                */
305
                */
306
 
306
 
307
               // STEP 1
307
               // STEP 1
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

Загрузка…
Отмена
Сохранить