recover print

This commit is contained in:
PavelSindler 2017-07-04 11:31:39 +02:00
parent d05e62813a
commit a8678cb2fd
7 changed files with 125 additions and 53 deletions

View file

@ -51,6 +51,10 @@
#define EEPROM_UVLO_CURRENT_POSITION (EEPROM_UVLO-2*4) // 2 x float for current_position in X and Y axes #define EEPROM_UVLO_CURRENT_POSITION (EEPROM_UVLO-2*4) // 2 x float for current_position in X and Y axes
#define EEPROM_FILENAME (EEPROM_UVLO_CURRENT_POSITION - 8) //8chars to store filename without extension #define EEPROM_FILENAME (EEPROM_UVLO_CURRENT_POSITION - 8) //8chars to store filename without extension
#define EEPROM_FILE_POSITION (EEPROM_FILENAME - 4) //32 bit for uint32_t file position #define EEPROM_FILE_POSITION (EEPROM_FILENAME - 4) //32 bit for uint32_t file position
#define EEPROM_UVLO_CURRENT_POSITION_Z (EEPROM_FILE_POSITION - 4) //float for current position in Z
#define EEPROM_UVLO_TARGET_HOTEND (EEPROM_UVLO_CURRENT_POSITION_Z - 1)
#define EEPROM_UVLO_TARGET_BED (EEPROM_UVLO_TARGET_HOTEND - 1)
// Currently running firmware, each digit stored as uint16_t. // Currently running firmware, each digit stored as uint16_t.
// The flavor differentiates a dev, alpha, beta, release candidate or a release version. // The flavor differentiates a dev, alpha, beta, release candidate or a release version.

View file

@ -209,7 +209,7 @@ void ClearToSend();
void get_coordinates(); void get_coordinates();
void prepare_move(); void prepare_move();
void kill(const char *full_screen_message = NULL); void kill(const char *full_screen_message = NULL, unsigned char id = 0);
void Stop(); void Stop();
bool IsStopped(); bool IsStopped();

View file

