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.

M605.cpp 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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/MarlinConfig.h"
  23. #if HAS_DUPLICATION_MODE
  24. //#define DEBUG_DXC_MODE
  25. #include "../gcode.h"
  26. #include "../../module/motion.h"
  27. #include "../../module/tool_change.h"
  28. #include "../../module/planner.h"
  29. #define DEBUG_OUT ENABLED(DEBUG_DXC_MODE)
  30. #include "../../core/debug_out.h"
  31. #if ENABLED(DUAL_X_CARRIAGE)
  32. /**
  33. * M605: Set dual x-carriage movement mode
  34. *
  35. * M605 S0 : (FULL_CONTROL) The slicer has full control over both X-carriages and can achieve optimal travel
  36. * results as long as it supports dual X-carriages.
  37. *
  38. * M605 S1 : (AUTO_PARK) The firmware automatically parks and unparks the X-carriages on tool-change so that
  39. * additional slicer support is not required.
  40. *
  41. * M605 S2 X R : (DUPLICATION) The firmware moves the second X-carriage and extruder in synchronization with
  42. * the first X-carriage and extruder, to print 2 copies of the same object at the same time.
  43. * Set the constant X-offset and temperature differential with M605 S2 X[offs] R[deg] and
  44. * follow with "M605 S2" to initiate duplicated movement. For example, use "M605 S2 X100 R2" to
  45. * make a copy 100mm to the right with E1 2° hotter than E0.
  46. *
  47. * M605 S3 : (MIRRORED) Formbot/Vivedino-inspired mirrored mode in which the second extruder duplicates
  48. * the movement of the first except the second extruder is reversed in the X axis.
  49. * The temperature differential and initial X offset must be set with "M605 S2 X[offs] R[deg]",
  50. * then followed by "M605 S3" to initiate mirrored movement.
  51. *
  52. * M605 W : IDEX What? command.
  53. *
  54. * Note: the X axis should be homed after changing Dual X-carriage mode.
  55. */
  56. void GcodeSuite::M605() {
  57. planner.synchronize();
  58. if (parser.seenval('S')) {
  59. const DualXMode previous_mode = dual_x_carriage_mode;
  60. dual_x_carriage_mode = (DualXMode)parser.value_byte();
  61. idex_set_mirrored_mode(false);
  62. switch (dual_x_carriage_mode) {
  63. case DXC_FULL_CONTROL_MODE:
  64. case DXC_AUTO_PARK_MODE:
  65. break;
  66. case DXC_DUPLICATION_MODE:
  67. // Set the X offset, but no less than the safety gap
  68. if (parser.seenval('X')) duplicate_extruder_x_offset = _MAX(parser.value_linear_units(), (X2_MIN_POS) - (X1_MIN_POS));
  69. if (parser.seenval('R')) duplicate_extruder_temp_offset = parser.value_celsius_diff();
  70. // Always switch back to tool 0
  71. if (active_extruder != 0) tool_change(0);
  72. break;
  73. case DXC_MIRRORED_MODE: {
  74. if (previous_mode != DXC_DUPLICATION_MODE) {
  75. SERIAL_ECHOLNPGM("Printer must be in DXC_DUPLICATION_MODE prior to ");
  76. SERIAL_ECHOLNPGM("specifying DXC_MIRRORED_MODE.");
  77. dual_x_carriage_mode = DEFAULT_DUAL_X_CARRIAGE_MODE;
  78. return;
  79. }
  80. idex_set_mirrored_mode(true);
  81. // Do a small 'jog' motion in the X axis
  82. xyze_pos_t dest = current_position; dest.x -= 0.1f;
  83. for (uint8_t i = 2; --i;) {
  84. planner.buffer_line(dest, feedrate_mm_s, 0);
  85. dest.x += 0.1f;
  86. }
  87. } return;
  88. default:
  89. dual_x_carriage_mode = DEFAULT_DUAL_X_CARRIAGE_MODE;
  90. break;
  91. }
  92. idex_set_parked(false);
  93. set_duplication_enabled(false);
  94. #ifdef EVENT_GCODE_IDEX_AFTER_MODECHANGE
  95. process_subcommands_now(F(EVENT_GCODE_IDEX_AFTER_MODECHANGE));
  96. #endif
  97. }
  98. else if (!parser.seen('W')) // if no S or W parameter, the DXC mode gets reset to the user's default
  99. dual_x_carriage_mode = DEFAULT_DUAL_X_CARRIAGE_MODE;
  100. #ifdef DEBUG_DXC_MODE
  101. if (parser.seen('W')) {
  102. DEBUG_ECHO_START();
  103. DEBUG_ECHOPGM("Dual X Carriage Mode ");
  104. switch (dual_x_carriage_mode) {
  105. case DXC_FULL_CONTROL_MODE: DEBUG_ECHOPGM("FULL_CONTROL"); break;
  106. case DXC_AUTO_PARK_MODE: DEBUG_ECHOPGM("AUTO_PARK"); break;
  107. case DXC_DUPLICATION_MODE: DEBUG_ECHOPGM("DUPLICATION"); break;
  108. case DXC_MIRRORED_MODE: DEBUG_ECHOPGM("MIRRORED"); break;
  109. }
  110. DEBUG_ECHOPGM("\nActive Ext: ", active_extruder);
  111. if (!active_extruder_parked) DEBUG_ECHOPGM(" NOT ");
  112. DEBUG_ECHOPGM(" parked.");
  113. DEBUG_ECHOPGM("\nactive_extruder_x_pos: ", current_position.x);
  114. DEBUG_ECHOPGM("\ninactive_extruder_x: ", inactive_extruder_x);
  115. DEBUG_ECHOPGM("\nextruder_duplication_enabled: ", extruder_duplication_enabled);
  116. DEBUG_ECHOPGM("\nduplicate_extruder_x_offset: ", duplicate_extruder_x_offset);
  117. DEBUG_ECHOPGM("\nduplicate_extruder_temp_offset: ", duplicate_extruder_temp_offset);
  118. DEBUG_ECHOPGM("\ndelayed_move_time: ", delayed_move_time);
  119. DEBUG_ECHOPGM("\nX1 Home X: ", x_home_pos(0), "\nX1_MIN_POS=", X1_MIN_POS, "\nX1_MAX_POS=", X1_MAX_POS);
  120. DEBUG_ECHOPGM("\nX2 Home X: ", x_home_pos(1), "\nX2_MIN_POS=", X2_MIN_POS, "\nX2_MAX_POS=", X2_MAX_POS);
  121. DEBUG_ECHOPGM("\nX2_HOME_DIR=", X2_HOME_DIR, "\nX2_HOME_POS=", X2_HOME_POS);
  122. DEBUG_ECHOPGM("\nDEFAULT_DUAL_X_CARRIAGE_MODE=", STRINGIFY(DEFAULT_DUAL_X_CARRIAGE_MODE));
  123. DEBUG_ECHOPGM("\toolchange_settings.z_raise=", toolchange_settings.z_raise);
  124. DEBUG_ECHOPGM("\nDEFAULT_DUPLICATION_X_OFFSET=", DEFAULT_DUPLICATION_X_OFFSET);
  125. DEBUG_EOL();
  126. HOTEND_LOOP() {
  127. DEBUG_ECHOPGM_P(SP_T_STR, e);
  128. LOOP_NUM_AXES(a) DEBUG_ECHOPGM(" hotend_offset[", e, "].", AS_CHAR(AXIS_CHAR(a) | 0x20), "=", hotend_offset[e][a]);
  129. DEBUG_EOL();
  130. }
  131. DEBUG_EOL();
  132. }
  133. #endif // DEBUG_DXC_MODE
  134. }
  135. #elif ENABLED(MULTI_NOZZLE_DUPLICATION)
  136. /**
  137. * M605: Set multi-nozzle duplication mode
  138. *
  139. * S2 - Enable duplication mode
  140. * P[mask] - Bit-mask of nozzles to include in the duplication set.
  141. * A value of 0 disables duplication.
  142. * E[index] - Last nozzle index to include in the duplication set.
  143. * A value of 0 disables duplication.
  144. */
  145. void GcodeSuite::M605() {
  146. bool ena = false;
  147. if (parser.seen("EPS")) {
  148. planner.synchronize();
  149. if (parser.seenval('P')) duplication_e_mask = parser.value_int(); // Set the mask directly
  150. else if (parser.seenval('E')) duplication_e_mask = pow(2, parser.value_int() + 1) - 1; // Set the mask by E index
  151. ena = (2 == parser.intval('S', extruder_duplication_enabled ? 2 : 0));
  152. set_duplication_enabled(ena && (duplication_e_mask >= 3));
  153. }
  154. SERIAL_ECHO_START();
  155. SERIAL_ECHOPGM(STR_DUPLICATION_MODE);
  156. serialprint_onoff(extruder_duplication_enabled);
  157. if (ena) {
  158. SERIAL_ECHOPGM(" ( ");
  159. HOTEND_LOOP() if (TEST(duplication_e_mask, e)) { SERIAL_ECHO(e); SERIAL_CHAR(' '); }
  160. SERIAL_CHAR(')');
  161. }
  162. SERIAL_EOL();
  163. }
  164. #endif // MULTI_NOZZLE_DUPLICATION
  165. #endif // HAS_DUPICATION_MODE