My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

M701_M702.cpp 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2019 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 <http://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 EXTRUDERS > 1
  30. #include "../../../module/tool_change.h"
  31. #endif
  32. #if HAS_LCD_MENU
  33. #include "../../../lcd/ultralcd.h"
  34. #endif
  35. #if ENABLED(PRUSA_MMU2)
  36. #include "../../../feature/prusa_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_need_homing()) 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. #if HAS_LCD_MENU
  73. lcd_pause_show_message(PAUSE_MESSAGE_LOAD, PAUSE_MODE_LOAD_FILAMENT, target_extruder);
  74. #endif
  75. #if EXTRUDERS > 1 && DISABLED(PRUSA_MMU2)
  76. // Change toolhead if specified
  77. uint8_t active_extruder_before_filament_change = active_extruder;
  78. if (active_extruder != target_extruder)
  79. tool_change(target_extruder, false);
  80. #endif
  81. // Lift Z axis
  82. if (park_point.z > 0)
  83. do_blocking_move_to_z(_MIN(current_position.z + park_point.z, Z_MAX_POS), feedRate_t(NOZZLE_PARK_Z_FEEDRATE));
  84. // Load filament
  85. #if ENABLED(PRUSA_MMU2)
  86. mmu2.load_filament_to_nozzle(target_extruder);
  87. #else
  88. constexpr float purge_length = ADVANCED_PAUSE_PURGE_LENGTH,
  89. slow_load_length = FILAMENT_CHANGE_SLOW_LOAD_LENGTH;
  90. const float fast_load_length = ABS(parser.seen('L') ? parser.value_axis_units(E_AXIS)
  91. : fc_settings[active_extruder].load_length);
  92. load_filament(
  93. slow_load_length, fast_load_length, purge_length,
  94. FILAMENT_CHANGE_ALERT_BEEPS,
  95. true, // show_lcd
  96. thermalManager.still_heating(target_extruder), // pause_for_user
  97. PAUSE_MODE_LOAD_FILAMENT // pause_mode
  98. #if ENABLED(DUAL_X_CARRIAGE)
  99. , target_extruder // Dual X target
  100. #endif
  101. );
  102. #endif
  103. // Restore Z axis
  104. if (park_point.z > 0)
  105. do_blocking_move_to_z(_MAX(current_position.z - park_point.z, 0), feedRate_t(NOZZLE_PARK_Z_FEEDRATE));
  106. #if EXTRUDERS > 1 && DISABLED(PRUSA_MMU2)
  107. // Restore toolhead if it was changed
  108. if (active_extruder_before_filament_change != active_extruder)
  109. tool_change(active_extruder_before_filament_change, false);
  110. #endif
  111. #if ENABLED(MIXING_EXTRUDER)
  112. mixer.T(old_mixing_tool); // Restore original mixing tool
  113. #endif
  114. // Show status screen
  115. #if HAS_LCD_MENU
  116. lcd_pause_show_message(PAUSE_MESSAGE_STATUS);
  117. #endif
  118. }
  119. /**
  120. * M702: Unload filament
  121. *
  122. * T<extruder> - Extruder number. Required for mixing extruder.
  123. * For non-mixing, if omitted, current extruder
  124. * (or ALL extruders with FILAMENT_UNLOAD_ALL_EXTRUDERS).
  125. * Z<distance> - Move the Z axis by this distance
  126. * U<distance> - Retract distance for removal (manual reload)
  127. *
  128. * Default values are used for omitted arguments.
  129. */
  130. void GcodeSuite::M702() {
  131. xyz_pos_t park_point = NOZZLE_PARK_POINT;
  132. #if ENABLED(NO_MOTION_BEFORE_HOMING)
  133. // Don't raise Z if the machine isn't homed
  134. if (axes_need_homing()) park_point.z = 0;
  135. #endif
  136. #if ENABLED(MIXING_EXTRUDER)
  137. const uint8_t old_mixing_tool = mixer.get_current_vtool();
  138. #if ENABLED(FILAMENT_UNLOAD_ALL_EXTRUDERS)
  139. float mix_multiplier = 1.0;
  140. if (!parser.seenval('T')) {
  141. mixer.T(MIXER_AUTORETRACT_TOOL);
  142. mix_multiplier = MIXING_STEPPERS;
  143. }
  144. else
  145. #endif
  146. {
  147. const int8_t target_e_stepper = get_target_e_stepper_from_command();
  148. if (target_e_stepper < 0) return;
  149. mixer.T(MIXER_DIRECT_SET_TOOL);
  150. MIXER_STEPPER_LOOP(i) mixer.set_collector(i, (i == (uint8_t)target_e_stepper) ? 1.0 : 0.0);
  151. mixer.normalize();
  152. }
  153. const int8_t target_extruder = active_extruder;
  154. #else
  155. const int8_t target_extruder = get_target_extruder_from_command();
  156. if (target_extruder < 0) return;
  157. #endif
  158. // Z axis lift
  159. if (parser.seenval('Z')) park_point.z = parser.linearval('Z');
  160. // Show initial "wait for unload" message
  161. #if HAS_LCD_MENU
  162. lcd_pause_show_message(PAUSE_MESSAGE_UNLOAD, PAUSE_MODE_UNLOAD_FILAMENT, target_extruder);
  163. #endif
  164. #if EXTRUDERS > 1 && DISABLED(PRUSA_MMU2)
  165. // Change toolhead if specified
  166. uint8_t active_extruder_before_filament_change = active_extruder;
  167. if (active_extruder != target_extruder)
  168. tool_change(target_extruder, false);
  169. #endif
  170. // Lift Z axis
  171. if (park_point.z > 0)
  172. do_blocking_move_to_z(_MIN(current_position.z + park_point.z, Z_MAX_POS), feedRate_t(NOZZLE_PARK_Z_FEEDRATE));
  173. // Unload filament
  174. #if ENABLED(PRUSA_MMU2)
  175. mmu2.unload();
  176. #else
  177. #if EXTRUDERS > 1 && ENABLED(FILAMENT_UNLOAD_ALL_EXTRUDERS)
  178. if (!parser.seenval('T')) {
  179. HOTEND_LOOP() {
  180. if (e != active_extruder) tool_change(e, false);
  181. unload_filament(-fc_settings[e].unload_length, true, PAUSE_MODE_UNLOAD_FILAMENT);
  182. }
  183. }
  184. else
  185. #endif
  186. {
  187. // Unload length
  188. const float unload_length = -ABS(parser.seen('U') ? parser.value_axis_units(E_AXIS)
  189. : fc_settings[target_extruder].unload_length);
  190. unload_filament(unload_length, true, PAUSE_MODE_UNLOAD_FILAMENT
  191. #if ALL(FILAMENT_UNLOAD_ALL_EXTRUDERS, MIXING_EXTRUDER)
  192. , mix_multiplier
  193. #endif
  194. );
  195. }
  196. #endif
  197. // Restore Z axis
  198. if (park_point.z > 0)
  199. do_blocking_move_to_z(_MAX(current_position.z - park_point.z, 0), feedRate_t(NOZZLE_PARK_Z_FEEDRATE));
  200. #if EXTRUDERS > 1 && DISABLED(PRUSA_MMU2)
  201. // Restore toolhead if it was changed
  202. if (active_extruder_before_filament_change != active_extruder)
  203. tool_change(active_extruder_before_filament_change, false);
  204. #endif
  205. #if ENABLED(MIXING_EXTRUDER)
  206. mixer.T(old_mixing_tool); // Restore original mixing tool
  207. #endif
  208. // Show status screen
  209. #if HAS_LCD_MENU
  210. lcd_pause_show_message(PAUSE_MESSAGE_STATUS);
  211. #endif
  212. }
  213. #endif // ADVANCED_PAUSE_FEATURE