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.

M217.cpp 8.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 HAS_MULTI_EXTRUDER
  24. #include "../gcode.h"
  25. #include "../../module/tool_change.h"
  26. #if ENABLED(TOOLCHANGE_MIGRATION_FEATURE)
  27. #include "../../module/motion.h"
  28. #endif
  29. #include "../../MarlinCore.h" // for SP_X_STR, etc.
  30. /**
  31. * M217 - Set toolchange parameters
  32. *
  33. * // Tool change command
  34. * Q Prime active tool and exit
  35. *
  36. * // Tool change settings
  37. * S[linear] Swap length
  38. * B[linear] Extra Swap resume length
  39. * E[linear] Extra Prime length (as used by M217 Q)
  40. * G[linear] Cutting wipe retract length (<=100mm)
  41. * R[linear/min] Retract speed
  42. * U[linear/min] UnRetract speed
  43. * P[linear/min] Prime speed
  44. * V[linear] 0/1 Enable auto prime first extruder used
  45. * W[linear] 0/1 Enable park & Z Raise
  46. * X[linear] Park X (Requires TOOLCHANGE_PARK)
  47. * Y[linear] Park Y (Requires TOOLCHANGE_PARK and NUM_AXES >= 2)
  48. * I[linear] Park I (Requires TOOLCHANGE_PARK and NUM_AXES >= 4)
  49. * J[linear] Park J (Requires TOOLCHANGE_PARK and NUM_AXES >= 5)
  50. * K[linear] Park K (Requires TOOLCHANGE_PARK and NUM_AXES >= 6)
  51. * C[linear] Park U (Requires TOOLCHANGE_PARK and NUM_AXES >= 7)
  52. * H[linear] Park V (Requires TOOLCHANGE_PARK and NUM_AXES >= 8)
  53. * O[linear] Park W (Requires TOOLCHANGE_PARK and NUM_AXES >= 9)
  54. * Z[linear] Z Raise
  55. * F[speed] Fan Speed 0-255
  56. * D[seconds] Fan time
  57. *
  58. * Tool migration settings
  59. * A[0|1] Enable auto-migration on runout
  60. * L[index] Last extruder to use for auto-migration
  61. *
  62. * Tool migration command
  63. * T[index] Migrate to next extruder or the given extruder
  64. */
  65. void GcodeSuite::M217() {
  66. #if ENABLED(TOOLCHANGE_FILAMENT_SWAP)
  67. static constexpr float max_extrude = TERN(PREVENT_LENGTHY_EXTRUDE, EXTRUDE_MAXLENGTH, 500);
  68. if (parser.seen('Q')) { tool_change_prime(); return; }
  69. if (parser.seenval('S')) { const float v = parser.value_linear_units(); toolchange_settings.swap_length = constrain(v, 0, max_extrude); }
  70. if (parser.seenval('B')) { const float v = parser.value_linear_units(); toolchange_settings.extra_resume = constrain(v, -10, 10); }
  71. if (parser.seenval('E')) { const float v = parser.value_linear_units(); toolchange_settings.extra_prime = constrain(v, 0, max_extrude); }
  72. if (parser.seenval('P')) { const int16_t v = parser.value_linear_units(); toolchange_settings.prime_speed = constrain(v, 10, 5400); }
  73. if (parser.seenval('G')) { const int16_t v = parser.value_linear_units(); toolchange_settings.wipe_retract = constrain(v, 0, 100); }
  74. if (parser.seenval('R')) { const int16_t v = parser.value_linear_units(); toolchange_settings.retract_speed = constrain(v, 10, 5400); }
  75. if (parser.seenval('U')) { const int16_t v = parser.value_linear_units(); toolchange_settings.unretract_speed = constrain(v, 10, 5400); }
  76. #if TOOLCHANGE_FS_FAN >= 0 && HAS_FAN
  77. if (parser.seenval('F')) { const uint16_t v = parser.value_ushort(); toolchange_settings.fan_speed = constrain(v, 0, 255); }
  78. if (parser.seenval('D')) { const uint16_t v = parser.value_ushort(); toolchange_settings.fan_time = constrain(v, 1, 30); }
  79. #endif
  80. #endif
  81. #if ENABLED(TOOLCHANGE_FS_PRIME_FIRST_USED)
  82. if (parser.seenval('V')) { enable_first_prime = parser.value_linear_units(); }
  83. #endif
  84. #if ENABLED(TOOLCHANGE_PARK)
  85. if (parser.seenval('W')) { toolchange_settings.enable_park = parser.value_linear_units(); }
  86. if (parser.seenval('X')) { const int16_t v = parser.value_linear_units(); toolchange_settings.change_point.x = constrain(v, X_MIN_POS, X_MAX_POS); }
  87. #if HAS_Y_AXIS
  88. if (parser.seenval('Y')) { const int16_t v = parser.value_linear_units(); toolchange_settings.change_point.y = constrain(v, Y_MIN_POS, Y_MAX_POS); }
  89. #endif
  90. #if HAS_I_AXIS
  91. if (parser.seenval('I')) { const int16_t v = parser.TERN(AXIS4_ROTATES, value_int, value_linear_units)(); toolchange_settings.change_point.i = constrain(v, I_MIN_POS, I_MAX_POS); }
  92. #endif
  93. #if HAS_J_AXIS
  94. if (parser.seenval('J')) { const int16_t v = parser.TERN(AXIS5_ROTATES, value_int, value_linear_units)(); toolchange_settings.change_point.j = constrain(v, J_MIN_POS, J_MAX_POS); }
  95. #endif
  96. #if HAS_K_AXIS
  97. if (parser.seenval('K')) { const int16_t v = parser.TERN(AXIS6_ROTATES, value_int, value_linear_units)(); toolchange_settings.change_point.k = constrain(v, K_MIN_POS, K_MAX_POS); }
  98. #endif
  99. #if HAS_U_AXIS
  100. if (parser.seenval('C')) { const int16_t v = parser.TERN(AXIS7_ROTATES, value_int, value_linear_units)(); toolchange_settings.change_point.u = constrain(v, U_MIN_POS, U_MAX_POS); }
  101. #endif
  102. #if HAS_V_AXIS
  103. if (parser.seenval('H')) { const int16_t v = parser.TERN(AXIS8_ROTATES, value_int, value_linear_units)(); toolchange_settings.change_point.v = constrain(v, V_MIN_POS, V_MAX_POS); }
  104. #endif
  105. #if HAS_W_AXIS
  106. if (parser.seenval('O')) { const int16_t v = parser.TERN(AXIS9_ROTATES, value_int, value_linear_units)(); toolchange_settings.change_point.w = constrain(v, W_MIN_POS, W_MAX_POS); }
  107. #endif
  108. #endif
  109. #if HAS_Z_AXIS
  110. if (parser.seenval('Z')) { toolchange_settings.z_raise = parser.value_linear_units(); }
  111. #endif
  112. #if ENABLED(TOOLCHANGE_MIGRATION_FEATURE)
  113. migration.target = 0; // 0 = disabled
  114. if (parser.seenval('L')) { // Last
  115. const int16_t lval = parser.value_int();
  116. if (WITHIN(lval, 0, EXTRUDERS - 1)) {
  117. migration.last = lval;
  118. migration.automode = (active_extruder < migration.last);
  119. }
  120. }
  121. if (parser.seen('A')) // Auto on/off
  122. migration.automode = parser.value_bool();
  123. if (parser.seen('T')) { // Migrate now
  124. if (parser.has_value()) {
  125. const int16_t tval = parser.value_int();
  126. if (WITHIN(tval, 0, EXTRUDERS - 1) && tval != active_extruder) {
  127. migration.target = tval + 1;
  128. extruder_migration();
  129. migration.target = 0; // disable
  130. return;
  131. }
  132. else
  133. migration.target = 0; // disable
  134. }
  135. else {
  136. extruder_migration();
  137. return;
  138. }
  139. }
  140. #endif
  141. M217_report();
  142. }
  143. void GcodeSuite::M217_report(const bool forReplay/*=true*/) {
  144. report_heading_etc(forReplay, F(STR_TOOL_CHANGING));
  145. SERIAL_ECHOPGM(" M217");
  146. #if ENABLED(TOOLCHANGE_FILAMENT_SWAP)
  147. SERIAL_ECHOPGM_P(
  148. PSTR(" S"), LINEAR_UNIT(toolchange_settings.swap_length),
  149. SP_B_STR, LINEAR_UNIT(toolchange_settings.extra_resume),
  150. SP_E_STR, LINEAR_UNIT(toolchange_settings.extra_prime),
  151. SP_P_STR, LINEAR_UNIT(toolchange_settings.prime_speed),
  152. PSTR(" G"), LINEAR_UNIT(toolchange_settings.wipe_retract),
  153. PSTR(" R"), LINEAR_UNIT(toolchange_settings.retract_speed),
  154. PSTR(" U"), LINEAR_UNIT(toolchange_settings.unretract_speed),
  155. PSTR(" F"), toolchange_settings.fan_speed,
  156. PSTR(" D"), toolchange_settings.fan_time
  157. );
  158. #if ENABLED(TOOLCHANGE_MIGRATION_FEATURE)
  159. SERIAL_ECHOPGM(" A", migration.automode, " L", LINEAR_UNIT(migration.last));
  160. #endif
  161. #if ENABLED(TOOLCHANGE_PARK)
  162. {
  163. SERIAL_ECHOPGM(" W", LINEAR_UNIT(toolchange_settings.enable_park));
  164. SERIAL_ECHOPGM_P(
  165. SP_X_STR, LINEAR_UNIT(toolchange_settings.change_point.x)
  166. #if HAS_Y_AXIS
  167. , SP_Y_STR, LINEAR_UNIT(toolchange_settings.change_point.y)
  168. #endif
  169. #if SECONDARY_AXES >= 1
  170. , LIST_N(DOUBLE(SECONDARY_AXES)
  171. , SP_I_STR, I_AXIS_UNIT(toolchange_settings.change_point.i)
  172. , SP_J_STR, J_AXIS_UNIT(toolchange_settings.change_point.j)
  173. , SP_K_STR, K_AXIS_UNIT(toolchange_settings.change_point.k)
  174. , SP_C_STR, U_AXIS_UNIT(toolchange_settings.change_point.u)
  175. , PSTR(" H"), V_AXIS_UNIT(toolchange_settings.change_point.v)
  176. , PSTR(" O"), W_AXIS_UNIT(toolchange_settings.change_point.w)
  177. )
  178. #endif
  179. );
  180. }
  181. #endif
  182. #if ENABLED(TOOLCHANGE_FS_PRIME_FIRST_USED)
  183. SERIAL_ECHOPGM(" V", LINEAR_UNIT(enable_first_prime));
  184. #endif
  185. #endif
  186. SERIAL_ECHOLNPGM_P(SP_Z_STR, LINEAR_UNIT(toolchange_settings.z_raise));
  187. }
  188. #endif // HAS_MULTI_EXTRUDER