Fix live Z offset.

This commit is contained in:
Knutwurst
2023-06-06 16:46:09 +02:00
parent fbd1b7b9bf
commit 9376b95148
2 changed files with 77 additions and 80 deletions

View File

@@ -32,7 +32,7 @@
#include "../../../module/motion.h" #include "../../../module/motion.h"
#include "../../../module/stepper.h" #include "../../../module/stepper.h"
//#define ANYCUBIC_TFT_DEBUG #define ANYCUBIC_TFT_DEBUG
//#define KNUTWURST_DGUS2_TFT //#define KNUTWURST_DGUS2_TFT
//#define KNUTWURST_TFT_LEVELING //#define KNUTWURST_TFT_LEVELING
@@ -121,6 +121,7 @@
CaseLight = false; CaseLight = false;
currentFlowRate = 100; currentFlowRate = 100;
flowRateBuffer = SM_FLOW_DISP_L; flowRateBuffer = SM_FLOW_DISP_L;
live_Zoffset = 0.0;
#if BOTH(SDSUPPORT, HAS_SD_DETECT) #if BOTH(SDSUPPORT, HAS_SD_DETECT)
SET_INPUT_PULLUP(SD_DETECT_PIN); SET_INPUT_PULLUP(SD_DETECT_PIN);
@@ -1493,7 +1494,7 @@ void AnycubicTouchscreenClass::RenderCurrentFolder(uint16_t selectedNumber) {
#if ENABLED(ANYCUBIC_TFT_DEBUG) #if ENABLED(ANYCUBIC_TFT_DEBUG)
SERIAL_ECHOLNPGM("Moving to mesh point at x: ", pos.x, " y: ", pos.y, " z: ", pos_z); SERIAL_ECHOLNPGM("Moving to mesh point at x: ", pos.x, " y: ", pos.y, " z: ", pos_z);
#endif #endif
setAxisPosition_mm(3.0,Z); setAxisPosition_mm(5.0,Z);
setAxisPosition_mm(17 + (93 * pos.x), X); setAxisPosition_mm(17 + (93 * pos.x), X);
setAxisPosition_mm(20 + (93 * pos.y), Y); setAxisPosition_mm(20 + (93 * pos.y), Y);
setAxisPosition_mm(0.0, Z); setAxisPosition_mm(0.0, Z);
@@ -1524,58 +1525,26 @@ void AnycubicTouchscreenClass::RenderCurrentFolder(uint16_t selectedNumber) {
break; break;
case 31: // A31 z-offset case 31: // A31 z-offset
if (CodeSeen('S')) { // Set offset (adjusts all points by value) if (CodeSeen('C')) { // Restore and apply original offsets
float Zshift = CodeValue(); if (!isPrinting()) {
setSoftEndstopState(false); injectCommands(F("M501\nM420 S1"));
if (isPrinting()) { selectedmeshpoint.x = selectedmeshpoint.y = 99;
#if ENABLED(ANYCUBIC_TFT_DEBUG) SERIAL_ECHOLNF(F("Mesh changes abandoned, previous mesh restored."));
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 else if (CodeSeen('D')) { // Save Z Offset tables and restore leveling state
if (!isPrinting()) {
setAxisPosition_mm(5.0,Z); // Lift nozzle before any further movements are made
injectCommands(F("M500"));
#if ENABLED(ANYCUBIC_TFT_DEBUG)
SERIAL_ECHOLNF(F("Mesh changes saved."));
#endif
selectedmeshpoint.x = selectedmeshpoint.y = 99;
}
}
else if (CodeSeen('G')) { // Get current offset
SENDLINE_PGM("A31V "); SENDLINE_PGM("A31V ");
if (isPrinting()) if (isPrinting())
LCD_SERIAL.println(live_Zoffset); LCD_SERIAL.println(live_Zoffset);
@@ -1585,27 +1554,57 @@ void AnycubicTouchscreenClass::RenderCurrentFolder(uint16_t selectedNumber) {
} }
} }
if (CodeSeen('C')) { // Restore and apply original offsets else {
if (!isPrinting()) { if (CodeSeen('S')) { // Set offset (adjusts all points by value)
injectCommands(F("M501\nM420 S1")); float Zshift = CodeValue();
selectedmeshpoint.x = selectedmeshpoint.y = 99; setSoftEndstopState(false);
#if ENABLED(ANYCUBIC_TFT_DEBUG) if (isPrinting()) {
SERIAL_ECHOLNF(F("Mesh changes abandoned, previous mesh restored.")); #if ENABLED(ANYCUBIC_TFT_DEBUG)
#endif 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
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
if (CodeSeen('D')) { // Save Z Offset tables and restore leveling state setZOffset_mm(currZOffset + Zshift);
if (!isPrinting()) { SENDLINE_PGM("A31V ");
setAxisPosition_mm(1.0,Z); // Lift nozzle before any further movements are made LCD_SERIAL.println(getZOffset_mm());
injectCommands(F("M500"));
#if ENABLED(ANYCUBIC_TFT_DEBUG) if (isAxisPositionKnown(Z)) {
SERIAL_ECHOLNF(F("Mesh changes saved.")); const float currZpos = getAxisPosition_mm(Z);
#endif #if ENABLED(ANYCUBIC_TFT_DEBUG)
selectedmeshpoint.x = selectedmeshpoint.y = 99; 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);
}
}
} }
} }
SENDLINE_PGM("");
break; break;
case 32: // a32 clean leveling beep flag case 32: // a32 clean leveling beep flag
@@ -1935,9 +1934,10 @@ void AnycubicTouchscreenClass::RenderCurrentFolder(uint16_t selectedNumber) {
void AnycubicTouchscreenClass::OnPrintTimerStarted() { void AnycubicTouchscreenClass::OnPrintTimerStarted() {
#if ENABLED(SDSUPPORT) #if ENABLED(SDSUPPORT)
if (mediaPrintingState == AMPRINTSTATE_PRINTING) if (mediaPrintingState == AMPRINTSTATE_PRINTING) {
SENDLINE_DBG_PGM("J04", "TFT Serial Debug: Starting SD Print... J04"); // J04 Starting Print SENDLINE_DBG_PGM("J04", "TFT Serial Debug: Starting SD Print... J04"); // J04 Starting Print
live_Zoffset = 0.0;
}
#endif #endif
} }

View File

@@ -199,9 +199,9 @@ void UserConfirmRequired(const char *);
void SDCardStateChange(bool); void SDCardStateChange(bool);
void SDCardError(); void SDCardError();
void KillTFT(); void KillTFT();
static void OnPrintTimerStarted(); void OnPrintTimerStarted();
static void OnPrintTimerPaused(); void OnPrintTimerPaused();
static void OnPrintTimerStopped(); void OnPrintTimerStopped();
#if BOTH(ANYCUBIC_TFT_DEBUG, KNUTWURST_DGUS2_TFT) #if BOTH(ANYCUBIC_TFT_DEBUG, KNUTWURST_DGUS2_TFT)
void Command(const char * const command); void Command(const char * const command);
@@ -226,11 +226,8 @@ uint16_t HeaterCheckCount = 0;
int currentFlowRate = 0; int currentFlowRate = 0;
bool PrintdoneAndPowerOFF = true; bool PrintdoneAndPowerOFF = true;
bool powerOFFflag = 0; bool powerOFFflag = 0;
xy_uint8_t selectedmeshpoint;
#if ENABLED(KNUTWURST_TFT_LEVELING) float live_Zoffset;
xy_uint8_t selectedmeshpoint;
float live_Zoffset;
#endif
static AnycubicMediaPrintState mediaPrintingState; static AnycubicMediaPrintState mediaPrintingState;
static AnycubicMediaPauseState mediaPauseState; static AnycubicMediaPauseState mediaPauseState;