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.6KB

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