Patches for leveling reactivation in G28 / M48

This commit is contained in:
Scott Lahteine 2017-05-01 17:34:28 -05:00
parent 7d5cd7e0d7
commit e79b335367
3 changed files with 36 additions and 50 deletions

View file

@ -2429,7 +2429,7 @@ static void clean_up_after_endstop_or_probe_move() {
ubl.state.active = enable;
//set_current_from_steppers_for_axis(Z_AXIS);
#elif HAS_ABL
#else
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
const bool can_change = (!enable || (bilinear_grid_spacing[0] && bilinear_grid_spacing[1]));
@ -3750,9 +3750,6 @@ inline void gcode_G28() {
// Disable the leveling matrix before homing
#if HAS_LEVELING
#if ENABLED(AUTO_BED_LEVELING_UBL)
const bool bed_leveling_state_at_entry = ubl.state.active;
#endif
set_bed_leveling_enabled(false);
#endif
@ -3895,25 +3892,6 @@ inline void gcode_G28() {
do_blocking_move_to_z(delta_clip_start_height);
#endif
#if ENABLED(AUTO_BED_LEVELING_UBL)
set_bed_leveling_enabled(bed_leveling_state_at_entry);
#endif
// Enable mesh leveling again
#if ENABLED(MESH_BED_LEVELING)
if (mbl.reactivate()) {
set_bed_leveling_enabled(true);
if (home_all_axis || (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && homeZ)) {
#if ENABLED(MESH_G28_REST_ORIGIN)
current_position[Z_AXIS] = LOGICAL_Z_POSITION(Z_MIN_POS);
set_destination_to_current();
line_to_destination(homing_feedrate_mm_s[Z_AXIS]);
stepper.synchronize();
#endif
}
}
#endif
clean_up_after_endstop_or_probe_move();
// Restore the active tool after homing
@ -3982,6 +3960,18 @@ void home_all_axes() { gcode_G28(); }
);
}
void mesh_probing_done() {
mbl.set_has_mesh(true);
home_all_axes();
set_bed_leveling_enabled(true);
#if ENABLED(MESH_G28_REST_ORIGIN)
current_position[Z_AXIS] = LOGICAL_Z_POSITION(Z_MIN_POS);
set_destination_to_current();
line_to_destination(homing_feedrate_mm_s[Z_AXIS]);
stepper.synchronize();
#endif
}
/**
* G29: Mesh-based Z probe, probes a grid and produces a
* mesh to compensate for variable bed height
@ -4072,14 +4062,12 @@ void home_all_axes() { gcode_G28(); }
line_to_current_position();
stepper.synchronize();
// After recording the last point, activate the mbl and home
SERIAL_PROTOCOLLNPGM("Mesh probing done.");
// After recording the last point, activate home and activate
mbl_probe_index = -1;
mbl.set_has_mesh(true);
mbl.set_reactivate(true);
enqueue_and_echo_commands_P(PSTR("G28"));
SERIAL_PROTOCOLLNPGM("Mesh probing done.");
BUZZ(100, 659);
BUZZ(100, 698);
mesh_probing_done();
}
break;
@ -5015,7 +5003,7 @@ void home_all_axes() { gcode_G28(); }
SYNC_PLAN_POSITION_KINEMATIC();
}
#endif // HAS_ABL && DISABLED(AUTO_BED_LEVELING_UBL)
#endif // HAS_ABL && !AUTO_BED_LEVELING_UBL
#if HAS_BED_PROBE
@ -6200,10 +6188,6 @@ inline void gcode_M42() {
* regenerated.
*/
inline void gcode_M48() {
#if ENABLED(AUTO_BED_LEVELING_UBL)
bool bed_leveling_state_at_entry=0;
bed_leveling_state_at_entry = ubl.state.active;
#endif
if (axis_unhomed_error(true, true, true)) return;
@ -6269,8 +6253,17 @@ inline void gcode_M42() {
SERIAL_PROTOCOLLNPGM("Positioning the probe...");
// Disable bed level correction in M48 because we want the raw data when we probe
#if HAS_ABL
const bool abl_was_enabled = planner.abl_enabled;
#if HAS_LEVELING
const bool was_enabled =
#if ENABLED(AUTO_BED_LEVELING_UBL)
ubl.state.active
#elif ENABLED(MESH_BED_LEVELING)
mbl.active()
#else
planner.abl_enabled
#endif
;
set_bed_leveling_enabled(false);
#endif
@ -6422,14 +6415,9 @@ inline void gcode_M42() {
clean_up_after_endstop_or_probe_move();
// Re-enable bed level correction if it has been on
// Re-enable bed level correction if it had been on
#if HAS_ABL
set_bed_leveling_enabled(abl_was_enabled);
#endif
#if ENABLED(AUTO_BED_LEVELING_UBL)
set_bed_leveling_enabled(bed_leveling_state_at_entry);
ubl.state.active = bed_leveling_state_at_entry;
set_bed_leveling_enabled(was_enabled);
#endif
report_current_position();

View file

@ -36,8 +36,7 @@
enum MBLStatus {
MBL_STATUS_NONE = 0,
MBL_STATUS_HAS_MESH_BIT = 0,
MBL_STATUS_ACTIVE_BIT = 1,
MBL_STATUS_REACTIVATE_BIT = 2
MBL_STATUS_ACTIVE_BIT = 1
};
#define MESH_X_DIST ((MESH_MAX_X - (MESH_MIN_X)) / (GRID_MAX_POINTS_X - 1))
@ -61,8 +60,6 @@
static void set_active(const bool onOff) { onOff ? SBI(status, MBL_STATUS_ACTIVE_BIT) : CBI(status, MBL_STATUS_ACTIVE_BIT); }
static bool has_mesh() { return TEST(status, MBL_STATUS_HAS_MESH_BIT); }
static void set_has_mesh(const bool onOff) { onOff ? SBI(status, MBL_STATUS_HAS_MESH_BIT) : CBI(status, MBL_STATUS_HAS_MESH_BIT); }
static bool reactivate() { bool b = TEST(status, MBL_STATUS_REACTIVATE_BIT); CBI(status, MBL_STATUS_REACTIVATE_BIT); return b; }
static void set_reactivate(const bool onOff) { onOff ? SBI(status, MBL_STATUS_REACTIVATE_BIT) : CBI(status, MBL_STATUS_REACTIVATE_BIT); }
static inline void zigzag(const int8_t index, int8_t &px, int8_t &py) {
px = index % (GRID_MAX_POINTS_X);

View file

@ -162,6 +162,7 @@ uint16_t max_display_update_time = 0;
#if ENABLED(MESH_BED_LEVELING) && ENABLED(LCD_BED_LEVELING)
#include "mesh_bed_leveling.h"
extern void mesh_probing_done();
#endif
////////////////////////////////////////////
@ -1539,9 +1540,9 @@ void kill_screen(const char* lcd_msg) {
// Enable leveling, if needed
#if ENABLED(MESH_BED_LEVELING)
lcd_synchronize();
mbl.set_has_mesh(true);
mbl.set_reactivate(true);
enqueue_and_echo_commands_P(PSTR("G28"));
mesh_probing_done();
#elif ENABLED(AUTO_BED_LEVELING_UBL)