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

Fix logic of UBL::fade_scaling_factor_for_z

Scott Lahteine 8 лет назад
Родитель
Сommit
7310110ec0
4 измененных файлов: 17 добавлений и 26 удалений
  1. 2
    2
      Marlin/Marlin_main.cpp
  2. 11
    18
      Marlin/UBL.h
  3. 3
    4
      Marlin/UBL_Bed_Leveling.cpp
  4. 1
    2
      Marlin/UBL_G29.cpp

+ 2
- 2
Marlin/Marlin_main.cpp Просмотреть файл

@@ -10175,6 +10175,8 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
10175 10175
   /**
10176 10176
    * Prepare a linear move in a Cartesian setup.
10177 10177
    * If Mesh Bed Leveling is enabled, perform a mesh move.
10178
+   *
10179
+   * Returns true if the caller didn't update current_position.
10178 10180
    */
10179 10181
   inline bool prepare_move_to_destination_cartesian() {
10180 10182
     // Do not use feedrate_percentage for E or Z only moves
@@ -10190,9 +10192,7 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
10190 10192
         else
10191 10193
       #elif ENABLED(AUTO_BED_LEVELING_UBL)
10192 10194
         if (ubl.state.active) {
10193
-
10194 10195
           ubl_line_to_destination(MMS_SCALED(feedrate_mm_s), active_extruder);
10195
-
10196 10196
           return false;
10197 10197
         }
10198 10198
         else

+ 11
- 18
Marlin/UBL.h Просмотреть файл

@@ -98,9 +98,6 @@
98 98
         float g29_correction_fade_height = 10.0,
99 99
               g29_fade_height_multiplier = 1.0 / 10.0; // It's cheaper to do a floating point multiply than divide,
100 100
                                                        // so keep this value and its reciprocal.
101
-      #else
102
-        const float g29_correction_fade_height = 10.0,
103
-                    g29_fade_height_multiplier = 1.0 / 10.0;
104 101
       #endif
105 102
 
106 103
       // If you change this struct, adjust TOTAL_STRUCT_SIZE
@@ -118,8 +115,7 @@
118 115
     class unified_bed_leveling {
119 116
       private:
120 117
 
121
-        static float last_specified_z,
122
-                     fade_scaling_factor_for_current_height;
118
+        static float last_specified_z;
123 119
 
124 120
       public:
125 121
 
@@ -307,32 +303,29 @@
307 303
         }
308 304
 
309 305
         /**
310
-         * This routine is used to scale the Z correction depending upon the current nozzle height. It is
311
-         * optimized for speed. It avoids floating point operations by checking if the requested scaling
312
-         * factor is going to be the same as the last time the function calculated a value. If so, it just
313
-         * returns it.
306
+         * This function sets the Z leveling fade factor based on the given Z height,
307
+         * only re-calculating when necessary.
314 308
          *
315
-         * It returns a scaling factor of 1.0 if UBL is inactive.
316
-         * It returns a scaling factor of 0.0 if Z is past the specified 'Fade Height'
309
+         *  Returns 1.0 if g29_correction_fade_height is 0.0.
310
+         *  Returns 0.0 if Z is past the specified 'Fade Height'.
317 311
          */
318 312
         #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
319 313
 
320 314
           static FORCE_INLINE float fade_scaling_factor_for_z(const float &lz) {
315
+            if (state.g29_correction_fade_height == 0.0) return 1.0;
316
+
317
+            static float fade_scaling_factor = 1.0;
321 318
             const float rz = RAW_Z_POSITION(lz);
322 319
             if (last_specified_z != rz) {
323 320
               last_specified_z = rz;
324
-              fade_scaling_factor_for_current_height =
325
-                state.active && rz < state.g29_correction_fade_height
321
+              fade_scaling_factor =
322
+                rz < state.g29_correction_fade_height
326 323
                   ? 1.0 - (rz * state.g29_fade_height_multiplier)
327 324
                   : 0.0;
328 325
             }
329
-            return fade_scaling_factor_for_current_height;
326
+            return fade_scaling_factor;
330 327
           }
331 328
 
332
-        #else
333
-
334
-          static constexpr float fade_scaling_factor_for_z(const float &lz) { UNUSED(lz); return 1.0; }
335
-
336 329
         #endif
337 330
 
338 331
     }; // class unified_bed_leveling

+ 3
- 4
Marlin/UBL_Bed_Leveling.cpp Просмотреть файл

@@ -61,7 +61,6 @@
61 61
 
62 62
   float unified_bed_leveling::z_values[UBL_MESH_NUM_X_POINTS][UBL_MESH_NUM_Y_POINTS],
63 63
         unified_bed_leveling::last_specified_z,
64
-        unified_bed_leveling::fade_scaling_factor_for_current_height,
65 64
         unified_bed_leveling::mesh_index_to_xpos[UBL_MESH_NUM_X_POINTS + 1], // +1 safety margin for now, until determinism prevails
66 65
         unified_bed_leveling::mesh_index_to_ypos[UBL_MESH_NUM_Y_POINTS + 1];
67 66
 
@@ -102,8 +101,9 @@
102 101
        * updated, but until then, we try to ease the transition
103 102
        * for our Beta testers.
104 103
        */
105
-      if (ubl.state.g29_fade_height_multiplier != 1.0 / ubl.state.g29_correction_fade_height) {
106
-        ubl.state.g29_fade_height_multiplier = 1.0 / ubl.state.g29_correction_fade_height;
104
+      const float recip = ubl.state.g29_correction_fade_height ? 1.0 / ubl.state.g29_correction_fade_height : 1.0;
105
+      if (ubl.state.g29_fade_height_multiplier != recip) {
106
+        ubl.state.g29_fade_height_multiplier = recip;
107 107
         store_state();
108 108
       }
109 109
     #endif
@@ -160,7 +160,6 @@
160 160
     ZERO(z_values);
161 161
 
162 162
     last_specified_z = -999.9;
163
-    fade_scaling_factor_for_current_height = 0.0;
164 163
   }
165 164
 
166 165
   void unified_bed_leveling::invalidate() {

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

@@ -1132,8 +1132,7 @@
1132 1132
     safe_delay(50);
1133 1133
 
1134 1134
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1135
-      SERIAL_PROTOCOLPAIR("g29_correction_fade_height : ", ubl.state.g29_correction_fade_height);
1136
-      SERIAL_EOL;
1135
+      SERIAL_PROTOCOLLNPAIR("g29_correction_fade_height : ", ubl.state.g29_correction_fade_height);
1137 1136
     #endif
1138 1137
 
1139 1138
     SERIAL_PROTOCOLPGM("z_offset: ");

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