Fix stuttering issues on detailed models

- Optimize TFT code for state handling (pause, runout, ...)
- Remove multiple state booleans in favour of a single integer
- Remove obsolete filament runout code
- Increase jerk/accel
- Decrease TX buffer size
- Revert minimum segment time to factory default
This commit is contained in:
David Ramiro 2019-04-03 15:48:11 +02:00
parent b18052c0c3
commit 425e10c29a
No known key found for this signature in database
GPG Key ID: 5B042737EBEEB736
6 changed files with 203 additions and 107 deletions

View File

@ -145,48 +145,64 @@ void AnycubicTFTClass::KillTFT()
void AnycubicTFTClass::StartPrint() {
// are we resuming from a pause?
if (TFTstate==ANYCUBIC_TFT_STATE_SDPAUSE) {
// was that a regular pause?
if((!PausedByRunout) && (!PausedByFilamentChange) && (!PausedByNozzleTimeout)) {
// which kind of starting behaviour is needed?
switch (ai3m_pause_state) {
case 0:
// no pause, just a regular start
starttime=millis();
card.startFileprint();
TFTstate=ANYCUBIC_TFT_STATE_SDPRINT;
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOPAIR(" DEBUG: AI3M Pause State: ", ai3m_pause_state);
SERIAL_EOL();
SERIAL_ECHOLNPGM("DEBUG: Regular Start");
#endif
break;
case 1:
// regular sd pause
enqueue_and_echo_commands_P(PSTR("M24")); // unpark nozzle
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOPAIR(" DEBUG: AI3M Pause State: ", ai3m_pause_state);
SERIAL_EOL();
SERIAL_ECHOLNPGM("DEBUG: M24 Resume from regular pause");
#endif
IsParked=false; // remove parked flag
}
}
starttime=millis();
#ifdef SDSUPPORT
// was that a regular pause or are we starting a print?
if((!PausedByRunout) && (!PausedByFilamentChange) && (!PausedByNozzleTimeout)) {
card.startFileprint(); // start or resume regularly
}
// resuming from a pause that was caused by filament runout
else if((PausedByRunout) && (!PausedByFilamentChange) && (!PausedByNozzleTimeout)) {
card.startFileprint(); // resume regularly
TFTstate=ANYCUBIC_TFT_STATE_SDPRINT;
ai3m_pause_state = 0;
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOPAIR(" DEBUG: AI3M Pause State: ", ai3m_pause_state);
SERIAL_EOL();
#endif
break;
case 2:
// paused by M600
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOPAIR(" DEBUG: AI3M Pause State: ", ai3m_pause_state);
SERIAL_EOL();
SERIAL_ECHOLNPGM("DEBUG: Start M108 routine");
#endif
FilamentChangeResume(); // enter display M108 routine
ai3m_pause_state = 0; // clear flag
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: Filament Change Flag cleared");
#endif
break;
case 3:
// paused by filament runout
enqueue_and_echo_commands_P(PSTR("M24")); // unpark nozzle and resume
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: M24 Resume from Filament Runout");
#endif
PausedByRunout = IsParked = false; // clear flags
IsParked = false; // clear flags
ai3m_pause_state = 0;
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: Filament Pause Flag cleared");
#endif
}
// was M600 called and the nozzle is not timed out?
else if((!PausedByRunout) && (PausedByFilamentChange) && (!PausedByNozzleTimeout)) {
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: Start M108 routine");
#endif
FilamentChangeResume(); // enter display M108 routine
PausedByFilamentChange=false; // clear flag
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: Filament Change Flag cleared");
#endif
}
#endif
if (PausedByNozzleTimeout) {
// nozzle was timed out before, do not enter printing state yet
break;
case 4:
// nozzle was timed out before (M600), do not enter printing state yet
TFTstate=ANYCUBIC_TFT_STATE_SDPAUSE_REQ;
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: Set Pause again because of timeout");
@ -194,31 +210,61 @@ void AnycubicTFTClass::StartPrint(){
// clear the timeout flag to ensure the print continues on the
// next push of CONTINUE
PausedByNozzleTimeout=false;
ai3m_pause_state = 2;
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: Nozzle timeout flag cleared");
#endif
} else {
// regular resume/start or all specific resume routines are done,
// set printing state again
TFTstate=ANYCUBIC_TFT_STATE_SDPRINT;
break;
case 5:
// nozzle was timed out before (runout), do not enter printing state yet
TFTstate=ANYCUBIC_TFT_STATE_SDPAUSE_REQ;
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: Set Pause again because of timeout");
#endif
// clear the timeout flag to ensure the print continues on the
// next push of CONTINUE
ai3m_pause_state = 3;
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: Nozzle timeout flag cleared");
#endif
break;
default:
break;
}
}
void AnycubicTFTClass::PausePrint() {
#ifdef SDSUPPORT
if((!PausedByRunout)) { // is this a regular pause?
if(ai3m_pause_state < 2) { // is this a regular pause?
card.pauseSDPrint(); // pause print regularly
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOPAIR(" DEBUG: AI3M Pause State: ", ai3m_pause_state);
SERIAL_EOL();
SERIAL_ECHOLNPGM("DEBUG: Regular Pause");
#endif
} else { // pause caused by filament runout
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: Filament Runout Pause");
#endif
// filament runout, retract and beep
enqueue_and_echo_commands_P(PSTR("G91")); // relative mode
enqueue_and_echo_commands_P(PSTR("G1 E-3 F1800")); // retract 3mm
enqueue_and_echo_commands_P(PSTR("G90")); // absolute mode
buzzer.tone(200, 1567);
buzzer.tone(200, 1174);
buzzer.tone(200, 1567);
buzzer.tone(200, 1174);
buzzer.tone(2000, 1567);
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: Filament runout - Retract, beep and park.");
#endif
enqueue_and_echo_commands_P(PSTR("M25")); // pause print and park nozzle
ai3m_pause_state = 3;
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: M25 sent, parking nozzle");
SERIAL_ECHOPAIR(" DEBUG: AI3M Pause State: ", ai3m_pause_state);
SERIAL_EOL();
#endif
IsParked = true;
// show filament runout prompt on screen
@ -230,24 +276,6 @@ void AnycubicTFTClass::PausePrint(){
}
#endif
TFTstate=ANYCUBIC_TFT_STATE_SDPAUSE_REQ;
#ifdef ANYCUBIC_FILAMENT_RUNOUT_SENSOR
// regular pause
if(FilamentTestStatus) {
ANYCUBIC_SERIAL_PROTOCOLPGM("J05");
ANYCUBIC_SERIAL_ENTER();
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("TFT Serial Debug: SD print paused... J05");
#endif
// pause because of filament sensor
} else {
// show filament runout prompt on screen
ANYCUBIC_SERIAL_PROTOCOLPGM("J23");
ANYCUBIC_SERIAL_ENTER();
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("TFT Serial Debug: Filament runout while printing... J23");
#endif
}
#endif
}
void AnycubicTFTClass::StopPrint(){
@ -259,12 +287,18 @@ void AnycubicTFTClass::StopPrint(){
#endif
print_job_timer.stop();
thermalManager.disable_all_heaters();
IsParked = false; // we are not parked yet, do it in the display state routine
// we are not parked yet, do it in the display state routine
IsParked = false;
// turn off fan, cancel any heatups and set display state
#if FAN_COUNT > 0
for (uint8_t i = 0; i < FAN_COUNT; i++) fanSpeeds[i] = 0;
#endif
wait_for_heatup=false;
ai3m_pause_state = 0;
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOPAIR(" DEBUG: AI3M Pause State: ", ai3m_pause_state);
SERIAL_EOL();
#endif
TFTstate=ANYCUBIC_TFT_STATE_SDSTOP_REQ;
}
@ -289,7 +323,11 @@ void AnycubicTFTClass::FilamentChangeResume(){
void AnycubicTFTClass::FilamentChangePause(){
// set filament change flag to ensure the M108 routine
// gets used when the user hits CONTINUE
PausedByFilamentChange=true;
ai3m_pause_state = 2;
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOPAIR(" DEBUG: AI3M Pause State: ", ai3m_pause_state);
SERIAL_EOL();
#endif
// call M600 and set display state to paused
enqueue_and_echo_commands_P(PSTR("M600"));
@ -313,11 +351,19 @@ void AnycubicTFTClass::ReheatNozzle(){
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: Clear flags");
#endif
nozzle_timed_out = false;
// clear waiting flags
nozzle_timed_out = false;
wait_for_user = false;
wait_for_heatup = false;
// lower the pause flag by two to restore initial pause condition
if (ai3m_pause_state > 3) {
ai3m_pause_state -= 2;
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOPAIR(" DEBUG: NTO done, AI3M Pause State: ", ai3m_pause_state);
SERIAL_EOL();
#endif
}
// set pause state to show CONTINUE button again
TFTstate=ANYCUBIC_TFT_STATE_SDPAUSE_REQ;
@ -339,6 +385,11 @@ void AnycubicTFTClass::ParkAfterStop(){
}
enqueue_and_echo_commands_P(PSTR("M84")); // disable stepper motors
enqueue_and_echo_commands_P(PSTR("M27")); // force report of SD status
ai3m_pause_state = 0;
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOPAIR(" DEBUG: AI3M Pause State: ", ai3m_pause_state);
SERIAL_EOL();
#endif
}
float AnycubicTFTClass::CodeValue()
@ -583,7 +634,7 @@ void AnycubicTFTClass::StateHandler()
if (card.isFileOpen()) {
// File is still open --> paused
TFTstate=ANYCUBIC_TFT_STATE_SDPAUSE;
} else {
} else if ((!card.isFileOpen()) && (ai3m_pause_state == 0)) {
// File is closed --> stopped
TFTstate=ANYCUBIC_TFT_STATE_IDLE;
ANYCUBIC_SERIAL_PROTOCOLPGM("J14");// J14 print done
@ -591,6 +642,11 @@ void AnycubicTFTClass::StateHandler()
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("TFT Serial Debug: SD print done... J14");
#endif
ai3m_pause_state = 0;
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOPAIR(" DEBUG: AI3M Pause State: ", ai3m_pause_state);
SERIAL_EOL();
#endif
}
}
#endif
@ -611,9 +667,13 @@ void AnycubicTFTClass::StateHandler()
#ifdef SDSUPPORT
if((!card.sdprinting) && (!planner.movesplanned())) {
// We have to wait until the sd card printing has been settled
if((!PausedByRunout) && (!PausedByFilamentChange) && (!PausedByNozzleTimeout)) {
if(ai3m_pause_state < 2) {
// no flags, this is a regular pause.
ai3m_pause_state = 1;
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOPAIR(" DEBUG: AI3M Pause State: ", ai3m_pause_state);
SERIAL_EOL();
SERIAL_ECHOLNPGM("DEBUG: Regular Pause requested");
#endif
if(!IsParked) {
@ -621,19 +681,6 @@ void AnycubicTFTClass::StateHandler()
enqueue_and_echo_commands_P(PSTR("M125 L2"));
IsParked = true;
}
} else if((PausedByRunout)) {
// filament runout, retract and beep
enqueue_and_echo_commands_P(PSTR("G91")); // relative mode
enqueue_and_echo_commands_P(PSTR("G1 E-3 F1800")); // retract 3mm
enqueue_and_echo_commands_P(PSTR("G90")); // absolute mode
buzzer.tone(200, 1567);
buzzer.tone(200, 1174);
buzzer.tone(200, 1567);
buzzer.tone(200, 1174);
buzzer.tone(2000, 1567);
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: Filament runout - Retract, beep and park.");
#endif
}
#ifdef ANYCUBIC_FILAMENT_RUNOUT_SENSOR
if(FilamentTestStatus) {
@ -659,6 +706,11 @@ void AnycubicTFTClass::StateHandler()
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("TFT Serial Debug: SD print stopped... J16");
#endif
ai3m_pause_state = 0;
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOPAIR(" DEBUG: AI3M Pause State: ", ai3m_pause_state);
SERIAL_EOL();
#endif
}
// did we park the hotend already?
if((!IsParked) && (!card.sdprinting) && (!planner.movesplanned())) {
@ -702,9 +754,10 @@ void AnycubicTFTClass::FilamentRunout()
SERIAL_ECHOLNPGM("DEBUG: 3000ms delay done");
#endif
if((card.sdprinting==true)) {
PausedByRunout=true; // set runout pause flag
ai3m_pause_state = 3; // set runout pause flag
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: Filament Pause Flag set");
SERIAL_ECHOPAIR(" DEBUG: AI3M Pause State: ", ai3m_pause_state);
SERIAL_EOL();
#endif
PausePrint();
} else if((card.sdprinting==false)) {
@ -877,6 +930,11 @@ void AnycubicTFTClass::GetCommandFromTFT()
}
else
{
ai3m_pause_state = 0;
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOPAIR(" DEBUG: AI3M Pause State: ", ai3m_pause_state);
SERIAL_EOL();
#endif
StopPrint();
}
#endif
@ -906,6 +964,11 @@ void AnycubicTFTClass::GetCommandFromTFT()
ANYCUBIC_SERIAL_PROTOCOLPGM("J16");
ANYCUBIC_SERIAL_ENTER();
TFTstate=ANYCUBIC_TFT_STATE_IDLE;
ai3m_pause_state = 0;
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOPAIR(" DEBUG: AI3M Pause State: ", ai3m_pause_state);
SERIAL_EOL();
#endif
}
#endif
break;
@ -949,6 +1012,11 @@ void AnycubicTFTClass::GetCommandFromTFT()
#ifdef SDSUPPORT
if((!planner.movesplanned()) && (TFTstate!=ANYCUBIC_TFT_STATE_SDPAUSE) && (TFTstate!=ANYCUBIC_TFT_STATE_SDOUTAGE) && (card.isFileOpen()))
{
ai3m_pause_state = 0;
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOPAIR(" DEBUG: AI3M Pause State: ", ai3m_pause_state);
SERIAL_EOL();
#endif
StartPrint();
IsParked = false;
ANYCUBIC_SERIAL_PROTOCOLPGM("J04"); // J04 Starting Print

View File

@ -56,9 +56,18 @@ public:
void FilamentRunout();
void KillTFT();
char TFTstate=ANYCUBIC_TFT_STATE_IDLE;
bool PausedByRunout=false;
bool PausedByFilamentChange=false;
bool PausedByNozzleTimeout=false;
/**
* Anycubic TFT pause states:
*
* 0 - printing / stopped
* 1 - regular pause
* 2 - M600 pause
* 3 - filament runout pause
* 4 - nozzle timeout on M600
* 5 - nozzle timeout on filament runout
*/
uint8_t ai3m_pause_state = 0;
private:
char TFTcmdbuffer[TFTBUFSIZE][TFT_MAX_CMD_SIZE];

View File

@ -629,7 +629,7 @@
* Override with M201
* X, Y, Z, E0 [, E1[, E2[, E3[, E4]]]]
*/
#define DEFAULT_MAX_ACCELERATION { 2000, 1200, 60, 10000 }
#define DEFAULT_MAX_ACCELERATION { 3000, 2000, 60, 10000 }
/**
* Default Acceleration (change/s) change = mm/s
@ -639,9 +639,9 @@
* M204 R Retract Acceleration
* M204 T Travel Acceleration
*/
#define DEFAULT_ACCELERATION 1200 // X, Y, Z and E acceleration for printing moves
#define DEFAULT_ACCELERATION 1500 // X, Y, Z and E acceleration for printing moves
#define DEFAULT_RETRACT_ACCELERATION 3000 // E acceleration for retracts
#define DEFAULT_TRAVEL_ACCELERATION 1500 // X, Y, Z acceleration for travel (non printing) moves
#define DEFAULT_TRAVEL_ACCELERATION 3000 // X, Y, Z acceleration for travel (non printing) moves
/**
* Default Jerk (mm/s)
@ -651,8 +651,8 @@
* When changing speed and direction, if the difference is less than the
* value set here, it may happen instantaneously.
*/
#define DEFAULT_XJERK 8.0
#define DEFAULT_YJERK 8.0
#define DEFAULT_XJERK 10.0
#define DEFAULT_YJERK 10.0
#define DEFAULT_ZJERK 0.4
#define DEFAULT_EJERK 5.0

View File

@ -431,7 +431,7 @@
// @section extras
// minimum time in microseconds that a movement needs to take if the buffer is emptied.
#define DEFAULT_MINSEGMENTTIME 30000
#define DEFAULT_MINSEGMENTTIME 20000
// If defined the movements slow down when the look ahead buffer is only half full
#define SLOWDOWN
@ -889,7 +889,7 @@
// For debug-echo: 128 bytes for the optimal speed.
// Other output doesn't need to be that speedy.
// :[0, 2, 4, 8, 16, 32, 64, 128, 256]
#define TX_BUFFER_SIZE 256
#define TX_BUFFER_SIZE 4
// Host Receive Buffer Size
// Without XON/XOFF flow control (see SERIAL_XON_XOFF below) 32 bytes should be enough.

View File

@ -7212,9 +7212,6 @@ inline void gcode_M17() {
*/
static void wait_for_filament_reload(const int8_t max_beep_count=0) {
nozzle_timed_out = false;
#ifdef ANYCUBIC_TFT_MODEL
AnycubicTFT.PausedByNozzleTimeout = false;
#endif
#if ENABLED(ULTIPANEL)
lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_INSERT);
@ -7249,7 +7246,13 @@ inline void gcode_M17() {
if (nozzle_timed_out) {
#ifdef ANYCUBIC_TFT_MODEL
AnycubicTFT.PausedByNozzleTimeout=true;
if (AnycubicTFT.ai3m_pause_state < 3) {
AnycubicTFT.ai3m_pause_state += 2;
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOPAIR(" DEBUG: NTO - AI3M Pause State set to: ", AnycubicTFT.ai3m_pause_state);
SERIAL_EOL();
#endif
}
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: Nozzle timeout flag set");
#endif
@ -7296,8 +7299,14 @@ inline void gcode_M17() {
wait_for_user = true; // Wait for user to load filament
nozzle_timed_out = false;
#ifdef ANYCUBIC_TFT_MODEL
if (AnycubicTFT.ai3m_pause_state > 3) {
AnycubicTFT.ai3m_pause_state -= 2;
#ifdef ANYCUBIC_TFT_DEBUG
AnycubicTFT.PausedByNozzleTimeout = false;
SERIAL_ECHOPAIR(" DEBUG: NTO - AI3M Pause State set to: ", AnycubicTFT.ai3m_pause_state);
SERIAL_EOL();
#endif
}
#endif
#if HAS_BUZZER
@ -7334,7 +7343,13 @@ inline void gcode_M17() {
// Re-enable the heaters if they timed out
nozzle_timed_out = false;
#ifdef ANYCUBIC_TFT_MODEL
AnycubicTFT.PausedByNozzleTimeout = false;
if (AnycubicTFT.ai3m_pause_state > 3) {
AnycubicTFT.ai3m_pause_state -= 2;
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOPAIR(" DEBUG: NTO - AI3M Pause State set to: ", AnycubicTFT.ai3m_pause_state);
SERIAL_EOL();
#endif
}
#endif
HOTEND_LOOP() {
@ -8569,7 +8584,7 @@ inline void gcode_M109() {
#endif
// flush the serial buffer after heating to prevent lockup by m105
SERIAL_FLUSH();
//SERIAL_FLUSH();
}
@ -8724,7 +8739,7 @@ inline void gcode_M109() {
#endif
// flush the serial buffer after heating to prevent lockup by m105
SERIAL_FLUSH();
//SERIAL_FLUSH();
}
#endif // HAS_HEATED_BED
@ -11011,6 +11026,13 @@ inline void gcode_M502() {
#ifdef ANYCUBIC_TFT_MODEL
#ifdef SDSUPPORT
if (card.sdprinting) { // are we printing from sd?
if (AnycubicTFT.ai3m_pause_state < 2) {
AnycubicTFT.ai3m_pause_state = 2;
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOPAIR(" DEBUG: M600 - AI3M Pause State set to: ", AnycubicTFT.ai3m_pause_state);
SERIAL_EOL();
#endif
}
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: Enter M600 TFTstate routine");
#endif
@ -11018,10 +11040,7 @@ inline void gcode_M502() {
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: Set TFTstate to SDPAUSE_REQ");
#endif
AnycubicTFT.PausedByFilamentChange=true; // set flag to ensure correct resume routine gets executed
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: Set filament change flag");
#endif
// set flag to ensure correct resume routine gets executed
}
#endif
#endif

View File

@ -54,7 +54,7 @@
* here we define this default string as the date where the latest release
* version was tagged.
*/
#define STRING_DISTRIBUTION_DATE "2019-03-24"
#define STRING_DISTRIBUTION_DATE "2019-04-03"
/**
* Required minimum Configuration.h and Configuration_adv.h file versions.