Browse Source

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

Scott Lahteine 5 years ago
parent
commit
6091e6300a
No account linked to committer's email address

+ 4
- 6
Marlin/src/feature/power_loss_recovery.cpp View File

215
       info.retract_hop = fwretract.current_hop;
215
       info.retract_hop = fwretract.current_hop;
216
     #endif
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
     // Elapsed print job time
221
     // Elapsed print job time
223
     info.print_job_elapsed = print_job_timer.duration();
222
     info.print_job_elapsed = print_job_timer.duration();
392
   sprintf_P(cmd, PSTR("G92.9 E%s"), dtostrf(info.current_position[E_AXIS], 1, 3, str_1));
391
   sprintf_P(cmd, PSTR("G92.9 E%s"), dtostrf(info.current_position[E_AXIS], 1, 3, str_1));
393
   gcode.process_subcommands_now(cmd);
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
   #if HAS_HOME_OFFSET || HAS_POSITION_SHIFT
397
   #if HAS_HOME_OFFSET || HAS_POSITION_SHIFT
400
     LOOP_XYZ(i) {
398
     LOOP_XYZ(i) {

+ 2
- 2
Marlin/src/feature/power_loss_recovery.h View File

89
     #endif
89
     #endif
90
   #endif
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
   // SD Filename and position
95
   // SD Filename and position
96
   char sd_filename[MAXPATHNAMELENGTH];
96
   char sd_filename[MAXPATHNAMELENGTH];

+ 0
- 9
Marlin/src/feature/prusa_MMU2/mmu2.cpp View File

698
     }
698
     }
699
 
699
 
700
     LCD_MESSAGEPGM(MSG_MMU2_EJECTING_FILAMENT);
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
     enable_E0();
702
     enable_E0();
705
     current_position[E_AXIS] -= MMU2_FILAMENTCHANGE_EJECT_FEED;
703
     current_position[E_AXIS] -= MMU2_FILAMENTCHANGE_EJECT_FEED;
735
 
733
 
736
     BUZZ(200, 404);
734
     BUZZ(200, 404);
737
 
735
 
738
-    gcode.axis_relative_modes[E_AXIS] = saved_e_relative_mode;
739
-
740
     disable_E0();
736
     disable_E0();
741
 
737
 
742
     return true;
738
     return true;
784
     planner.synchronize();
780
     planner.synchronize();
785
     enable_E0();
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
     const E_Step* step = sequence;
783
     const E_Step* step = sequence;
791
 
784
 
792
     for (uint8_t i = 0; i < steps; i++) {
785
     for (uint8_t i = 0; i < steps; i++) {
804
       step++;
797
       step++;
805
     }
798
     }
806
 
799
 
807
-    gcode.axis_relative_modes[E_AXIS] = saved_e_relative_mode;
808
-
809
     disable_E0();
800
     disable_E0();
810
   }
801
   }
811
 
802
 

+ 10
- 6
Marlin/src/gcode/gcode.cpp View File

49
 
49
 
50
 millis_t GcodeSuite::previous_move_ms;
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
 #if ENABLED(HOST_KEEPALIVE_FEATURE)
60
 #if ENABLED(HOST_KEEPALIVE_FEATURE)
55
   GcodeSuite::MarlinBusyState GcodeSuite::busy_state = NOT_BUSY;
61
   GcodeSuite::MarlinBusyState GcodeSuite::busy_state = NOT_BUSY;
110
   LOOP_XYZE(i) {
116
   LOOP_XYZE(i) {
111
     if ( (seen[i] = parser.seenval(axis_codes[i])) ) {
117
     if ( (seen[i] = parser.seenval(axis_codes[i])) ) {
112
       const float v = parser.value_axis_units((AxisEnum)i);
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
     else
121
     else
118
       destination[i] = current_position[i];
122
       destination[i] = current_position[i];
295
         case 80: G80(); break;                                    // G80: Reset the current motion mode
299
         case 80: G80(); break;                                    // G80: Reset the current motion mode
296
       #endif
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
       case 92: G92(); break;                                      // G92: Set current axis position(s)
305
       case 92: G92(); break;                                      // G92: Set current axis position(s)
302
 
306
 

+ 22
- 3
Marlin/src/gcode/gcode.h View File

283
   #include "../feature/I2CPositionEncoder.h"
283
   #include "../feature/I2CPositionEncoder.h"
284
 #endif
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
 class GcodeSuite {
288
 class GcodeSuite {
287
 public:
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
   #if ENABLED(CNC_WORKSPACE_PLANES)
312
   #if ENABLED(CNC_WORKSPACE_PLANES)
294
     /**
313
     /**

+ 2
- 2
Marlin/src/gcode/units/M82_M83.cpp View File

25
 /**
25
 /**
26
  * M82: Set E codes absolute (default)
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
  * M83: Set E codes relative while in Absolute Coordinates (G90) mode
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(); }

Loading…
Cancel
Save