@ -544,14 +544,14 @@ static uint8_t target_extruder;
# if ENABLED(AUTO_BED_LEVELING_BILINEAR)
# if ENABLED(DELTA)
# define ADJUST_DELTA(V) \
if ( planner . abl_enabled ) { \
if ( planner . leveling_active ) { \
const float zadj = bilinear_z_offset ( V ) ; \
delta [ A_AXIS ] + = zadj ; \
delta [ B_AXIS ] + = zadj ; \
delta [ C_AXIS ] + = zadj ; \
}
# else
# define ADJUST_DELTA(V) if (planner. abl_enabled ) { delta[Z_AXIS] += bilinear_z_offset(V); }
# define ADJUST_DELTA(V) if (planner. leveling_active ) { delta[Z_AXIS] += bilinear_z_offset(V); }
# endif
# elif IS_KINEMATIC
# define ADJUST_DELTA(V) NOOP
@ -2460,7 +2460,7 @@ static void clean_up_after_endstop_or_probe_move() {
bool leveling_is_valid ( ) {
return
# if ENABLED(MESH_BED_LEVELING)
mbl . has_mesh ( )
mbl . has_mesh
# elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
! ! bilinear_grid_spacing [ X_AXIS ]
# elif ENABLED(AUTO_BED_LEVELING_UBL)
@ -2471,18 +2471,6 @@ static void clean_up_after_endstop_or_probe_move() {
;
}
bool leveling_is_active ( ) {
return
# if ENABLED(MESH_BED_LEVELING)
mbl . active ( )
# elif ENABLED(AUTO_BED_LEVELING_UBL)
ubl . state . active
# else
planner . abl_enabled
# endif
;
}
/**
* Turn bed leveling on or off , fixing the current
* position as - needed .
@ -2498,7 +2486,7 @@ static void clean_up_after_endstop_or_probe_move() {
constexpr bool can_change = true ;
# endif
if ( can_change & & enable ! = leveling_is_ active( ) ) {
if ( can_change & & enable ! = planner. leveling_active) {
# if ENABLED(MESH_BED_LEVELING)
@ -2506,23 +2494,23 @@ static void clean_up_after_endstop_or_probe_move() {
planner . apply_leveling ( current_position [ X_AXIS ] , current_position [ Y_AXIS ] , current_position [ Z_AXIS ] ) ;
const bool enabling = enable & & leveling_is_valid ( ) ;
mbl. set_active ( enabling ) ;
planner. leveling_active = enabling ;
if ( enabling ) planner . unapply_leveling ( current_position ) ;
# elif ENABLED(AUTO_BED_LEVELING_UBL)
# if PLANNER_LEVELING
if ( ubl. state . active) { // leveling from on to off
if ( planner. leveling_ active) { // leveling from on to off
// change unleveled current_position to physical current_position without moving steppers.
planner . apply_leveling ( current_position [ X_AXIS ] , current_position [ Y_AXIS ] , current_position [ Z_AXIS ] ) ;
ubl. state . active = false ; // disable only AFTER calling apply_leveling
planner. leveling_ active = false ; // disable only AFTER calling apply_leveling
}
else { // leveling from off to on
ubl. state . active = true ; // enable BEFORE calling unapply_leveling, otherwise ignored
planner. leveling_ active = true ; // enable BEFORE calling unapply_leveling, otherwise ignored
// change physical current_position to unleveled current_position without moving steppers.
planner . unapply_leveling ( current_position ) ;
}
# else
ubl. state . active = enable ; // just flip the bit, current_position will be wrong until next move.
planner. leveling_ active = enable ; // just flip the bit, current_position will be wrong until next move.
# endif
# else // ABL
@ -2534,7 +2522,7 @@ static void clean_up_after_endstop_or_probe_move() {
# endif
// Enable or disable leveling compensation in the planner
planner . abl_enabled = enable ;
planner . leveling_active = enable ;
if ( ! enable )
// When disabling just get the current position from the steppers.
@ -2559,23 +2547,18 @@ static void clean_up_after_endstop_or_probe_move() {
void set_z_fade_height ( const float zfh ) {
const bool level_active = leveling_is_ active( ) ;
const bool level_active = planner. leveling_active;
# if ENABLED(AUTO_BED_LEVELING_UBL)
if ( level_active ) set_bed_leveling_enabled ( false ) ; // turn off before changing fade height for proper apply/unapply leveling to maintain current_position
# endif
if ( level_active )
set_bed_leveling_enabled ( false ) ; // turn off before changing fade height for proper apply/unapply leveling to maintain current_position
planner . z_fade_height = zfh ;
planner . inverse_z_fade_height = RECIPROCAL ( zfh ) ;
if ( level_active )
set_bed_leveling_enabled ( true ) ; // turn back on after changing fade height
# else
planner . z_fade_height = zfh ;
planner . inverse_z_fade_height = RECIPROCAL ( zfh ) ;
planner . set_z_fade_height ( zfh ) ;
if ( level_active ) {
# if ENABLED(AUTO_BED_LEVELING_UBL)
set_bed_leveling_enabled ( true ) ; // turn back on after changing fade height
# else
set_current_from_steppers_for_axis (
# if ABL_PLANAR
ALL_AXES
@ -2583,9 +2566,9 @@ static void clean_up_after_endstop_or_probe_move() {
Z_AXIS
# endif
) ;
}
# endif
}
}
# endif // LEVELING_FADE_HEIGHT
@ -2597,7 +2580,7 @@ static void clean_up_after_endstop_or_probe_move() {
# if ENABLED(MESH_BED_LEVELING)
if ( leveling_is_valid ( ) ) {
mbl . reset ( ) ;
mbl . set_has_mesh( false ) ;
mbl . has_mesh = false ;
}
# else
# if ENABLED(DEBUG_LEVELING_FEATURE)
@ -3771,7 +3754,7 @@ inline void gcode_G4() {
# elif ENABLED(AUTO_BED_LEVELING_UBL)
SERIAL_ECHOPGM ( " UBL " ) ;
# endif
if ( leveling_is_ active( ) ) {
if ( planner. leveling_active) {
SERIAL_ECHOLNPGM ( " (enabled) " ) ;
# if ABL_PLANAR
const float diff [ XYZ ] = {
@ -3802,7 +3785,7 @@ inline void gcode_G4() {
# elif ENABLED(MESH_BED_LEVELING)
SERIAL_ECHOPGM ( " Mesh Bed Leveling " ) ;
if ( leveling_is_ active( ) ) {
if ( planner. leveling_active) {
float lz = current_position [ Z_AXIS ] ;
planner . apply_leveling ( current_position [ X_AXIS ] , current_position [ Y_AXIS ] , lz ) ;
SERIAL_ECHOLNPGM ( " (enabled) " ) ;
@ -3971,7 +3954,7 @@ inline void gcode_G28(const bool always_home_all) {
// Disable the leveling matrix before homing
# if HAS_LEVELING
# if ENABLED(AUTO_BED_LEVELING_UBL)
const bool ubl_state_at_entry = leveling_is_ active( ) ;
const bool ubl_state_at_entry = planner. leveling_active;
# endif
set_bed_leveling_enabled ( false ) ;
# endif
@ -4211,7 +4194,7 @@ void home_all_axes() { gcode_G28(true); }
}
void mesh_probing_done ( ) {
mbl . set_has_mesh( true ) ;
mbl . has_mesh = true ;
home_all_axes ( ) ;
set_bed_leveling_enabled ( true ) ;
# if ENABLED(MESH_G28_REST_ORIGIN)
@ -4261,7 +4244,7 @@ void home_all_axes() { gcode_G28(true); }
switch ( state ) {
case MeshReport :
if ( leveling_is_valid ( ) ) {
SERIAL_PROTOCOLLNPAIR ( " State: " , leveling_is_ active( ) ? MSG_ON : MSG_OFF ) ;
SERIAL_PROTOCOLLNPAIR ( " State: " , planner. leveling_active ? MSG_ON : MSG_OFF ) ;
mbl_mesh_report ( ) ;
}
else
@ -4374,7 +4357,7 @@ void home_all_axes() { gcode_G28(true); }
report_current_position ( ) ;
}
# elif HAS_ABL && DISABLED(AUTO_BED_LEVELING_UBL)
# elif OLDSCHOOL_ABL
# if ABL_GRID
# if ENABLED(PROBE_Y_FIRST)
@ -4580,7 +4563,7 @@ void home_all_axes() { gcode_G28(true); }
abl_probe_index = - 1 ;
# endif
abl_should_enable = leveling_is_ active( ) ;
abl_should_enable = planner. leveling_active;
# if ENABLED(AUTO_BED_LEVELING_BILINEAR)
@ -4720,7 +4703,7 @@ void home_all_axes() { gcode_G28(true); }
stepper . synchronize ( ) ;
// Disable auto bed leveling during G29
planner . abl_enabled = false ;
planner . leveling_active = false ;
if ( ! dryrun ) {
// Re-orient the current position without leveling
@ -4734,7 +4717,7 @@ void home_all_axes() { gcode_G28(true); }
# if HAS_BED_PROBE
// Deploy the probe. Probe will raise if needed.
if ( DEPLOY_PROBE ( ) ) {
planner . abl_enabled = abl_should_enable ;
planner . leveling_active = abl_should_enable ;
return ;
}
# endif
@ -4753,7 +4736,7 @@ void home_all_axes() { gcode_G28(true); }
) {
if ( dryrun ) {
// Before reset bed level, re-enable to correct the position
planner . abl_enabled = abl_should_enable ;
planner . leveling_active = abl_should_enable ;
}
// Reset grid to 0.0 or "not probed". (Also disables ABL)
reset_bed_level ( ) ;
@ -4798,7 +4781,7 @@ void home_all_axes() { gcode_G28(true); }
# if HAS_SOFTWARE_ENDSTOPS
soft_endstops_enabled = enable_soft_endstops ;
# endif
planner . abl_enabled = abl_should_enable ;
planner . leveling_active = abl_should_enable ;
g29_in_progress = false ;
# if ENABLED(LCD_BED_LEVELING)
lcd_wait_for_move = false ;
@ -4999,7 +4982,7 @@ void home_all_axes() { gcode_G28(true); }
measured_z = faux ? 0.001 * random ( - 100 , 101 ) : probe_pt ( xProbe , yProbe , stow_probe_after_each , verbose_level ) ;
if ( isnan ( measured_z ) ) {
planner . abl_enabled = abl_should_enable ;
planner . leveling_active = abl_should_enable ;
break ;
}
@ -5035,7 +5018,7 @@ void home_all_axes() { gcode_G28(true); }
yProbe = LOGICAL_Y_POSITION ( points [ i ] . y ) ;
measured_z = faux ? 0.001 * random ( - 100 , 101 ) : probe_pt ( xProbe , yProbe , stow_probe_after_each , verbose_level ) ;
if ( isnan ( measured_z ) ) {
planner . abl_enabled = abl_should_enable ;
planner . leveling_active = abl_should_enable ;
break ;
}
points [ i ] . z = measured_z ;
@ -5058,7 +5041,7 @@ void home_all_axes() { gcode_G28(true); }
// Raise to _Z_CLEARANCE_DEPLOY_PROBE. Stow the probe.
if ( STOW_PROBE ( ) ) {
planner . abl_enabled = abl_should_enable ;
planner . leveling_active = abl_should_enable ;
measured_z = NAN ;
}
}
@ -5226,9 +5209,9 @@ void home_all_axes() { gcode_G28(true); }
float converted [ XYZ ] ;
COPY ( converted , current_position ) ;
planner . abl_enabled = true ;
planner . leveling_active = true ;
planner . unapply_leveling ( converted ) ; // use conversion machinery
planner . abl_enabled = false ;
planner . leveling_active = false ;
// Use the last measured distance to the bed, if possible
if ( NEAR ( current_position [ X_AXIS ] , xProbe - ( X_PROBE_OFFSET_FROM_EXTRUDER ) )
@ -5280,7 +5263,7 @@ void home_all_axes() { gcode_G28(true); }
# endif
// Auto Bed Leveling is complete! Enable if possible.
planner . abl_enabled = dryrun ? abl_should_enable : true ;
planner . leveling_active = dryrun ? abl_should_enable : true ;
} // !isnan(measured_z)
// Restore state after probing
@ -5294,11 +5277,11 @@ void home_all_axes() { gcode_G28(true); }
KEEPALIVE_STATE ( IN_HANDLER ) ;
if ( planner . abl_enabled )
if ( planner . leveling_active )
SYNC_PLAN_POSITION_KINEMATIC ( ) ;
}
# endif // HAS_ABL && !AUTO_BED_LEVELING_U BL
# endif // OLDSCHOOL_A BL
# if HAS_BED_PROBE
@ -5886,7 +5869,7 @@ void home_all_axes() { gcode_G28(true); }
# endif // G38_PROBE_TARGET
# if ENABLED(AUTO_BED_LEVELING_BILINEAR) || ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(MESH_BED_LEVELING)
# if HAS_MESH
/**
* G42 : Move X & Y axes to mesh coordinates ( I & J )
@ -5938,7 +5921,7 @@ void home_all_axes() { gcode_G28(true); }
}
}
# endif // AUTO_BED_LEVELING_UBL
# endif // HAS_MESH
/**
* G92 : Set current position to given X Y Z E
@ -7077,7 +7060,7 @@ inline void gcode_M42() {
// Disable bed level correction in M48 because we want the raw data when we probe
# if HAS_LEVELING
const bool was_enabled = leveling_is_ active( ) ;
const bool was_enabled = planner. leveling_active;
set_bed_leveling_enabled ( false ) ;
# endif
@ -9352,7 +9335,7 @@ void quickstop_stepper() {
if ( parser . seen ( ' L ' ) ) {
# if ENABLED(EEPROM_SETTINGS)
const int8_t storage_slot = parser . has_value ( ) ? parser . value_int ( ) : ubl . st ate. st orage_slot;
const int8_t storage_slot = parser . has_value ( ) ? parser . value_int ( ) : ubl . st orage_slot;
const int16_t a = settings . calc_num_meshes ( ) ;
if ( ! a ) {
@ -9367,7 +9350,7 @@ void quickstop_stepper() {
}
settings . load_mesh ( storage_slot ) ;
ubl . st ate. st orage_slot = storage_slot ;
ubl . st orage_slot = storage_slot ;
# else
@ -9381,7 +9364,7 @@ void quickstop_stepper() {
if ( parser . seen ( ' L ' ) | | parser . seen ( ' V ' ) ) {
ubl . display_map ( 0 ) ; // Currently only supports one map type
SERIAL_ECHOLNPAIR ( " UBL_MESH_VALID = " , UBL_MESH_VALID ) ;
SERIAL_ECHOLNPAIR ( " ubl.st ate.st orage_slot = " , ubl . state . storage_slot ) ;
SERIAL_ECHOLNPAIR ( " ubl.st orage_slot = " , ubl . storage_slot ) ;
}
# endif // AUTO_BED_LEVELING_UBL
@ -9413,7 +9396,7 @@ void quickstop_stepper() {
if ( parser . seen ( ' Z ' ) ) set_z_fade_height ( parser . value_linear_units ( ) ) ;
# endif
const bool new_status = leveling_is_ active( ) ;
const bool new_status = planner. leveling_active;
if ( to_enable & & ! new_status ) {
SERIAL_ERROR_START ( ) ;
@ -9644,7 +9627,7 @@ inline void gcode_M502() {
# endif
# if ENABLED(BABYSTEP_ZPROBE_OFFSET)
if ( ! no_babystep & & leveling_is_ active( ) )
if ( ! no_babystep & & planner. leveling_active)
thermalManager . babystep_axis ( Z_AXIS , - LROUND ( diff * planner . axis_steps_per_mm [ Z_AXIS ] ) ) ;
# else
UNUSED ( no_babystep ) ;
@ -10521,13 +10504,13 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
+ ( tmp_extruder = = 0 ? - ( PARKING_EXTRUDER_GRAB_DISTANCE ) : PARKING_EXTRUDER_GRAB_DISTANCE ) ;
/**
* Steps :
* 1. raise Z - Axis to ha ve enough clearance
* 2. move to park po ition of old extruder
* 3. disengage magnet c field , wait for delay
* 4. m ove near new extruder
* 5. e ngage magnetic field for new extruder
* 6. m ove to parking incl . offset of new extruder
* 7. l ower Z - Axis
* 1. Raise Z - Axis to gi ve enough clearance
* 2. Move to park pos ition of old extruder
* 3. Disengage magneti c field , wait for delay
* 4. M ove near new extruder
* 5. E ngage magnetic field for new extruder
* 6. M ove to parking incl . offset of new extruder
* 7. L ower Z - Axis
*/
// STEP 1
@ -10691,7 +10674,7 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
# if ENABLED(MESH_BED_LEVELING)
if ( leveling_is_ active( ) ) {
if ( planner. leveling_active) {
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( DEBUGGING ( LEVELING ) ) SERIAL_ECHOPAIR ( " Z before MBL: " , current_position [ Z_AXIS ] ) ;
# endif
@ -10809,7 +10792,7 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
* F [ units / min ] Set the movement feedrate
* S1 Don ' t move the tool in XY after change
*/
inline void gcode_T ( uint8_t tmp_extruder ) {
inline void gcode_T ( const uint8_t tmp_extruder ) {
# if ENABLED(DEBUG_LEVELING_FEATURE)
if ( DEBUGGING ( LEVELING ) ) {
@ -11006,7 +10989,7 @@ void process_next_command() {
gcode_G92 ( ) ;
break ;
# if ENABLED(AUTO_BED_LEVELING_BILINEAR) || ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(MESH_BED_LEVELING)
# if HAS_MESH
case 42 :
gcode_G42 ( ) ;
break ;
@ -11491,7 +11474,7 @@ void process_next_command() {
break ;
# endif
# if ENABLED(MESH_BED_LEVELING) || ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(AUTO_BED_LEVELING_BILINEAR)
# if HAS_MESH
case 421 : // M421: Set a Mesh Bed Leveling Z coordinate
gcode_M421 ( ) ;
break ;
@ -12389,39 +12372,28 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
* Prepare a linear move in a Cartesian setup .
* If Mesh Bed Leveling is enabled , perform a mesh move .
*
* Returns true if the caller didn ' t update current_position .
* Returns true if current_position[ ] was set to destination [ ]
*/
inline bool prepare_move_to_destination_cartesian ( ) {
# if ENABLED(AUTO_BED_LEVELING_UBL)
if ( current_position [ X_AXIS ] ! = destination [ X_AXIS ] | | current_position [ Y_AXIS ] ! = destination [ Y_AXIS ] ) {
const float fr_scaled = MMS_SCALED ( feedrate_mm_s ) ;
if ( ubl . state . active ) { // direct use of ubl.state.active for speed
# if HAS_MESH
if ( planner . leveling_active ) {
# if ENABLED(AUTO_BED_LEVELING_UBL)
ubl . line_to_destination_cartesian ( fr_scaled , active_extruder ) ;
return true ;
}
else
line_to_destination ( fr_scaled ) ;
# else
// Do not use feedrate_percentage for E or Z only moves
if ( current_position [ X_AXIS ] = = destination [ X_AXIS ] & & current_position [ Y_AXIS ] = = destination [ Y_AXIS ] )
line_to_destination ( ) ;
else {
const float fr_scaled = MMS_SCALED ( feedrate_mm_s ) ;
# if ENABLED(MESH_BED_LEVELING)
if ( mbl . active ( ) ) { // direct used of mbl.active() for speed
# elif ENABLED(MESH_BED_LEVELING)
mesh_line_to_destination ( fr_scaled ) ;
return true ;
}
else
# elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
if ( planner . abl_enabled ) { // direct use of abl_enabled for speed
bilinear_line_to_destination ( fr_scaled ) ;
# endif
return true ;
}
else
# endif
# endif // HAS_MESH
line_to_destination ( fr_scaled ) ;
}
# endif
else
line_to_destination ( ) ;
return false ;
}