Browse Source

Fix logic of UBL::fade_scaling_factor_for_z

pull/1/head
Scott Lahteine 8 years ago
parent
commit
7310110ec0
  1. 4
      Marlin/Marlin_main.cpp
  2. 29
      Marlin/UBL.h
  3. 7
      Marlin/UBL_Bed_Leveling.cpp
  4. 3
      Marlin/UBL_G29.cpp

4
Marlin/Marlin_main.cpp

@ -10175,6 +10175,8 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
/** /**
* Prepare a linear move in a Cartesian setup. * Prepare a linear move in a Cartesian setup.
* If Mesh Bed Leveling is enabled, perform a mesh move. * If Mesh Bed Leveling is enabled, perform a mesh move.
*
* Returns true if the caller didn't update current_position.
*/ */
inline bool prepare_move_to_destination_cartesian() { inline bool prepare_move_to_destination_cartesian() {
// Do not use feedrate_percentage for E or Z only moves // 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) {
else else
#elif ENABLED(AUTO_BED_LEVELING_UBL) #elif ENABLED(AUTO_BED_LEVELING_UBL)
if (ubl.state.active) { if (ubl.state.active) {
ubl_line_to_destination(MMS_SCALED(feedrate_mm_s), active_extruder); ubl_line_to_destination(MMS_SCALED(feedrate_mm_s), active_extruder);
return false; return false;
} }
else else

29
Marlin/UBL.h

@ -98,9 +98,6 @@
float g29_correction_fade_height = 10.0, float g29_correction_fade_height = 10.0,
g29_fade_height_multiplier = 1.0 / 10.0; // It's cheaper to do a floating point multiply than divide, g29_fade_height_multiplier = 1.0 / 10.0; // It's cheaper to do a floating point multiply than divide,
// so keep this value and its reciprocal. // so keep this value and its reciprocal.
#else
const float g29_correction_fade_height = 10.0,
g29_fade_height_multiplier = 1.0 / 10.0;
#endif #endif
// If you change this struct, adjust TOTAL_STRUCT_SIZE // If you change this struct, adjust TOTAL_STRUCT_SIZE
@ -118,8 +115,7 @@
class unified_bed_leveling { class unified_bed_leveling {
private: private:
static float last_specified_z, static float last_specified_z;
fade_scaling_factor_for_current_height;
public: public:
@ -307,32 +303,29 @@
} }
/** /**
* This routine is used to scale the Z correction depending upon the current nozzle height. It is * This function sets the Z leveling fade factor based on the given Z height,
* optimized for speed. It avoids floating point operations by checking if the requested scaling * only re-calculating when necessary.
* factor is going to be the same as the last time the function calculated a value. If so, it just
* returns it.
* *
* It returns a scaling factor of 1.0 if UBL is inactive. * Returns 1.0 if g29_correction_fade_height is 0.0.
* It returns a scaling factor of 0.0 if Z is past the specified 'Fade Height' * Returns 0.0 if Z is past the specified 'Fade Height'.
*/ */
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
static FORCE_INLINE float fade_scaling_factor_for_z(const float &lz) { static FORCE_INLINE float fade_scaling_factor_for_z(const float &lz) {
if (state.g29_correction_fade_height == 0.0) return 1.0;
static float fade_scaling_factor = 1.0;
const float rz = RAW_Z_POSITION(lz); const float rz = RAW_Z_POSITION(lz);
if (last_specified_z != rz) { if (last_specified_z != rz) {
last_specified_z = rz; last_specified_z = rz;
fade_scaling_factor_for_current_height = fade_scaling_factor =
state.active && rz < state.g29_correction_fade_height rz < state.g29_correction_fade_height
? 1.0 - (rz * state.g29_fade_height_multiplier) ? 1.0 - (rz * state.g29_fade_height_multiplier)
: 0.0; : 0.0;
} }
return fade_scaling_factor_for_current_height; return fade_scaling_factor;
} }
#else
static constexpr float fade_scaling_factor_for_z(const float &lz) { UNUSED(lz); return 1.0; }
#endif #endif
}; // class unified_bed_leveling }; // class unified_bed_leveling

7
Marlin/UBL_Bed_Leveling.cpp

@ -61,7 +61,6 @@
float unified_bed_leveling::z_values[UBL_MESH_NUM_X_POINTS][UBL_MESH_NUM_Y_POINTS], float unified_bed_leveling::z_values[UBL_MESH_NUM_X_POINTS][UBL_MESH_NUM_Y_POINTS],
unified_bed_leveling::last_specified_z, unified_bed_leveling::last_specified_z,
unified_bed_leveling::fade_scaling_factor_for_current_height,
unified_bed_leveling::mesh_index_to_xpos[UBL_MESH_NUM_X_POINTS + 1], // +1 safety margin for now, until determinism prevails unified_bed_leveling::mesh_index_to_xpos[UBL_MESH_NUM_X_POINTS + 1], // +1 safety margin for now, until determinism prevails
unified_bed_leveling::mesh_index_to_ypos[UBL_MESH_NUM_Y_POINTS + 1]; unified_bed_leveling::mesh_index_to_ypos[UBL_MESH_NUM_Y_POINTS + 1];
@ -102,8 +101,9 @@
* updated, but until then, we try to ease the transition * updated, but until then, we try to ease the transition
* for our Beta testers. * for our Beta testers.
*/ */
if (ubl.state.g29_fade_height_multiplier != 1.0 / ubl.state.g29_correction_fade_height) { const float recip = ubl.state.g29_correction_fade_height ? 1.0 / ubl.state.g29_correction_fade_height : 1.0;
ubl.state.g29_fade_height_multiplier = 1.0 / ubl.state.g29_correction_fade_height; if (ubl.state.g29_fade_height_multiplier != recip) {
ubl.state.g29_fade_height_multiplier = recip;
store_state(); store_state();
} }
#endif #endif
@ -160,7 +160,6 @@
ZERO(z_values); ZERO(z_values);
last_specified_z = -999.9; last_specified_z = -999.9;
fade_scaling_factor_for_current_height = 0.0;
} }
void unified_bed_leveling::invalidate() { void unified_bed_leveling::invalidate() {

3
Marlin/UBL_G29.cpp

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

Loading…
Cancel
Save