|
@@ -29,77 +29,90 @@
|
29
|
29
|
#endif
|
30
|
30
|
|
31
|
31
|
/**
|
32
|
|
- * G92: Set current position to given X Y Z E
|
|
32
|
+ * G92: Set the Current Position to the given X Y Z E values.
|
|
33
|
+ *
|
|
34
|
+ * Behind the scenes the G92 command may modify the Current Position
|
|
35
|
+ * or the Position Shift depending on settings and sub-commands.
|
|
36
|
+ *
|
|
37
|
+ * Since E has no Workspace Offset, it is always set directly.
|
|
38
|
+ *
|
|
39
|
+ * Without Workspace Offsets (e.g., with NO_WORKSPACE_OFFSETS):
|
|
40
|
+ * G92 : Set NATIVE Current Position to the given X Y Z E.
|
|
41
|
+ *
|
|
42
|
+ * Using Workspace Offsets (default Marlin behavior):
|
|
43
|
+ * G92 : Modify Workspace Offsets so the reported position shows the given X Y Z E.
|
|
44
|
+ * G92.1 : Zero XYZ Workspace Offsets (so the reported position = the native position).
|
|
45
|
+ *
|
|
46
|
+ * With POWER_LOSS_RECOVERY:
|
|
47
|
+ * G92.9 : Set NATIVE Current Position to the given X Y Z E.
|
33
|
48
|
*/
|
34
|
49
|
void GcodeSuite::G92() {
|
35
|
50
|
|
36
|
|
- bool sync_E = false, sync_XYZ = false;
|
|
51
|
+ bool sync_E = false, sync_XYZE = false;
|
37
|
52
|
|
38
|
|
- #if ENABLED(USE_GCODE_SUBCODES)
|
|
53
|
+ #if USE_GCODE_SUBCODES
|
39
|
54
|
const uint8_t subcode_G92 = parser.subcode;
|
40
|
55
|
#else
|
41
|
56
|
constexpr uint8_t subcode_G92 = 0;
|
42
|
57
|
#endif
|
43
|
58
|
|
44
|
59
|
switch (subcode_G92) {
|
45
|
|
- default: break;
|
46
|
|
- #if ENABLED(CNC_COORDINATE_SYSTEMS)
|
47
|
|
- case 1: {
|
48
|
|
- // Zero the G92 values and restore current position
|
49
|
|
- #if !IS_SCARA
|
50
|
|
- LOOP_XYZ(i) if (position_shift[i]) {
|
51
|
|
- position_shift[i] = 0;
|
52
|
|
- update_workspace_offset((AxisEnum)i);
|
53
|
|
- }
|
54
|
|
- #endif // Not SCARA
|
55
|
|
- } return;
|
|
60
|
+ default: return; // Ignore unknown G92.x
|
|
61
|
+
|
|
62
|
+ #if ENABLED(CNC_COORDINATE_SYSTEMS) && !IS_SCARA
|
|
63
|
+ case 1: // G92.1 - Zero the Workspace Offset
|
|
64
|
+ LOOP_XYZ(i) if (position_shift[i]) {
|
|
65
|
+ position_shift[i] = 0;
|
|
66
|
+ update_workspace_offset((AxisEnum)i);
|
|
67
|
+ }
|
|
68
|
+ break;
|
56
|
69
|
#endif
|
|
70
|
+
|
57
|
71
|
#if ENABLED(POWER_LOSS_RECOVERY)
|
58
|
|
- case 9: {
|
|
72
|
+ case 9: // G92.9 - Set Current Position directly (like Marlin 1.0)
|
59
|
73
|
LOOP_XYZE(i) {
|
60
|
74
|
if (parser.seenval(axis_codes[i])) {
|
|
75
|
+ if (i == E_AXIS) sync_E = true; else sync_XYZE = true;
|
61
|
76
|
current_position[i] = parser.value_axis_units((AxisEnum)i);
|
62
|
|
- if (i == E_AXIS) sync_E = true; else sync_XYZ = true;
|
63
|
77
|
}
|
64
|
78
|
}
|
65
|
|
- } break;
|
|
79
|
+ break;
|
66
|
80
|
#endif
|
67
|
|
- case 0: {
|
|
81
|
+
|
|
82
|
+ case 0:
|
68
|
83
|
LOOP_XYZE(i) {
|
69
|
84
|
if (parser.seenval(axis_codes[i])) {
|
70
|
|
- const float l = parser.value_axis_units((AxisEnum)i),
|
71
|
|
- v = i == E_AXIS ? l : LOGICAL_TO_NATIVE(l, i),
|
72
|
|
- d = v - current_position[i];
|
|
85
|
+ const float l = parser.value_axis_units((AxisEnum)i), // Given axis coordinate value, converted to millimeters
|
|
86
|
+ v = i == E_AXIS ? l : LOGICAL_TO_NATIVE(l, i), // Axis position in NATIVE space (applying the existing offset)
|
|
87
|
+ d = v - current_position[i]; // How much is the current axis position altered by?
|
73
|
88
|
if (!NEAR_ZERO(d)) {
|
74
|
|
- #if IS_SCARA || !HAS_POSITION_SHIFT
|
75
|
|
- if (i == E_AXIS) sync_E = true; else sync_XYZ = true;
|
76
|
|
- current_position[i] = v; // Without workspaces revert to Marlin 1.0 behavior
|
77
|
|
- #elif HAS_POSITION_SHIFT
|
|
89
|
+ #if HAS_POSITION_SHIFT && !IS_SCARA // When using workspaces...
|
78
|
90
|
if (i == E_AXIS) {
|
79
|
91
|
sync_E = true;
|
80
|
|
- current_position.e = v; // When using coordinate spaces, only E is set directly
|
|
92
|
+ current_position.e = v; // ...E is still set directly
|
81
|
93
|
}
|
82
|
94
|
else {
|
83
|
|
- position_shift[i] += d; // Other axes simply offset the coordinate space
|
|
95
|
+ position_shift[i] += d; // ...but other axes offset the workspace.
|
84
|
96
|
update_workspace_offset((AxisEnum)i);
|
85
|
97
|
}
|
|
98
|
+ #else // Without workspaces...
|
|
99
|
+ if (i == E_AXIS) sync_E = true; else sync_XYZE = true;
|
|
100
|
+ current_position[i] = v; // ...set Current Position directly (like Marlin 1.0)
|
86
|
101
|
#endif
|
87
|
102
|
}
|
88
|
103
|
}
|
89
|
104
|
}
|
90
|
|
- } break;
|
|
105
|
+ break;
|
91
|
106
|
}
|
92
|
107
|
|
93
|
108
|
#if ENABLED(CNC_COORDINATE_SYSTEMS)
|
94
|
|
- // Apply workspace offset to the active coordinate system
|
|
109
|
+ // Apply Workspace Offset to the active coordinate system
|
95
|
110
|
if (WITHIN(active_coordinate_system, 0, MAX_COORDINATE_SYSTEMS - 1))
|
96
|
111
|
coordinate_system[active_coordinate_system] = position_shift;
|
97
|
112
|
#endif
|
98
|
113
|
|
99
|
|
- if (sync_XYZ) sync_plan_position();
|
|
114
|
+ if (sync_XYZE) sync_plan_position();
|
100
|
115
|
else if (sync_E) sync_plan_position_e();
|
101
|
116
|
|
102
|
|
- #if DISABLED(DIRECT_STEPPING)
|
103
|
|
- report_current_position();
|
104
|
|
- #endif
|
|
117
|
+ IF_DISABLED(DIRECT_STEPPING, report_current_position());
|
105
|
118
|
}
|