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 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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 "../../../Marlin.h"
  26. #include "../../../module/motion.h"
  27. #include "../../../module/temperature.h"
  28. #include "../../../libs/point_t.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. /**
  39. * M701: Load filament
  40. *
  41. * T<extruder> - Optional extruder number. Current extruder if omitted.
  42. * Z<distance> - Move the Z axis by this distance
  43. * L<distance> - Extrude distance for insertion (positive value) (manual reload)
  44. *
  45. * Default values are used for omitted arguments.
  46. */
  47. void GcodeSuite::M701() {
  48. point_t park_point = NOZZLE_PARK_POINT;
  49. #if ENABLED(NO_MOTION_BEFORE_HOMING)
  50. // Only raise Z if the machine is homed
  51. if (axis_unhomed_error()) park_point.z = 0;
  52. #endif
  53. const int8_t target_extruder = get_target_extruder_from_command();
  54. if (target_extruder < 0) return;
  55. // Z axis lift
  56. if (parser.seenval('Z')) park_point.z = parser.linearval('Z');
  57. // Show initial "wait for load" message
  58. #if HAS_LCD_MENU
  59. lcd_pause_show_message(PAUSE_MESSAGE_LOAD, PAUSE_MODE_LOAD_FILAMENT, target_extruder);
  60. #endif
  61. #if EXTRUDERS > 1 && DISABLED(PRUSA_MMU2)
  62. // Change toolhead if specified
  63. uint8_t active_extruder_before_filament_change = active_extruder;
  64. if (active_extruder != target_extruder)
  65. tool_change(target_extruder, 0, false);
  66. #endif
  67. // Lift Z axis
  68. if (park_point.z > 0)
  69. do_blocking_move_to_z(MIN(current_position[Z_AXIS] + park_point.z, Z_MAX_POS), NOZZLE_PARK_Z_FEEDRATE);
  70. // Load filament
  71. #if ENABLED(PRUSA_MMU2)
  72. mmu2.loadFilamentToNozzle(target_extruder);
  73. #else
  74. constexpr float slow_load_length = FILAMENT_CHANGE_SLOW_LOAD_LENGTH;
  75. const float fast_load_length = ABS(parser.seen('L') ? parser.value_axis_units(E_AXIS)
  76. : fc_settings[active_extruder].load_length);
  77. load_filament(slow_load_length, fast_load_length, ADVANCED_PAUSE_PURGE_LENGTH, FILAMENT_CHANGE_ALERT_BEEPS,
  78. true, thermalManager.still_heating(target_extruder), PAUSE_MODE_LOAD_FILAMENT
  79. #if ENABLED(DUAL_X_CARRIAGE)
  80. , target_extruder
  81. #endif
  82. );
  83. #endif
  84. // Restore Z axis
  85. if (park_point.z > 0)
  86. do_blocking_move_to_z(MAX(current_position[Z_AXIS] - park_point.z, 0), NOZZLE_PARK_Z_FEEDRATE);
  87. #if EXTRUDERS > 1 && DISABLED(PRUSA_MMU2)
  88. // Restore toolhead if it was changed
  89. if (active_extruder_before_filament_change != active_extruder)
  90. tool_change(active_extruder_before_filament_change, 0, false);
  91. #endif
  92. // Show status screen
  93. #if HAS_LCD_MENU
  94. lcd_pause_show_message(PAUSE_MESSAGE_STATUS);
  95. #endif
  96. }
  97. /**
  98. * M702: Unload filament
  99. *
  100. * T<extruder> - Optional extruder number. If omitted, current extruder
  101. * (or ALL extruders with FILAMENT_UNLOAD_ALL_EXTRUDERS).
  102. * Z<distance> - Move the Z axis by this distance
  103. * U<distance> - Retract distance for removal (manual reload)
  104. *
  105. * Default values are used for omitted arguments.
  106. */
  107. void GcodeSuite::M702() {
  108. point_t park_point = NOZZLE_PARK_POINT;
  109. #if ENABLED(NO_MOTION_BEFORE_HOMING)
  110. // Only raise Z if the machine is homed
  111. if (axis_unhomed_error()) park_point.z = 0;
  112. #endif
  113. const int8_t target_extruder = get_target_extruder_from_command();
  114. if (target_extruder < 0) return;
  115. // Z axis lift
  116. if (parser.seenval('Z')) park_point.z = parser.linearval('Z');
  117. // Show initial "wait for unload" message
  118. #if HAS_LCD_MENU
  119. lcd_pause_show_message(PAUSE_MESSAGE_UNLOAD, PAUSE_MODE_UNLOAD_FILAMENT, target_extruder);
  120. #endif
  121. #if EXTRUDERS > 1 && DISABLED(PRUSA_MMU2)
  122. // Change toolhead if specified
  123. uint8_t active_extruder_before_filament_change = active_extruder;
  124. if (active_extruder != target_extruder)
  125. tool_change(target_extruder, 0, false);
  126. #endif
  127. // Lift Z axis
  128. if (park_point.z > 0)
  129. do_blocking_move_to_z(MIN(current_position[Z_AXIS] + park_point.z, Z_MAX_POS), NOZZLE_PARK_Z_FEEDRATE);
  130. // Unload filament
  131. #if ENABLED(PRUSA_MMU2)
  132. mmu2.unload();
  133. #else
  134. #if EXTRUDERS > 1 && ENABLED(FILAMENT_UNLOAD_ALL_EXTRUDERS)
  135. if (!parser.seenval('T')) {
  136. HOTEND_LOOP() {
  137. if (e != active_extruder) tool_change(e, 0, false);
  138. unload_filament(-fc_settings[e].unload_length, true, PAUSE_MODE_UNLOAD_FILAMENT);
  139. }
  140. }
  141. else
  142. #endif
  143. {
  144. // Unload length
  145. const float unload_length = -ABS(parser.seen('U') ? parser.value_axis_units(E_AXIS)
  146. : fc_settings[target_extruder].unload_length);
  147. unload_filament(unload_length, true, PAUSE_MODE_UNLOAD_FILAMENT);
  148. }
  149. #endif
  150. // Restore Z axis
  151. if (park_point.z > 0)
  152. do_blocking_move_to_z(MAX(current_position[Z_AXIS] - park_point.z, 0), NOZZLE_PARK_Z_FEEDRATE);
  153. #if EXTRUDERS > 1 && DISABLED(PRUSA_MMU2)
  154. // Restore toolhead if it was changed
  155. if (active_extruder_before_filament_change != active_extruder)
  156. tool_change(active_extruder_before_filament_change, 0, false);
  157. #endif
  158. // Show status screen
  159. #if HAS_LCD_MENU
  160. lcd_pause_show_message(PAUSE_MESSAGE_STATUS);
  161. #endif
  162. }
  163. #endif // ADVANCED_PAUSE_FEATURE