Browse Source

Move fade_scaling_factor_for_z to Planner

Scott Lahteine 7 years ago
parent
commit
ca1e47375c

+ 10
- 14
Marlin/src/feature/bedlevel/bedlevel.cpp View File

134
     const bool level_active = LEVELING_IS_ACTIVE();
134
     const bool level_active = LEVELING_IS_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
138
+    #endif
137
 
139
 
138
-      if (level_active)
139
-        set_bed_leveling_enabled(false);  // turn off before changing fade height for proper apply/unapply leveling to maintain current_position
140
-      planner.z_fade_height = zfh;
141
-      planner.inverse_z_fade_height = RECIPROCAL(zfh);
142
-      if (level_active)
143
-        set_bed_leveling_enabled(true);  // turn back on after changing fade height
144
-
145
-    #else
146
-
147
-      planner.z_fade_height = zfh;
148
-      planner.inverse_z_fade_height = RECIPROCAL(zfh);
140
+    planner.z_fade_height = zfh;
141
+    planner.inverse_z_fade_height = RECIPROCAL(zfh);
149
 
142
 
150
-      if (level_active) {
143
+    if (level_active) {
144
+      #if ENABLED(AUTO_BED_LEVELING_UBL)
145
+        set_bed_leveling_enabled(true);  // turn back on after changing fade height
146
+      #else
151
         set_current_from_steppers_for_axis(
147
         set_current_from_steppers_for_axis(
152
           #if ABL_PLANAR
148
           #if ABL_PLANAR
153
             ALL_AXES
149
             ALL_AXES
155
             Z_AXIS
151
             Z_AXIS
156
           #endif
152
           #endif
157
         );
153
         );
158
-      }
159
-    #endif
154
+      #endif
155
+    }
160
   }
156
   }
161
 
157
 
162
 #endif // ENABLE_LEVELING_FADE_HEIGHT
158
 #endif // ENABLE_LEVELING_FADE_HEIGHT

+ 0
- 25
Marlin/src/feature/bedlevel/ubl/ubl.h View File

367
       return z0;
367
       return z0;
368
     }
368
     }
369
 
369
 
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) {
370
     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);
371
       return i < GRID_MAX_POINTS_X ? pgm_read_float(&_mesh_index_to_xpos[i]) : UBL_MESH_MIN_X + i * (MESH_X_DIST);
397
     }
372
     }

+ 6
- 6
Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp View File

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
259
 
259
 
260
         float z0 = z_correction_for_x_on_horizontal_mesh_line(x, current_xi, current_yi);
260
         float z0 = z_correction_for_x_on_horizontal_mesh_line(x, current_xi, current_yi);
261
 
261
 
262
-        z0 *= fade_scaling_factor_for_z(end[Z_AXIS]);
262
+        z0 *= planner.fade_scaling_factor_for_z(end[Z_AXIS]);
263
 
263
 