@ -1227,18 +1227,21 @@ void setup()
// Show the message. // Show the message.
lcd_show_fullscreen_message_and_wait_P(MSG_FOLLOW_CALIBRATION_FLOW); lcd_show_fullscreen_message_and_wait_P(MSG_FOLLOW_CALIBRATION_FLOW);
} }
if (eeprom_read_byte((uint8_t*)EEPROM_UVLO) == 1) { //previous print was terminated by UVLO
if (lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_RECOVER_PRINT)) recover_print();
else eeprom_update_byte((uint8_t*)EEPROM_UVLO, 0);
}
for (int i = 0; i<4; i++) EEPROM_read_B(EEPROM_BOWDEN_LENGTH + i * 2, &bowden_length[i]); for (int i = 0; i<4; i++) EEPROM_read_B(EEPROM_BOWDEN_LENGTH + i * 2, &bowden_length[i]);
lcd_update_enable(true); lcd_update_enable(true);
// Store the currently running firmware into an eeprom, // Store the currently running firmware into an eeprom,
// so the next time the firmware gets updated, it will know from which version it has been updated. // so the next time the firmware gets updated, it will know from which version it has been updated.
update_current_firmware_version_to_eeprom(); update_current_firmware_version_to_eeprom();
if (eeprom_read_byte((uint8_t*)EEPROM_UVLO) == 1) { //previous print was terminated by UVLO
if (lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_RECOVER_PRINT)) recover_print();
else {
eeprom_update_byte((uint8_t*)EEPROM_UVLO, 0);
lcd_update_enable(true);
lcd_update(2);
lcd_setstatuspgm(WELCOME_MSG);
}
}
} }
@ -1494,7 +1497,7 @@ void get_command()
//If command was e-stop process now //If command was e-stop process now
if(strcmp(cmdbuffer+bufindw+1, "M112") == 0) if(strcmp(cmdbuffer+bufindw+1, "M112") == 0)
kill(); kill("", 2);
// Store the current line into buffer, move to the next line. // Store the current line into buffer, move to the next line.
cmdbuffer[bufindw] = CMDBUFFER_CURRENT_TYPE_USB; cmdbuffer[bufindw] = CMDBUFFER_CURRENT_TYPE_USB;
@ -4149,7 +4152,7 @@ Sigma_Exit:
setWatch(); setWatch();
break; break;
case 112: // M112 -Emergency Stop case 112: // M112 -Emergency Stop
kill(); kill("", 3);
break; break;
case 140: // M140 set bed temp case 140: // M140 set bed temp
if (code_seen('S')) setTargetBed(code_value()); if (code_seen('S')) setTargetBed(code_value());
@ -6028,7 +6031,7 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) //default argument s
if( (millis() - previous_millis_cmd) > max_inactive_time ) if( (millis() - previous_millis_cmd) > max_inactive_time )
if(max_inactive_time) if(max_inactive_time)
kill(); kill("", 4);
if(stepper_inactive_time) { if(stepper_inactive_time) {
if( (millis() - previous_millis_cmd) > stepper_inactive_time ) if( (millis() - previous_millis_cmd) > stepper_inactive_time )
{ {
@ -6070,7 +6073,7 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) //default argument s
// ---------------------------------------------------------------- // ----------------------------------------------------------------
if ( killCount >= KILL_DELAY) if ( killCount >= KILL_DELAY)
{ {
kill(); kill("", 5);
} }
#endif #endif
@ -6102,8 +6105,11 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) //default argument s
check_axes_activity(); check_axes_activity();
} }
void kill(const char *full_screen_message) void kill(const char *full_screen_message, unsigned char id)
{ {
SERIAL_ECHOPGM("KILL: ");
MYSERIAL.println(int(id));
//return;
cli(); // Stop interrupts cli(); // Stop interrupts
disable_heater(); disable_heater();
@ -6790,37 +6796,70 @@ void serialecho_temperatures() {
void uvlo_() { void uvlo_() {
//SERIAL_ECHOLNPGM("UVLO"); //SERIAL_ECHOLNPGM("UVLO");
save_print_to_eeprom(); save_print_to_eeprom();
eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 0), current_position[X_AXIS]); eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 0), current_position[X_AXIS]);
eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 4), current_position[Y_AXIS]); eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 4), current_position[Y_AXIS]);
disable_x(); eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION_Z), current_position[Z_AXIS]);
disable_y(); eeprom_update_byte((uint8_t*)EEPROM_UVLO_TARGET_HOTEND, target_temperature[active_extruder]);
planner_abort_hard(); eeprom_update_byte((uint8_t*)EEPROM_UVLO_TARGET_BED, target_temperature_bed);
// Because the planner_abort_hard() initialized current_position[Z] from the stepper, disable_x();
// Z baystep is no more applied. Reset it. disable_y();
babystep_reset(); planner_abort_hard();
// Clean the input command queue. // Because the planner_abort_hard() initialized current_position[Z] from the stepper,
cmdqueue_reset(); // Z baystep is no more applied. Reset it.
card.sdprinting = false; babystep_reset();
card.closefile(); // Clean the input command queue.
cmdqueue_reset();
card.sdprinting = false;
card.closefile();
current_position[E_AXIS] -= DEFAULT_RETRACTION; current_position[E_AXIS] -= DEFAULT_RETRACTION;
sei(); //enable stepper driver interrupt to move Z axis sei(); //enable stepper driver interrupt to move Z axis
plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 400, active_extruder); plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 400, active_extruder);
st_synchronize(); st_synchronize();
current_position[Z_AXIS] += UVLO_Z_AXIS_SHIFT; current_position[Z_AXIS] += UVLO_Z_AXIS_SHIFT;
plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 40, active_extruder); plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 40, active_extruder);
st_synchronize(); st_synchronize();
eeprom_update_byte((uint8_t*)EEPROM_UVLO, 1); eeprom_update_byte((uint8_t*)EEPROM_UVLO, 1);
} }
void recover_print() { void recover_print() {
char cmd[30];
lcd_update_enable(true);
lcd_update(2);
lcd_setstatuspgm(WELCOME_MSG);
//char cmd1[30]; //char cmd1[30];
target_temperature[active_extruder] = eeprom_read_byte((uint8_t*)EEPROM_UVLO_TARGET_HOTEND);
target_temperature_bed = eeprom_read_byte((uint8_t*)EEPROM_UVLO_TARGET_BED);
setTargetHotend0(210); //need to change to stored temperature setTargetHotend0(210); //need to change to stored temperature
setTargetBed(55); setTargetBed(55);
homeaxis(X_AXIS); //SERIAL_ECHOPGM("Target temperature:");
homeaxis(Y_AXIS); //MYSERIAL.println(target_temperature[0]);
//SERIAL_ECHOPGM("Target temp bed:");
//MYSERIAL.println(target_temperature_bed);
//homeaxis(X_AXIS);
//homeaxis(Y_AXIS);
//home_xy();
float z_pos = UVLO_Z_AXIS_SHIFT + eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION_Z));
//plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
SERIAL_ECHOPGM("current_position[Z_AXIS]:");
MYSERIAL.println(current_position[Z_AXIS]);
SERIAL_ECHOPGM("z_pos");
MYSERIAL.println(z_pos);
enquecommand_P(PSTR("G28 X"));
enquecommand_P(PSTR("G28 Y"));
strcpy(cmd, "G92 Z");
strcat(cmd, ftostr43(z_pos));
//fprintf(cmd, PSTR("G92 Z3.3%f"), z_pos);
enquecommand(cmd);
//enquecommand_P(PSTR("G92 Z2.2"));
eeprom_update_byte((uint8_t*)EEPROM_UVLO, 0);
while ((abs(degHotend(0)- target_temperature[0])>5) || (abs(degBed() -target_temperature_bed)>3)) { //wait for heater and bed to reach target temp
delay_keep_alive(1000);
}
//enquecommand_P("G28 W");
/*float x_rec, y_rec; /*float x_rec, y_rec;
x_rec = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 0)); x_rec = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 0));
y_rec = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 4)); y_rec = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 4));
@ -6833,24 +6872,27 @@ void recover_print() {
enquecommand_P(PSTR("G1 E" STRINGIFY(DEFAULT_RETRACTION)));*/ enquecommand_P(PSTR("G1 E" STRINGIFY(DEFAULT_RETRACTION)));*/
current_position[X_AXIS] = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 0)); //current_position[X_AXIS] = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 0));
current_position[Y_AXIS] = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 4)); //current_position[Y_AXIS] = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 4));
/*SERIAL_ECHOPGM("Current position [X_AXIS]:"); /*SERIAL_ECHOPGM("Current position [X_AXIS]:");
MYSERIAL.println(current_position[X_AXIS]); MYSERIAL.println(current_position[X_AXIS]);
SERIAL_ECHOPGM("Current position [Y_AXIS]:"); SERIAL_ECHOPGM("Current position [Y_AXIS]:");
MYSERIAL.println(current_position[Y_AXIS]);*/ MYSERIAL.println(current_position[Y_AXIS]);*/
plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 40, active_extruder); //plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 40, active_extruder);
st_synchronize(); //st_synchronize();
current_position[Z_AXIS] -= UVLO_Z_AXIS_SHIFT; /*current_position[Z_AXIS] -= UVLO_Z_AXIS_SHIFT;
plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 40, active_extruder); plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 40, active_extruder);
st_synchronize(); st_synchronize();
current_position[E_AXIS] += DEFAULT_RETRACTION; //unretract current_position[E_AXIS] += DEFAULT_RETRACTION; //unretract
plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 400, active_extruder); plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 400, active_extruder);
st_synchronize(); st_synchronize();*/
//enquecommand_P(PSTR("G1 Z" STRINGIFY(-UVLO_Z_AXIS_SHIFT)));
//enquecommand_P(PSTR("G1 E" STRINGIFY(DEFAULT_RETRACTION)));
restore_print_from_eeprom(); restore_print_from_eeprom();
eeprom_update_byte((uint8_t*)EEPROM_UVLO, 0); SERIAL_ECHOPGM("current_position[Z_AXIS]:");
MYSERIAL.print(current_position[Z_AXIS]);
} }
void restore_print_from_eeprom() { void restore_print_from_eeprom() {
@ -6877,6 +6919,10 @@ void restore_print_from_eeprom() {
enquecommand_P(PSTR("M24")); enquecommand_P(PSTR("M24"));
sprintf_P(cmd, PSTR("M26 S%d"), position); sprintf_P(cmd, PSTR("M26 S%d"), position);
enquecommand(cmd); enquecommand(cmd);
enquecommand_P(PSTR("M83"));
//SERIAL_ECHO(cmdbuffer + bufindr + 1);
enquecommand_P(PSTR("G1 Z" STRINGIFY(-UVLO_Z_AXIS_SHIFT)));
enquecommand_P(PSTR("G1 E" STRINGIFY(DEFAULT_RETRACTION)" F2000"));
} }
@ -6895,10 +6941,30 @@ void setup_uvlo_interrupt() {
ISR(INT4_vect) { ISR(INT4_vect) {
EIMSK &= ~(1 << 4); //disable INT4 interrupt to make sure that this code will be executed just once EIMSK &= ~(1 << 4); //disable INT4 interrupt to make sure that this code will be executed just once
SERIAL_ECHOLNPGM("INT4"); SERIAL_ECHOLNPGM("INT4");
uvlo_(); if(IS_SD_PRINTING) uvlo_();
} }
void save_print_to_eeprom() { void save_print_to_eeprom() {
eeprom_update_dword((uint32_t*)(EEPROM_FILE_POSITION), card.get_sdpos()); //eeprom_update_word((uint16_t*)(EPROM_UVLO_CMD_QUEUE), bufindw - bufindr );
//BLOCK_BUFFER_SIZE: max. 16 linear moves in planner buffer
#define TYP_GCODE_LENGTH 29 //G1 X117.489 Y22.814 E1.46695 + null
//card.get_sdpos() -> byte currently read from SD card
//bufindw -> position in circular buffer where to write
//bufindr -> position in circular buffer where to read
//bufflen -> number of lines in buffer -> for each line one special character??
//TYP_GCODE_LENGTH* BLOCK_BUFFER_SIZE -> worst case from planner
long sd_position = card.get_sdpos() - ((bufindw > bufindr) ? (bufindw - bufindr) : sizeof(cmdbuffer) - bufindr + bufindw) - buflen - TYP_GCODE_LENGTH* BLOCK_BUFFER_SIZE;
if (sd_position < 0) sd_position = 0;
/*SERIAL_ECHOPGM("sd position before correction:");
MYSERIAL.println(card.get_sdpos());
SERIAL_ECHOPGM("bufindw:");
MYSERIAL.println(bufindw);
SERIAL_ECHOPGM("bufindr:");
MYSERIAL.println(bufindr);
SERIAL_ECHOPGM("sizeof(cmd_buffer):");
MYSERIAL.println(sizeof(cmdbuffer));
SERIAL_ECHOPGM("sd position after correction:");
MYSERIAL.println(sd_position);*/
eeprom_update_dword((uint32_t*)(EEPROM_FILE_POSITION), sd_position);
} }

View file

@ -262,7 +262,7 @@ void CardReader::openFile(char* name,bool read, bool replace_current/*=true*/)
SERIAL_ERROR_START; SERIAL_ERROR_START;
SERIAL_ERRORPGM("trying to call sub-gcode files with too many levels. MAX level is:"); SERIAL_ERRORPGM("trying to call sub-gcode files with too many levels. MAX level is:");
SERIAL_ERRORLN(SD_PROCEDURE_DEPTH); SERIAL_ERRORLN(SD_PROCEDURE_DEPTH);
kill(); kill("", 1);
return; return;
} }

