Refactor Chiron A31 Adjust all Probe Points routine

This commit is contained in:
Knutwurst
2023-06-03 19:29:59 +02:00
parent 6bc410a0e3
commit 70ccd6a957

View File

@@ -1480,9 +1480,8 @@ void AnycubicTouchscreenClass::RenderCurrentFolder(uint16_t selectedNumber) {
pos_z = getMeshPoint(pos); pos_z = getMeshPoint(pos);
SEND_PGM("A29V "); SENDLINE_PGM("A29V ");
LCD_SERIAL.print(pos_z * 100, 2); LCD_SERIAL.println(pos_z * 100);
SENDLINE_PGM("");
if (!isPrinting()) { if (!isPrinting()) {
setSoftEndstopState(true); setSoftEndstopState(true);
@@ -1515,7 +1514,8 @@ void AnycubicTouchscreenClass::RenderCurrentFolder(uint16_t selectedNumber) {
SENDLINE_DBG_PGM("J24", "TFT Serial Debug: Forbid auto leveling... J24"); SENDLINE_DBG_PGM("J24", "TFT Serial Debug: Forbid auto leveling... J24");
} else { } else {
SENDLINE_DBG_PGM("J26", "TFT Serial Debug: Start auto leveling... J26"); SENDLINE_DBG_PGM("J26", "TFT Serial Debug: Start auto leveling... J26");
injectCommands(F("G28\nG29")); //injectCommands(F("G28\nG29"));
injectCommands(F("G28\nG29\nG90\nM300 S440 P200\nM300 S660 P250\nM300 S880 P300\nG1 Z30 F4000\nG1 X5 F4000\nG91\nM84\nM420 S1"));
mediaPrintingState = AMPRINTSTATE_PROBING; mediaPrintingState = AMPRINTSTATE_PROBING;
} }
} else { } else {
@@ -1524,17 +1524,78 @@ void AnycubicTouchscreenClass::RenderCurrentFolder(uint16_t selectedNumber) {
break; break;
case 31: // A31 z-offset case 31: // A31 z-offset
// The tokens can occur in different places on the new panel so we need to find it. if (CodeSeen('S')) { // Set offset (adjusts all points by value)
float Zshift = CodeValue();
setSoftEndstopState(false);
if (isPrinting()) {
#if ENABLED(ANYCUBIC_TFT_DEBUG)
SERIAL_ECHOLNPGM("Change Zoffset from:", live_Zoffset, " to ", live_Zoffset + Zshift);
#endif
if (isAxisPositionKnown(Z)) {
#if ENABLED(ANYCUBIC_TFT_DEBUG)
const float currZpos = getAxisPosition_mm(Z);
SERIAL_ECHOLNPGM("Nudge Z pos from ", currZpos, " to ", currZpos + constrain(Zshift, -0.05, 0.05));
#endif
// Use babystepping to adjust the head position
int16_t steps = mmToWholeSteps(constrain(Zshift,-0.05,0.05), Z);
#if ENABLED(ANYCUBIC_TFT_DEBUG)
SERIAL_ECHOLNPGM("Steps to move Z: ", steps);
#endif
babystepAxis_steps(steps, Z);
live_Zoffset += Zshift;
}
SENDLINE_PGM("A31V ");
LCD_SERIAL.println(live_Zoffset);
}
else {
GRID_LOOP(x, y) {
const xy_uint8_t pos { x, y };
const float currval = getMeshPoint(pos);
setMeshPoint(pos, constrain(currval + Zshift, -10, 2));
#if ENABLED(ANYCUBIC_TFT_DEBUG)
SERIAL_ECHOLNPGM("Change mesh point X", x," Y",y ," from ", currval, " to ", getMeshPoint(pos) );
#endif
}
const float currZOffset = getZOffset_mm();
#if ENABLED(ANYCUBIC_TFT_DEBUG)
SERIAL_ECHOLNPGM("Change probe offset from ", currZOffset, " to ", currZOffset + Zshift);
#endif
setZOffset_mm(currZOffset + Zshift);
SENDLINE_PGM("A31V ");
LCD_SERIAL.println(getZOffset_mm());
if (isAxisPositionKnown(Z)) {
const float currZpos = getAxisPosition_mm(Z);
#if ENABLED(ANYCUBIC_TFT_DEBUG)
SERIAL_ECHOLNPGM("Move Z pos from ", currZpos, " to ", currZpos + constrain(Zshift, -0.05, 0.05));
#endif
setAxisPosition_mm(currZpos+constrain(Zshift,-0.05,0.05),Z);
}
}
}
if (CodeSeen('G')) { // Get current offset
SENDLINE_PGM("A31V ");
if (isPrinting())
LCD_SERIAL.println(live_Zoffset);
else {
LCD_SERIAL.println(getZOffset_mm());
selectedmeshpoint.x = selectedmeshpoint.y = 99;
}
}
if (CodeSeen('C')) { // Restore and apply original offsets if (CodeSeen('C')) { // Restore and apply original offsets
if (!isPrinting()) { if (!isPrinting()) {
injectCommands(F("M501\nM420 S1")); injectCommands(F("M501\nM420 S1"));
selectedmeshpoint.x = selectedmeshpoint.y = 99; selectedmeshpoint.x = selectedmeshpoint.y = 99;
SERIAL_ECHOLNF(F("Mesh changes abandoned, previous mesh restored.")); #if ENABLED(ANYCUBIC_TFT_DEBUG)
SERIAL_ECHOLNF(F("Mesh changes abandoned, previous mesh restored."));
#endif
} }
} }
else if (CodeSeen('D')) { // Save Z Offset tables and restore leveling state if (CodeSeen('D')) { // Save Z Offset tables and restore leveling state
if (!isPrinting()) { if (!isPrinting()) {
setAxisPosition_mm(1.0,Z); // Lift nozzle before any further movements are made setAxisPosition_mm(1.0,Z); // Lift nozzle before any further movements are made
injectCommands(F("M500")); injectCommands(F("M500"));
@@ -1544,71 +1605,7 @@ void AnycubicTouchscreenClass::RenderCurrentFolder(uint16_t selectedNumber) {
selectedmeshpoint.x = selectedmeshpoint.y = 99; selectedmeshpoint.x = selectedmeshpoint.y = 99;
} }
} }
SENDLINE_PGM("");
else if (CodeSeen('G')) { // Get current offset
SENDLINE_PGM("A31V ");
// When printing use the live z Offset position
// we will use babystepping to move the print head
if (isPrinting())
LCD_SERIAL.println(live_Zoffset);
else {
LCD_SERIAL.println(getZOffset_mm());
selectedmeshpoint.x = selectedmeshpoint.y = 99;
}
}
else {
if (CodeSeen('S')) { // Set offset (adjusts all points by value)
float Zshift = CodeValue();
setSoftEndstopState(false);
if (isPrinting()) {
#if ENABLED(ANYCUBIC_TFT_DEBUG)
SERIAL_ECHOLNPGM("Change Zoffset from:", live_Zoffset, " to ", live_Zoffset + Zshift);
#endif
if (isAxisPositionKnown(Z)) {
#if ENABLED(ANYCUBIC_TFT_DEBUG)
const float currZpos = getAxisPosition_mm(Z);
SERIAL_ECHOLNPGM("Nudge Z pos from ", currZpos, " to ", currZpos + constrain(Zshift, -0.05, 0.05));
#endif
// Use babystepping to adjust the head position
int16_t steps = mmToWholeSteps(constrain(Zshift,-0.05,0.05), Z);
#if ENABLED(ANYCUBIC_TFT_DEBUG)
SERIAL_ECHOLNPGM("Steps to move Z: ", steps);
#endif
babystepAxis_steps(steps, Z);
live_Zoffset += Zshift;
}
SENDLINE_PGM("A31V ");
LCD_SERIAL.println(live_Zoffset);
}
else {
GRID_LOOP(x, y) {
const xy_uint8_t pos { x, y };
const float currval = getMeshPoint(pos);
setMeshPoint(pos, constrain(currval + Zshift, -10, 2));
#if ENABLED(ANYCUBIC_TFT_DEBUG)
SERIAL_ECHOLNPGM("Change mesh point X", x," Y",y ," from ", currval, " to ", getMeshPoint(pos) );
#endif
}
const float currZOffset = getZOffset_mm();
#if ENABLED(ANYCUBIC_TFT_DEBUG)
SERIAL_ECHOLNPGM("Change probe offset from ", currZOffset, " to ", currZOffset + Zshift);
#endif
setZOffset_mm(currZOffset + Zshift);
SENDLINE_PGM("A31V ");
LCD_SERIAL.println(getZOffset_mm());
if (isAxisPositionKnown(Z)) {
const float currZpos = getAxisPosition_mm(Z);
#if ENABLED(ANYCUBIC_TFT_DEBUG)
SERIAL_ECHOLNPGM("Move Z pos from ", currZpos, " to ", currZpos + constrain(Zshift, -0.05, 0.05));
#endif
setAxisPosition_mm(currZpos+constrain(Zshift,-0.05,0.05),Z);
}
}
}
}
break; break;
case 32: // a32 clean leveling beep flag case 32: // a32 clean leveling beep flag