G92, subcodes flag cleanup

This commit is contained in:
Scott Lahteine 2021-02-23 16:08:00 -06:00
parent ba301fd800
commit 27f9437d31
4 changed files with 52 additions and 39 deletions

View File

@ -29,77 +29,90 @@
#endif #endif
/** /**
* G92: Set current position to given X Y Z E * G92: Set the Current Position to the given X Y Z E values.
*
* Behind the scenes the G92 command may modify the Current Position
* or the Position Shift depending on settings and sub-commands.
*
* Since E has no Workspace Offset, it is always set directly.
*
* Without Workspace Offsets (e.g., with NO_WORKSPACE_OFFSETS):
* G92 : Set NATIVE Current Position to the given X Y Z E.
*
* Using Workspace Offsets (default Marlin behavior):
* G92 : Modify Workspace Offsets so the reported position shows the given X Y Z E.
* G92.1 : Zero XYZ Workspace Offsets (so the reported position = the native position).
*
* With POWER_LOSS_RECOVERY:
* G92.9 : Set NATIVE Current Position to the given X Y Z E.
*/ */
void GcodeSuite::G92() { void GcodeSuite::G92() {
bool sync_E = false, sync_XYZ = false; bool sync_E = false, sync_XYZE = false;
#if ENABLED(USE_GCODE_SUBCODES) #if USE_GCODE_SUBCODES
const uint8_t subcode_G92 = parser.subcode; const uint8_t subcode_G92 = parser.subcode;
#else #else
constexpr uint8_t subcode_G92 = 0; constexpr uint8_t subcode_G92 = 0;
#endif #endif
switch (subcode_G92) { switch (subcode_G92) {
default: break; default: return; // Ignore unknown G92.x
#if ENABLED(CNC_COORDINATE_SYSTEMS)
case 1: { #if ENABLED(CNC_COORDINATE_SYSTEMS) && !IS_SCARA
// Zero the G92 values and restore current position case 1: // G92.1 - Zero the Workspace Offset
#if !IS_SCARA LOOP_XYZ(i) if (position_shift[i]) {
LOOP_XYZ(i) if (position_shift[i]) { position_shift[i] = 0;
position_shift[i] = 0; update_workspace_offset((AxisEnum)i);
update_workspace_offset((AxisEnum)i); }
} break;
#endif // Not SCARA
} return;
#endif #endif
#if ENABLED(POWER_LOSS_RECOVERY) #if ENABLED(POWER_LOSS_RECOVERY)
case 9: { case 9: // G92.9 - Set Current Position directly (like Marlin 1.0)
LOOP_XYZE(i) { LOOP_XYZE(i) {
if (parser.seenval(axis_codes[i])) { if (parser.seenval(axis_codes[i])) {
if (i == E_AXIS) sync_E = true; else sync_XYZE = true;
current_position[i] = parser.value_axis_units((AxisEnum)i); current_position[i] = parser.value_axis_units((AxisEnum)i);
if (i == E_AXIS) sync_E = true; else sync_XYZ = true;
} }
} }
} break; break;
#endif #endif
case 0: {
case 0:
LOOP_XYZE(i) { LOOP_XYZE(i) {
if (parser.seenval(axis_codes[i])) { if (parser.seenval(axis_codes[i])) {
const float l = parser.value_axis_units((AxisEnum)i), const float l = parser.value_axis_units((AxisEnum)i), // Given axis coordinate value, converted to millimeters
v = i == E_AXIS ? l : LOGICAL_TO_NATIVE(l, i), v = i == E_AXIS ? l : LOGICAL_TO_NATIVE(l, i), // Axis position in NATIVE space (applying the existing offset)
d = v - current_position[i]; d = v - current_position[i]; // How much is the current axis position altered by?
if (!NEAR_ZERO(d)) { if (!NEAR_ZERO(d)) {
#if IS_SCARA || !HAS_POSITION_SHIFT #if HAS_POSITION_SHIFT && !IS_SCARA // When using workspaces...
if (i == E_AXIS) sync_E = true; else sync_XYZ = true;
current_position[i] = v; // Without workspaces revert to Marlin 1.0 behavior
#elif HAS_POSITION_SHIFT
if (i == E_AXIS) { if (i == E_AXIS) {
sync_E = true; sync_E = true;
current_position.e = v; // When using coordinate spaces, only E is set directly current_position.e = v; // ...E is still set directly
} }
else { else {
position_shift[i] += d; // Other axes simply offset the coordinate space position_shift[i] += d; // ...but other axes offset the workspace.
update_workspace_offset((AxisEnum)i); update_workspace_offset((AxisEnum)i);
} }
#else // Without workspaces...
if (i == E_AXIS) sync_E = true; else sync_XYZE = true;
current_position[i] = v; // ...set Current Position directly (like Marlin 1.0)
#endif #endif
} }
} }
} }
} break; break;
} }
#if ENABLED(CNC_COORDINATE_SYSTEMS) #if ENABLED(CNC_COORDINATE_SYSTEMS)
// Apply workspace offset to the active coordinate system // Apply Workspace Offset to the active coordinate system
if (WITHIN(active_coordinate_system, 0, MAX_COORDINATE_SYSTEMS - 1)) if (WITHIN(active_coordinate_system, 0, MAX_COORDINATE_SYSTEMS - 1))
coordinate_system[active_coordinate_system] = position_shift; coordinate_system[active_coordinate_system] = position_shift;
#endif #endif
if (sync_XYZ) sync_plan_position(); if (sync_XYZE) sync_plan_position();
else if (sync_E) sync_plan_position_e(); else if (sync_E) sync_plan_position_e();
#if DISABLED(DIRECT_STEPPING) IF_DISABLED(DIRECT_STEPPING, report_current_position());
report_current_position();
#endif
} }

