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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. #if HAS_MULTI_EXTRUDER
  30. #include "../../../module/tool_change.h"
  31. #endif
  32. #if HAS_LCD_MENU
  33. #include "../../../lcd/marlinui.h"
  34. #endif
  35. #if ENABLED(PRUSA_MMU2)
  36. #include "../../../feature/mmu2/mmu2.h"
  37. #endif
  38. #if ENABLED(MIXING_EXTRUDER)
  39. #include "../../../feature/mixing.h"
  40. #endif
  41. /**
  42. * M701: Load filament
  43. *
  44. * T<extruder> - Extruder number. Required for mixing extruder.
  45. * For non-mixing, current extruder if omitted.
  46. * Z<distance> - Move the Z axis by this distance
  47. * L<distance> - Extrude distance for insertion (positive value) (manual reload)
  48. *
  49. * Default values are used for omitted arguments.
  50. */
  51. void GcodeSuite::M701() {
  52. xyz_pos_t park_point = NOZZLE_PARK_POINT;
  53. #if ENABLED(NO_MOTION_BEFORE_HOMING)
  54. // Don't raise Z if the machine isn't homed
  55. if (axes_should_home()) park_point.z = 0;
  56. #endif
  57. #if ENABLED(MIXING_EXTRUDER)
  58. const int8_t target_e_stepper = get_target_e_stepper_from_command();
  59. if (target_e_stepper < 0) return;
  60. const uint8_t old_mixing_tool = mixer.get_current_vtool();
  61. mixer.T(MIXER_DIRECT_SET_TOOL);
  62. MIXER_STEPPER_LOOP(i) mixer.set_collector(i, (i == (uint8_t)target_e_stepper) ? 1.0 : 0.0);
  63. mixer.normalize();
  64. const int8_t target_extruder = active_extruder;
  65. #else
  66. const int8_t target_extruder = get_target_extruder_from_command();
  67. if (target_extruder < 0) return;
  68. #endif
  69. // Z axis lift
  70. if (parser.seenval('Z')) park_point.z = parser.linearval('Z');
  71. // Show initial "wait for load" message
  72. TERN_(HAS_LCD_MENU, lcd_pause_show_message(PAUSE_MESSAGE_LOAD, PAUSE_MODE_LOAD_FILAMENT, target_extruder));
  73. #if HAS_MULTI_EXTRUDER && DISABLED(PRUSA_MMU2)
  74. // Change toolhead if specified
  75. uint8_t active_extruder_before_filament_change = active_extruder;
  76. if (active_extruder != target_extruder)
  77. tool_change(target_extruder, false);
  78. #endif
  79. // Lift Z axis
  80. if (park_point.z > 0)
  81. do_blocking_move_to_z(_MIN(current_position.z + park_point.z, Z_MAX_POS), feedRate_t(NOZZLE_PARK_Z_FEEDRATE));
  82. // Load filament
  83. #if ENABLED(PRUSA_MMU2)
  84. mmu2.load_filament_to_nozzle(target_extruder);
  85. #else
  86. constexpr float purge_length = ADVANCED_PAUSE_PURGE_LENGTH,
  87. slow_load_length = FILAMENT_CHANGE_SLOW_LOAD_LENGTH;
  88. const float fast_load_length = ABS(parser.seen('L') ? parser.value_axis_units(E_AXIS)
  89. : fc_settings[active_extruder].load_length);
  90. load_filament(
  91. slow_load_length, fast_load_length, purge_length,
  92. FILAMENT_CHANGE_ALERT_BEEPS,
  93. true, // show_lcd
  94. thermalManager.still_heating(target_extruder), // pause_for_user
  95. PAUSE_MODE_LOAD_FILAMENT // pause_mode
  96. #if ENABLED(DUAL_X_CARRIAGE)
  97. , target_extruder // Dual X target
  98. #endif
  99. );
  100. #endif
  101. // Restore Z axis
  102. if (park_point.z > 0)
  103. do_blocking_move_to_z(_MAX(current_position.z - park_point.z, 0), feedRate_t(NOZZLE_PARK_Z_FEEDRATE));
  104. #if HAS_MULTI_EXTRUDER && DISABLED(PRUSA_MMU2)
  105. // Restore toolhead if it was changed
  106. if (active_extruder_before_filament_change != active_extruder)
  107. tool_change(active_extruder_before_filament_change, false);
  108. #endif
  109. TERN_(MIXING_EXTRUDER, mixer.T(old_mixing_tool)); // Restore original mixing tool
  110. // Show status screen
  111. TERN_(HAS_LCD_MENU, lcd_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. #if ENABLED(NO_MOTION_BEFORE_HOMING)
  127. // Don't raise Z if the machine isn't homed
  128. if (axes_should_home()) park_point.z = 0;
  129. #endif
  130. #if ENABLED(MIXING_EXTRUDER)
  131. const uint8_t old_mixing_tool = mixer.get_current_vtool();
  132. #if ENABLED(FILAMENT_UNLOAD_ALL_EXTRUDERS)
  133. float mix_multiplier = 1.0;
  134. const bool seenT = parser.seenval('T');
  135. if (!seenT) {
  136. mixer.T(MIXER_AUTORETRACT_TOOL);
  137. mix_multiplier = MIXING_STEPPERS;
  138. }
  139. #else
  140. constexpr bool seenT = true;
  141. #endif
  142. if (seenT) {
  143. const int8_t target_e_stepper = get_target_e_stepper_from_command();
  144. if (target_e_stepper < 0) return;
  145. mixer.T(MIXER_DIRECT_SET_TOOL);
  146. MIXER_STEPPER_LOOP(i) mixer.set_collector(i, (i == (uint8_t)target_e_stepper) ? 1.0 : 0.0);
  147. mixer.normalize();
  148. }
  149. const int8_t target_extruder = active_extruder;
  150. #else
  151. const int8_t target_extruder = get_target_extruder_from_command();
  152. if (target_extruder < 0) return;
  153. #endif
  154. // Z axis lift
  155. if (parser.seenval('Z')) park_point.z = parser.linearval('Z');
  156. // Show initial "wait for unload" message
  157. TERN_(HAS_LCD_MENU, lcd_pause_show_message(PAUSE_MESSAGE_UNLOAD, PAUSE_MODE_UNLOAD_FILAMENT, target_extruder));
  158. #if HAS_MULTI_EXTRUDER && DISABLED(PRUSA_MMU2)
  159. // Change toolhead if specified
  160. uint8_t active_extruder_before_filament_change = active_extruder;
  161. if (active_extruder != target_extruder)
  162. tool_change(target_extruder, false);
  163. #endif
  164. // Lift Z axis
  165. if (park_point.z > 0)
  166. do_blocking_move_to_z(_MIN(current_position.z + park_point.z, Z_MAX_POS), feedRate_t(NOZZLE_PARK_Z_FEEDRATE));
  167. // Unload filament
  168. #if ENABLED(PRUSA_MMU2)
  169. mmu2.unload();
  170. #else
  171. #if BOTH(HAS_MULTI_EXTRUDER, FILAMENT_UNLOAD_ALL_EXTRUDERS)
  172. if (!parser.seenval('T')) {
  173. HOTEND_LOOP() {
  174. if (e != active_extruder) tool_change(e, false);
  175. unload_filament(-fc_settings[e].unload_length, true, PAUSE_MODE_UNLOAD_FILAMENT);
  176. }
  177. }
  178. else
  179. #endif
  180. {
  181. // Unload length
  182. const float unload_length = -ABS(parser.seen('U') ? parser.value_axis_units(E_AXIS)
  183. : fc_settings[target_extruder].unload_length);
  184. unload_filament(unload_length, true, PAUSE_MODE_UNLOAD_FILAMENT
  185. #if ALL(FILAMENT_UNLOAD_ALL_EXTRUDERS, MIXING_EXTRUDER)
  186. , mix_multiplier
  187. #endif
  188. );
  189. }
  190. #endif
  191. // Restore Z axis
  192. if (park_point.z > 0)
  193. do_blocking_move_to_z(_MAX(current_position.z - park_point.z, 0), feedRate_t(NOZZLE_PARK_Z_FEEDRATE));
  194. #if HAS_MULTI_EXTRUDER && DISABLED(PRUSA_MMU2)
  195. // Restore toolhead if it was changed
  196. if (active_extruder_before_filament_change != active_extruder)
  197. tool_change(active_extruder_before_filament_change, false);
  198. #endif
  199. TERN_(MIXING_EXTRUDER, mixer.T(old_mixing_tool)); // Restore original mixing tool
  200. // Show status screen
  201. TERN_(HAS_LCD_MENU, lcd_pause_show_message(PAUSE_MESSAGE_STATUS));
  202. }
  203. #endif // ADVANCED_PAUSE_FEATURE