Refactor Z axis full-step movement to G88 command

Moved Z axis full-step positioning logic from M88 to G88 command. Extracted movement code into a new move_z_to_next_fullstep() function, updated references in power_panic and LCD menu, and removed the old M88 implementation.
This commit is contained in:
Mathias Gyldenberg 2025-09-10 19:28:36 +02:00
parent e866db6a28
commit 688e40a5ae
5 changed files with 25 additions and 33 deletions

View File

@ -4606,15 +4606,15 @@ void process_commands()
calibration_status_set(CALIBRATION_STATUS_LIVE_ADJUST);
break;
/*!
### G88 - Reserved <a href="https://reprap.org/wiki/G-code#G88:_Reserved">G88: Reserved</a>
Currently has no effect.
/*!
### G88 - Move Z axis to next full-step position
*/
// Prusa3D specific: Don't know what it is for, it is in V2Calibration.gcode
case 88:
if (axis_known_position[Z_AXIS]) {
move_z_to_next_fullstep();
}
break;
@ -5707,22 +5707,6 @@ void process_commands()
break;
#endif
/*!
### M88 - Move Z axis to a full-step position
*/
#ifdef TMC2130
case 88:
if (axis_known_position[Z_AXIS]) {
float target_z = current_position[Z_AXIS] + float(1024 - tmc2130_rd_MSCNT(Z_AXIS)) / (tmc2130_get_res(Z_AXIS) * cs.axis_steps_per_mm[Z_AXIS]) + 0.16f;
if (target_z <= max_pos[Z_AXIS]) {
current_position[Z_AXIS] = target_z;
plan_buffer_line_curposXYZE(homing_feedrate[Z_AXIS]/60);
st_synchronize();
}
}
break;
#endif
/*!
### M92 - Set Axis steps-per-unit <a href="https://reprap.org/wiki/G-code#M92:_Set_axis_steps_per_unit">M92: Set axis_steps_per_unit</a>
Allows programming of steps per unit (usually mm) for motor drives. These values are reset to firmware defaults on power on, unless saved to EEPROM if available (M500 in Marlin)

View File

@ -135,17 +135,7 @@ void uvlo_() {
st_synchronize();
disable_e0();
// Read out the current Z motor microstep counter to move the axis up towards
// a full step before powering off. NOTE: we need to ensure to schedule more
// than "dropsegments" steps in order to move (this is always the case here
// due to UVLO_Z_AXIS_SHIFT being used)
uint16_t z_res = tmc2130_get_res(Z_AXIS);
uint16_t z_microsteps = tmc2130_rd_MSCNT(Z_AXIS);
current_position[Z_AXIS] += float(1024 - z_microsteps)
/ (z_res * cs.axis_steps_per_mm[Z_AXIS])
+ UVLO_Z_AXIS_SHIFT;
plan_buffer_line_curposXYZE(homing_feedrate[Z_AXIS]/60);
st_synchronize();
move_z_to_next_fullstep();
poweroff_z();
// Write the file position.

View File

@ -250,6 +250,22 @@ void invert_z_endstop(bool endstop_invert)
z_endstop_invert = endstop_invert;
}
void move_z_to_next_fullstep() {
#ifdef TMC2130
// Read out the current Z motor microstep counter to move the axis up towards
// a full step before powering off. NOTE: we need to ensure to schedule more
// than "dropsegments" steps in order to move (this is always the case here
// due to UVLO_Z_AXIS_SHIFT being used)
uint16_t z_res = tmc2130_get_res(Z_AXIS);
uint16_t z_microsteps = tmc2130_rd_MSCNT(Z_AXIS);
current_position[Z_AXIS] += float(1024 - z_microsteps)
/ (z_res * cs.axis_steps_per_mm[Z_AXIS])
+ UVLO_Z_AXIS_SHIFT;
plan_buffer_line_curposXYZE(homing_feedrate[Z_AXIS]/60);
st_synchronize();
#endif
}
// __________________________
// /| |\ _________________ ^
// / | | \ /| |\ |

View File

@ -67,6 +67,8 @@ bool enable_endstops(bool check); // Enable/disable endstop checking. Return the
bool enable_z_endstop(bool check);
void invert_z_endstop(bool endstop_invert);
void move_z_to_next_fullstep(); //Move Z axis up to the next fullstep
void checkStepperErrors(); //Print errors detected by the stepper
extern block_t *current_block; // A pointer to the block currently being traced

View File

@ -4526,7 +4526,7 @@ static void lcd_calibration_menu()
}
MENU_ITEM_GCODE_P(_T(MSG_AUTO_HOME), G28W);
if (axis_known_position[Z_AXIS]) {
MENU_ITEM_GCODE_P(_T(MSG_FULLSTEP_Z), PSTR("M88"));
MENU_ITEM_GCODE_P(_T(MSG_FULLSTEP_Z), PSTR("G88"));
}
#ifdef TMC2130
MENU_ITEM_FUNCTION_P(_T(MSG_BELTTEST), lcd_belttest_v);