|
@ -66,12 +66,16 @@ PrintJobRecovery recovery; |
|
|
#ifndef POWER_LOSS_PURGE_LEN |
|
|
#ifndef POWER_LOSS_PURGE_LEN |
|
|
#define POWER_LOSS_PURGE_LEN 0 |
|
|
#define POWER_LOSS_PURGE_LEN 0 |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
#ifndef POWER_LOSS_ZRAISE |
|
|
|
|
|
#define POWER_LOSS_ZRAISE 2 // Move on loss with backup power, or on resume without it
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
#if DISABLED(BACKUP_POWER_SUPPLY) |
|
|
|
|
|
#undef POWER_LOSS_RETRACT_LEN // No retract at outage without backup power
|
|
|
|
|
|
#endif |
|
|
#ifndef POWER_LOSS_RETRACT_LEN |
|
|
#ifndef POWER_LOSS_RETRACT_LEN |
|
|
#define POWER_LOSS_RETRACT_LEN 0 |
|
|
#define POWER_LOSS_RETRACT_LEN 0 |
|
|
#endif |
|
|
#endif |
|
|
#ifndef POWER_LOSS_ZRAISE |
|
|
|
|
|
#define POWER_LOSS_ZRAISE 2 |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* Clear the recovery info |
|
|
* Clear the recovery info |
|
@ -144,7 +148,7 @@ void PrintJobRecovery::prepare() { |
|
|
/**
|
|
|
/**
|
|
|
* Save the current machine state to the power-loss recovery file |
|
|
* Save the current machine state to the power-loss recovery file |
|
|
*/ |
|
|
*/ |
|
|
void PrintJobRecovery::save(const bool force/*=false*/) { |
|
|
void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=0*/) { |
|
|
|
|
|
|
|
|
#if SAVE_INFO_INTERVAL_MS > 0 |
|
|
#if SAVE_INFO_INTERVAL_MS > 0 |
|
|
static millis_t next_save_ms; // = 0
|
|
|
static millis_t next_save_ms; // = 0
|
|
@ -177,6 +181,7 @@ void PrintJobRecovery::save(const bool force/*=false*/) { |
|
|
|
|
|
|
|
|
// Machine state
|
|
|
// Machine state
|
|
|
info.current_position = current_position; |
|
|
info.current_position = current_position; |
|
|
|
|
|
info.zraise = zraise; |
|
|
TERN_(HAS_HOME_OFFSET, info.home_offset = home_offset); |
|
|
TERN_(HAS_HOME_OFFSET, info.home_offset = home_offset); |
|
|
TERN_(HAS_POSITION_SHIFT, info.position_shift = position_shift); |
|
|
TERN_(HAS_POSITION_SHIFT, info.position_shift = position_shift); |
|
|
info.feedrate = uint16_t(feedrate_mm_s * 60.0f); |
|
|
info.feedrate = uint16_t(feedrate_mm_s * 60.0f); |
|
@ -228,30 +233,73 @@ void PrintJobRecovery::save(const bool force/*=false*/) { |
|
|
|
|
|
|
|
|
#if PIN_EXISTS(POWER_LOSS) |
|
|
#if PIN_EXISTS(POWER_LOSS) |
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(BACKUP_POWER_SUPPLY) |
|
|
|
|
|
|
|
|
|
|
|
void PrintJobRecovery::retract_and_lift(const float &zraise) { |
|
|
|
|
|
#if POWER_LOSS_RETRACT_LEN || POWER_LOSS_ZRAISE |
|
|
|
|
|
|
|
|
|
|
|
gcode.set_relative_mode(true); // Use relative coordinates
|
|
|
|
|
|
|
|
|
|
|
|
#if POWER_LOSS_RETRACT_LEN |
|
|
|
|
|
// Retract filament now
|
|
|
|
|
|
gcode.process_subcommands_now_P(PSTR("G1 F3000 E-" STRINGIFY(POWER_LOSS_RETRACT_LEN))); |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
#if POWER_LOSS_ZRAISE |
|
|
|
|
|
// Raise the Z axis now
|
|
|
|
|
|
if (zraise) { |
|
|
|
|
|
char cmd[20], str_1[16]; |
|
|
|
|
|
sprintf_P(cmd, PSTR("G0 Z%s"), dtostrf(zraise, 1, 3, str_1)); |
|
|
|
|
|
gcode.process_subcommands_now(cmd); |
|
|
|
|
|
} |
|
|
|
|
|
#else |
|
|
|
|
|
UNUSED(zraise); |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
//gcode.axis_relative = info.axis_relative;
|
|
|
|
|
|
planner.synchronize(); |
|
|
|
|
|
#endif |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* An outage was detected by a sensor pin. |
|
|
|
|
|
* - If not SD printing, let the machine turn off on its own with no "KILL" screen |
|
|
|
|
|
* - Disable all heaters first to save energy |
|
|
|
|
|
* - Save the recovery data for the current instant |
|
|
|
|
|
* - If backup power is available Retract E and Raise Z |
|
|
|
|
|
* - Go to the KILL screen |
|
|
|
|
|
*/ |
|
|
void PrintJobRecovery::_outage() { |
|
|
void PrintJobRecovery::_outage() { |
|
|
#if ENABLED(BACKUP_POWER_SUPPLY) |
|
|
#if ENABLED(BACKUP_POWER_SUPPLY) |
|
|
static bool lock = false; |
|
|
static bool lock = false; |
|
|
if (lock) return; // No re-entrance from idle() during raise_z()
|
|
|
if (lock) return; // No re-entrance from idle() during retract_and_lift()
|
|
|
lock = true; |
|
|
lock = true; |
|
|
#endif |
|
|
#endif |
|
|
if (IS_SD_PRINTING()) save(true); |
|
|
|
|
|
TERN_(BACKUP_POWER_SUPPLY, raise_z()); |
|
|
|
|
|
|
|
|
|
|
|
kill(GET_TEXT(MSG_OUTAGE_RECOVERY)); |
|
|
#if POWER_LOSS_ZRAISE |
|
|
} |
|
|
// Get the limited Z-raise to do now or on resume
|
|
|
|
|
|
const float zraise = _MAX(0, _MIN(current_position.z + POWER_LOSS_ZRAISE, Z_MAX_POS - 1) - current_position.z); |
|
|
|
|
|
#else |
|
|
|
|
|
constexpr float zraise = 0; |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
#if ENABLED(BACKUP_POWER_SUPPLY) |
|
|
// Save, including the limited Z raise
|
|
|
|
|
|
if (IS_SD_PRINTING()) save(true, zraise); |
|
|
|
|
|
|
|
|
|
|
|
// Disable all heaters to reduce power loss
|
|
|
|
|
|
thermalManager.disable_all_heaters(); |
|
|
|
|
|
|
|
|
void PrintJobRecovery::raise_z() { |
|
|
#if ENABLED(BACKUP_POWER_SUPPLY) |
|
|
// Disable all heaters to reduce power loss
|
|
|
// Do a hard-stop of the steppers (with possibly a loud thud)
|
|
|
thermalManager.disable_all_heaters(); |
|
|
|
|
|
quickstop_stepper(); |
|
|
quickstop_stepper(); |
|
|
// Raise Z axis
|
|
|
// With backup power a retract and raise can be done now
|
|
|
gcode.process_subcommands_now_P(PSTR("G91\nG0 Z" STRINGIFY(POWER_LOSS_ZRAISE))); |
|
|
retract_and_lift(zraise); |
|
|
planner.synchronize(); |
|
|
#endif |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endif |
|
|
kill(GET_TEXT(MSG_OUTAGE_RECOVERY)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
@ -274,6 +322,8 @@ void PrintJobRecovery::write() { |
|
|
*/ |
|
|
*/ |
|
|
void PrintJobRecovery::resume() { |
|
|
void PrintJobRecovery::resume() { |
|
|
|
|
|
|
|
|
|
|
|
char cmd[MAX_CMD_SIZE+16], str_1[16], str_2[16]; |
|
|
|
|
|
|
|
|
const uint32_t resume_sdpos = info.sdpos; // Get here before the stepper ISR overwrites it
|
|
|
const uint32_t resume_sdpos = info.sdpos; // Get here before the stepper ISR overwrites it
|
|
|
|
|
|
|
|
|
#if HAS_LEVELING |
|
|
#if HAS_LEVELING |
|
@ -282,52 +332,46 @@ void PrintJobRecovery::resume() { |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
// Reset E, raise Z, home XY...
|
|
|
// Reset E, raise Z, home XY...
|
|
|
gcode.process_subcommands_now_P(PSTR("G92.9 E0" |
|
|
#if Z_HOME_DIR > 0 |
|
|
#if Z_HOME_DIR > 0 |
|
|
|
|
|
|
|
|
|
|
|
// If Z homing goes to max, just reset E and home all
|
|
|
// If Z homing goes to max, just reset E and home all
|
|
|
"\n" |
|
|
gcode.process_subcommands_now_P(PSTR( |
|
|
"G28R0" |
|
|
"G92.9 E0\n" |
|
|
TERN_(MARLIN_DEV_MODE, "S") |
|
|
"G28R0" TERN_(MARLIN_DEV_MODE, "S") |
|
|
|
|
|
)); |
|
|
|
|
|
|
|
|
#else // "G92.9 E0 ..."
|
|
|
#else // "G92.9 E0 ..."
|
|
|
|
|
|
|
|
|
// Set Z to 0, raise Z by RECOVERY_ZRAISE, and Home (XY only for Cartesian)
|
|
|
// Set Z to 0, raise Z by info.zraise, and Home (XY only for Cartesian)
|
|
|
// with no raise. (Only do simulated homing in Marlin Dev Mode.)
|
|
|
// with no raise. (Only do simulated homing in Marlin Dev Mode.)
|
|
|
#if ENABLED(BACKUP_POWER_SUPPLY) |
|
|
|
|
|
"Z" STRINGIFY(POWER_LOSS_ZRAISE) // Z-axis was already raised at outage
|
|
|
|
|
|
#else |
|
|
|
|
|
"Z0\n" // Set Z=0
|
|
|
|
|
|
"G1Z" STRINGIFY(POWER_LOSS_ZRAISE) // Raise Z
|
|
|
|
|
|
#endif |
|
|
|
|
|
"\n" |
|
|
|
|
|
|
|
|
|
|
|
"G28R0" |
|
|
sprintf_P(cmd, PSTR("G92.9 E0 " |
|
|
#if ENABLED(MARLIN_DEV_MODE) |
|
|
#if ENABLED(BACKUP_POWER_SUPPLY) |
|
|
"S" |
|
|
"Z%s" // Z was already raised at outage
|
|
|
#elif !IS_KINEMATIC |
|
|
#else |
|
|
"XY" |
|
|
"Z0\nG1Z%s" // Set Z=0 and Raise Z now
|
|
|
#endif |
|
|
#endif |
|
|
#endif |
|
|
), |
|
|
)); |
|
|
dtostrf(info.zraise, 1, 3, str_1) |
|
|
|
|
|
); |
|
|
// Pretend that all axes are homed
|
|
|
gcode.process_subcommands_now(cmd); |
|
|
axis_homed = axis_known_position = xyz_bits; |
|
|
|
|
|
|
|
|
|
|
|
char cmd[MAX_CMD_SIZE+16], str_1[16], str_2[16]; |
|
|
gcode.process_subcommands_now_P(PSTR( |
|
|
|
|
|
"G28R0" // No raise during G28
|
|
|
|
|
|
TERN_(MARLIN_DEV_MODE, "S") // Simulated Homing
|
|
|
|
|
|
TERN_(IS_CARTESIAN, "XY") // Don't home Z on Cartesian
|
|
|
|
|
|
)); |
|
|
|
|
|
|
|
|
// Select the previously active tool (with no_move)
|
|
|
|
|
|
#if EXTRUDERS > 1 |
|
|
|
|
|
sprintf_P(cmd, PSTR("T%i S"), info.active_extruder); |
|
|
|
|
|
gcode.process_subcommands_now(cmd); |
|
|
|
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
// Pretend that all axes are homed
|
|
|
|
|
|
axis_homed = axis_known_position = xyz_bits; |
|
|
|
|
|
|
|
|
// Recover volumetric extrusion state
|
|
|
// Recover volumetric extrusion state
|
|
|
#if DISABLED(NO_VOLUMETRICS) |
|
|
#if DISABLED(NO_VOLUMETRICS) |
|
|
#if EXTRUDERS > 1 |
|
|
#if EXTRUDERS > 1 |
|
|
for (int8_t e = 0; e < EXTRUDERS; e++) { |
|
|
for (int8_t e = 0; e < EXTRUDERS; e++) { |
|
|
dtostrf(info.filament_size[e], 1, 3, str_1); |
|
|
sprintf_P(cmd, PSTR("M200 T%i D%s"), e, dtostrf(info.filament_size[e], 1, 3, str_1)); |
|
|
sprintf_P(cmd, PSTR("M200 T%i D%s"), e, str_1); |
|
|
|
|
|
gcode.process_subcommands_now(cmd); |
|
|
gcode.process_subcommands_now(cmd); |
|
|
} |
|
|
} |
|
|
if (!info.volumetric_enabled) { |
|
|
if (!info.volumetric_enabled) { |
|
@ -336,8 +380,7 @@ void PrintJobRecovery::resume() { |
|
|
} |
|
|
} |
|
|
#else |
|
|
#else |
|
|
if (info.volumetric_enabled) { |
|
|
if (info.volumetric_enabled) { |
|
|
dtostrf(info.filament_size[0], 1, 3, str_1); |
|
|
sprintf_P(cmd, PSTR("M200 D%s"), dtostrf(info.filament_size[0], 1, 3, str_1)); |
|
|
sprintf_P(cmd, PSTR("M200 D%s"), str_1); |
|
|
|
|
|
gcode.process_subcommands_now(cmd); |
|
|
gcode.process_subcommands_now(cmd); |
|
|
} |
|
|
} |
|
|
#endif |
|
|
#endif |
|
@ -358,7 +401,7 @@ void PrintJobRecovery::resume() { |
|
|
const int16_t et = info.target_temperature[e]; |
|
|
const int16_t et = info.target_temperature[e]; |
|
|
if (et) { |
|
|
if (et) { |
|
|
#if HAS_MULTI_HOTEND |
|
|
#if HAS_MULTI_HOTEND |
|
|
sprintf_P(cmd, PSTR("T%i"), e); |
|
|
sprintf_P(cmd, PSTR("T%i S"), e); |
|
|
gcode.process_subcommands_now(cmd); |
|
|
gcode.process_subcommands_now(cmd); |
|
|
#endif |
|
|
#endif |
|
|
sprintf_P(cmd, PSTR("M109 S%i"), et); |
|
|
sprintf_P(cmd, PSTR("M109 S%i"), et); |
|
@ -367,6 +410,12 @@ void PrintJobRecovery::resume() { |
|
|
} |
|
|
} |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
// Select the previously active tool (with no_move)
|
|
|
|
|
|
#if EXTRUDERS > 1 |
|
|
|
|
|
sprintf_P(cmd, PSTR("T%i S"), info.active_extruder); |
|
|
|
|
|
gcode.process_subcommands_now(cmd); |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
// Restore print cooling fan speeds
|
|
|
// Restore print cooling fan speeds
|
|
|
FANS_LOOP(i) { |
|
|
FANS_LOOP(i) { |
|
|
uint8_t f = info.fan_speed[i]; |
|
|
uint8_t f = info.fan_speed[i]; |
|
@ -400,18 +449,21 @@ void PrintJobRecovery::resume() { |
|
|
memcpy(&mixer.gradient, &info.gradient, sizeof(info.gradient)); |
|
|
memcpy(&mixer.gradient, &info.gradient, sizeof(info.gradient)); |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
// Extrude and retract to clean the nozzle
|
|
|
// Un-retract if there was a retract at outage
|
|
|
#if POWER_LOSS_PURGE_LEN |
|
|
#if POWER_LOSS_RETRACT_LEN |
|
|
//sprintf_P(cmd, PSTR("G1 E%d F200"), POWER_LOSS_PURGE_LEN);
|
|
|
gcode.process_subcommands_now_P(PSTR("G1 E" STRINGIFY(POWER_LOSS_RETRACT_LEN) " F3000")); |
|
|
//gcode.process_subcommands_now(cmd);
|
|
|
|
|
|
gcode.process_subcommands_now_P(PSTR("G1 E" STRINGIFY(POWER_LOSS_PURGE_LEN) " F200")); |
|
|
|
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
#if POWER_LOSS_RETRACT_LEN |
|
|
// Additional purge if configured
|
|
|
sprintf_P(cmd, PSTR("G1 E%d F3000"), POWER_LOSS_PURGE_LEN - (POWER_LOSS_RETRACT_LEN)); |
|
|
#if POWER_LOSS_PURGE_LEN |
|
|
|
|
|
sprintf_P(cmd, PSTR("G1 E%d F200"), (POWER_LOSS_PURGE_LEN) + (POWER_LOSS_RETRACT_LEN)); |
|
|
gcode.process_subcommands_now(cmd); |
|
|
gcode.process_subcommands_now(cmd); |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(NOZZLE_CLEAN_FEATURE) |
|
|
|
|
|
gcode.process_subcommands_now_P(PSTR("G12")); |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
// Move back to the saved XY
|
|
|
// Move back to the saved XY
|
|
|
sprintf_P(cmd, PSTR("G1 X%s Y%s F3000"), |
|
|
sprintf_P(cmd, PSTR("G1 X%s Y%s F3000"), |
|
|
dtostrf(info.current_position.x, 1, 3, str_1), |
|
|
dtostrf(info.current_position.x, 1, 3, str_1), |
|
@ -429,13 +481,6 @@ void PrintJobRecovery::resume() { |
|
|
#endif |
|
|
#endif |
|
|
gcode.process_subcommands_now(cmd); |
|
|
gcode.process_subcommands_now(cmd); |
|
|
|
|
|
|
|
|
// Un-retract
|
|
|
|
|
|
#if POWER_LOSS_PURGE_LEN |
|
|
|
|
|
//sprintf_P(cmd, PSTR("G1 E%d F3000"), POWER_LOSS_PURGE_LEN);
|
|
|
|
|
|
//gcode.process_subcommands_now(cmd);
|
|
|
|
|
|
gcode.process_subcommands_now_P(PSTR("G1 E" STRINGIFY(POWER_LOSS_PURGE_LEN) " F3000")); |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
// Restore the feedrate
|
|
|
// Restore the feedrate
|
|
|
sprintf_P(cmd, PSTR("G1 F%d"), info.feedrate); |
|
|
sprintf_P(cmd, PSTR("G1 F%d"), info.feedrate); |
|
|
gcode.process_subcommands_now(cmd); |
|
|
gcode.process_subcommands_now(cmd); |
|
@ -476,6 +521,8 @@ void PrintJobRecovery::resume() { |
|
|
} |
|
|
} |
|
|
DEBUG_EOL(); |
|
|
DEBUG_EOL(); |
|
|
|
|
|
|
|
|
|
|
|
DEBUG_ECHOLNPAIR("zraise: ", info.zraise); |
|
|
|
|
|
|
|
|
#if HAS_HOME_OFFSET |
|
|
#if HAS_HOME_OFFSET |
|
|
DEBUG_ECHOPGM("home_offset: "); |
|
|
DEBUG_ECHOPGM("home_offset: "); |
|
|
LOOP_XYZ(i) { |
|
|
LOOP_XYZ(i) { |
|
|