Browse Source

Prevent Z misaligment on tool change (#16518)

Giuliano Zaro 5 years ago
parent
commit
0391e5bcc7
1 changed files with 15 additions and 6 deletions
  1. 15
    6
      Marlin/src/module/tool_change.cpp

+ 15
- 6
Marlin/src/module/tool_change.cpp View File

929
       #elif ENABLED(SWITCHING_NOZZLE) && !SWITCHING_NOZZLE_TWO_SERVOS   // Switching Nozzle (single servo)
929
       #elif ENABLED(SWITCHING_NOZZLE) && !SWITCHING_NOZZLE_TWO_SERVOS   // Switching Nozzle (single servo)
930
         // Raise by a configured distance to avoid workpiece, except with
930
         // Raise by a configured distance to avoid workpiece, except with
931
         // SWITCHING_NOZZLE_TWO_SERVOS, as both nozzles will lift instead.
931
         // SWITCHING_NOZZLE_TWO_SERVOS, as both nozzles will lift instead.
932
-        current_position.z += _MAX(-diff.z, 0.0) + toolchange_settings.z_raise;
933
-        #if HAS_SOFTWARE_ENDSTOPS
934
-          NOMORE(current_position.z, soft_endstop.max.z);
935
-        #endif
936
-        if (!no_move) fast_line_to_current(Z_AXIS);
932
+        if (!no_move) {
933
+          #if HAS_SOFTWARE_ENDSTOPS
934
+            const float maxz = _MIN(soft_endstop.max.z, Z_MAX_POS);
935
+          #else
936
+            constexpr float maxz = Z_MAX_POS;
937
+          #endif
938
+
939
+          // Check if Z has space to compensate at least z_offset, and if not, just abort now
940
+          const float newz = current_position.z + _MAX(-diff.z, 0.0);
941
+          if (newz > maxz) return;
942
+
943
+          current_position.z = _MIN(newz + toolchange_settings.z_raise, maxz);
944
+          fast_line_to_current(Z_AXIS);
945
+        }
937
         move_nozzle_servo(new_tool);
946
         move_nozzle_servo(new_tool);
938
       #endif
947
       #endif
939
 
948
 
942
       #endif
951
       #endif
943
 
952
 
944
       // The newly-selected extruder XYZ is actually at...
953
       // The newly-selected extruder XYZ is actually at...
945
-      if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Offset Tool XY by { ", diff.x, ", ", diff.y, ", ", diff.z, " }");
954
+      if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Offset Tool XYZ by { ", diff.x, ", ", diff.y, ", ", diff.z, " }");
946
       current_position += diff;
955
       current_position += diff;
947
 
956
 
948
       // Tell the planner the new "current position"
957
       // Tell the planner the new "current position"

Loading…
Cancel
Save