264
         /**
264
         /**
265
          * If part of the Mesh is undefined, it will show up as NAN
265
          * If part of the Mesh is undefined, it will show up as NAN
324
 
324
 
325
         float z0 = z_correction_for_y_on_vertical_mesh_line(y, current_xi, current_yi);
325
         float z0 = z_correction_for_y_on_vertical_mesh_line(y, current_xi, current_yi);
326
 
326
 
327
-        z0 *= fade_scaling_factor_for_z(end[Z_AXIS]);
327
+        z0 *= planner.fade_scaling_factor_for_z(end[Z_AXIS]);
328
 
328
 
329
         /**
329
         /**
330
          * If part of the Mesh is undefined, it will show up as NAN
330
          * If part of the Mesh is undefined, it will show up as NAN
397
         // Yes!  Crossing a Y Mesh Line next
397
         // 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);
398
         float z0 = z_correction_for_x_on_horizontal_mesh_line(x, current_xi - left_flag, current_yi + dyi);
399
 
399
 
400
-        z0 *= fade_scaling_factor_for_z(end[Z_AXIS]);
400
+        z0 *= planner.fade_scaling_factor_for_z(end[Z_AXIS]);
401
 
401
 
402
         /**
402
         /**
403
          * If part of the Mesh is undefined, it will show up as NAN
403
          * If part of the Mesh is undefined, it will show up as NAN
425
         // Yes!  Crossing a X Mesh Line next
425
         // 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);
426
         float z0 = z_correction_for_y_on_vertical_mesh_line(y, current_xi + dxi, current_yi - down_flag);
427
 
427
 
428
-        z0 *= fade_scaling_factor_for_z(end[Z_AXIS]);
428
+        z0 *= planner.fade_scaling_factor_for_z(end[Z_AXIS]);
429
 
429
 
430
         /**
430
         /**
431
          * If part of the Mesh is undefined, it will show up as NAN
431
          * If part of the Mesh is undefined, it will show up as NAN
616
       // Otherwise perform per-segment leveling
616
       // Otherwise perform per-segment leveling
617
 
617
 
618
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
618
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
619
-        const float fade_scaling_factor = fade_scaling_factor_for_z(ltarget[Z_AXIS]);
619
+        const float fade_scaling_factor = planner.fade_scaling_factor_for_z(ltarget[Z_AXIS]);
620
       #endif
620
       #endif
621
 
621
 
622
       // increment to first segment destination
622
       // increment to first segment destination

+ 17
- 31
Marlin/src/module/planner.cpp View File

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)
557
 
558
 
558
     if (!LEVELING_IS_ACTIVE()) return;
559
     if (!LEVELING_IS_ACTIVE()) return;
559
 
560
 
560
-    #if ENABLED(AUTO_BED_LEVELING_UBL)
561
-      #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
562
-        // if z_fade_height enabled (nonzero) and raw_z above it, no leveling required
563
-        if (planner.z_fade_height && planner.z_fade_height <= RAW_Z_POSITION(lz)) return;
564
-        lz += ubl.get_z_correction(lx, ly) * ubl.fade_scaling_factor_for_z(lz);
565
-      #else // no fade
566
-        lz += ubl.get_z_correction(lx, ly);
567
-      #endif // FADE
568
-    #endif // UBL
569
-
570
-    #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) && DISABLED(AUTO_BED_LEVELING_UBL)
571
-      static float z_fade_factor = 1.0, last_raw_lz = -999.0;
572
-      if (z_fade_height) {
573
-        const float raw_lz = RAW_Z_POSITION(lz);
574
-        if (raw_lz >= z_fade_height) return;
575
-        if (last_raw_lz != raw_lz) {
576
-          last_raw_lz = raw_lz;
577
-          z_fade_factor = 1.0 - raw_lz * inverse_z_fade_height;
578
-        }
579
-      }
580
-      else
581
-        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;
582
     #endif
566
     #endif
583
 
567
 
584
-    #if ENABLED(MESH_BED_LEVELING)
568
+    #if ENABLED(AUTO_BED_LEVELING_UBL)
569
+
570
+      lz += ubl.get_z_correction(lx, ly) * fade_scaling_factor;
571
+
572
+    #elif ENABLED(MESH_BED_LEVELING)
585
 
573
 
586
       lz += mbl.get_z(RAW_X_POSITION(lx), RAW_Y_POSITION(ly)
574
       lz += mbl.get_z(RAW_X_POSITION(lx), RAW_Y_POSITION(ly)
587
         #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
575
         #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
588
-          , z_fade_factor
576
+          , fade_scaling_factor
589
         #endif
577
         #endif
590
-        );
578
+      );
591
 
579
 
592
     #elif ABL_PLANAR
580
     #elif ABL_PLANAR
593
 
581
 
582
+      UNUSED(fade_scaling_factor);
583
+
594
       float dx = RAW_X_POSITION(lx) - (X_TILT_FULCRUM),
584
       float dx = RAW_X_POSITION(lx) - (X_TILT_FULCRUM),
595
             dy = RAW_Y_POSITION(ly) - (Y_TILT_FULCRUM),
585
             dy = RAW_Y_POSITION(ly) - (Y_TILT_FULCRUM),
596
             dz = RAW_Z_POSITION(lz);
586
             dz = RAW_Z_POSITION(lz);
604
     #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
594
     #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
605
 
595
 
606
       float tmp[XYZ] = { lx, ly, 0 };
596
       float tmp[XYZ] = { lx, ly, 0 };
607
-      lz += bilinear_z_offset(tmp)
608
-        #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
609
-          * z_fade_factor
610
-        #endif
611
-      ;
597
+      lz += bilinear_z_offset(tmp) * fade_scaling_factor;
612
 
598
 
613
     #endif
599
     #endif
614
   }
600
   }

+ 32
- 0
Marlin/src/module/planner.h View File

263
         if (!filament_size[i]) filament_size[i] = DEFAULT_NOMINAL_FILAMENT_DIA;
263
         if (!filament_size[i]) filament_size[i] = DEFAULT_NOMINAL_FILAMENT_DIA;
264
     }
264
     }
265
 
265
 
266
+    #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
267
+
268
+      /**
269
+       * Get the Z leveling fade factor based on the given Z height,
270
+       * re-calculating only when needed.
271
+       *
272
+       *  Returns 1.0 if planner.z_fade_height is 0.0.
273
+       *  Returns 0.0 if Z is past the specified 'Fade Height'.
274
+       */
275
+      inline static float fade_scaling_factor_for_z(const float &lz) {
276
+        static float z_fade_factor = 1.0, last_raw_lz = -999.0;
277
+        if (z_fade_height) {
278
+          const float raw_lz = RAW_Z_POSITION(lz);
279
+          if (raw_lz >= z_fade_height) return 0.0;
280
+          if (last_raw_lz != raw_lz) {
281
+            last_raw_lz = raw_lz;
282
+            z_fade_factor = 1.0 - raw_lz * inverse_z_fade_height;
283
+          }
284
+          return z_fade_factor;
285
+        }
286
+        return 1.0;
287
+      }
288
+
289
+    #else
290
+
291
+      FORCE_INLINE static float fade_scaling_factor_for_z(const float &lz) {
292
+        UNUSED(lz);
293
+        return 1.0;
294
+      }
295
+
296
+    #endif
297
+
266
     #if PLANNER_LEVELING
298
     #if PLANNER_LEVELING
267
 
299
 
268
       #define ARG_X float lx
300
       #define ARG_X float lx

Loading…
Cancel
Save