@ -29,12 +29,12 @@
# include "Marlin.h"
# include "Marlin.h"
# if ENABLED( ENABLE_ AUTO_BED_LEVELING)
# if ENABLED( AUTO_BED_LEVELING_FEATURE )
# include "vector_3.h"
# include "vector_3.h"
# if ENABLED(AUTO_BED_LEVELING_GRID)
# if ENABLED(AUTO_BED_LEVELING_GRID)
# include "qr_solve.h"
# include "qr_solve.h"
# endif
# endif
# endif // ENABLE_ AUTO_BED_LEVELING
# endif // AUTO_BED_LEVELING_FEATURE
# if ENABLED(MESH_BED_LEVELING)
# if ENABLED(MESH_BED_LEVELING)
# include "mesh_bed_leveling.h"
# include "mesh_bed_leveling.h"
@ -288,7 +288,7 @@ static uint8_t target_extruder;
bool no_wait_for_cooling = true ;
bool no_wait_for_cooling = true ;
bool target_direction ;
bool target_direction ;
# if ENABLED( ENABLE_ AUTO_BED_LEVELING)
# if ENABLED( AUTO_BED_LEVELING_FEATURE )
int xy_travel_speed = XY_TRAVEL_SPEED ;
int xy_travel_speed = XY_TRAVEL_SPEED ;
float zprobe_zoffset = Z_PROBE_OFFSET_FROM_EXTRUDER ;
float zprobe_zoffset = Z_PROBE_OFFSET_FROM_EXTRUDER ;
# endif
# endif
@ -366,7 +366,7 @@ bool target_direction;
float delta_diagonal_rod = DELTA_DIAGONAL_ROD ;
float delta_diagonal_rod = DELTA_DIAGONAL_ROD ;
float delta_diagonal_rod_2 = sq ( delta_diagonal_rod ) ;
float delta_diagonal_rod_2 = sq ( delta_diagonal_rod ) ;
float delta_segments_per_second = DELTA_SEGMENTS_PER_SECOND ;
float delta_segments_per_second = DELTA_SEGMENTS_PER_SECOND ;
# if ENABLED( ENABLE_ AUTO_BED_LEVELING)
# if ENABLED( AUTO_BED_LEVELING_FEATURE )
int delta_grid_spacing [ 2 ] = { 0 , 0 } ;
int delta_grid_spacing [ 2 ] = { 0 , 0 } ;
float bed_level [ AUTO_BED_LEVELING_GRID_POINTS ] [ AUTO_BED_LEVELING_GRID_POINTS ] ;
float bed_level [ AUTO_BED_LEVELING_GRID_POINTS ] [ AUTO_BED_LEVELING_GRID_POINTS ] ;
# endif
# endif
@ -1033,6 +1033,19 @@ XYZ_CONSTS_FROM_CONFIG(signed char, home_dir, HOME_DIR);
# endif //DUAL_X_CARRIAGE
# endif //DUAL_X_CARRIAGE
# if ENABLED(DEBUG_LEVELING_FEATURE)
void print_xyz ( const char * prefix , const float x , const float y , const float z ) {
SERIAL_ECHO ( prefix ) ;
SERIAL_ECHOPAIR ( " : ( " , x ) ;
SERIAL_ECHOPAIR ( " , " , y ) ;
SERIAL_ECHOPAIR ( " , " , z ) ;
SERIAL_ECHOLNPGM ( " ) " ) ;
}
void print_xyz ( const char * prefix , const float xyz [ ] ) {
print_xyz ( prefix , xyz [ X_AXIS ] , xyz [ Y_AXIS ] , xyz [ Z_AXIS ] ) ;
}
# endif
static void set_axis_is_at_home ( AxisEnum axis ) {
static void set_axis_is_at_home ( AxisEnum axis ) {
# if ENABLED(DUAL_X_CARRIAGE)
# if ENABLED(DUAL_X_CARRIAGE)
@ -1095,9 +1108,17 @@ static void set_axis_is_at_home(AxisEnum axis) {
min_pos [ axis ] = base_min_pos ( axis ) + home_offset [ axis ] ;
min_pos [ axis ] = base_min_pos ( axis ) + home_offset [ axis ] ;
max_pos [ axis ] = base_max_pos ( axis ) + home_offset [ axis ] ;
max_pos [ axis ] = base_max_pos ( axis ) + home_offset [ axis ] ;
# if ENABLED( ENABLE_ AUTO_BED_LEVELING) && Z_HOME_DIR < 0
# if ENABLED( AUTO_BED_LEVELING_FEATURE ) && Z_HOME_DIR < 0
if ( axis = = Z_AXIS ) current_position [ Z_AXIS ] - = zprobe_zoffset ;
if ( axis = = Z_AXIS ) current_position [ Z_AXIS ] - = zprobe_zoffset ;
# endif
# endif
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOPAIR ( " set_axis_is_at_home " , ( unsigned long ) axis ) ;
SERIAL_ECHOPAIR ( " > (home_offset[axis]== " , home_offset [ axis ] ) ;
print_xyz ( " ) > current_position " , current_position ) ;
}
# endif
}
}
}
}
@ -1143,16 +1164,26 @@ static void setup_for_endstop_move() {
saved_feedrate_multiplier = feedrate_multiplier ;
saved_feedrate_multiplier = feedrate_multiplier ;
feedrate_multiplier = 100 ;
feedrate_multiplier = 100 ;
refresh_cmd_timeout ( ) ;
refresh_cmd_timeout ( ) ;
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOLNPGM ( " setup_for_endstop_move > enable_endstops(true) " ) ;
}
# endif
enable_endstops ( true ) ;
enable_endstops ( true ) ;
}
}
# if ENABLED(ENABLE_AUTO_BED_LEVELING)
# if ENABLED( AUTO_BED_LEVELING_FEATURE )
# if ENABLED(DELTA)
# if ENABLED(DELTA)
/**
/**
* Calculate delta , start a line , and set current_position to destination
* Calculate delta , start a line , and set current_position to destination
*/
*/
void prepare_move_raw ( ) {
void prepare_move_raw ( ) {
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
print_xyz ( " prepare_move_raw > destination " , destination ) ;
}
# endif
refresh_cmd_timeout ( ) ;
refresh_cmd_timeout ( ) ;
calculate_delta ( destination ) ;
calculate_delta ( destination ) ;
plan_buffer_line ( delta [ X_AXIS ] , delta [ Y_AXIS ] , delta [ Z_AXIS ] , destination [ E_AXIS ] , ( feedrate / 60 ) * ( feedrate_multiplier / 100.0 ) , active_extruder ) ;
plan_buffer_line ( delta [ X_AXIS ] , delta [ Y_AXIS ] , delta [ Z_AXIS ] , destination [ E_AXIS ] , ( feedrate / 60 ) * ( feedrate_multiplier / 100.0 ) , active_extruder ) ;
@ -1180,6 +1211,12 @@ static void setup_for_endstop_move() {
current_position [ Y_AXIS ] = corrected_position . y ;
current_position [ Y_AXIS ] = corrected_position . y ;
current_position [ Z_AXIS ] = corrected_position . z ;
current_position [ Z_AXIS ] = corrected_position . z ;
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
print_xyz ( " set_bed_level_equation_lsq > current_position " , current_position ) ;
}
# endif
sync_plan_position ( ) ;
sync_plan_position ( ) ;
}
}
@ -1209,6 +1246,12 @@ static void setup_for_endstop_move() {
current_position [ Y_AXIS ] = corrected_position . y ;
current_position [ Y_AXIS ] = corrected_position . y ;
current_position [ Z_AXIS ] = corrected_position . z ;
current_position [ Z_AXIS ] = corrected_position . z ;
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
print_xyz ( " set_bed_level_equation_3pts > current_position " , current_position ) ;
}
# endif
sync_plan_position ( ) ;
sync_plan_position ( ) ;
}
}
@ -1221,6 +1264,12 @@ static void setup_for_endstop_move() {
float start_z = current_position [ Z_AXIS ] ;
float start_z = current_position [ Z_AXIS ] ;
long start_steps = st_get_position ( Z_AXIS ) ;
long start_steps = st_get_position ( Z_AXIS ) ;
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOLNPGM ( " run_z_probe (DELTA) 1 " ) ;
}
# endif
// move down slowly until you find the bed
// move down slowly until you find the bed
feedrate = homing_feedrate [ Z_AXIS ] / 4 ;
feedrate = homing_feedrate [ Z_AXIS ] / 4 ;
destination [ Z_AXIS ] = - 10 ;
destination [ Z_AXIS ] = - 10 ;
@ -1232,6 +1281,13 @@ static void setup_for_endstop_move() {
long stop_steps = st_get_position ( Z_AXIS ) ;
long stop_steps = st_get_position ( Z_AXIS ) ;
float mm = start_z - float ( start_steps - stop_steps ) / axis_steps_per_unit [ Z_AXIS ] ;
float mm = start_z - float ( start_steps - stop_steps ) / axis_steps_per_unit [ Z_AXIS ] ;
current_position [ Z_AXIS ] = mm ;
current_position [ Z_AXIS ] = mm ;
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
print_xyz ( " run_z_probe (DELTA) 2 > current_position " , current_position ) ;
}
# endif
sync_plan_position_delta ( ) ;
sync_plan_position_delta ( ) ;
# else // !DELTA
# else // !DELTA
@ -1266,6 +1322,12 @@ static void setup_for_endstop_move() {
current_position [ Z_AXIS ] = st_get_position_mm ( Z_AXIS ) ;
current_position [ Z_AXIS ] = st_get_position_mm ( Z_AXIS ) ;
sync_plan_position ( ) ;
sync_plan_position ( ) ;
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
print_xyz ( " run_z_probe > current_position " , current_position ) ;
}
# endif
# endif // !DELTA
# endif // !DELTA
}
}
@ -1276,6 +1338,12 @@ static void setup_for_endstop_move() {
static void do_blocking_move_to ( float x , float y , float z ) {
static void do_blocking_move_to ( float x , float y , float z ) {
float oldFeedRate = feedrate ;
float oldFeedRate = feedrate ;
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
print_xyz ( " do_blocking_move_to " , x , y , z ) ;
}
# endif
# if ENABLED(DELTA)
# if ENABLED(DELTA)
feedrate = XY_TRAVEL_SPEED ;
feedrate = XY_TRAVEL_SPEED ;
@ -1312,6 +1380,11 @@ static void setup_for_endstop_move() {
static void clean_up_after_endstop_move ( ) {
static void clean_up_after_endstop_move ( ) {
# if ENABLED(ENDSTOPS_ONLY_FOR_HOMING)
# if ENABLED(ENDSTOPS_ONLY_FOR_HOMING)
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOLNPGM ( " clean_up_after_endstop_move > ENDSTOPS_ONLY_FOR_HOMING > enable_endstops(false) " ) ;
}
# endif
enable_endstops ( false ) ;
enable_endstops ( false ) ;
# endif
# endif
feedrate = saved_feedrate ;
feedrate = saved_feedrate ;
@ -1321,6 +1394,12 @@ static void setup_for_endstop_move() {
static void deploy_z_probe ( ) {
static void deploy_z_probe ( ) {
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
print_xyz ( " deploy_z_probe > current_position " , current_position ) ;
}
# endif
# if HAS_SERVO_ENDSTOPS
# if HAS_SERVO_ENDSTOPS
// Engage Z Servo endstop if enabled
// Engage Z Servo endstop if enabled
@ -1411,6 +1490,12 @@ static void setup_for_endstop_move() {
static void stow_z_probe ( bool doRaise = true ) {
static void stow_z_probe ( bool doRaise = true ) {
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
print_xyz ( " stow_z_probe > current_position " , current_position ) ;
}
# endif
# if HAS_SERVO_ENDSTOPS
# if HAS_SERVO_ENDSTOPS
// Retract Z Servo endstop if enabled
// Retract Z Servo endstop if enabled
@ -1418,6 +1503,14 @@ static void setup_for_endstop_move() {
# if Z_RAISE_AFTER_PROBING > 0
# if Z_RAISE_AFTER_PROBING > 0
if ( doRaise ) {
if ( doRaise ) {
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOPAIR ( " Raise Z (after) by " , ( float ) Z_RAISE_AFTER_PROBING ) ;
SERIAL_EOL ;
SERIAL_ECHOPAIR ( " > SERVO_ENDSTOPS > do_blocking_move_to_z " , current_position [ Z_AXIS ] + Z_RAISE_AFTER_PROBING ) ;
SERIAL_EOL ;
}
# endif
do_blocking_move_to_z ( current_position [ Z_AXIS ] + Z_RAISE_AFTER_PROBING ) ; // this also updates current_position
do_blocking_move_to_z ( current_position [ Z_AXIS ] + Z_RAISE_AFTER_PROBING ) ; // this also updates current_position
st_synchronize ( ) ;
st_synchronize ( ) ;
}
}
@ -1506,19 +1599,61 @@ static void setup_for_endstop_move() {
// Probe bed height at position (x,y), returns the measured z value
// Probe bed height at position (x,y), returns the measured z value
static float probe_pt ( float x , float y , float z_before , ProbeAction probe_action = ProbeDeployAndStow , int verbose_level = 1 ) {
static float probe_pt ( float x , float y , float z_before , ProbeAction probe_action = ProbeDeployAndStow , int verbose_level = 1 ) {
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOLNPGM ( " probe_pt >>> " ) ;
SERIAL_ECHOPAIR ( " > ProbeAction: " , ( unsigned long ) probe_action ) ;
SERIAL_EOL ;
print_xyz ( " > current_position " , current_position ) ;
}
# endif
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOPAIR ( " Z Raise to z_before " , z_before ) ;
SERIAL_EOL ;
SERIAL_ECHOPAIR ( " > do_blocking_move_to_z " , z_before ) ;
SERIAL_EOL ;
}
# endif
// Move Z up to the z_before height, then move the Z probe to the given XY
// Move Z up to the z_before height, then move the Z probe to the given XY
do_blocking_move_to_z ( z_before ) ; // this also updates current_position
do_blocking_move_to_z ( z_before ) ; // this also updates current_position
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOPAIR ( " > do_blocking_move_to_xy " , x - X_PROBE_OFFSET_FROM_EXTRUDER ) ;
SERIAL_ECHOPAIR ( " , " , y - Y_PROBE_OFFSET_FROM_EXTRUDER ) ;
SERIAL_EOL ;
}
# endif
do_blocking_move_to_xy ( x - X_PROBE_OFFSET_FROM_EXTRUDER , y - Y_PROBE_OFFSET_FROM_EXTRUDER ) ; // this also updates current_position
do_blocking_move_to_xy ( x - X_PROBE_OFFSET_FROM_EXTRUDER , y - Y_PROBE_OFFSET_FROM_EXTRUDER ) ; // this also updates current_position
# if DISABLED(Z_PROBE_SLED) && DISABLED(Z_PROBE_ALLEN_KEY)
# if DISABLED(Z_PROBE_SLED) && DISABLED(Z_PROBE_ALLEN_KEY)
if ( probe_action & ProbeDeploy ) deploy_z_probe ( ) ;
if ( probe_action & ProbeDeploy ) {
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOLNPGM ( " > ProbeDeploy " ) ;
}
# endif
deploy_z_probe ( ) ;
}
# endif
# endif
run_z_probe ( ) ;
run_z_probe ( ) ;
float measured_z = current_position [ Z_AXIS ] ;
float measured_z = current_position [ Z_AXIS ] ;
# if DISABLED(Z_PROBE_SLED) && DISABLED(Z_PROBE_ALLEN_KEY)
# if DISABLED(Z_PROBE_SLED) && DISABLED(Z_PROBE_ALLEN_KEY)
if ( probe_action & ProbeStow ) stow_z_probe ( ) ;
if ( probe_action & ProbeStow ) {
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOLNPGM ( " > ProbeStow (stow_z_probe will do Z Raise) " ) ;
}
# endif
stow_z_probe ( ) ;
}
# endif
# endif
if ( verbose_level > 2 ) {
if ( verbose_level > 2 ) {
@ -1530,6 +1665,13 @@ static void setup_for_endstop_move() {
SERIAL_PROTOCOL_F ( measured_z , 3 ) ;
SERIAL_PROTOCOL_F ( measured_z , 3 ) ;
SERIAL_EOL ;
SERIAL_EOL ;
}
}
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOLNPGM ( " <<< probe_pt " ) ;
}
# endif
return measured_z ;
return measured_z ;
}
}
@ -1585,6 +1727,11 @@ static void setup_for_endstop_move() {
// Reset calibration results to zero.
// Reset calibration results to zero.
void reset_bed_level ( ) {
void reset_bed_level ( ) {
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOLNPGM ( " reset_bed_level " ) ;
}
# endif
for ( int y = 0 ; y < AUTO_BED_LEVELING_GRID_POINTS ; y + + ) {
for ( int y = 0 ; y < AUTO_BED_LEVELING_GRID_POINTS ; y + + ) {
for ( int x = 0 ; x < AUTO_BED_LEVELING_GRID_POINTS ; x + + ) {
for ( int x = 0 ; x < AUTO_BED_LEVELING_GRID_POINTS ; x + + ) {
bed_level [ x ] [ y ] = 0.0 ;
bed_level [ x ] [ y ] = 0.0 ;
@ -1604,7 +1751,7 @@ static void setup_for_endstop_move() {
# endif
# endif
# endif // ENABLE_ AUTO_BED_LEVELING
# endif // AUTO_BED_LEVELING_FEATURE
# if ENABLED(Z_PROBE_SLED)
# if ENABLED(Z_PROBE_SLED)
@ -1620,6 +1767,12 @@ static void setup_for_endstop_move() {
* offset [ in ] The additional distance to move to adjust docking location
* offset [ in ] The additional distance to move to adjust docking location
*/
*/
static void dock_sled ( bool dock , int offset = 0 ) {
static void dock_sled ( bool dock , int offset = 0 ) {
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOPAIR ( " dock_sled " , dock ) ;
SERIAL_EOL ;
}
# endif
if ( ! axis_known_position [ X_AXIS ] | | ! axis_known_position [ Y_AXIS ] ) {
if ( ! axis_known_position [ X_AXIS ] | | ! axis_known_position [ Y_AXIS ] ) {
LCD_MESSAGEPGM ( MSG_POSITION_UNKNOWN ) ;
LCD_MESSAGEPGM ( MSG_POSITION_UNKNOWN ) ;
SERIAL_ECHO_START ;
SERIAL_ECHO_START ;
@ -1654,6 +1807,13 @@ static void setup_for_endstop_move() {
# define HOMEAXIS(LETTER) homeaxis(LETTER##_AXIS)
# define HOMEAXIS(LETTER) homeaxis(LETTER##_AXIS)
static void homeaxis ( AxisEnum axis ) {
static void homeaxis ( AxisEnum axis ) {
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOPAIR ( " >>> homeaxis( " , ( unsigned long ) axis ) ;
SERIAL_CHAR ( ' ) ' ) ;
SERIAL_EOL ;
}
# endif
# define HOMEAXIS_DO(LETTER) \
# define HOMEAXIS_DO(LETTER) \
( ( LETTER # # _MIN_PIN > - 1 & & LETTER # # _HOME_DIR = = - 1 ) | | ( LETTER # # _MAX_PIN > - 1 & & LETTER # # _HOME_DIR = = 1 ) )
( ( LETTER # # _MIN_PIN > - 1 & & LETTER # # _HOME_DIR = = - 1 ) | | ( LETTER # # _MAX_PIN > - 1 & & LETTER # # _HOME_DIR = = 1 ) )
@ -1706,6 +1866,11 @@ static void homeaxis(AxisEnum axis) {
current_position [ axis ] = 0 ;
current_position [ axis ] = 0 ;
sync_plan_position ( ) ;
sync_plan_position ( ) ;
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOLNPGM ( " > enable_endstops(false) " ) ;
}
# endif
enable_endstops ( false ) ; // Disable endstops while moving away
enable_endstops ( false ) ; // Disable endstops while moving away
// Move away from the endstop by the axis HOME_BUMP_MM
// Move away from the endstop by the axis HOME_BUMP_MM
@ -1713,6 +1878,11 @@ static void homeaxis(AxisEnum axis) {
line_to_destination ( ) ;
line_to_destination ( ) ;
st_synchronize ( ) ;
st_synchronize ( ) ;
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOLNPGM ( " > enable_endstops(true) " ) ;
}
# endif
enable_endstops ( true ) ; // Enable endstops for next homing move
enable_endstops ( true ) ; // Enable endstops for next homing move
// Slow down the feedrate for the next move
// Slow down the feedrate for the next move
@ -1723,6 +1893,12 @@ static void homeaxis(AxisEnum axis) {
line_to_destination ( ) ;
line_to_destination ( ) ;
st_synchronize ( ) ;
st_synchronize ( ) ;
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
print_xyz ( " > TRIGGER ENDSTOP > current_position " , current_position ) ;
}
# endif
# if ENABLED(Z_DUAL_ENDSTOPS)
# if ENABLED(Z_DUAL_ENDSTOPS)
if ( axis = = Z_AXIS ) {
if ( axis = = Z_AXIS ) {
float adj = fabs ( z_endstop_adj ) ;
float adj = fabs ( z_endstop_adj ) ;
@ -1751,19 +1927,49 @@ static void homeaxis(AxisEnum axis) {
# if ENABLED(DELTA)
# if ENABLED(DELTA)
// retrace by the amount specified in endstop_adj
// retrace by the amount specified in endstop_adj
if ( endstop_adj [ axis ] * axis_home_dir < 0 ) {
if ( endstop_adj [ axis ] * axis_home_dir < 0 ) {
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOLNPGM ( " > enable_endstops(false) " ) ;
}
# endif
enable_endstops ( false ) ; // Disable endstops while moving away
enable_endstops ( false ) ; // Disable endstops while moving away
sync_plan_position ( ) ;
sync_plan_position ( ) ;
destination [ axis ] = endstop_adj [ axis ] ;
destination [ axis ] = endstop_adj [ axis ] ;
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOPAIR ( " > endstop_adj = " , endstop_adj [ axis ] ) ;
print_xyz ( " > destination " , destination ) ;
}
# endif
line_to_destination ( ) ;
line_to_destination ( ) ;
st_synchronize ( ) ;
st_synchronize ( ) ;
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOLNPGM ( " > enable_endstops(true) " ) ;
}
# endif
enable_endstops ( true ) ; // Enable endstops for next homing move
enable_endstops ( true ) ; // Enable endstops for next homing move
}
}
# if ENABLED(DEBUG_LEVELING_FEATURE)
else {
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOPAIR ( " > endstop_adj * axis_home_dir = " , endstop_adj [ axis ] * axis_home_dir ) ;
SERIAL_EOL ;
}
}
# endif
# endif
# endif
// Set the axis position to its home position (plus home offsets)
// Set the axis position to its home position (plus home offsets)
set_axis_is_at_home ( axis ) ;
set_axis_is_at_home ( axis ) ;
sync_plan_position ( ) ;
sync_plan_position ( ) ;
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
print_xyz ( " > AFTER set_axis_is_at_home > current_position " , current_position ) ;
}
# endif
destination [ axis ] = current_position [ axis ] ;
destination [ axis ] = current_position [ axis ] ;
feedrate = 0.0 ;
feedrate = 0.0 ;
endstops_hit_on_purpose ( ) ; // clear endstop hit flags
endstops_hit_on_purpose ( ) ; // clear endstop hit flags
@ -1780,7 +1986,14 @@ static void homeaxis(AxisEnum axis) {
// Deploy a Z probe if there is one, and homing towards the bed
// Deploy a Z probe if there is one, and homing towards the bed
if ( axis = = Z_AXIS ) {
if ( axis = = Z_AXIS ) {
if ( axis_home_dir < 0 ) stow_z_probe ( ) ;
if ( axis_home_dir < 0 ) {
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOLNPGM ( " > SERVO_LEVELING > stow_z_probe " ) ;
}
# endif
stow_z_probe ( ) ;
}
}
}
else
else
@ -1789,12 +2002,26 @@ static void homeaxis(AxisEnum axis) {
{
{
# if HAS_SERVO_ENDSTOPS
# if HAS_SERVO_ENDSTOPS
// Retract Servo endstop if enabled
// Retract Servo endstop if enabled
if ( servo_endstop_id [ axis ] > = 0 )
if ( servo_endstop_id [ axis ] > = 0 ) {
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOLNPGM ( " > SERVO_ENDSTOPS > Stow with servo.move() " ) ;
}
# endif
servo [ servo_endstop_id [ axis ] ] . move ( servo_endstop_angle [ axis ] [ 1 ] ) ;
servo [ servo_endstop_id [ axis ] ] . move ( servo_endstop_angle [ axis ] [ 1 ] ) ;
}
# endif
# endif
}
}
}
}
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOPAIR ( " <<< homeaxis( " , ( unsigned long ) axis ) ;
SERIAL_CHAR ( ' ) ' ) ;
SERIAL_EOL ;
}
# endif
}
}
# if ENABLED(FWRETRACT)
# if ENABLED(FWRETRACT)
@ -1996,11 +2223,17 @@ inline void gcode_G4() {
*/
*/
inline void gcode_G28 ( ) {
inline void gcode_G28 ( ) {
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOLNPGM ( " gcode_G28 >>> " ) ;
}
# endif
// Wait for planner moves to finish!
// Wait for planner moves to finish!
st_synchronize ( ) ;
st_synchronize ( ) ;
// For auto bed leveling, clear the level matrix
// For auto bed leveling, clear the level matrix
# if ENABLED(ENABLE_AUTO_BED_LEVELING)
# if ENABLED( AUTO_BED_LEVELING_FEATURE )
plan_bed_level_matrix . set_to_identity ( ) ;
plan_bed_level_matrix . set_to_identity ( ) ;
# if ENABLED(DELTA)
# if ENABLED(DELTA)
reset_bed_level ( ) ;
reset_bed_level ( ) ;
@ -2044,6 +2277,12 @@ inline void gcode_G28() {
sync_plan_position_delta ( ) ;
sync_plan_position_delta ( ) ;
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
print_xyz ( " (DELTA) > current_position " , current_position ) ;
}
# endif
# else // NOT DELTA
# else // NOT DELTA
bool homeX = code_seen ( axis_codes [ X_AXIS ] ) ,
bool homeX = code_seen ( axis_codes [ X_AXIS ] ) ,
@ -2057,12 +2296,24 @@ inline void gcode_G28() {
# if Z_HOME_DIR > 0 // If homing away from BED do Z first
# if Z_HOME_DIR > 0 // If homing away from BED do Z first
HOMEAXIS ( Z ) ;
HOMEAXIS ( Z ) ;
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
print_xyz ( " > HOMEAXIS(Z) > current_position " , current_position ) ;
}
# endif
# elif DISABLED(Z_SAFE_HOMING) && defined(Z_RAISE_BEFORE_HOMING) && Z_RAISE_BEFORE_HOMING > 0
# elif DISABLED(Z_SAFE_HOMING) && defined(Z_RAISE_BEFORE_HOMING) && Z_RAISE_BEFORE_HOMING > 0
// Raise Z before homing any other axes
// Raise Z before homing any other axes
// (Does this need to be "negative home direction?" Why not just use Z_RAISE_BEFORE_HOMING?)
// (Does this need to be "negative home direction?" Why not just use Z_RAISE_BEFORE_HOMING?)
destination [ Z_AXIS ] = - Z_RAISE_BEFORE_HOMING * home_dir ( Z_AXIS ) ;
destination [ Z_AXIS ] = - Z_RAISE_BEFORE_HOMING * home_dir ( Z_AXIS ) ;
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOPAIR ( " Raise Z (before homing) by " , ( float ) Z_RAISE_BEFORE_HOMING ) ;
SERIAL_EOL ;
print_xyz ( " > (home_all_axis || homeZ) > destination " , destination ) ;
}
# endif
feedrate = max_feedrate [ Z_AXIS ] * 60 ;
feedrate = max_feedrate [ Z_AXIS ] * 60 ;
line_to_destination ( ) ;
line_to_destination ( ) ;
st_synchronize ( ) ;
st_synchronize ( ) ;
@ -2099,6 +2350,12 @@ inline void gcode_G28() {
set_axis_is_at_home ( Y_AXIS ) ;
set_axis_is_at_home ( Y_AXIS ) ;
sync_plan_position ( ) ;
sync_plan_position ( ) ;
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
print_xyz ( " > QUICK_HOME > current_position 1 " , current_position ) ;
}
# endif
destination [ X_AXIS ] = current_position [ X_AXIS ] ;
destination [ X_AXIS ] = current_position [ X_AXIS ] ;
destination [ Y_AXIS ] = current_position [ Y_AXIS ] ;
destination [ Y_AXIS ] = current_position [ Y_AXIS ] ;
line_to_destination ( ) ;
line_to_destination ( ) ;
@ -2111,6 +2368,12 @@ inline void gcode_G28() {
# if DISABLED(SCARA)
# if DISABLED(SCARA)
current_position [ Z_AXIS ] = destination [ Z_AXIS ] ;
current_position [ Z_AXIS ] = destination [ Z_AXIS ] ;
# endif
# endif
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
print_xyz ( " > QUICK_HOME > current_position 2 " , current_position ) ;
}
# endif
}
}
# endif // QUICK_HOME
# endif // QUICK_HOME
@ -2137,11 +2400,23 @@ inline void gcode_G28() {
# else
# else
HOMEAXIS ( X ) ;
HOMEAXIS ( X ) ;
# endif
# endif
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
print_xyz ( " > homeX " , current_position ) ;
}
# endif
}
}
# if DISABLED(HOME_Y_BEFORE_X)
# if DISABLED(HOME_Y_BEFORE_X)
// Home Y
// Home Y
if ( home_all_axis | | homeY ) HOMEAXIS ( Y ) ;
if ( home_all_axis | | homeY ) {
HOMEAXIS ( Y ) ;
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
print_xyz ( " > homeY " , current_position ) ;
}
# endif
}
# endif
# endif
// Home Z last if homing towards the bed
// Home Z last if homing towards the bed
@ -2151,6 +2426,12 @@ inline void gcode_G28() {
# if ENABLED(Z_SAFE_HOMING)
# if ENABLED(Z_SAFE_HOMING)
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOLNPGM ( " > Z_SAFE_HOMING >>> " ) ;
}
# endif
if ( home_all_axis ) {
if ( home_all_axis ) {
current_position [ Z_AXIS ] = 0 ;
current_position [ Z_AXIS ] = 0 ;
@ -2165,6 +2446,16 @@ inline void gcode_G28() {
destination [ Y_AXIS ] = round ( Z_SAFE_HOMING_Y_POINT - Y_PROBE_OFFSET_FROM_EXTRUDER ) ;
destination [ Y_AXIS ] = round ( Z_SAFE_HOMING_Y_POINT - Y_PROBE_OFFSET_FROM_EXTRUDER ) ;
destination [ Z_AXIS ] = - Z_RAISE_BEFORE_HOMING * home_dir ( Z_AXIS ) ; // Set destination away from bed
destination [ Z_AXIS ] = - Z_RAISE_BEFORE_HOMING * home_dir ( Z_AXIS ) ; // Set destination away from bed
feedrate = XY_TRAVEL_SPEED ;
feedrate = XY_TRAVEL_SPEED ;
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOPAIR ( " Raise Z (before homing) by " , ( float ) Z_RAISE_BEFORE_HOMING ) ;
SERIAL_EOL ;
print_xyz ( " > home_all_axis > current_position " , current_position ) ;
print_xyz ( " > home_all_axis > destination " , destination ) ;
}
# endif
// This could potentially move X, Y, Z all together
// This could potentially move X, Y, Z all together
line_to_destination ( ) ;
line_to_destination ( ) ;
st_synchronize ( ) ;
st_synchronize ( ) ;
@ -2197,6 +2488,16 @@ inline void gcode_G28() {
// NOTE: This should always just be Z_RAISE_BEFORE_HOMING unless...???
// NOTE: This should always just be Z_RAISE_BEFORE_HOMING unless...???
destination [ Z_AXIS ] = - Z_RAISE_BEFORE_HOMING * home_dir ( Z_AXIS ) ;
destination [ Z_AXIS ] = - Z_RAISE_BEFORE_HOMING * home_dir ( Z_AXIS ) ;
feedrate = max_feedrate [ Z_AXIS ] * 60 ; // feedrate (mm/m) = max_feedrate (mm/s)
feedrate = max_feedrate [ Z_AXIS ] * 60 ; // feedrate (mm/m) = max_feedrate (mm/s)
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOPAIR ( " Raise Z (before homing) by " , ( float ) Z_RAISE_BEFORE_HOMING ) ;
SERIAL_EOL ;
print_xyz ( " > homeZ > current_position " , current_position ) ;
print_xyz ( " > homeZ > destination " , destination ) ;
}
# endif
line_to_destination ( ) ;
line_to_destination ( ) ;
st_synchronize ( ) ;
st_synchronize ( ) ;
@ -2217,12 +2518,24 @@ inline void gcode_G28() {
} // !home_all_axes && homeZ
} // !home_all_axes && homeZ
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOLNPGM ( " <<< Z_SAFE_HOMING " ) ;
}
# endif
# else // !Z_SAFE_HOMING
# else // !Z_SAFE_HOMING
HOMEAXIS ( Z ) ;
HOMEAXIS ( Z ) ;
# endif // !Z_SAFE_HOMING
# endif // !Z_SAFE_HOMING
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
print_xyz ( " > (home_all_axis || homeZ) > final " , current_position ) ;
}
# endif
} // home_all_axis || homeZ
} // home_all_axis || homeZ
# endif // Z_HOME_DIR < 0
# endif // Z_HOME_DIR < 0
@ -2236,6 +2549,11 @@ inline void gcode_G28() {
# endif
# endif
# if ENABLED(ENDSTOPS_ONLY_FOR_HOMING)
# if ENABLED(ENDSTOPS_ONLY_FOR_HOMING)
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOLNPGM ( " ENDSTOPS_ONLY_FOR_HOMING enable_endstops(false) " ) ;
}
# endif
enable_endstops ( false ) ;
enable_endstops ( false ) ;
# endif
# endif
@ -2251,6 +2569,11 @@ inline void gcode_G28() {
current_position [ Z_AXIS ] = MESH_HOME_SEARCH_Z ;
current_position [ Z_AXIS ] = MESH_HOME_SEARCH_Z ;
sync_plan_position ( ) ;
sync_plan_position ( ) ;
mbl . active = 1 ;
mbl . active = 1 ;
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
print_xyz ( " mbl_was_active > current_position " , current_position ) ;
}
# endif
}
}
# endif
# endif
@ -2258,6 +2581,13 @@ inline void gcode_G28() {
feedrate_multiplier = saved_feedrate_multiplier ;
feedrate_multiplier = saved_feedrate_multiplier ;
refresh_cmd_timeout ( ) ;
refresh_cmd_timeout ( ) ;
endstops_hit_on_purpose ( ) ; // clear endstop hit flags
endstops_hit_on_purpose ( ) ; // clear endstop hit flags
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOLNPGM ( " <<< gcode_G28 " ) ;
}
# endif
}
}
# if ENABLED(MESH_BED_LEVELING)
# if ENABLED(MESH_BED_LEVELING)
@ -2395,7 +2725,7 @@ inline void gcode_G28() {
} // switch(state)
} // switch(state)
}
}
# elif ENABLED( ENABLE_ AUTO_BED_LEVELING)
# elif ENABLED( AUTO_BED_LEVELING_FEATURE )
void out_of_range_error ( const char * p_edge ) {
void out_of_range_error ( const char * p_edge ) {
SERIAL_PROTOCOLPGM ( " ?Probe " ) ;
SERIAL_PROTOCOLPGM ( " ?Probe " ) ;
@ -2443,6 +2773,12 @@ inline void gcode_G28() {
*/
*/
inline void gcode_G29 ( ) {
inline void gcode_G29 ( ) {
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOLNPGM ( " gcode_G29 >>> " ) ;
}
# endif
// Don't allow auto-leveling without homing first
// Don't allow auto-leveling without homing first
if ( ! axis_known_position [ X_AXIS ] | | ! axis_known_position [ Y_AXIS ] ) {
if ( ! axis_known_position [ X_AXIS ] | | ! axis_known_position [ Y_AXIS ] ) {
LCD_MESSAGEPGM ( MSG_POSITION_UNKNOWN ) ;
LCD_MESSAGEPGM ( MSG_POSITION_UNKNOWN ) ;
@ -2601,6 +2937,23 @@ inline void gcode_G28() {
float measured_z ,
float measured_z ,
z_before = probePointCounter ? Z_RAISE_BETWEEN_PROBINGS + current_position [ Z_AXIS ] : Z_RAISE_BEFORE_PROBING ;
z_before = probePointCounter ? Z_RAISE_BETWEEN_PROBINGS + current_position [ Z_AXIS ] : Z_RAISE_BEFORE_PROBING ;
if ( probePointCounter ) {
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOPAIR ( " z_before = (between) " , ( float ) ( Z_RAISE_BETWEEN_PROBINGS + current_position [ Z_AXIS ] ) ) ;
SERIAL_EOL ;
}
# endif
}
else {
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOPAIR ( " z_before = (before) " , ( float ) Z_RAISE_BEFORE_PROBING ) ;
SERIAL_EOL ;
}
# endif
}
# if ENABLED(DELTA)
# if ENABLED(DELTA)
// Avoid probing the corners (outside the round or hexagon print surface) on a delta printer.
// Avoid probing the corners (outside the round or hexagon print surface) on a delta printer.
float distance_from_center = sqrt ( xProbe * xProbe + yProbe * yProbe ) ;
float distance_from_center = sqrt ( xProbe * xProbe + yProbe * yProbe ) ;
@ -2638,6 +2991,12 @@ inline void gcode_G28() {
} //xProbe
} //xProbe
} //yProbe
} //yProbe
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
print_xyz ( " > probing complete > current_position " , current_position ) ;
}
# endif
clean_up_after_endstop_move ( ) ;
clean_up_after_endstop_move ( ) ;
# if ENABLED(DELTA)
# if ENABLED(DELTA)
@ -2734,6 +3093,12 @@ inline void gcode_G28() {
# else // !AUTO_BED_LEVELING_GRID
# else // !AUTO_BED_LEVELING_GRID
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOLNPGM ( " > 3-point Leveling " ) ;
}
# endif
// Actions for each probe
// Actions for each probe
ProbeAction p1 , p2 , p3 ;
ProbeAction p1 , p2 , p3 ;
if ( deploy_probe_for_each_reading )
if ( deploy_probe_for_each_reading )
@ -2763,6 +3128,15 @@ inline void gcode_G28() {
z_tmp = current_position [ Z_AXIS ] ,
z_tmp = current_position [ Z_AXIS ] ,
real_z = st_get_position_mm ( Z_AXIS ) ; //get the real Z (since plan_get_position is now correcting the plane)
real_z = st_get_position_mm ( Z_AXIS ) ; //get the real Z (since plan_get_position is now correcting the plane)
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOPAIR ( " > BEFORE apply_rotation_xyz > z_tmp = " , z_tmp ) ;
SERIAL_EOL ;
SERIAL_ECHOPAIR ( " > BEFORE apply_rotation_xyz > real_z = " , real_z ) ;
SERIAL_EOL ;
}
# endif
apply_rotation_xyz ( plan_bed_level_matrix , x_tmp , y_tmp , z_tmp ) ; // Apply the correction sending the Z probe offset
apply_rotation_xyz ( plan_bed_level_matrix , x_tmp , y_tmp , z_tmp ) ; // Apply the correction sending the Z probe offset
// Get the current Z position and send it to the planner.
// Get the current Z position and send it to the planner.
@ -2781,6 +3155,13 @@ inline void gcode_G28() {
// adjust for inaccurate endstops, not for reasonably accurate probes. If it were
// adjust for inaccurate endstops, not for reasonably accurate probes. If it were
// added here, it could be seen as a compensating factor for the Z probe.
// added here, it could be seen as a compensating factor for the Z probe.
//
//
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOPAIR ( " > AFTER apply_rotation_xyz > z_tmp = " , z_tmp ) ;
SERIAL_EOL ;
}
# endif
current_position [ Z_AXIS ] = - zprobe_zoffset + ( z_tmp - real_z )
current_position [ Z_AXIS ] = - zprobe_zoffset + ( z_tmp - real_z )
# if HAS_SERVO_ENDSTOPS || ENABLED(Z_PROBE_ALLEN_KEY) || ENABLED(Z_PROBE_SLED)
# if HAS_SERVO_ENDSTOPS || ENABLED(Z_PROBE_ALLEN_KEY) || ENABLED(Z_PROBE_SLED)
+ Z_RAISE_AFTER_PROBING
+ Z_RAISE_AFTER_PROBING
@ -2788,6 +3169,12 @@ inline void gcode_G28() {
;
;
// current_position[Z_AXIS] += home_offset[Z_AXIS]; // The Z probe determines Z=0, not "Z home"
// current_position[Z_AXIS] += home_offset[Z_AXIS]; // The Z probe determines Z=0, not "Z home"
sync_plan_position ( ) ;
sync_plan_position ( ) ;
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
print_xyz ( " > corrected Z in G29 " , current_position ) ;
}
# endif
}
}
# endif // !DELTA
# endif // !DELTA
@ -2798,9 +3185,22 @@ inline void gcode_G28() {
# endif
# endif
# ifdef Z_PROBE_END_SCRIPT
# ifdef Z_PROBE_END_SCRIPT
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHO ( " Z Probe End Script: " ) ;
SERIAL_ECHOLNPGM ( Z_PROBE_END_SCRIPT ) ;
}
# endif
enqueuecommands_P ( PSTR ( Z_PROBE_END_SCRIPT ) ) ;
enqueuecommands_P ( PSTR ( Z_PROBE_END_SCRIPT ) ) ;
st_synchronize ( ) ;
st_synchronize ( ) ;
# endif
# endif
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOLNPGM ( " <<< gcode_G29 " ) ;
}
# endif
}
}
# if DISABLED(Z_PROBE_SLED)
# if DISABLED(Z_PROBE_SLED)
@ -2839,7 +3239,7 @@ inline void gcode_G28() {
# endif //!Z_PROBE_SLED
# endif //!Z_PROBE_SLED
# endif // ENABLE_ AUTO_BED_LEVELING
# endif // AUTO_BED_LEVELING_FEATURE
/**
/**
* G92 : Set current position to given X Y Z E
* G92 : Set current position to given X Y Z E
@ -3116,7 +3516,7 @@ inline void gcode_M42() {
} // code_seen('S')
} // code_seen('S')
}
}
# if ENABLED( ENABLE_ AUTO_BED_LEVELING) && ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST)
# if ENABLED( AUTO_BED_LEVELING_FEATURE ) && ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST)
// This is redundant since the SanityCheck.h already checks for a valid Z_MIN_PROBE_PIN, but here for clarity.
// This is redundant since the SanityCheck.h already checks for a valid Z_MIN_PROBE_PIN, but here for clarity.
# if ENABLED(Z_MIN_PROBE_ENDSTOP)
# if ENABLED(Z_MIN_PROBE_ENDSTOP)
@ -3366,7 +3766,7 @@ inline void gcode_M42() {
SERIAL_EOL ; SERIAL_EOL ;
SERIAL_EOL ; SERIAL_EOL ;
}
}
# endif // ENABLE_ AUTO_BED_LEVELING && Z_MIN_PROBE_REPEATABILITY_TEST
# endif // AUTO_BED_LEVELING_FEATURE && Z_MIN_PROBE_REPEATABILITY_TEST
/**
/**
* M104 : Set hot end temperature
* M104 : Set hot end temperature
@ -3609,6 +4009,12 @@ inline void gcode_M111() {
SERIAL_ECHOLNPGM ( MSG_DEBUG_DRYRUN ) ;
SERIAL_ECHOLNPGM ( MSG_DEBUG_DRYRUN ) ;
disable_all_heaters ( ) ;
disable_all_heaters ( ) ;
}
}
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHO_START ;
SERIAL_ECHOLNPGM ( MSG_DEBUG_LEVELING ) ;
}
# endif
}
}
/**
/**
@ -4095,11 +4501,29 @@ inline void gcode_M206() {
* M666 : Set delta endstop adjustment
* M666 : Set delta endstop adjustment
*/
*/
inline void gcode_M666 ( ) {
inline void gcode_M666 ( ) {
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOLNPGM ( " >>> gcode_M666 " ) ;
}
# endif
for ( int8_t i = X_AXIS ; i < = Z_AXIS ; i + + ) {
for ( int8_t i = X_AXIS ; i < = Z_AXIS ; i + + ) {
if ( code_seen ( axis_codes [ i ] ) ) {
if ( code_seen ( axis_codes [ i ] ) ) {
endstop_adj [ i ] = code_value ( ) ;
endstop_adj [ i ] = code_value ( ) ;
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOPGM ( " endstop_adj[ " ) ;
SERIAL_ECHO ( axis_codes [ i ] ) ;
SERIAL_ECHOPAIR ( " ] = " , endstop_adj [ i ] ) ;
SERIAL_EOL ;
}
# endif
}
}
}
}
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOLNPGM ( " <<< gcode_M666 " ) ;
}
# endif
}
}
# elif ENABLED(Z_DUAL_ENDSTOPS) // !DELTA && ENABLED(Z_DUAL_ENDSTOPS)
# elif ENABLED(Z_DUAL_ENDSTOPS) // !DELTA && ENABLED(Z_DUAL_ENDSTOPS)
/**
/**
@ -4585,7 +5009,7 @@ inline void gcode_M303() {
*/
*/
inline void gcode_M400 ( ) { st_synchronize ( ) ; }
inline void gcode_M400 ( ) { st_synchronize ( ) ; }
# if ENABLED( ENABLE_ AUTO_BED_LEVELING) && DISABLED(Z_PROBE_SLED) && (HAS_SERVO_ENDSTOPS || ENABLED(Z_PROBE_ALLEN_KEY))
# if ENABLED( AUTO_BED_LEVELING_FEATURE ) && DISABLED(Z_PROBE_SLED) && (HAS_SERVO_ENDSTOPS || ENABLED(Z_PROBE_ALLEN_KEY))
/**
/**
* M401 : Engage Z Servo endstop if available
* M401 : Engage Z Servo endstop if available
@ -4607,7 +5031,7 @@ inline void gcode_M400() { st_synchronize(); }
stow_z_probe ( false ) ;
stow_z_probe ( false ) ;
}
}
# endif // ENABLE_ AUTO_BED_LEVELING && (HAS_SERVO_ENDSTOPS || Z_PROBE_ALLEN_KEY) && !Z_PROBE_SLED
# endif // AUTO_BED_LEVELING_FEATURE && (HAS_SERVO_ENDSTOPS || Z_PROBE_ALLEN_KEY) && !Z_PROBE_SLED
# if ENABLED(FILAMENT_SENSOR)
# if ENABLED(FILAMENT_SENSOR)
@ -5282,13 +5706,13 @@ void process_next_command() {
gcode_G28 ( ) ;
gcode_G28 ( ) ;
break ;
break ;
# if ENABLED( ENABLE_ AUTO_BED_LEVELING) || ENABLED(MESH_BED_LEVELING)
# if ENABLED( AUTO_BED_LEVELING_FEATURE ) || ENABLED(MESH_BED_LEVELING)
case 29 : // G29 Detailed Z probe, probes the bed at 3 or more points.
case 29 : // G29 Detailed Z probe, probes the bed at 3 or more points.
gcode_G29 ( ) ;
gcode_G29 ( ) ;
break ;
break ;
# endif
# endif
# if ENABLED( ENABLE_ AUTO_BED_LEVELING)
# if ENABLED( AUTO_BED_LEVELING_FEATURE )
# if DISABLED(Z_PROBE_SLED)
# if DISABLED(Z_PROBE_SLED)
@ -5305,7 +5729,7 @@ void process_next_command() {
# endif // Z_PROBE_SLED
# endif // Z_PROBE_SLED
# endif // ENABLE_ AUTO_BED_LEVELING
# endif // AUTO_BED_LEVELING_FEATURE
case 90 : // G90
case 90 : // G90
relative_mode = false ;
relative_mode = false ;
@ -5377,11 +5801,11 @@ void process_next_command() {
gcode_M42 ( ) ;
gcode_M42 ( ) ;
break ;
break ;
# if ENABLED( ENABLE_ AUTO_BED_LEVELING) && ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST)
# if ENABLED( AUTO_BED_LEVELING_FEATURE ) && ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST)
case 48 : // M48 Z probe repeatability
case 48 : // M48 Z probe repeatability
gcode_M48 ( ) ;
gcode_M48 ( ) ;
break ;
break ;
# endif // ENABLE_ AUTO_BED_LEVELING && Z_MIN_PROBE_REPEATABILITY_TEST
# endif // AUTO_BED_LEVELING_FEATURE && Z_MIN_PROBE_REPEATABILITY_TEST
# if ENABLED(M100_FREE_MEMORY_WATCHER)
# if ENABLED(M100_FREE_MEMORY_WATCHER)
case 100 :
case 100 :
@ -5650,14 +6074,14 @@ void process_next_command() {
gcode_M400 ( ) ;
gcode_M400 ( ) ;
break ;
break ;
# if ENABLED( ENABLE_ AUTO_BED_LEVELING) && (HAS_SERVO_ENDSTOPS || ENABLED(Z_PROBE_ALLEN_KEY)) && DISABLED(Z_PROBE_SLED)
# if ENABLED( AUTO_BED_LEVELING_FEATURE ) && (HAS_SERVO_ENDSTOPS || ENABLED(Z_PROBE_ALLEN_KEY)) && DISABLED(Z_PROBE_SLED)
case 401 :
case 401 :
gcode_M401 ( ) ;
gcode_M401 ( ) ;
break ;
break ;
case 402 :
case 402 :
gcode_M402 ( ) ;
gcode_M402 ( ) ;
break ;
break ;
# endif // ENABLE_ AUTO_BED_LEVELING && (HAS_SERVO_ENDSTOPS || Z_PROBE_ALLEN_KEY) && !Z_PROBE_SLED
# endif // AUTO_BED_LEVELING_FEATURE && (HAS_SERVO_ENDSTOPS || Z_PROBE_ALLEN_KEY) && !Z_PROBE_SLED
# if ENABLED(FILAMENT_SENSOR)
# if ENABLED(FILAMENT_SENSOR)
case 404 : //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or display nominal filament width
case 404 : //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or display nominal filament width
@ -5799,9 +6223,17 @@ void clamp_to_software_endstops(float target[3]) {
NOLESS ( target [ Y_AXIS ] , min_pos [ Y_AXIS ] ) ;
NOLESS ( target [ Y_AXIS ] , min_pos [ Y_AXIS ] ) ;
float negative_z_offset = 0 ;
float negative_z_offset = 0 ;
# if ENABLED( ENABLE_ AUTO_BED_LEVELING)
# if ENABLED( AUTO_BED_LEVELING_FEATURE )
if ( zprobe_zoffset < 0 ) negative_z_offset + = zprobe_zoffset ;
if ( zprobe_zoffset < 0 ) negative_z_offset + = zprobe_zoffset ;
if ( home_offset [ Z_AXIS ] < 0 ) negative_z_offset + = home_offset [ Z_AXIS ] ;
if ( home_offset [ Z_AXIS ] < 0 ) {
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( marlin_debug_flags & DEBUG_LEVELING ) {
SERIAL_ECHOPAIR ( " > clamp_to_software_endstops > Add home_offset[Z_AXIS]: " , home_offset [ Z_AXIS ] ) ;
SERIAL_EOL ;
}
# endif
negative_z_offset + = home_offset [ Z_AXIS ] ;
}
# endif
# endif
NOLESS ( target [ Z_AXIS ] , min_pos [ Z_AXIS ] + negative_z_offset ) ;
NOLESS ( target [ Z_AXIS ] , min_pos [ Z_AXIS ] + negative_z_offset ) ;
}
}
@ -5849,7 +6281,7 @@ void clamp_to_software_endstops(float target[3]) {
*/
*/
}
}
# if ENABLED( ENABLE_ AUTO_BED_LEVELING)
# if ENABLED( AUTO_BED_LEVELING_FEATURE )
// Adjust print surface height by linear interpolation over the bed_level array.
// Adjust print surface height by linear interpolation over the bed_level array.
void adjust_delta ( float cartesian [ 3 ] ) {
void adjust_delta ( float cartesian [ 3 ] ) {
@ -5889,7 +6321,7 @@ void clamp_to_software_endstops(float target[3]) {
SERIAL_ECHOPGM ( " offset= " ) ; SERIAL_ECHOLN ( offset ) ;
SERIAL_ECHOPGM ( " offset= " ) ; SERIAL_ECHOLN ( offset ) ;
*/
*/
}
}
# endif // ENABLE_ AUTO_BED_LEVELING
# endif // AUTO_BED_LEVELING_FEATURE
# endif // DELTA
# endif // DELTA
@ -6008,7 +6440,7 @@ void mesh_plan_buffer_line(float x, float y, float z, const float e, float feed_
calculate_delta ( target ) ;
calculate_delta ( target ) ;
# if ENABLED( ENABLE_ AUTO_BED_LEVELING)
# if ENABLED( AUTO_BED_LEVELING_FEATURE )
adjust_delta ( target ) ;
adjust_delta ( target ) ;
# endif
# endif
@ -6236,7 +6668,7 @@ void plan_arc(
# if ENABLED(DELTA) || ENABLED(SCARA)
# if ENABLED(DELTA) || ENABLED(SCARA)
calculate_delta ( arc_target ) ;
calculate_delta ( arc_target ) ;
# if ENABLED( ENABLE_ AUTO_BED_LEVELING)
# if ENABLED( AUTO_BED_LEVELING_FEATURE )
adjust_delta ( arc_target ) ;
adjust_delta ( arc_target ) ;
# endif
# endif
plan_buffer_line ( delta [ X_AXIS ] , delta [ Y_AXIS ] , delta [ Z_AXIS ] , arc_target [ E_AXIS ] , feed_rate , active_extruder ) ;
plan_buffer_line ( delta [ X_AXIS ] , delta [ Y_AXIS ] , delta [ Z_AXIS ] , arc_target [ E_AXIS ] , feed_rate , active_extruder ) ;
@ -6248,7 +6680,7 @@ void plan_arc(
// Ensure last segment arrives at target location.
// Ensure last segment arrives at target location.
# if ENABLED(DELTA) || ENABLED(SCARA)
# if ENABLED(DELTA) || ENABLED(SCARA)
calculate_delta ( target ) ;
calculate_delta ( target ) ;
# if ENABLED( ENABLE_ AUTO_BED_LEVELING)
# if ENABLED( AUTO_BED_LEVELING_FEATURE )
adjust_delta ( target ) ;
adjust_delta ( target ) ;
# endif
# endif
plan_buffer_line ( delta [ X_AXIS ] , delta [ Y_AXIS ] , delta [ Z_AXIS ] , target [ E_AXIS ] , feed_rate , active_extruder ) ;
plan_buffer_line ( delta [ X_AXIS ] , delta [ Y_AXIS ] , delta [ Z_AXIS ] , target [ E_AXIS ] , feed_rate , active_extruder ) ;