Ver código fonte

Fix G90, G91, M82, M83 rel/abs modes (#15218)

Scott Lahteine 4 anos atrás
pai
commit
6091e6300a
Nenhuma conta vinculada ao e-mail do autor do commit

+ 4
- 6
Marlin/src/feature/power_loss_recovery.cpp Ver arquivo

@@ -215,9 +215,8 @@ void PrintJobRecovery::save(const bool force/*=false*/, const bool save_queue/*=
215 215
       info.retract_hop = fwretract.current_hop;
216 216
     #endif
217 217
 
218
-    // Relative mode
219
-    info.relative_mode = relative_mode;
220
-    info.relative_modes_e = gcode.axis_relative_modes[E_AXIS];
218
+    // Relative axis modes
219
+    info.axis_relative = gcode.axis_relative;
221 220
 
222 221
     // Elapsed print job time
223 222
     info.print_job_elapsed = print_job_timer.duration();
@@ -392,9 +391,8 @@ void PrintJobRecovery::resume() {
392 391
   sprintf_P(cmd, PSTR("G92.9 E%s"), dtostrf(info.current_position[E_AXIS], 1, 3, str_1));
393 392
   gcode.process_subcommands_now(cmd);
394 393
 
395
-  // Relative mode
396
-  relative_mode = info.relative_mode;
397
-  gcode.axis_relative_modes[E_AXIS] = info.relative_modes_e;
394
+  // Relative axis modes
395
+  gcode.axis_relative = info.axis_relative;
398 396
 
399 397
   #if HAS_HOME_OFFSET || HAS_POSITION_SHIFT
400 398
     LOOP_XYZ(i) {

+ 2
- 2
Marlin/src/feature/power_loss_recovery.h Ver arquivo

@@ -89,8 +89,8 @@ typedef struct {
89 89
     #endif
90 90
   #endif
91 91
 
92
-  // Relative mode
93
-  bool relative_mode, relative_modes_e;
92
+  // Relative axis modes
93
+  uint8_t axis_relative;
94 94
 
95 95
   // SD Filename and position
96 96
   char sd_filename[MAXPATHNAMELENGTH];

+ 0
- 9
Marlin/src/feature/prusa_MMU2/mmu2.cpp Ver arquivo

@@ -698,8 +698,6 @@ void MMU2::filament_runout() {
698 698
     }
699 699
 
700 700
     LCD_MESSAGEPGM(MSG_MMU2_EJECTING_FILAMENT);
701
-    const bool saved_e_relative_mode = gcode.axis_relative_modes[E_AXIS];
702
-    gcode.axis_relative_modes[E_AXIS] = true;
703 701
 
704 702
     enable_E0();
705 703
     current_position[E_AXIS] -= MMU2_FILAMENTCHANGE_EJECT_FEED;
@@ -735,8 +733,6 @@ void MMU2::filament_runout() {
735 733
 
736 734
     BUZZ(200, 404);
737 735
 
738
-    gcode.axis_relative_modes[E_AXIS] = saved_e_relative_mode;
739
-
740 736
     disable_E0();
741 737
 
742 738
     return true;
@@ -784,9 +780,6 @@ void MMU2::filament_runout() {
784 780
     planner.synchronize();
785 781
     enable_E0();
786 782
 
787
-    const bool saved_e_relative_mode = gcode.axis_relative_modes[E_AXIS];
788
-    gcode.axis_relative_modes[E_AXIS] = true;
789
-
790 783
     const E_Step* step = sequence;
791 784
 
792 785
     for (uint8_t i = 0; i < steps; i++) {
@@ -804,8 +797,6 @@ void MMU2::filament_runout() {
804 797
       step++;
805 798
     }
806 799
 
807
-    gcode.axis_relative_modes[E_AXIS] = saved_e_relative_mode;
808
-
809 800
     disable_E0();
810 801
   }
811 802
 

+ 10
- 6
Marlin/src/gcode/gcode.cpp Ver arquivo

@@ -49,7 +49,13 @@ GcodeSuite gcode;
49 49
 
50 50
 millis_t GcodeSuite::previous_move_ms;
51 51
 
52
-bool GcodeSuite::axis_relative_modes[] = AXIS_RELATIVE_MODES;
52
+static constexpr bool ar_init[XYZE] = AXIS_RELATIVE_MODES;
53
+uint8_t GcodeSuite::axis_relative = (
54
+    (ar_init[X_AXIS] ? _BV(REL_X) : 0)
55
+  | (ar_init[Y_AXIS] ? _BV(REL_Y) : 0)
56
+  | (ar_init[Z_AXIS] ? _BV(REL_Z) : 0)
57
+  | (ar_init[E_AXIS] ? _BV(REL_E) : 0)
58
+);
53 59
 
54 60
 #if ENABLED(HOST_KEEPALIVE_FEATURE)
55 61
   GcodeSuite::MarlinBusyState GcodeSuite::busy_state = NOT_BUSY;
@@ -110,9 +116,7 @@ void GcodeSuite::get_destination_from_command() {
110 116
   LOOP_XYZE(i) {
111 117
     if ( (seen[i] = parser.seenval(axis_codes[i])) ) {
112 118
       const float v = parser.value_axis_units((AxisEnum)i);
113
-      destination[i] = (axis_relative_modes[i] || relative_mode)
114
-        ? current_position[i] + v
115
-        : (i == E_AXIS) ? v : LOGICAL_TO_NATIVE(v, i);
119
+      destination[i] = axis_is_relative(AxisEnum(i)) ? current_position[i] + v : (i == E_AXIS) ? v : LOGICAL_TO_NATIVE(v, i);
116 120
     }
117 121
     else
118 122
       destination[i] = current_position[i];
@@ -295,8 +299,8 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
295 299
         case 80: G80(); break;                                    // G80: Reset the current motion mode
296 300
       #endif
297 301
 
298
-      case 90: relative_mode = false; break;                      // G90: Relative Mode
299
-      case 91: relative_mode = true; break;                       // G91: Absolute Mode
302
+      case 90: set_relative_mode(false); break;                   // G90: Absolute Mode
303
+      case 91: set_relative_mode(true);  break;                   // G91: Relative Mode
300 304
 
301 305
       case 92: G92(); break;                                      // G92: Set current axis position(s)
302 306
 

+ 22
- 3
Marlin/src/gcode/gcode.h Ver arquivo

@@ -283,12 +283,31 @@
283 283
   #include "../feature/I2CPositionEncoder.h"
284 284
 #endif
285 285
 
286
+enum AxisRelative : uint8_t { REL_X, REL_Y, REL_Z, REL_E, E_MODE_ABS, E_MODE_REL };
287
+
286 288
 class GcodeSuite {
287 289
 public:
288 290
 
289
-  GcodeSuite() {}
290
-
291
-  static bool axis_relative_modes[];
291
+  static uint8_t axis_relative;
292
+
293
+  static inline bool axis_is_relative(const AxisEnum a) {
294
+    if (a == E_AXIS) {
295
+      if (TEST(axis_relative, E_MODE_REL)) return true;
296
+      if (TEST(axis_relative, E_MODE_ABS)) return false;
297
+    }
298
+    return TEST(axis_relative, a);
299
+  }
300
+  static inline void set_relative_mode(const bool rel) {
301
+    axis_relative = rel ? _BV(REL_X) | _BV(REL_Y) | _BV(REL_Z) | _BV(REL_E) : 0;
302
+  }
303
+  static inline void set_e_relative() {
304
+    CBI(axis_relative, E_MODE_ABS);
305
+    SBI(axis_relative, E_MODE_REL);
306
+  }
307
+  static inline void set_e_absolute() {
308
+    CBI(axis_relative, E_MODE_REL);
309
+    SBI(axis_relative, E_MODE_ABS);
310
+  }
292 311
 
293 312
   #if ENABLED(CNC_WORKSPACE_PLANES)
294 313
     /**

+ 2
- 2
Marlin/src/gcode/units/M82_M83.cpp Ver arquivo

@@ -25,9 +25,9 @@
25 25
 /**
26 26
  * M82: Set E codes absolute (default)
27 27
  */
28
-void GcodeSuite::M82() { axis_relative_modes[E_AXIS] = false; }
28
+void GcodeSuite::M82() { set_e_absolute(); }
29 29
 
30 30
 /**
31 31
  * M83: Set E codes relative while in Absolute Coordinates (G90) mode
32 32
  */
33
-void GcodeSuite::M83() { axis_relative_modes[E_AXIS] = true; }
33
+void GcodeSuite::M83() { set_e_relative(); }

Carregando…
Cancelar
Salvar