@ -3450,7 +3450,7 @@ inline void gcode_G28() {
stepper . synchronize ( ) ;
stepper . synchronize ( ) ;
// Disable the leveling matrix before homing
// Disable the leveling matrix before homing
# if PLANNER_LEVELING
# if PLANNER_LEVELING || ENABLED(MESH_BED_LEVELING)
set_bed_leveling_enabled ( false ) ;
set_bed_leveling_enabled ( false ) ;
# endif
# endif
@ -3464,31 +3464,6 @@ inline void gcode_G28() {
extruder_duplication_enabled = false ;
extruder_duplication_enabled = false ;
# endif
# endif
/**
* For mesh bed leveling deactivate the mesh calculations , will be turned
* on again when homing all axis
*/
# if ENABLED(MESH_BED_LEVELING)
float pre_home_z = MESH_HOME_SEARCH_Z ;
if ( mbl . active ( ) ) {
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( DEBUGGING ( LEVELING ) ) SERIAL_ECHOLNPGM ( " MBL was active " ) ;
# endif
// Use known Z position if already homed
if ( axis_homed [ X_AXIS ] & & axis_homed [ Y_AXIS ] & & axis_homed [ Z_AXIS ] ) {
set_bed_leveling_enabled ( false ) ;
pre_home_z = current_position [ Z_AXIS ] ;
}
else {
mbl . set_active ( false ) ;
current_position [ Z_AXIS ] = pre_home_z ;
}
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( DEBUGGING ( LEVELING ) ) DEBUG_POS ( " Set Z to pre_home_z " , current_position ) ;
# endif
}
# endif
setup_for_endstop_or_probe_move ( ) ;
setup_for_endstop_or_probe_move ( ) ;
# if ENABLED(DEBUG_LEVELING_FEATURE)
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( DEBUGGING ( LEVELING ) ) SERIAL_ECHOLNPGM ( " > endstops.enable(true) " ) ;
if ( DEBUGGING ( LEVELING ) ) SERIAL_ECHOLNPGM ( " > endstops.enable(true) " ) ;
@ -3620,43 +3595,14 @@ inline void gcode_G28() {
// Enable mesh leveling again
// Enable mesh leveling again
# if ENABLED(MESH_BED_LEVELING)
# if ENABLED(MESH_BED_LEVELING)
if ( mbl . has_mesh ( ) ) {
if ( mbl . reactivate ( ) ) {
# if ENABLED(DEBUG_LEVELING_FEATURE)
set_bed_leveling_enabled ( true ) ;
if ( DEBUGGING ( LEVELING ) ) SERIAL_ECHOLNPGM ( " MBL has mesh " ) ;
# endif
if ( home_all_axis | | ( axis_homed [ X_AXIS ] & & axis_homed [ Y_AXIS ] & & homeZ ) ) {
if ( home_all_axis | | ( axis_homed [ X_AXIS ] & & axis_homed [ Y_AXIS ] & & homeZ ) ) {
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( DEBUGGING ( LEVELING ) ) SERIAL_ECHOLNPGM ( " MBL Z homing " ) ;
# endif
current_position [ Z_AXIS ] = MESH_HOME_SEARCH_Z
# if Z_HOME_DIR > 0
+ Z_MAX_POS
# endif
;
SYNC_PLAN_POSITION_KINEMATIC ( ) ;
mbl . set_active ( true ) ;
# if ENABLED(MESH_G28_REST_ORIGIN)
# if ENABLED(MESH_G28_REST_ORIGIN)
current_position [ Z_AXIS ] = 0.0 ;
current_position [ Z_AXIS ] = LOGICAL_Z_POSITION ( Z_MIN_POS ) ;
set_destination_to_current ( ) ;
set_destination_to_current ( ) ;
line_to_destination ( homing_feedrate_mm_s [ Z_AXIS ] ) ;
line_to_destination ( homing_feedrate_mm_s [ Z_AXIS ] ) ;
stepper . synchronize ( ) ;
stepper . synchronize ( ) ;
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( DEBUGGING ( LEVELING ) ) DEBUG_POS ( " MBL Rest Origin " , current_position ) ;
# endif
# else
planner . unapply_leveling ( current_position ) ;
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( DEBUGGING ( LEVELING ) ) DEBUG_POS ( " MBL adjusted MESH_HOME_SEARCH_Z " , current_position ) ;
# endif
# endif
}
else if ( ( axis_homed [ X_AXIS ] & & axis_homed [ Y_AXIS ] & & axis_homed [ Z_AXIS ] ) & & ( homeX | | homeY ) ) {
current_position [ Z_AXIS ] = pre_home_z ;
SYNC_PLAN_POSITION_KINEMATIC ( ) ;
mbl . set_active ( true ) ;
planner . unapply_leveling ( current_position ) ;
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( DEBUGGING ( LEVELING ) ) DEBUG_POS ( " MBL Home X or Y " , current_position ) ;
# endif
# endif
}
}
}
}
@ -3664,16 +3610,16 @@ inline void gcode_G28() {
clean_up_after_endstop_or_probe_move ( ) ;
clean_up_after_endstop_or_probe_move ( ) ;
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( DEBUGGING ( LEVELING ) ) SERIAL_ECHOLNPGM ( " <<< gcode_G28 " ) ;
# endif
// Restore the active tool after homing
// Restore the active tool after homing
# if HOTENDS > 1
# if HOTENDS > 1
tool_change ( old_tool_index , 0 , true ) ;
tool_change ( old_tool_index , 0 , true ) ;
# endif
# endif
report_current_position ( ) ;
report_current_position ( ) ;
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( DEBUGGING ( LEVELING ) ) SERIAL_ECHOLNPGM ( " <<< gcode_G28 " ) ;
# endif
}
}
# if HAS_PROBING_PROCEDURE
# if HAS_PROBING_PROCEDURE
@ -3690,25 +3636,21 @@ inline void gcode_G28() {
inline void _mbl_goto_xy ( const float & x , const float & y ) {
inline void _mbl_goto_xy ( const float & x , const float & y ) {
const float old_feedrate_mm_s = feedrate_mm_s ;
const float old_feedrate_mm_s = feedrate_mm_s ;
feedrate_mm_s = homing_feedrate_mm_s [ Z_AXIS ] ;
current_position [ Z_AXIS ] = MESH_HOME_SEARCH_Z
# if MANUAL_PROBE_HEIGHT > 0
# if Z_CLEARANCE_BETWEEN_PROBES > Z_HOMING_HEIGHT
feedrate_mm_s = homing_feedrate_mm_s [ Z_AXIS ] ;
+ Z_CLEARANCE_BETWEEN_PROBES
current_position [ Z_AXIS ] = LOGICAL_Z_POSITION ( Z_MIN_POS ) + MANUAL_PROBE_HEIGHT ;
# elif Z_HOMING_HEIGHT > 0
line_to_current_position ( ) ;
+ Z_HOMING_HEIGHT
# endif
# endif
;
line_to_current_position ( ) ;
feedrate_mm_s = MMM_TO_MMS ( XY_PROBE_SPEED ) ;
feedrate_mm_s = MMM_TO_MMS ( XY_PROBE_SPEED ) ;
current_position [ X_AXIS ] = LOGICAL_X_POSITION ( x ) ;
current_position [ X_AXIS ] = LOGICAL_X_POSITION ( x ) ;
current_position [ Y_AXIS ] = LOGICAL_Y_POSITION ( y ) ;
current_position [ Y_AXIS ] = LOGICAL_Y_POSITION ( y ) ;
line_to_current_position ( ) ;
line_to_current_position ( ) ;
# if Z_CLEARANCE_BETWEEN_PROBES > 0 || Z_HOMING _HEIGHT > 0
# if MANUAL_PROBE _HEIGHT > 0
feedrate_mm_s = homing_feedrate_mm_s [ Z_AXIS ] ;
feedrate_mm_s = homing_feedrate_mm_s [ Z_AXIS ] ;
current_position [ Z_AXIS ] = LOGICAL_Z_POSITION ( MESH_HOME_SEARCH_Z) ;
current_position [ Z_AXIS ] = LOGICAL_Z_POSITION ( Z_MIN_POS) + 0.2 ; // just slightly over the bed
line_to_current_position ( ) ;
line_to_current_position ( ) ;
# endif
# endif
@ -3721,7 +3663,6 @@ inline void gcode_G28() {
void mbl_mesh_report ( ) {
void mbl_mesh_report ( ) {
SERIAL_PROTOCOLLNPGM ( " Num X,Y: " STRINGIFY ( MESH_NUM_X_POINTS ) " , " STRINGIFY ( MESH_NUM_Y_POINTS ) ) ;
SERIAL_PROTOCOLLNPGM ( " Num X,Y: " STRINGIFY ( MESH_NUM_X_POINTS ) " , " STRINGIFY ( MESH_NUM_Y_POINTS ) ) ;
SERIAL_PROTOCOLLNPGM ( " Z search height: " STRINGIFY ( MESH_HOME_SEARCH_Z ) ) ;
SERIAL_PROTOCOLPGM ( " Z offset: " ) ; SERIAL_PROTOCOL_F ( mbl . z_offset , 5 ) ;
SERIAL_PROTOCOLPGM ( " Z offset: " ) ; SERIAL_PROTOCOL_F ( mbl . z_offset , 5 ) ;
SERIAL_PROTOCOLLNPGM ( " \n Measured points: " ) ;
SERIAL_PROTOCOLLNPGM ( " \n Measured points: " ) ;
for ( uint8_t py = 0 ; py < MESH_NUM_Y_POINTS ; py + + ) {
for ( uint8_t py = 0 ; py < MESH_NUM_Y_POINTS ; py + + ) {
@ -3757,6 +3698,10 @@ inline void gcode_G28() {
inline void gcode_G29 ( ) {
inline void gcode_G29 ( ) {
static int probe_index = - 1 ;
static int probe_index = - 1 ;
# if ENABLED(min_software_endstops) || ENABLED(max_software_endstops)
static bool enable_soft_endstops ;
# endif
const MeshLevelingState state = code_seen ( ' S ' ) ? ( MeshLevelingState ) code_value_byte ( ) : MeshReport ;
const MeshLevelingState state = code_seen ( ' S ' ) ? ( MeshLevelingState ) code_value_byte ( ) : MeshReport ;
if ( state < 0 | | state > 5 ) {
if ( state < 0 | | state > 5 ) {
SERIAL_PROTOCOLLNPGM ( " S out of range (0-5). " ) ;
SERIAL_PROTOCOLLNPGM ( " S out of range (0-5). " ) ;
@ -3788,33 +3733,34 @@ inline void gcode_G28() {
}
}
// For each G29 S2...
// For each G29 S2...
if ( probe_index = = 0 ) {
if ( probe_index = = 0 ) {
// For the initial G29 S2 make Z a positive value (e.g., 4.0)
# if ENABLED(min_software_endstops) || ENABLED(max_software_endstops)
current_position [ Z_AXIS ] = MESH_HOME_SEARCH_Z
// For the initial G29 S2 save software endstop state
# if Z_HOME_DIR > 0
enable_soft_endstops = soft_endstops_enabled ;
+ Z_MAX_POS
# endif
# endif
;
SYNC_PLAN_POSITION_KINEMATIC ( ) ;
}
}
else {
else {
// For G29 S2 after adjusting Z.
// For G29 S2 after adjusting Z.
mbl . set_zigzag_z ( probe_index - 1 , current_position [ Z_AXIS ] ) ;
mbl . set_zigzag_z ( probe_index - 1 , current_position [ Z_AXIS ] ) ;
# if ENABLED(min_software_endstops) || ENABLED(max_software_endstops)
soft_endstops_enabled = enable_soft_endstops ;
# endif
}
}
// If there's another point to sample, move there with optional lift.
// If there's another point to sample, move there with optional lift.
if ( probe_index < ( MESH_NUM_X_POINTS ) * ( MESH_NUM_Y_POINTS ) ) {
if ( probe_index < ( MESH_NUM_X_POINTS ) * ( MESH_NUM_Y_POINTS ) ) {
mbl . zigzag ( probe_index , px , py ) ;
mbl . zigzag ( probe_index , px , py ) ;
_mbl_goto_xy ( mbl . get_probe_x ( px ) , mbl . get_probe_y ( py ) ) ;
_mbl_goto_xy ( mbl . get_probe_x ( px ) , mbl . get_probe_y ( py ) ) ;
# if ENABLED(min_software_endstops) || ENABLED(max_software_endstops)
// Disable software endstops to allow manual adjustment
// If G29 is not completed, they will not be re-enabled
soft_endstops_enabled = false ;
# endif
probe_index + + ;
probe_index + + ;
}
}
else {
else {
// One last "return to the bed" (as originally coded) at completion
// One last "return to the bed" (as originally coded) at completion
current_position [ Z_AXIS ] = MESH_HOME_SEARCH_Z
current_position [ Z_AXIS ] = LOGICAL_Z_POSITION ( Z_MIN_POS ) + MANUAL_PROBE_HEIGHT ;
# if Z_CLEARANCE_BETWEEN_PROBES > Z_HOMING_HEIGHT
+ Z_CLEARANCE_BETWEEN_PROBES
# elif Z_HOMING_HEIGHT > 0
+ Z_HOMING_HEIGHT
# endif
;
line_to_current_position ( ) ;
line_to_current_position ( ) ;
stepper . synchronize ( ) ;
stepper . synchronize ( ) ;
@ -3822,7 +3768,12 @@ inline void gcode_G28() {
SERIAL_PROTOCOLLNPGM ( " Mesh probing done. " ) ;
SERIAL_PROTOCOLLNPGM ( " Mesh probing done. " ) ;
probe_index = - 1 ;
probe_index = - 1 ;
mbl . set_has_mesh ( true ) ;
mbl . set_has_mesh ( true ) ;
mbl . set_reactivate ( true ) ;
enqueue_and_echo_commands_P ( PSTR ( " G28 " ) ) ;
enqueue_and_echo_commands_P ( PSTR ( " G28 " ) ) ;
# if HAS_BUZZER
lcd_buzz ( 200 , 659 ) ;
lcd_buzz ( 200 , 698 ) ;
# endif
}
}
break ;
break ;
@ -3871,14 +3822,8 @@ inline void gcode_G28() {
break ;
break ;
case MeshReset :
case MeshReset :
if ( mbl . active ( ) ) {
reset_bed_level ( ) ;
current_position [ Z_AXIS ] - = MESH_HOME_SEARCH_Z ;
break ;
planner . apply_leveling ( current_position [ X_AXIS ] , current_position [ Y_AXIS ] , current_position [ Z_AXIS ] ) ;
mbl . reset ( ) ;
SYNC_PLAN_POSITION_KINEMATIC ( ) ;
}
else
mbl . reset ( ) ;
} // switch(state)
} // switch(state)