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.

G28.cpp 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 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/MarlinConfig.h"
  23. #include "../gcode.h"
  24. #include "../../module/stepper.h"
  25. #include "../../module/endstops.h"
  26. #if HOTENDS > 1
  27. #include "../../module/tool_change.h"
  28. #endif
  29. #if HAS_LEVELING
  30. #include "../../feature/bedlevel/bedlevel.h"
  31. #endif
  32. #include "../../lcd/ultralcd.h"
  33. #if ENABLED(QUICK_HOME)
  34. static void quick_home_xy() {
  35. // Pretend the current position is 0,0
  36. current_position[X_AXIS] = current_position[Y_AXIS] = 0.0;
  37. sync_plan_position();
  38. const int x_axis_home_dir =
  39. #if ENABLED(DUAL_X_CARRIAGE)
  40. x_home_dir(active_extruder)
  41. #else
  42. home_dir(X_AXIS)
  43. #endif
  44. ;
  45. const float mlx = max_length(X_AXIS),
  46. mly = max_length(Y_AXIS),
  47. mlratio = mlx > mly ? mly / mlx : mlx / mly,
  48. fr_mm_s = min(homing_feedrate(X_AXIS), homing_feedrate(Y_AXIS)) * SQRT(sq(mlratio) + 1.0);
  49. do_blocking_move_to_xy(1.5 * mlx * x_axis_home_dir, 1.5 * mly * home_dir(Y_AXIS), fr_mm_s);
  50. endstops.hit_on_purpose(); // clear endstop hit flags
  51. current_position[X_AXIS] = current_position[Y_AXIS] = 0.0;
  52. #if ENABLED(SENSORLESS_HOMING)
  53. safe_delay(500); // Short delay needed to settle
  54. #endif
  55. }
  56. #endif // QUICK_HOME
  57. #if ENABLED(Z_SAFE_HOMING)
  58. inline void home_z_safely() {
  59. // Disallow Z homing if X or Y are unknown
  60. if (!axis_known_position[X_AXIS] || !axis_known_position[Y_AXIS]) {
  61. LCD_MESSAGEPGM(MSG_ERR_Z_HOMING);
  62. SERIAL_ECHO_START();
  63. SERIAL_ECHOLNPGM(MSG_ERR_Z_HOMING);
  64. return;
  65. }
  66. #if ENABLED(DEBUG_LEVELING_FEATURE)
  67. if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("Z_SAFE_HOMING >>>");
  68. #endif
  69. SYNC_PLAN_POSITION_KINEMATIC();
  70. /**
  71. * Move the Z probe (or just the nozzle) to the safe homing point
  72. */
  73. destination[X_AXIS] = Z_SAFE_HOMING_X_POINT;
  74. destination[Y_AXIS] = Z_SAFE_HOMING_Y_POINT;
  75. destination[Z_AXIS] = current_position[Z_AXIS]; // Z is already at the right height
  76. #if HOMING_Z_WITH_PROBE
  77. destination[X_AXIS] -= X_PROBE_OFFSET_FROM_EXTRUDER;
  78. destination[Y_AXIS] -= Y_PROBE_OFFSET_FROM_EXTRUDER;
  79. #endif
  80. if (position_is_reachable(destination[X_AXIS], destination[Y_AXIS])) {
  81. #if ENABLED(DEBUG_LEVELING_FEATURE)
  82. if (DEBUGGING(LEVELING)) DEBUG_POS("Z_SAFE_HOMING", destination);
  83. #endif
  84. // This causes the carriage on Dual X to unpark
  85. #if ENABLED(DUAL_X_CARRIAGE)
  86. active_extruder_parked = false;
  87. #endif
  88. #if ENABLED(SENSORLESS_HOMING)
  89. safe_delay(500); // Short delay needed to settle
  90. #endif
  91. do_blocking_move_to_xy(destination[X_AXIS], destination[Y_AXIS]);
  92. HOMEAXIS(Z);
  93. }
  94. else {
  95. LCD_MESSAGEPGM(MSG_ZPROBE_OUT);
  96. SERIAL_ECHO_START();
  97. SERIAL_ECHOLNPGM(MSG_ZPROBE_OUT);
  98. }
  99. #if ENABLED(DEBUG_LEVELING_FEATURE)
  100. if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("<<< Z_SAFE_HOMING");
  101. #endif
  102. }
  103. #endif // Z_SAFE_HOMING
  104. /**
  105. * G28: Home all axes according to settings
  106. *
  107. * Parameters
  108. *
  109. * None Home to all axes with no parameters.
  110. * With QUICK_HOME enabled XY will home together, then Z.
  111. *
  112. * Cartesian parameters
  113. *
  114. * X Home to the X endstop
  115. * Y Home to the Y endstop
  116. * Z Home to the Z endstop
  117. *
  118. */
  119. void GcodeSuite::G28(const bool always_home_all) {
  120. #if ENABLED(DEBUG_LEVELING_FEATURE)
  121. if (DEBUGGING(LEVELING)) {
  122. SERIAL_ECHOLNPGM(">>> G28");
  123. log_machine_info();
  124. }
  125. #endif
  126. // Wait for planner moves to finish!
  127. stepper.synchronize();
  128. // Cancel the active G29 session
  129. #if ENABLED(PROBE_MANUALLY)
  130. g29_in_progress = false;
  131. #endif
  132. // Disable the leveling matrix before homing
  133. #if HAS_LEVELING
  134. #if ENABLED(AUTO_BED_LEVELING_UBL)
  135. const bool ubl_state_at_entry = planner.leveling_active;
  136. #endif
  137. set_bed_leveling_enabled(false);
  138. #endif
  139. #if ENABLED(CNC_WORKSPACE_PLANES)
  140. workspace_plane = PLANE_XY;
  141. #endif
  142. // Always home with tool 0 active
  143. #if HOTENDS > 1
  144. const uint8_t old_tool_index = active_extruder;
  145. tool_change(0, 0, true);
  146. #endif
  147. #if ENABLED(DUAL_X_CARRIAGE) || ENABLED(DUAL_NOZZLE_DUPLICATION_MODE)
  148. extruder_duplication_enabled = false;
  149. #endif
  150. setup_for_endstop_or_probe_move();
  151. #if ENABLED(DEBUG_LEVELING_FEATURE)
  152. if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("> endstops.enable(true)");
  153. #endif
  154. endstops.enable(true); // Enable endstops for next homing move
  155. #if ENABLED(DELTA)
  156. home_delta();
  157. UNUSED(always_home_all);
  158. #else // NOT DELTA
  159. const bool homeX = always_home_all || parser.seen('X'),
  160. homeY = always_home_all || parser.seen('Y'),
  161. homeZ = always_home_all || parser.seen('Z'),
  162. home_all = (!homeX && !homeY && !homeZ) || (homeX && homeY && homeZ);
  163. set_destination_from_current();
  164. #if Z_HOME_DIR > 0 // If homing away from BED do Z first
  165. if (home_all || homeZ) HOMEAXIS(Z);
  166. #endif
  167. if (home_all || homeX || homeY) {
  168. // Raise Z before homing any other axes and z is not already high enough (never lower z)
  169. destination[Z_AXIS] = Z_HOMING_HEIGHT;
  170. if (destination[Z_AXIS] > current_position[Z_AXIS]) {
  171. #if ENABLED(DEBUG_LEVELING_FEATURE)
  172. if (DEBUGGING(LEVELING))
  173. SERIAL_ECHOLNPAIR("Raise Z (before homing) to ", destination[Z_AXIS]);
  174. #endif
  175. do_blocking_move_to_z(destination[Z_AXIS]);
  176. }
  177. }
  178. #if ENABLED(QUICK_HOME)
  179. if (home_all || (homeX && homeY)) quick_home_xy();
  180. #endif
  181. // Home Y (before X)
  182. #if ENABLED(HOME_Y_BEFORE_X)
  183. if (home_all || homeY
  184. #if ENABLED(CODEPENDENT_XY_HOMING)
  185. || homeX
  186. #endif
  187. ) HOMEAXIS(Y);
  188. #endif
  189. // Home X
  190. if (home_all || homeX
  191. #if ENABLED(CODEPENDENT_XY_HOMING) && DISABLED(HOME_Y_BEFORE_X)
  192. || homeY
  193. #endif
  194. ) {
  195. #if ENABLED(DUAL_X_CARRIAGE)
  196. // Always home the 2nd (right) extruder first
  197. active_extruder = 1;
  198. HOMEAXIS(X);
  199. // Remember this extruder's position for later tool change
  200. inactive_extruder_x_pos = current_position[X_AXIS];
  201. // Home the 1st (left) extruder
  202. active_extruder = 0;
  203. HOMEAXIS(X);
  204. // Consider the active extruder to be parked
  205. COPY(raised_parked_position, current_position);
  206. delayed_move_time = 0;
  207. active_extruder_parked = true;
  208. #else
  209. HOMEAXIS(X);
  210. #endif
  211. }
  212. // Home Y (after X)
  213. #if DISABLED(HOME_Y_BEFORE_X)
  214. if (home_all || homeY) HOMEAXIS(Y);
  215. #endif
  216. // Home Z last if homing towards the bed
  217. #if Z_HOME_DIR < 0
  218. if (home_all || homeZ) {
  219. #if ENABLED(Z_SAFE_HOMING)
  220. home_z_safely();
  221. #else
  222. HOMEAXIS(Z);
  223. #endif
  224. } // home_all || homeZ
  225. #endif // Z_HOME_DIR < 0
  226. SYNC_PLAN_POSITION_KINEMATIC();
  227. #endif // !DELTA (G28)
  228. endstops.not_homing();
  229. #if ENABLED(DELTA) && ENABLED(DELTA_HOME_TO_SAFE_ZONE)
  230. // move to a height where we can use the full xy-area
  231. do_blocking_move_to_z(delta_clip_start_height);
  232. #endif
  233. #if ENABLED(AUTO_BED_LEVELING_UBL)
  234. set_bed_leveling_enabled(ubl_state_at_entry);
  235. #endif
  236. clean_up_after_endstop_or_probe_move();
  237. // Restore the active tool after homing
  238. #if HOTENDS > 1
  239. #if ENABLED(PARKING_EXTRUDER)
  240. #define NO_FETCH false // fetch the previous toolhead
  241. #else
  242. #define NO_FETCH true
  243. #endif
  244. tool_change(old_tool_index, 0, NO_FETCH);
  245. #endif
  246. lcd_refresh();
  247. report_current_position();
  248. #if ENABLED(NANODLP_Z_SYNC)
  249. #if ENABLED(NANODLP_ALL_AXIS)
  250. #define _HOME_SYNC true // For any axis, output sync text.
  251. #else
  252. #define _HOME_SYNC (home_all || homeZ) // Only for Z-axis
  253. #endif
  254. if (_HOME_SYNC)
  255. SERIAL_ECHOLNPGM(MSG_Z_MOVE_COMP);
  256. #endif
  257. #if ENABLED(DEBUG_LEVELING_FEATURE)
  258. if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("<<< G28");
  259. #endif
  260. }