|
|
|
@ -66,12 +66,16 @@ PrintJobRecovery recovery;
|
|
|
|
|
#ifndef POWER_LOSS_PURGE_LEN
|
|
|
|
|
#define POWER_LOSS_PURGE_LEN 0
|
|
|
|
|
#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
|
|
|
|
|
#define POWER_LOSS_RETRACT_LEN 0
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef POWER_LOSS_ZRAISE
|
|
|
|
|
#define POWER_LOSS_ZRAISE 2
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Clear the recovery info
|
|
|
|
@ -144,7 +148,7 @@ void PrintJobRecovery::prepare() {
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
static millis_t next_save_ms; // = 0
|
|
|
|
@ -177,6 +181,7 @@ void PrintJobRecovery::save(const bool force/*=false*/) {
|
|
|
|
|
|
|
|
|
|
// Machine state
|
|
|
|
|
info.current_position = current_position;
|
|
|
|
|
info.zraise = zraise;
|
|
|
|
|
TERN_(HAS_HOME_OFFSET, info.home_offset = home_offset);
|
|
|
|
|
TERN_(HAS_POSITION_SHIFT, info.position_shift = position_shift);
|
|
|
|
|
info.feedrate = uint16_t(feedrate_mm_s * 60.0f);
|
|
|
|
@ -228,31 +233,74 @@ void PrintJobRecovery::save(const bool force/*=false*/) {
|
|
|
|
|
|
|
|
|
|
#if PIN_EXISTS(POWER_LOSS)
|
|
|
|
|
|
|
|
|
|
void PrintJobRecovery::_outage() {
|
|
|
|
|
#if ENABLED(BACKUP_POWER_SUPPLY)
|
|
|
|
|
static bool lock = false;
|
|
|
|
|
if (lock) return; // No re-entrance from idle() during raise_z()
|
|
|
|
|
lock = true;
|
|
|
|
|
#endif
|
|
|
|
|
if (IS_SD_PRINTING()) save(true);
|
|
|
|
|
TERN_(BACKUP_POWER_SUPPLY, raise_z());
|
|
|
|
|
|
|
|
|
|
kill(GET_TEXT(MSG_OUTAGE_RECOVERY));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if ENABLED(BACKUP_POWER_SUPPLY)
|
|
|
|
|
|
|
|
|
|
void PrintJobRecovery::raise_z() {
|
|
|
|
|
// Disable all heaters to reduce power loss
|
|
|
|
|
thermalManager.disable_all_heaters();
|
|
|
|
|
quickstop_stepper();
|
|
|
|
|
// Raise Z axis
|
|
|
|
|
gcode.process_subcommands_now_P(PSTR("G91\nG0 Z" STRINGIFY(POWER_LOSS_ZRAISE)));
|
|
|
|
|
planner.synchronize();
|
|
|
|
|
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() {
|
|
|
|
|
#if ENABLED(BACKUP_POWER_SUPPLY)
|
|
|
|
|
static bool lock = false;
|
|
|
|
|
if (lock) return; // No re-entrance from idle() during retract_and_lift()
|
|
|
|
|
lock = true;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
|
|
|
// Save, including the limited Z raise
|
|
|
|
|
if (IS_SD_PRINTING()) save(true, zraise);
|
|
|
|
|
|
|
|
|
|
// Disable all heaters to reduce power loss
|
|
|
|
|
thermalManager.disable_all_heaters();
|
|
|
|
|
|
|
|
|
|
#if ENABLED(BACKUP_POWER_SUPPLY)
|
|
|
|
|
// Do a hard-stop of the steppers (with possibly a loud thud)
|
|
|
|
|
quickstop_stepper();
|
|
|
|
|
// With backup power a retract and raise can be done now
|
|
|
|
|
retract_and_lift(zraise);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
kill(GET_TEXT(MSG_OUTAGE_RECOVERY));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -274,6 +322,8 @@ void PrintJobRecovery::write() {
|
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
#if HAS_LEVELING
|
|
|
|
@ -282,52 +332,46 @@ void PrintJobRecovery::resume() {
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
"\n"
|
|
|
|
|
"G28R0"
|
|
|
|
|
TERN_(MARLIN_DEV_MODE, "S")
|
|
|
|
|
// If Z homing goes to max, just reset E and home all
|
|
|
|
|
gcode.process_subcommands_now_P(PSTR(
|
|
|
|
|
"G92.9 E0\n"
|
|
|
|
|
"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)
|
|
|
|
|
// 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"
|
|
|
|
|
// 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.)
|
|
|
|
|
|
|
|
|
|
"G28R0"
|
|
|
|
|
#if ENABLED(MARLIN_DEV_MODE)
|
|
|
|
|
"S"
|
|
|
|
|
#elif !IS_KINEMATIC
|
|
|
|
|
"XY"
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
));
|
|
|
|
|
sprintf_P(cmd, PSTR("G92.9 E0 "
|
|
|
|
|
#if ENABLED(BACKUP_POWER_SUPPLY)
|
|
|
|
|
"Z%s" // Z was already raised at outage
|
|
|
|
|
#else
|
|
|
|
|
"Z0\nG1Z%s" // Set Z=0 and Raise Z now
|
|
|
|
|
#endif
|
|
|
|
|
),
|
|
|
|
|
dtostrf(info.zraise, 1, 3, str_1)
|
|
|
|
|
);
|
|
|
|
|
gcode.process_subcommands_now(cmd);
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Pretend that all axes are homed
|
|
|
|
|
axis_homed = axis_known_position = xyz_bits;
|
|
|
|
|
|
|
|
|
|
char cmd[MAX_CMD_SIZE+16], str_1[16], str_2[16];
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
|
|
// Recover volumetric extrusion state
|
|
|
|
|
#if DISABLED(NO_VOLUMETRICS)
|
|
|
|
|
#if EXTRUDERS > 1
|
|
|
|
|
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, str_1);
|
|
|
|
|
sprintf_P(cmd, PSTR("M200 T%i D%s"), e, dtostrf(info.filament_size[e], 1, 3, str_1));
|
|
|
|
|
gcode.process_subcommands_now(cmd);
|
|
|
|
|
}
|
|
|
|
|
if (!info.volumetric_enabled) {
|
|
|
|
@ -336,8 +380,7 @@ void PrintJobRecovery::resume() {
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
if (info.volumetric_enabled) {
|
|
|
|
|
dtostrf(info.filament_size[0], 1, 3, str_1);
|
|
|
|
|
sprintf_P(cmd, PSTR("M200 D%s"), str_1);
|
|
|
|
|
sprintf_P(cmd, PSTR("M200 D%s"), dtostrf(info.filament_size[0], 1, 3, str_1));
|
|
|
|
|
gcode.process_subcommands_now(cmd);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
@ -358,7 +401,7 @@ void PrintJobRecovery::resume() {
|
|
|
|
|
const int16_t et = info.target_temperature[e];
|
|
|
|
|
if (et) {
|
|
|
|
|
#if HAS_MULTI_HOTEND
|
|
|
|
|
sprintf_P(cmd, PSTR("T%i"), e);
|
|
|
|
|
sprintf_P(cmd, PSTR("T%i S"), e);
|
|
|
|
|
gcode.process_subcommands_now(cmd);
|
|
|
|
|
#endif
|
|
|
|
|
sprintf_P(cmd, PSTR("M109 S%i"), et);
|
|
|
|
@ -367,6 +410,12 @@ void PrintJobRecovery::resume() {
|
|
|
|
|
}
|
|
|
|
|
#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
|
|
|
|
|
FANS_LOOP(i) {
|
|
|
|
|
uint8_t f = info.fan_speed[i];
|
|
|
|
@ -400,18 +449,21 @@ void PrintJobRecovery::resume() {
|
|
|
|
|
memcpy(&mixer.gradient, &info.gradient, sizeof(info.gradient));
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Extrude and retract to clean the nozzle
|
|
|
|
|
#if POWER_LOSS_PURGE_LEN
|
|
|
|
|
//sprintf_P(cmd, PSTR("G1 E%d F200"), POWER_LOSS_PURGE_LEN);
|
|
|
|
|
//gcode.process_subcommands_now(cmd);
|
|
|
|
|
gcode.process_subcommands_now_P(PSTR("G1 E" STRINGIFY(POWER_LOSS_PURGE_LEN) " F200"));
|
|
|
|
|
// Un-retract if there was a retract at outage
|
|
|
|
|
#if POWER_LOSS_RETRACT_LEN
|
|
|
|
|
gcode.process_subcommands_now_P(PSTR("G1 E" STRINGIFY(POWER_LOSS_RETRACT_LEN) " F3000"));
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if POWER_LOSS_RETRACT_LEN
|
|
|
|
|
sprintf_P(cmd, PSTR("G1 E%d F3000"), POWER_LOSS_PURGE_LEN - (POWER_LOSS_RETRACT_LEN));
|
|
|
|
|
// Additional purge if configured
|
|
|
|
|
#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);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if ENABLED(NOZZLE_CLEAN_FEATURE)
|
|
|
|
|
gcode.process_subcommands_now_P(PSTR("G12"));
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Move back to the saved XY
|
|
|
|
|
sprintf_P(cmd, PSTR("G1 X%s Y%s F3000"),
|
|
|
|
|
dtostrf(info.current_position.x, 1, 3, str_1),
|
|
|
|
@ -429,13 +481,6 @@ void PrintJobRecovery::resume() {
|
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
|
sprintf_P(cmd, PSTR("G1 F%d"), info.feedrate);
|
|
|
|
|
gcode.process_subcommands_now(cmd);
|
|
|
|
@ -476,6 +521,8 @@ void PrintJobRecovery::resume() {
|
|
|
|
|
}
|
|
|
|
|
DEBUG_EOL();
|
|
|
|
|
|
|
|
|
|
DEBUG_ECHOLNPAIR("zraise: ", info.zraise);
|
|
|
|
|
|
|
|
|
|
#if HAS_HOME_OFFSET
|
|
|
|
|
DEBUG_ECHOPGM("home_offset: ");
|
|
|
|
|
LOOP_XYZ(i) {
|
|
|
|
|