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
 #if ENABLED(CNC_COORDINATE_SYSTEMS)
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
    * System index -1 is used to specify machine-native.
31
    * System index -1 is used to specify machine-native.
32
    */
32
    */
33
   bool GCodeSuite::select_coordinate_system(const int8_t _new) {
33
   bool GCodeSuite::select_coordinate_system(const int8_t _new) {
39
     if (WITHIN(_new, 0, MAX_COORDINATE_SYSTEMS - 1))
39
     if (WITHIN(_new, 0, MAX_COORDINATE_SYSTEMS - 1))
40
       COPY(new_offset, coordinate_system[_new]);
40
       COPY(new_offset, coordinate_system[_new]);
41
     active_coordinate_system = _new;
41
     active_coordinate_system = _new;
42
-    bool didXYZ = false;
43
     LOOP_XYZ(i) {
42
     LOOP_XYZ(i) {
44
       const float diff = new_offset[i] - old_offset[i];
43
       const float diff = new_offset[i] - old_offset[i];
45
       if (diff) {
44
       if (diff) {
46
         position_shift[i] += diff;
45
         position_shift[i] += diff;
47
         update_software_endstops((AxisEnum)i);
46
         update_software_endstops((AxisEnum)i);
48
-        didXYZ = true;
49
       }
47
       }
50
     }
48
     }
51
-    if (didXYZ) SYNC_PLAN_POSITION_KINEMATIC();
52
     return true;
49
     return true;
53
   }
50
   }
54
 
51
 

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

58
     #define IS_G92_0 true
58
     #define IS_G92_0 true
59
   #endif
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
   if (IS_G92_0) LOOP_XYZE(i) {
68
   if (IS_G92_0) LOOP_XYZE(i) {
64
     if (parser.seenval(axis_codes[i])) {
69
     if (parser.seenval(axis_codes[i])) {
66
                   v = i == E_AXIS ? l : LOGICAL_TO_NATIVE(l, i),
71
                   v = i == E_AXIS ? l : LOGICAL_TO_NATIVE(l, i),
67
                   d = v - current_position[i];
72
                   d = v - current_position[i];
68
       if (!NEAR_ZERO(d)) {
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
         #elif HAS_POSITION_SHIFT
77
         #elif HAS_POSITION_SHIFT
73
-          if (i == E_AXIS)
78
+          if (i == E_AXIS) {
79
+            didE = true;
74
             current_position[E_AXIS] = v; // When using coordinate spaces, only E is set directly
80
             current_position[E_AXIS] = v; // When using coordinate spaces, only E is set directly
81
+          }
75
           else {
82
           else {
76
             position_shift[i] += d;       // Other axes simply offset the coordinate space
83
             position_shift[i] += d;       // Other axes simply offset the coordinate space
77
             update_software_endstops((AxisEnum)i);
84
             update_software_endstops((AxisEnum)i);
78
           }
85
           }
79
-        #else
80
-          current_position[i] = v;        // Without workspaces revert to Marlin 1.0 behavior
81
         #endif
86
         #endif
82
       }
87
       }
83
     }
88
     }

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

47
     if (parser.seen('P')) set_home_offset(B_AXIS, parser.value_linear_units()); // Psi
47
     if (parser.seen('P')) set_home_offset(B_AXIS, parser.value_linear_units()); // Psi
48
   #endif
48
   #endif
49
 
49
 
50
-  SYNC_PLAN_POSITION_KINEMATIC();
51
   report_current_position();
50
   report_current_position();
52
 }
51
 }
53
 
52
 
63
  *       Use M206 to set these values directly.
62
  *       Use M206 to set these values directly.
64
  */
63
  */
65
 void GcodeSuite::M428() {
64
 void GcodeSuite::M428() {
66
-  bool err = false;
65
+  if (axis_unhomed_error()) return;
66
+
67
+  float diff[XYZ];
67
   LOOP_XYZ(i) {
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
 #endif // HAS_M206_COMMAND
88
 #endif // HAS_M206_COMMAND

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

173
       || ENABLED(NOZZLE_CLEAN_FEATURE)                                             \
173
       || ENABLED(NOZZLE_CLEAN_FEATURE)                                             \
174
       || ENABLED(NOZZLE_PARK_FEATURE)                                              \
174
       || ENABLED(NOZZLE_PARK_FEATURE)                                              \
175
       || (ENABLED(ADVANCED_PAUSE_FEATURE) && ENABLED(HOME_BEFORE_FILAMENT_CHANGE)) \
175
       || (ENABLED(ADVANCED_PAUSE_FEATURE) && ENABLED(HOME_BEFORE_FILAMENT_CHANGE)) \
176
+      || HAS_M206_COMMAND                                                          \
176
     ) || ENABLED(NO_MOTION_BEFORE_HOMING)
177
     ) || ENABLED(NO_MOTION_BEFORE_HOMING)
177
 
178
 
178
 #if HAS_AXIS_UNHOMED_ERR
179
 #if HAS_AXIS_UNHOMED_ERR

Loading…
Cancel
Save