diff --git a/Marlin/src/feature/bedlevel/bedlevel.cpp b/Marlin/src/feature/bedlevel/bedlevel.cpp index 4aa6eb4a42..f6b5160184 100644 --- a/Marlin/src/feature/bedlevel/bedlevel.cpp +++ b/Marlin/src/feature/bedlevel/bedlevel.cpp @@ -128,13 +128,17 @@ void set_bed_leveling_enabled(const bool enable/*=true*/) { // so compensation will give the right stepper counts. planner.unapply_leveling(current_position); + SYNC_PLAN_POSITION_KINEMATIC(); + #endif // OLDSCHOOL_ABL } } #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) - void set_z_fade_height(const float zfh) { + void set_z_fade_height(const float zfh, const bool do_report/*=true*/) { + + if (planner.z_fade_height == zfh) return; // do nothing if no change const bool level_active = planner.leveling_active; @@ -145,6 +149,10 @@ void set_bed_leveling_enabled(const bool enable/*=true*/) { planner.set_z_fade_height(zfh); if (level_active) { + const float oldpos[XYZE] = { + current_position[X_AXIS], current_position[Y_AXIS], + current_position[Z_AXIS], current_position[E_AXIS] + }; #if ENABLED(AUTO_BED_LEVELING_UBL) set_bed_leveling_enabled(true); // turn back on after changing fade height #else @@ -155,7 +163,10 @@ void set_bed_leveling_enabled(const bool enable/*=true*/) { Z_AXIS #endif ); + SYNC_PLAN_POSITION_KINEMATIC(); #endif + if (do_report && memcmp(oldpos, current_position, sizeof(oldpos))) + report_current_position(); } } diff --git a/Marlin/src/feature/bedlevel/bedlevel.h b/Marlin/src/feature/bedlevel/bedlevel.h index 57d69db31e..623fb07859 100644 --- a/Marlin/src/feature/bedlevel/bedlevel.h +++ b/Marlin/src/feature/bedlevel/bedlevel.h @@ -47,7 +47,7 @@ void set_bed_leveling_enabled(const bool enable=true); void reset_bed_level(); #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) - void set_z_fade_height(const float zfh); + void set_z_fade_height(const float zfh, const bool do_report=true); #endif #if ENABLED(AUTO_BED_LEVELING_BILINEAR) || ENABLED(MESH_BED_LEVELING) diff --git a/Marlin/src/feature/bedlevel/ubl/ubl.cpp b/Marlin/src/feature/bedlevel/ubl/ubl.cpp index f32bfe3fa2..3e6e983ad1 100644 --- a/Marlin/src/feature/bedlevel/ubl/ubl.cpp +++ b/Marlin/src/feature/bedlevel/ubl/ubl.cpp @@ -71,17 +71,19 @@ volatile int unified_bed_leveling::encoder_diff; unified_bed_leveling::unified_bed_leveling() { - ubl_cnt++; // Debug counter to insure we only have one UBL object present in memory. We can eliminate this (and all references to ubl_cnt) very soon. + ubl_cnt++; // Debug counter to ensure we only have one UBL object present in memory. We can eliminate this (and all references to ubl_cnt) very soon. reset(); } void unified_bed_leveling::reset() { + const bool was_enabled = planner.leveling_active; set_bed_leveling_enabled(false); storage_slot = -1; #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) planner.set_z_fade_height(10.0); #endif ZERO(z_values); + if (was_enabled) report_current_position(); } void unified_bed_leveling::invalidate() { diff --git a/Marlin/src/gcode/bedlevel/M420.cpp b/Marlin/src/gcode/bedlevel/M420.cpp index 30050ae9d1..71bf7e2738 100644 --- a/Marlin/src/gcode/bedlevel/M420.cpp +++ b/Marlin/src/gcode/bedlevel/M420.cpp @@ -108,7 +108,7 @@ void GcodeSuite::M420() { if (parser.seen('S')) set_bed_leveling_enabled(to_enable); #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) - if (parser.seen('Z')) set_z_fade_height(parser.value_linear_units()); + if (parser.seen('Z')) set_z_fade_height(parser.value_linear_units(), false); #endif const bool new_status = planner.leveling_active; diff --git a/Marlin/src/gcode/bedlevel/abl/G29.cpp b/Marlin/src/gcode/bedlevel/abl/G29.cpp index 892d71030b..0b32d8144f 100644 --- a/Marlin/src/gcode/bedlevel/abl/G29.cpp +++ b/Marlin/src/gcode/bedlevel/abl/G29.cpp @@ -285,6 +285,7 @@ void GcodeSuite::G29() { bed_level_virt_interpolate(); #endif set_bed_leveling_enabled(abl_should_enable); + if (abl_should_enable) report_current_position(); } return; } // parser.seen('W') diff --git a/Marlin/src/module/motion.cpp b/Marlin/src/module/motion.cpp index b013faf353..1384cb9c52 100644 --- a/Marlin/src/module/motion.cpp +++ b/Marlin/src/module/motion.cpp @@ -211,6 +211,12 @@ void get_cartesian_from_steppers() { * Set the current_position for an axis based on * the stepper positions, removing any leveling that * may have been applied. + * + * To prevent small shifts in axis position always call + * SYNC_PLAN_POSITION_KINEMATIC after updating axes with this. + * + * To keep hosts in sync, always call report_current_position + * after updating the current_position. */ void set_current_from_steppers_for_axis(const AxisEnum axis) { get_cartesian_from_steppers();