Browse Source

Merge pull request #8397 from RowanMeara/rm-M428-1.1.x

[1.1.x] Fix M428
Scott Lahteine 7 years ago
parent
commit
8b684637bc
No account linked to committer's email address
2 changed files with 31 additions and 32 deletions
  1. 1
    0
      Marlin/Marlin.h
  2. 30
    32
      Marlin/Marlin_main.cpp

+ 1
- 0
Marlin/Marlin.h View File

@@ -439,6 +439,7 @@ void do_blocking_move_to_xy(const float &x, const float &y, const float &fr_mm_s
439 439
       || ENABLED(NOZZLE_CLEAN_FEATURE)                                             \
440 440
       || ENABLED(NOZZLE_PARK_FEATURE)                                              \
441 441
       || (ENABLED(ADVANCED_PAUSE_FEATURE) && ENABLED(HOME_BEFORE_FILAMENT_CHANGE)) \
442
+      || HAS_M206_COMMAND                                                          \
442 443
     ) || ENABLED(NO_MOTION_BEFORE_HOMING)
443 444
 
444 445
 #if HAS_AXIS_UNHOMED_ERR

+ 30
- 32
Marlin/Marlin_main.cpp View File

@@ -3653,7 +3653,7 @@ inline void gcode_G4() {
3653 3653
 #if ENABLED(CNC_COORDINATE_SYSTEMS)
3654 3654
 
3655 3655
   /**
3656
-   * Select a coordinate system and update the current position.
3656
+   * Select a coordinate system and update the workspace offset.
3657 3657
    * System index -1 is used to specify machine-native.
3658 3658
    */
3659 3659
   bool select_coordinate_system(const int8_t _new) {
@@ -3664,16 +3664,13 @@ inline void gcode_G4() {
3664 3664
     if (WITHIN(_new, 0, MAX_COORDINATE_SYSTEMS - 1))
3665 3665
       COPY(new_offset, coordinate_system[_new]);
3666 3666
     active_coordinate_system = _new;
3667
-    bool didXYZ = false;
3668 3667
     LOOP_XYZ(i) {
3669 3668
       const float diff = new_offset[i] - old_offset[i];
3670 3669
       if (diff) {
3671 3670
         position_shift[i] += diff;
3672 3671
         update_software_endstops((AxisEnum)i);
3673
-        didXYZ = true;
3674 3672
       }
3675 3673
     }
3676
-    if (didXYZ) SYNC_PLAN_POSITION_KINEMATIC();
3677 3674
     return true;
3678 3675
   }
3679 3676
 
@@ -6257,7 +6254,12 @@ inline void gcode_G92() {
6257 6254
     #define IS_G92_0 true
6258 6255
   #endif
6259 6256
 
6260
-  bool didXYZ = false, didE = false;
6257
+  bool didE = false;
6258
+  #if IS_SCARA || !HAS_POSITION_SHIFT
6259
+    bool didXYZ = false;
6260
+  #else
6261
+    constexpr bool didXYZ = false;
6262
+  #endif
6261 6263
 
6262 6264
   if (IS_G92_0) LOOP_XYZE(i) {
6263 6265
     if (parser.seenval(axis_codes[i])) {
@@ -6265,18 +6267,18 @@ inline void gcode_G92() {
6265 6267
                   v = i == E_AXIS ? l : LOGICAL_TO_NATIVE(l, i),
6266 6268
                   d = v - current_position[i];
6267 6269
       if (!NEAR_ZERO(d)) {
6268
-        if (i == E_AXIS) didE = true; else didXYZ = true;
6269
-        #if IS_SCARA
6270
-          current_position[i] = v;        // For SCARA just set the position directly
6270
+        #if IS_SCARA || !HAS_POSITION_SHIFT
6271
+          if (i == E_AXIS) didE = true; else didXYZ = true;
6272
+          current_position[i] = v;        // Without workspaces revert to Marlin 1.0 behavior
6271 6273
         #elif HAS_POSITION_SHIFT
6272
-          if (i == E_AXIS)
6274
+          if (i == E_AXIS) {
6275
+            didE = true;
6273 6276
             current_position[E_AXIS] = v; // When using coordinate spaces, only E is set directly
6277
+          }
6274 6278
           else {
6275 6279
             position_shift[i] += d;       // Other axes simply offset the coordinate space
6276 6280
             update_software_endstops((AxisEnum)i);
6277 6281
           }
6278
-        #else
6279
-          current_position[i] = v;        // Without workspaces revert to Marlin 1.0 behavior
6280 6282
         #endif
6281 6283
       }
6282 6284
     }
@@ -9958,31 +9960,27 @@ void quickstop_stepper() {
9958 9960
    *       Use M206 to set these values directly.
9959 9961
    */
9960 9962
   inline void gcode_M428() {
9961
-    bool err = false;
9963
+    if (axis_unhomed_error()) return;
9964
+
9965
+    float diff[XYZ];
9962 9966
     LOOP_XYZ(i) {
9963
-      if (axis_homed[i]) {
9964
-        const float base = (current_position[i] > (soft_endstop_min[i] + soft_endstop_max[i]) * 0.5) ? base_home_pos((AxisEnum)i) : 0,
9965
-                    diff = base - current_position[i];
9966
-        if (WITHIN(diff, -20, 20)) {
9967
-          set_home_offset((AxisEnum)i, diff);
9968
-        }
9969
-        else {
9970
-          SERIAL_ERROR_START();
9971
-          SERIAL_ERRORLNPGM(MSG_ERR_M428_TOO_FAR);
9972
-          LCD_ALERTMESSAGEPGM("Err: Too far!");
9973
-          BUZZ(200, 40);
9974
-          err = true;
9975
-          break;
9976
-        }
9967
+      diff[i] = base_home_pos((AxisEnum)i) - current_position[i];
9968
+      if (!WITHIN(diff[i], -20, 20) && home_dir((AxisEnum)i) > 0)
9969
+        diff[i] = -current_position[i];
9970
+      if (!WITHIN(diff[i], -20, 20)) {
9971
+        SERIAL_ERROR_START();
9972
+        SERIAL_ERRORLNPGM(MSG_ERR_M428_TOO_FAR);
9973
+        LCD_ALERTMESSAGEPGM("Err: Too far!");
9974
+        BUZZ(200, 40);
9975
+        return;
9977 9976
       }
9978 9977
     }
9979 9978
 
9980
-    if (!err) {
9981
-      report_current_position();
9982
-      LCD_MESSAGEPGM(MSG_HOME_OFFSETS_APPLIED);
9983
-      BUZZ(100, 659);
9984
-      BUZZ(100, 698);
9985
-    }
9979
+    LOOP_XYZ(i) set_home_offset((AxisEnum)i, diff[i]);
9980
+    report_current_position();
9981
+    LCD_MESSAGEPGM(MSG_HOME_OFFSETS_APPLIED);
9982
+    BUZZ(100, 659);
9983
+    BUZZ(100, 698);
9986 9984
   }
9987 9985
 
9988 9986
 #endif // HAS_M206_COMMAND

Loading…
Cancel
Save