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

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