My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

M701_M702.cpp 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "../../../inc/MarlinConfigPre.h"
  23. #if ENABLED(FILAMENT_LOAD_UNLOAD_GCODES)
  24. #include "../../gcode.h"
  25. #include "../../../MarlinCore.h"
  26. #include "../../../module/motion.h"
  27. #include "../../../module/temperature.h"
  28. #include "../../../feature/pause.h"
  29. #include "../../../lcd/marlinui.h"
  30. #if HAS_MULTI_EXTRUDER
  31. #include "../../../module/tool_change.h"
  32. #endif
  33. #if HAS_PRUSA_MMU2
  34. #include "../../../feature/mmu/mmu2.h"
  35. #endif
  36. #if ENABLED(MIXING_EXTRUDER)
  37. #include "../../../feature/mixing.h"
  38. #endif
  39. /**
  40. * M701: Load filament
  41. *
  42. * T<extruder> - Extruder number. Required for mixing extruder.
  43. * For non-mixing, current extruder if omitted.
  44. * Z<distance> - Move the Z axis by this distance
  45. * L<distance> - Extrude distance for insertion (positive value) (manual reload)
  46. *
  47. * Default values are used for omitted arguments.
  48. */
  49. void GcodeSuite::M701() {
  50. xyz_pos_t park_point = NOZZLE_PARK_POINT;
  51. // Don't raise Z if the machine isn't homed
  52. if (TERN0(NO_MOTION_BEFORE_HOMING, axes_should_home())) park_point.z = 0;
  53. #if ENABLED(MIXING_EXTRUDER)
  54. const int8_t eindex = get_target_e_stepper_from_command();
  55. if (eindex < 0) return;
  56. const uint8_t old_mixing_tool = mixer.get_current_vtool();
  57. mixer.T(MIXER_DIRECT_SET_TOOL);
  58. MIXER_STEPPER_LOOP(i) mixer.set_collector(i, i == uint8_t(eindex) ? 1.0 : 0.0);
  59. mixer.normalize();
  60. const int8_t target_extruder = active_extruder;
  61. #else
  62. const int8_t target_extruder = get_target_extruder_from_command();
  63. if (target_extruder < 0) return;
  64. #endif
  65. // Z axis lift
  66. if (parser.seenval('Z')) park_point.z = parser.linearval('Z');
  67. // Show initial "wait for load" message
  68. ui.pause_show_message(PAUSE_MESSAGE_LOAD, PAUSE_MODE_LOAD_FILAMENT, target_extruder);
  69. #if HAS_MULTI_EXTRUDER && (HAS_PRUSA_MMU1 || !HAS_MMU)
  70. // Change toolhead if specified
  71. uint8_t active_extruder_before_filament_change = active_extruder;
  72. if (active_extruder != target_extruder)
  73. tool_change(target_extruder);
  74. #endif
  75. auto move_z_by = [](const_float_t zdist) {
  76. if (zdist) {
  77. destination = current_position;
  78. destination.z += zdist;
  79. prepare_internal_move_to_destination(NOZZLE_PARK_Z_FEEDRATE);
  80. }
  81. };
  82. // Raise the Z axis (with max limit)
  83. const float park_raise = _MIN(park_point.z, (Z_MAX_POS) - current_position.z);
  84. move_z_by(park_raise);
  85. // Load filament
  86. #if HAS_PRUSA_MMU2
  87. mmu2.load_filament_to_nozzle(target_extruder);
  88. #else
  89. constexpr float purge_length = ADVANCED_PAUSE_PURGE_LENGTH,
  90. slow_load_length = FILAMENT_CHANGE_SLOW_LOAD_LENGTH;
  91. const float fast_load_length = ABS(parser.seen('L') ? parser.value_axis_units(E_AXIS)
  92. : fc_settings[active_extruder].load_length);
  93. load_filament(
  94. slow_load_length, fast_load_length, purge_length,
  95. FILAMENT_CHANGE_ALERT_BEEPS,
  96. true, // show_lcd
  97. thermalManager.still_heating(target_extruder), // pause_for_user
  98. PAUSE_MODE_LOAD_FILAMENT // pause_mode
  99. OPTARG(DUAL_X_CARRIAGE, target_extruder) // Dual X target
  100. );
  101. #endif
  102. // Restore Z axis
  103. move_z_by(-park_raise);
  104. #if HAS_MULTI_EXTRUDER && (HAS_PRUSA_MMU1 || !HAS_MMU)
  105. // Restore toolhead if it was changed
  106. if (active_extruder_before_filament_change != active_extruder)
  107. tool_change(active_extruder_before_filament_change);
  108. #endif
  109. TERN_(MIXING_EXTRUDER, mixer.T(old_mixing_tool)); // Restore original mixing tool
  110. // Show status screen
  111. ui.pause_show_message(PAUSE_MESSAGE_STATUS);
  112. }
  113. /**
  114. * M702: Unload filament
  115. *
  116. * T<extruder> - Extruder number. Required for mixing extruder.
  117. * For non-mixing, if omitted, current extruder
  118. * (or ALL extruders with FILAMENT_UNLOAD_ALL_EXTRUDERS).
  119. * Z<distance> - Move the Z axis by this distance
  120. * U<distance> - Retract distance for removal (manual reload)
  121. *
  122. * Default values are used for omitted arguments.
  123. */
  124. void GcodeSuite::M702() {
  125. xyz_pos_t park_point = NOZZLE_PARK_POINT;
  126. // Don't raise Z if the machine isn't homed
  127. if (TERN0(NO_MOTION_BEFORE_HOMING, axes_should_home())) park_point.z = 0;
  128. #if ENABLED(MIXING_EXTRUDER)
  129. const uint8_t old_mixing_tool = mixer.get_current_vtool();
  130. #if ENABLED(FILAMENT_UNLOAD_ALL_EXTRUDERS)
  131. float mix_multiplier = 1.0;
  132. const bool seenT = parser.seenval('T');
  133. if (!seenT) {
  134. mixer.T(MIXER_AUTORETRACT_TOOL);
  135. mix_multiplier = MIXING_STEPPERS;
  136. }
  137. #else
  138. constexpr bool seenT = true;
  139. #endif
  140. if (seenT) {
  141. const int8_t eindex = get_target_e_stepper_from_command();
  142. if (eindex < 0) return;
  143. mixer.T(MIXER_DIRECT_SET_TOOL);
  144. MIXER_STEPPER_LOOP(i) mixer.set_collector(i, i == uint8_t(eindex) ? 1.0 : 0.0);
  145. mixer.normalize();
  146. }
  147. const int8_t target_extruder = active_extruder;
  148. #else
  149. const int8_t target_extruder = get_target_extruder_from_command();
  150. if (target_extruder < 0) return;
  151. #endif
  152. // Z axis lift
  153. if (parser.seenval('Z')) park_point.z = parser.linearval('Z');
  154. // Show initial "wait for unload" message
  155. ui.pause_show_message(PAUSE_MESSAGE_UNLOAD, PAUSE_MODE_UNLOAD_FILAMENT, target_extruder);
  156. #if HAS_MULTI_EXTRUDER && (HAS_PRUSA_MMU1 || !HAS_MMU)
  157. // Change toolhead if specified
  158. uint8_t active_extruder_before_filament_change = active_extruder;
  159. if (active_extruder != target_extruder)
  160. tool_change(target_extruder);
  161. #endif
  162. // Lift Z axis
  163. if (park_point.z > 0)
  164. do_blocking_move_to_z(_MIN(current_position.z + park_point.z, Z_MAX_POS), feedRate_t(NOZZLE_PARK_Z_FEEDRATE));
  165. // Unload filament
  166. #if HAS_PRUSA_MMU2
  167. mmu2.unload();
  168. #else
  169. #if BOTH(HAS_MULTI_EXTRUDER, FILAMENT_UNLOAD_ALL_EXTRUDERS)
  170. if (!parser.seenval('T')) {
  171. HOTEND_LOOP() {
  172. if (e != active_extruder) tool_change(e);
  173. unload_filament(-fc_settings[e].unload_length, true, PAUSE_MODE_UNLOAD_FILAMENT);
  174. }
  175. }
  176. else
  177. #endif
  178. {
  179. // Unload length
  180. const float unload_length = -ABS(parser.seen('U') ? parser.value_axis_units(E_AXIS)
  181. : fc_settings[target_extruder].unload_length);
  182. unload_filament(unload_length, true, PAUSE_MODE_UNLOAD_FILAMENT
  183. #if ALL(FILAMENT_UNLOAD_ALL_EXTRUDERS, MIXING_EXTRUDER)
  184. , mix_multiplier
  185. #endif
  186. );
  187. }
  188. #endif
  189. // Restore Z axis
  190. if (park_point.z > 0)
  191. do_blocking_move_to_z(_MAX(current_position.z - park_point.z, 0), feedRate_t(NOZZLE_PARK_Z_FEEDRATE));
  192. #if HAS_MULTI_EXTRUDER && (HAS_PRUSA_MMU1 || !HAS_MMU)
  193. // Restore toolhead if it was changed
  194. if (active_extruder_before_filament_change != active_extruder)
  195. tool_change(active_extruder_before_filament_change);
  196. #endif
  197. TERN_(MIXING_EXTRUDER, mixer.T(old_mixing_tool)); // Restore original mixing tool
  198. // Show status screen
  199. ui.pause_show_message(PAUSE_MESSAGE_STATUS);
  200. }
  201. #endif // ADVANCED_PAUSE_FEATURE