View file

@ -406,10 +406,7 @@ void setExtruderAutoFanState(int pin, bool state)
} }
void countFanSpeed() void countFanSpeed()
{ {
SERIAL_ECHOPGM("UVLO:");
MYSERIAL.println(UVLO);
fan_speed[0] = (fan_edge_counter[0] * (float(250) / (millis() - extruder_autofan_last_check))); fan_speed[0] = (fan_edge_counter[0] * (float(250) / (millis() - extruder_autofan_last_check)));
fan_speed[1] = (fan_edge_counter[1] * (float(250) / (millis() - extruder_autofan_last_check))); fan_speed[1] = (fan_edge_counter[1] * (float(250) / (millis() - extruder_autofan_last_check)));
@ -757,7 +754,7 @@ static float analog2temp(int raw, uint8_t e) {
SERIAL_ERROR_START; SERIAL_ERROR_START;
SERIAL_ERROR((int)e); SERIAL_ERROR((int)e);
SERIAL_ERRORLNPGM(" - Invalid extruder number !"); SERIAL_ERRORLNPGM(" - Invalid extruder number !");
kill(); kill("", 6);
return 0.0; return 0.0;
} }
#ifdef HEATER_0_USES_MAX6675 #ifdef HEATER_0_USES_MAX6675

View file

@ -162,10 +162,13 @@ void tmc2130_check_overtemp()
//drivers_disabled[0] = 1; //TEST //drivers_disabled[0] = 1; //TEST
if( millis() - checktime > 1000 ) if( millis() - checktime > 1000 )
{ {
//SERIAL_ECHOLNPGM("drv_status:");
for(int i=0;i<4;i++) for(int i=0;i<4;i++)
{ {
uint32_t drv_status = 0; uint32_t drv_status = 0;
tmc2130_rd(cs[i], TMC2130_REG_DRV_STATUS, &drv_status); tmc2130_rd(cs[i], TMC2130_REG_DRV_STATUS, &drv_status);
//MYSERIAL.print(drv_status);
//SERIAL_ECHOPGM(" ");
if (drv_status & ((uint32_t)1<<26)) if (drv_status & ((uint32_t)1<<26))
{ // BIT 26 - over temp prewarning ~120C (+-20C) { // BIT 26 - over temp prewarning ~120C (+-20C)
SERIAL_ERRORRPGM(TMC_OVERTEMP_MSG); SERIAL_ERRORRPGM(TMC_OVERTEMP_MSG);
@ -175,6 +178,7 @@ void tmc2130_check_overtemp()
kill(TMC_OVERTEMP_MSG); kill(TMC_OVERTEMP_MSG);
} }
} }
//SERIAL_ECHOLNPGM("");
checktime = millis(); checktime = millis();
} }
} }

View file

@ -3698,7 +3698,8 @@ static void lcd_main_menu()
MENU_ITEM(back, MSG_WATCH, lcd_status_screen); MENU_ITEM(back, MSG_WATCH, lcd_status_screen);
MENU_ITEM(function, PSTR("restore_print"), restore_print_from_eeprom); MENU_ITEM(function, PSTR("restore_print"), restore_print_from_eeprom);
/* if (farm_mode && !IS_SD_PRINTING ) MENU_ITEM(function, PSTR("recover print"), recover_print);
/* if (farm_mode && !IS_SD_PRINTING )
{ {
int tempScrool = 0; int tempScrool = 0;