power panic: re-use saved_pos

This allows us to restore the position of all axis saved in RAM

If the extruder had been parked to the side for example
due to filament runout. Then the original position (before parking)
should now be restored

Change in memory:
Flash: +40 bytes
SRAM: 0 bytes
This commit is contained in:
Guðni Már Gilbert 2023-07-01 12:17:46 +00:00 committed by DRracer
parent 97c27525d4
commit 6ccd12c7e8
3 changed files with 17 additions and 16 deletions

View File

@ -307,6 +307,7 @@ extern uint16_t saved_extruder_temperature; //!< Active extruder temperature
extern uint8_t saved_bed_temperature; //!< Bed temperature
extern bool saved_extruder_relative_mode;
extern uint8_t saved_fan_speed; //!< Print fan speed, ranges from 0 to 255
extern float saved_pos[NUM_AXIS];
extern uint16_t saved_feedrate2;
//estimated time to end of the print

View File

@ -311,7 +311,7 @@ static bool chdkActive = false;
bool saved_printing = false; //!< Print is paused and saved in RAM
uint32_t saved_sdpos = 0; //!< SD card position, or line number in case of USB printing
uint8_t saved_printing_type = PRINTING_TYPE_SD;
static float saved_pos[4] = { X_COORD_INVALID, 0, 0, 0 };
float saved_pos[NUM_AXIS] = { X_COORD_INVALID, 0, 0, 0 };
uint16_t saved_feedrate2 = 0; //!< Default feedrate (truncated from float)
static int saved_feedmultiply2 = 0;
uint16_t saved_extruder_temperature; //!< Active extruder temperature

View File

@ -71,15 +71,20 @@ void uvlo_() {
saved_extruder_relative_mode = axis_relative_modes & E_AXIS_MASK;
}
// Stop all heaters
// Stop all heaters before continuing
setTargetHotend(0);
setTargetBed(0);
// Calculate the file position, from which to resume this print.
save_print_file_state();
if (!sd_print_saved_in_ram) {
// Calculate the file position, from which to resume this print.
save_print_file_state();
// save the global state at planning time
save_planner_global_state();
// save the global state at planning time
save_planner_global_state();
memcpy(saved_pos, current_position, sizeof(saved_pos));
if (pos_invalid) saved_pos[X_AXIS] = X_COORD_INVALID;
}
// From this point on and up to the print recovery, Z should not move during X/Y travels and
// should be controlled precisely. Reset the MBL status before planner_abort_hard in order to
@ -94,12 +99,12 @@ void uvlo_() {
// Store the print logical Z position, which we need to recover (a slight error here would be
// recovered on the next Gcode instruction, while a physical location error would not)
float logical_z = current_position[Z_AXIS];
if(mbl_was_active) logical_z -= mbl.get_z(st_get_position_mm(X_AXIS), st_get_position_mm(Y_AXIS));
float logical_z = saved_pos[Z_AXIS];
if(mbl_was_active) logical_z = current_position[Z_AXIS] - mbl.get_z(st_get_position_mm(X_AXIS), st_get_position_mm(Y_AXIS));
eeprom_update_float((float*)EEPROM_UVLO_CURRENT_POSITION_Z, logical_z);
// Store the print E position before we lose track
eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION_E), current_position[E_AXIS]);
eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION_E), saved_pos[E_AXIS]);
eeprom_update_byte((uint8_t*)EEPROM_UVLO_E_ABS, !saved_extruder_relative_mode);
// Clean the input command queue, inhibit serial processing using saved_printing
@ -150,13 +155,8 @@ void uvlo_() {
eeprom_update_word((uint16_t*)(EEPROM_UVLO_Z_MICROSTEPS), z_microsteps);
// Store the current position.
if (pos_invalid)
eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 0), X_COORD_INVALID);
else
{
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 + 0), saved_pos[X_AXIS]);
eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 4), saved_pos[Y_AXIS]);
// Store the current feed rate, temperatures, fan speed and extruder multipliers (flow rates)
eeprom_update_word((uint16_t*)EEPROM_UVLO_FEEDRATE, saved_feedrate2);