Automatic recovery after crash is detected

This commit is contained in:
michalprusa 2017-09-26 11:48:46 +01:00
parent a4a90aa9ed
commit 5ff28682be
3 changed files with 61 additions and 50 deletions

View file

@ -76,12 +76,15 @@ const bool Z_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic o
#define Z_AXIS_ALWAYS_ON 1 #define Z_AXIS_ALWAYS_ON 1
// Automatic recovery after crash is detected
#define AUTOMATIC_RECOVERY_AFTER_CRASH
//DEBUG //DEBUG
#define DEBUG_DCODES //D codes #define DEBUG_DCODES //D codes
#if 1 #if 1
//#define DEBUG_CRASHDET_COUNTERS //Display crash-detection counters on LCD //#define DEBUG_CRASHDET_COUNTERS //Display crash-detection counters on LCD
//#define DEBUG_RESUME_PRINT //Resume/save print debug enable //#define DEBUG_RESUME_PRINT //Resume/save print debug enable
//#define DEBUG_UVLO_AUTOMATIC_RECOVER // Power panic automatic recovery debug output //#define DEBUG_UVLO_AUTOMATIC_RECOVER // Power panic automatic recovery debug output
//#define DEBUG_DISABLE_XMINLIMIT //x min limit ignored //#define DEBUG_DISABLE_XMINLIMIT //x min limit ignored
//#define DEBUG_DISABLE_XMAXLIMIT //x max limit ignored //#define DEBUG_DISABLE_XMAXLIMIT //x max limit ignored
//#define DEBUG_DISABLE_YMINLIMIT //y min limit ignored //#define DEBUG_DISABLE_YMINLIMIT //y min limit ignored
@ -496,7 +499,7 @@ const bool Z_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic o
// At 400 microsteps per mm, a full step lifts the Z axis by 0.04mm, and a stepper driver cycle is 0.16mm. // At 400 microsteps per mm, a full step lifts the Z axis by 0.04mm, and a stepper driver cycle is 0.16mm.
// The following example, 12 * (4 * 16 / 400) = 12 * 0.16mm = 1.92mm. // The following example, 12 * (4 * 16 / 400) = 12 * 0.16mm = 1.92mm.
#define UVLO_Z_AXIS_SHIFT 1.92 #define UVLO_Z_AXIS_SHIFT 1.92
// If power panic occured, and the current temperature is higher then target temperature before interrupt minus this offset, print will be recovered automatically. // If power panic occured, and the current temperature is higher then target temperature before interrupt minus this offset, print will be recovered automatically.
#define AUTOMATIC_UVLO_BED_TEMP_OFFSET 5 #define AUTOMATIC_UVLO_BED_TEMP_OFFSET 5
#define HEATBED_V2 #define HEATBED_V2

View file

