Fix, improve Power Loss Recovery (#13703)

- Save and restore workspace offsets
- Add retract and purge (hidden) options
- Always restore axis relative modes
- Use added `G92.9` to do position restores
This commit is contained in:
Msq001
2019-04-16 07:53:39 +08:00
committed by Scott Lahteine
parent df75a606ff
commit 455ee23499
5 changed files with 127 additions and 59 deletions

View File

@ -33,9 +33,23 @@
*/
void GcodeSuite::G92() {
#if ENABLED(CNC_COORDINATE_SYSTEMS)
switch (parser.subcode) {
case 1:
bool didE = false;
#if IS_SCARA || !HAS_POSITION_SHIFT
bool didXYZ = false;
#else
constexpr bool didXYZ = false;
#endif
#if USE_GCODE_SUBCODES
const uint8_t subcode_G92 = parser.subcode;
#else
constexpr uint8_t subcode_G92 = 0;
#endif
switch (subcode_G92) {
default: break;
#if ENABLED(CNC_COORDINATE_SYSTEMS)
case 1: {
// Zero the G92 values and restore current position
#if !IS_SCARA
LOOP_XYZ(i) {
@ -46,44 +60,42 @@ void GcodeSuite::G92() {
}
}
#endif // Not SCARA
return;
}
#endif
#if ENABLED(CNC_COORDINATE_SYSTEMS)
#define IS_G92_0 (parser.subcode == 0)
#else
#define IS_G92_0 true
#endif
bool didE = false;
#if IS_SCARA || !HAS_POSITION_SHIFT
bool didXYZ = false;
#else
constexpr bool didXYZ = false;
#endif
if (IS_G92_0) LOOP_XYZE(i) {
if (parser.seenval(axis_codes[i])) {
const float l = parser.value_axis_units((AxisEnum)i),
v = i == E_AXIS ? l : LOGICAL_TO_NATIVE(l, i),
d = v - current_position[i];
if (!NEAR_ZERO(d)) {
#if IS_SCARA || !HAS_POSITION_SHIFT
if (i == E_AXIS) didE = true; else didXYZ = true;
current_position[i] = v; // Without workspaces revert to Marlin 1.0 behavior
#elif HAS_POSITION_SHIFT
if (i == E_AXIS) {
didE = true;
current_position[E_AXIS] = v; // When using coordinate spaces, only E is set directly
} return;
#endif
#if ENABLED(POWER_LOSS_RECOVERY)
case 9: {
LOOP_XYZE(i) {
if (parser.seenval(axis_codes[i])) {
current_position[i] = parser.value_axis_units((AxisEnum)i);
if (i == E_AXIS) didE = true; else didXYZ = true;
}
else {
position_shift[i] += d; // Other axes simply offset the coordinate space
update_workspace_offset((AxisEnum)i);
}
} break;
#endif
case 0: {
LOOP_XYZE(i) {
if (parser.seenval(axis_codes[i])) {
const float l = parser.value_axis_units((AxisEnum)i),
v = i == E_AXIS ? l : LOGICAL_TO_NATIVE(l, i),
d = v - current_position[i];
if (!NEAR_ZERO(d)) {
#if IS_SCARA || !HAS_POSITION_SHIFT
if (i == E_AXIS) didE = true; else didXYZ = true;
current_position[i] = v; // Without workspaces revert to Marlin 1.0 behavior
#elif HAS_POSITION_SHIFT
if (i == E_AXIS) {
didE = true;
current_position[E_AXIS] = v; // When using coordinate spaces, only E is set directly
}
else {
position_shift[i] += d; // Other axes simply offset the coordinate space
update_workspace_offset((AxisEnum)i);
}
#endif
}
#endif
}
}
}
} break;
}
#if ENABLED(CNC_COORDINATE_SYSTEMS)

View File

@ -31,9 +31,6 @@
* M23: Open a file
*/
void GcodeSuite::M23() {
#if ENABLED(POWER_LOSS_RECOVERY)
card.removeJobRecoveryFile();
#endif
// Simplify3D includes the size, so zero out all spaces (#7227)
for (char *fn = parser.string_arg; *fn; ++fn) if (*fn == ' ') *fn = '\0';
card.openFile(parser.string_arg, true);