View File

@ -47,13 +47,13 @@ char *GCodeParser::command_ptr,
char GCodeParser::command_letter; char GCodeParser::command_letter;
uint16_t GCodeParser::codenum; uint16_t GCodeParser::codenum;
#if ENABLED(USE_GCODE_SUBCODES) #if USE_GCODE_SUBCODES
uint8_t GCodeParser::subcode; uint8_t GCodeParser::subcode;
#endif #endif
#if ENABLED(GCODE_MOTION_MODES) #if ENABLED(GCODE_MOTION_MODES)
int16_t GCodeParser::motion_mode_codenum = -1; int16_t GCodeParser::motion_mode_codenum = -1;
#if ENABLED(USE_GCODE_SUBCODES) #if USE_GCODE_SUBCODES
uint8_t GCodeParser::motion_mode_subcode; uint8_t GCodeParser::motion_mode_subcode;
#endif #endif
#endif #endif
@ -189,7 +189,7 @@ void GCodeParser::parse(char *p) {
} }
// Allow for decimal point in command // Allow for decimal point in command
#if ENABLED(USE_GCODE_SUBCODES) #if USE_GCODE_SUBCODES
if (*p == '.') { if (*p == '.') {
p++; p++;
while (NUMERIC(*p)) while (NUMERIC(*p))

View File

@ -85,13 +85,13 @@ public:
*string_arg, // string of command line *string_arg, // string of command line
command_letter; // G, M, or T command_letter; // G, M, or T
static uint16_t codenum; // 123 static uint16_t codenum; // 123
#if ENABLED(USE_GCODE_SUBCODES) #if USE_GCODE_SUBCODES
static uint8_t subcode; // .1 static uint8_t subcode; // .1
#endif #endif
#if ENABLED(GCODE_MOTION_MODES) #if ENABLED(GCODE_MOTION_MODES)
static int16_t motion_mode_codenum; static int16_t motion_mode_codenum;
#if ENABLED(USE_GCODE_SUBCODES) #if USE_GCODE_SUBCODES
static uint8_t motion_mode_subcode; static uint8_t motion_mode_subcode;
#endif #endif
FORCE_INLINE static void cancel_motion_mode() { motion_mode_codenum = -1; } FORCE_INLINE static void cancel_motion_mode() { motion_mode_codenum = -1; }

View File

@ -2758,7 +2758,7 @@
// Add commands that need sub-codes to this list // Add commands that need sub-codes to this list
#if ANY(G38_PROBE_TARGET, CNC_COORDINATE_SYSTEMS, POWER_LOSS_RECOVERY) #if ANY(G38_PROBE_TARGET, CNC_COORDINATE_SYSTEMS, POWER_LOSS_RECOVERY)
#define USE_GCODE_SUBCODES #define USE_GCODE_SUBCODES 1
#endif #endif
// Parking Extruder // Parking Extruder