@ -572,18 +572,18 @@ extern int8_t CrashDetectMenu;
void crashdet_enable() void crashdet_enable()
{ {
MYSERIAL.println("crashdet_enable"); MYSERIAL.println("crashdet_enable");
tmc2130_sg_stop_on_crash = true; tmc2130_sg_stop_on_crash = true;
eeprom_update_byte((uint8_t*)EEPROM_CRASH_DET, 0xFF); eeprom_update_byte((uint8_t*)EEPROM_CRASH_DET, 0xFF);
CrashDetectMenu = 1; CrashDetectMenu = 1;
} }
void crashdet_disable() void crashdet_disable()
{ {
MYSERIAL.println("crashdet_disable"); MYSERIAL.println("crashdet_disable");
tmc2130_sg_stop_on_crash = false; tmc2130_sg_stop_on_crash = false;
eeprom_update_byte((uint8_t*)EEPROM_CRASH_DET, 0x00); eeprom_update_byte((uint8_t*)EEPROM_CRASH_DET, 0x00);
CrashDetectMenu = 0; CrashDetectMenu = 0;
} }
@ -651,7 +651,7 @@ void fsensor_enable()
fsensor_enabled = true; fsensor_enabled = true;
fsensor_ignore_error = true; fsensor_ignore_error = true;
fsensor_M600 = false; fsensor_M600 = false;
eeprom_update_byte((uint8_t*)EEPROM_FSENSOR, 0xFF); eeprom_update_byte((uint8_t*)EEPROM_FSENSOR, 0xFF);
FSensorStateMenu = 1; FSensorStateMenu = 1;
} }
@ -659,7 +659,7 @@ void fsensor_disable()
{ {
MYSERIAL.println("fsensor_disable"); MYSERIAL.println("fsensor_disable");
fsensor_enabled = false; fsensor_enabled = false;
eeprom_update_byte((uint8_t*)EEPROM_FSENSOR, 0x00); eeprom_update_byte((uint8_t*)EEPROM_FSENSOR, 0x00);
FSensorStateMenu = 0; FSensorStateMenu = 0;
} }
@ -1135,33 +1135,33 @@ void setup()
lcd_setstatuspgm(WELCOME_MSG); lcd_setstatuspgm(WELCOME_MSG);
} }
*/ */
manage_heater(); // Update temperatures manage_heater(); // Update temperatures
#ifdef DEBUG_UVLO_AUTOMATIC_RECOVER #ifdef DEBUG_UVLO_AUTOMATIC_RECOVER
MYSERIAL.println("Power panic detected!"); MYSERIAL.println("Power panic detected!");
MYSERIAL.print("Current bed temp:"); MYSERIAL.print("Current bed temp:");
MYSERIAL.println(degBed()); MYSERIAL.println(degBed());
MYSERIAL.print("Saved bed temp:"); MYSERIAL.print("Saved bed temp:");
MYSERIAL.println((float)eeprom_read_byte((uint8_t*)EEPROM_UVLO_TARGET_BED)); MYSERIAL.println((float)eeprom_read_byte((uint8_t*)EEPROM_UVLO_TARGET_BED));
#endif #endif
if ( degBed() > ( (float)eeprom_read_byte((uint8_t*)EEPROM_UVLO_TARGET_BED) - AUTOMATIC_UVLO_BED_TEMP_OFFSET) ){ if ( degBed() > ( (float)eeprom_read_byte((uint8_t*)EEPROM_UVLO_TARGET_BED) - AUTOMATIC_UVLO_BED_TEMP_OFFSET) ){
#ifdef DEBUG_UVLO_AUTOMATIC_RECOVER #ifdef DEBUG_UVLO_AUTOMATIC_RECOVER
MYSERIAL.println("Automatic recovery!"); MYSERIAL.println("Automatic recovery!");
#endif #endif
recover_print(1); recover_print(1);
} }
else{ else{
#ifdef DEBUG_UVLO_AUTOMATIC_RECOVER #ifdef DEBUG_UVLO_AUTOMATIC_RECOVER
MYSERIAL.println("Normal recovery!"); MYSERIAL.println("Normal recovery!");
#endif #endif
if ( lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_RECOVER_PRINT, false) ) recover_print(0); if ( lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_RECOVER_PRINT, false) ) recover_print(0);
else { else {
eeprom_update_byte((uint8_t*)EEPROM_UVLO, 0); eeprom_update_byte((uint8_t*)EEPROM_UVLO, 0);
lcd_update_enable(true); lcd_update_enable(true);
lcd_update(2); lcd_update(2);
lcd_setstatuspgm(WELCOME_MSG); lcd_setstatuspgm(WELCOME_MSG);
} }
} }
} }
@ -5827,8 +5827,8 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp
MYSERIAL.print("selectedSerialPort = "); MYSERIAL.print("selectedSerialPort = ");
MYSERIAL.println(selectedSerialPort, DEC); MYSERIAL.println(selectedSerialPort, DEC);
break; break;
case 10: // D10 - Tell the printer that XYZ calibration went OK case 10: // D10 - Tell the printer that XYZ calibration went OK
calibration_status_store(CALIBRATION_STATUS_LIVE_ADJUST); calibration_status_store(CALIBRATION_STATUS_LIVE_ADJUST);
break; break;
case 999: case 999:
{ {
@ -5844,7 +5844,11 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp
lcd_update_enable(true); lcd_update_enable(true);
lcd_implementation_clear(); lcd_implementation_clear();
lcd_update(2); lcd_update(2);
bool yesno = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_CRASH_DETECTED, false); #ifdef AUTOMATIC_RECOVERY_AFTER_CRASH
bool yesno = true;
#else
bool yesno = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_CRASH_DETECTED, false);
#endif
lcd_update_enable(true); lcd_update_enable(true);
lcd_update(2); lcd_update(2);
lcd_setstatuspgm(WELCOME_MSG); lcd_setstatuspgm(WELCOME_MSG);
@ -7099,10 +7103,10 @@ void recover_print(uint8_t automatic) {
recover_machine_state_after_power_panic(); recover_machine_state_after_power_panic();
// Set the target bed and nozzle temperatures. // Set the target bed and nozzle temperatures.
sprintf_P(cmd, PSTR("M104 S%d"), target_temperature[active_extruder]); sprintf_P(cmd, PSTR("M104 S%d"), target_temperature[active_extruder]);
enquecommand(cmd); enquecommand(cmd);
sprintf_P(cmd, PSTR("M140 S%d"), target_temperature_bed); sprintf_P(cmd, PSTR("M140 S%d"), target_temperature_bed);
enquecommand(cmd); enquecommand(cmd);
// Lift the print head, so one may remove the excess priming material. // Lift the print head, so one may remove the excess priming material.
@ -7117,9 +7121,9 @@ void recover_print(uint8_t automatic) {
enquecommand(cmd); enquecommand(cmd);
enquecommand_P(PSTR("M83")); //E axis relative mode enquecommand_P(PSTR("M83")); //E axis relative mode
//enquecommand_P(PSTR("G1 E5 F120")); //Extrude some filament to stabilize pessure //enquecommand_P(PSTR("G1 E5 F120")); //Extrude some filament to stabilize pessure
// If not automatically recoreverd (long power loss), extrude extra filament to stabilize // If not automatically recoreverd (long power loss), extrude extra filament to stabilize
if(automatic == 0){ if(automatic == 0){
enquecommand_P(PSTR("G1 E5 F120")); //Extrude some filament to stabilize pessure enquecommand_P(PSTR("G1 E5 F120")); //Extrude some filament to stabilize pessure
} }
enquecommand_P(PSTR("G1 E" STRINGIFY(-DEFAULT_RETRACTION)" F480")); enquecommand_P(PSTR("G1 E" STRINGIFY(-DEFAULT_RETRACTION)" F480"));
// Mark the power panic status as inactive. // Mark the power panic status as inactive.

View file

@ -1074,6 +1074,10 @@ static void lcd_support_menu()
MENU_ITEM(function, PSTR("Check fans [DIS]"), lcd_set_fan_check); MENU_ITEM(function, PSTR("Check fans [DIS]"), lcd_set_fan_check);
} }
#endif //MK1BP #endif //MK1BP
#ifdef AUTOMATIC_RECOVERY_AFTER_CRASH
MENU_ITEM(back, PSTR("Auto recover crash"), lcd_main_menu);
#else
END_MENU(); END_MENU();
} }
@ -3873,12 +3877,12 @@ static void lcd_main_menu()
MENU_ITEM(back, MSG_WATCH, lcd_status_screen); MENU_ITEM(back, MSG_WATCH, lcd_status_screen);
#ifdef RESUME_DEBUG #ifdef RESUME_DEBUG
if (!saved_printing) if (!saved_printing)
MENU_ITEM(function, PSTR("tst - Save"), lcd_menu_test_save); MENU_ITEM(function, PSTR("tst - Save"), lcd_menu_test_save);
else else
MENU_ITEM(function, PSTR("tst - Restore"), lcd_menu_test_restore); MENU_ITEM(function, PSTR("tst - Restore"), lcd_menu_test_restore);
#endif //RESUME_DEBUG #endif //RESUME_DEBUG
#ifdef TMC2130_DEBUG #ifdef TMC2130_DEBUG
MENU_ITEM(function, PSTR("recover print"), recover_print); MENU_ITEM(function, PSTR("recover print"), recover_print);