Browse Source

Merge pull request #8399 from thinkyhead/bf2_fix_M428

[2.0] Improve and clarify M428 code
Scott Lahteine 7 years ago
parent
commit
98efc18f2c
No account linked to committer's email address

+ 1
- 4
Marlin/src/gcode/geometry/G53-G59.cpp View File

@@ -27,7 +27,7 @@
27 27
 #if ENABLED(CNC_COORDINATE_SYSTEMS)
28 28
 
29 29
   /**
30
-   * Select a coordinate system and update the current position.
30
+   * Select a coordinate system and update the workspace offset.
31 31
    * System index -1 is used to specify machine-native.
32 32
    */
33 33
   bool GCodeSuite::select_coordinate_system(const int8_t _new) {
@@ -39,16 +39,13 @@
39 39
     if (WITHIN(_new, 0, MAX_COORDINATE_SYSTEMS - 1))
40 40
       COPY(new_offset, coordinate_system[_new]);
41 41
     active_coordinate_system = _new;
42
-    bool didXYZ = false;
43 42
     LOOP_XYZ(i) {
44 43
       const float diff = new_offset[i] - old_offset[i];
45 44
       if (diff) {
46 45
         position_shift[i] += diff;
47 46
         update_software_endstops((AxisEnum)i);
48
-        didXYZ = true;
49 47
       }
50 48
     }
51
-    if (didXYZ) SYNC_PLAN_POSITION_KINEMATIC();
52 49
     return true;
53 50
   }
54 51
 

+ 12
- 7
Marlin/src/gcode/geometry/G92.cpp View File

@@ -58,7 +58,12 @@ void GcodeSuite::G92() {
58 58
     #define IS_G92_0 true
59 59
   #endif
60 60
 
61
-  bool didXYZ = false, didE = false;
61
+  bool didE = false;
62
+  #if IS_SCARA || !HAS_POSITION_SHIFT
63
+    bool didXYZ = false;
64
+  #else
65
+    constexpr bool didXYZ = false;
66
+  #endif
62 67
 
63 68
   if (IS_G92_0) LOOP_XYZE(i) {
64 69
     if (parser.seenval(axis_codes[i])) {
@@ -66,18 +71,18 @@ void GcodeSuite::G92() {
66 71
                   v = i == E_AXIS ? l : LOGICAL_TO_NATIVE(l, i),
67 72
                   d = v - current_position[i];
68 73
       if (!NEAR_ZERO(d)) {
69
-        if (i == E_AXIS) didE = true; else didXYZ = true;
70
-        #if IS_SCARA
71
-          current_position[i] = v;        // For SCARA just set the position directly
74
+        #if IS_SCARA || !HAS_POSITION_SHIFT
75
+          if (i == E_AXIS) didE = true; else didXYZ = true;
76
+          current_position[i] = v;        // Without workspaces revert to Marlin 1.0 behavior
72 77
         #elif HAS_POSITION_SHIFT
73
-          if (i == E_AXIS)
78
+          if (i == E_AXIS) {
79
+            didE = true;
74 80
             current_position[E_AXIS] = v; // When using coordinate spaces, only E is set directly
81
+          }
75 82
           else {
76 83
             position_shift[i] += d;       // Other axes simply offset the coordinate space
77 84
             update_software_endstops((AxisEnum)i);
78 85
           }
79
-        #else
80
-          current_position[i] = v;        // Without workspaces revert to Marlin 1.0 behavior
81 86
         #endif
82 87
       }
83 88
     }

+ 17
- 23
Marlin/src/gcode/geometry/M206_M428.cpp View File

@@ -47,7 +47,6 @@ void GcodeSuite::M206() {
47 47
     if (parser.seen('P')) set_home_offset(B_AXIS, parser.value_linear_units()); // Psi
48 48
   #endif
49 49
 
50
-  SYNC_PLAN_POSITION_KINEMATIC();
51 50
   report_current_position();
52 51
 }
53 52
 
@@ -63,32 +62,27 @@ void GcodeSuite::M206() {
63 62
  *       Use M206 to set these values directly.
64 63
  */
65 64
 void GcodeSuite::M428() {
66
-  bool err = false;
65
+  if (axis_unhomed_error()) return;
66
+
67
+  float diff[XYZ];
67 68
   LOOP_XYZ(i) {
68
-    if (axis_homed[i]) {
69
-      const float base = (current_position[i] > (soft_endstop_min[i] + soft_endstop_max[i]) * 0.5) ? base_home_pos((AxisEnum)i) : 0,
70
-                  diff = base - current_position[i];
71
-      if (WITHIN(diff, -20, 20)) {
72
-        set_home_offset((AxisEnum)i, diff);
73
-      }
74
-      else {
75
-        SERIAL_ERROR_START();
76
-        SERIAL_ERRORLNPGM(MSG_ERR_M428_TOO_FAR);
77
-        LCD_ALERTMESSAGEPGM("Err: Too far!");
78
-        BUZZ(200, 40);
79
-        err = true;
80
-        break;
81
-      }
69
+    diff[i] = base_home_pos((AxisEnum)i) - current_position[i];
70
+    if (!WITHIN(diff[i], -20, 20) && home_dir((AxisEnum)i) > 0)
71
+      diff[i] = -current_position[i];
72
+    if (!WITHIN(diff[i], -20, 20)) {
73
+      SERIAL_ERROR_START();
74
+      SERIAL_ERRORLNPGM(MSG_ERR_M428_TOO_FAR);
75
+      LCD_ALERTMESSAGEPGM("Err: Too far!");
76
+      BUZZ(200, 40);
77
+      return;
82 78
     }
83 79
   }
84 80
 
85
-  if (!err) {
86
-    SYNC_PLAN_POSITION_KINEMATIC();
87
-    report_current_position();
88
-    LCD_MESSAGEPGM(MSG_HOME_OFFSETS_APPLIED);
89
-    BUZZ(100, 659);
90
-    BUZZ(100, 698);
91
-  }
81
+  LOOP_XYZ(i) set_home_offset((AxisEnum)i, diff[i]);
82
+  report_current_position();
83
+  LCD_MESSAGEPGM(MSG_HOME_OFFSETS_APPLIED);
84
+  BUZZ(100, 659);
85
+  BUZZ(100, 698);
92 86
 }
93 87
 
94 88
 #endif // HAS_M206_COMMAND

+ 1
- 0
Marlin/src/module/motion.h View File

@@ -173,6 +173,7 @@ void clean_up_after_endstop_or_probe_move();
173 173
       || ENABLED(NOZZLE_CLEAN_FEATURE)                                             \
174 174
       || ENABLED(NOZZLE_PARK_FEATURE)                                              \
175 175
       || (ENABLED(ADVANCED_PAUSE_FEATURE) && ENABLED(HOME_BEFORE_FILAMENT_CHANGE)) \
176
+      || HAS_M206_COMMAND                                                          \
176 177
     ) || ENABLED(NO_MOTION_BEFORE_HOMING)
177 178
 
178 179
 #if HAS_AXIS_UNHOMED_ERR

Loading…
Cancel
Save