Browse Source

G92, subcodes flag cleanup

Scott Lahteine 3 years ago
parent
commit
27f9437d31

+ 46
- 33
Marlin/src/gcode/geometry/G92.cpp View File

@@ -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
 }

+ 3
- 3
Marlin/src/gcode/parser.cpp View File

@@ -47,13 +47,13 @@ char *GCodeParser::command_ptr,
47 47
 char GCodeParser::command_letter;
48 48
 uint16_t GCodeParser::codenum;
49 49
 
50
-#if ENABLED(USE_GCODE_SUBCODES)
50
+#if USE_GCODE_SUBCODES
51 51
   uint8_t GCodeParser::subcode;
52 52
 #endif
53 53
 
54 54
 #if ENABLED(GCODE_MOTION_MODES)
55 55
   int16_t GCodeParser::motion_mode_codenum = -1;
56
-  #if ENABLED(USE_GCODE_SUBCODES)
56
+  #if USE_GCODE_SUBCODES
57 57
     uint8_t GCodeParser::motion_mode_subcode;
58 58
   #endif
59 59
 #endif
@@ -189,7 +189,7 @@ void GCodeParser::parse(char *p) {
189 189
       }
190 190
 
191 191
       // Allow for decimal point in command
192
-      #if ENABLED(USE_GCODE_SUBCODES)
192
+      #if USE_GCODE_SUBCODES
193 193
         if (*p == '.') {
194 194
           p++;
195 195
           while (NUMERIC(*p))

+ 2
- 2
Marlin/src/gcode/parser.h View File

@@ -85,13 +85,13 @@ public:
85 85
               *string_arg,                // string of command line
86 86
               command_letter;             // G, M, or T
87 87
   static uint16_t codenum;                // 123
88
-  #if ENABLED(USE_GCODE_SUBCODES)
88
+  #if USE_GCODE_SUBCODES
89 89
     static uint8_t subcode;               // .1
90 90
   #endif
91 91
 
92 92
   #if ENABLED(GCODE_MOTION_MODES)
93 93
     static int16_t motion_mode_codenum;
94
-    #if ENABLED(USE_GCODE_SUBCODES)
94
+    #if USE_GCODE_SUBCODES
95 95
       static uint8_t motion_mode_subcode;
96 96
     #endif
97 97
     FORCE_INLINE static void cancel_motion_mode() { motion_mode_codenum = -1; }

+ 1
- 1
Marlin/src/inc/Conditionals_post.h View File

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

Loading…
Cancel
Save