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.

motion.cpp 54KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2019 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. /**
  23. * motion.cpp
  24. */
  25. #include "motion.h"
  26. #include "endstops.h"
  27. #include "stepper.h"
  28. #include "planner.h"
  29. #include "temperature.h"
  30. #include "../gcode/gcode.h"
  31. #include "../inc/MarlinConfig.h"
  32. #if IS_SCARA
  33. #include "../libs/buzzer.h"
  34. #include "../lcd/ultralcd.h"
  35. #endif
  36. #if HAS_BED_PROBE
  37. #include "probe.h"
  38. #endif
  39. #if HAS_LEVELING
  40. #include "../feature/bedlevel/bedlevel.h"
  41. #endif
  42. #if ENABLED(ULTRA_LCD) || ENABLED(EXTENSIBLE_UI)
  43. #include "../lcd/ultralcd.h"
  44. #endif
  45. #if ENABLED(SENSORLESS_HOMING)
  46. #include "../feature/tmc_util.h"
  47. #endif
  48. #if ENABLED(FWRETRACT)
  49. #include "../feature/fwretract.h"
  50. #endif
  51. #define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE)
  52. #include "../core/debug_out.h"
  53. #define XYZ_CONSTS(type, array, CONFIG) const PROGMEM type array##_P[XYZ] = { X_##CONFIG, Y_##CONFIG, Z_##CONFIG }
  54. XYZ_CONSTS(float, base_min_pos, MIN_POS);
  55. XYZ_CONSTS(float, base_max_pos, MAX_POS);
  56. XYZ_CONSTS(float, base_home_pos, HOME_POS);
  57. XYZ_CONSTS(float, max_length, MAX_LENGTH);
  58. XYZ_CONSTS(float, home_bump_mm, HOME_BUMP_MM);
  59. XYZ_CONSTS(signed char, home_dir, HOME_DIR);
  60. /**
  61. * axis_homed
  62. * Flags that each linear axis was homed.
  63. * XYZ on cartesian, ABC on delta, ABZ on SCARA.
  64. *
  65. * axis_known_position
  66. * Flags that the position is known in each linear axis. Set when homed.
  67. * Cleared whenever a stepper powers off, potentially losing its position.
  68. */
  69. uint8_t axis_homed, axis_known_position; // = 0
  70. // Relative Mode. Enable with G91, disable with G90.
  71. bool relative_mode; // = false;
  72. /**
  73. * Cartesian Current Position
  74. * Used to track the native machine position as moves are queued.
  75. * Used by 'line_to_current_position' to do a move after changing it.
  76. * Used by 'sync_plan_position' to update 'planner.position'.
  77. */
  78. float current_position[XYZE] = { X_HOME_POS, Y_HOME_POS, Z_HOME_POS };
  79. /**
  80. * Cartesian Destination
  81. * The destination for a move, filled in by G-code movement commands,
  82. * and expected by functions like 'prepare_move_to_destination'.
  83. * Set with 'get_destination_from_command' or 'set_destination_from_current'.
  84. */
  85. float destination[XYZE]; // = { 0 }
  86. // The active extruder (tool). Set with T<extruder> command.
  87. #if EXTRUDERS > 1
  88. uint8_t active_extruder; // = 0
  89. #endif
  90. // Extruder offsets
  91. #if HAS_HOTEND_OFFSET
  92. float hotend_offset[XYZ][HOTENDS]; // Initialized by settings.load()
  93. void reset_hotend_offsets() {
  94. constexpr float tmp[XYZ][HOTENDS] = { HOTEND_OFFSET_X, HOTEND_OFFSET_Y, HOTEND_OFFSET_Z };
  95. static_assert(
  96. tmp[X_AXIS][0] == 0 && tmp[Y_AXIS][0] == 0 && tmp[Z_AXIS][0] == 0,
  97. "Offsets for the first hotend must be 0.0."
  98. );
  99. LOOP_XYZ(i) HOTEND_LOOP() hotend_offset[i][e] = tmp[i][e];
  100. #if ENABLED(DUAL_X_CARRIAGE)
  101. hotend_offset[X_AXIS][1] = MAX(X2_HOME_POS, X2_MAX_POS);
  102. #endif
  103. }
  104. #endif
  105. // The feedrate for the current move, often used as the default if
  106. // no other feedrate is specified. Overridden for special moves.
  107. // Set by the last G0 through G5 command's "F" parameter.
  108. // Functions that override this for custom moves *must always* restore it!
  109. float feedrate_mm_s = MMM_TO_MMS(1500.0f);
  110. int16_t feedrate_percentage = 100;
  111. // Homing feedrate is const progmem - compare to constexpr in the header
  112. const float homing_feedrate_mm_s[XYZ] PROGMEM = {
  113. #if ENABLED(DELTA)
  114. MMM_TO_MMS(HOMING_FEEDRATE_Z), MMM_TO_MMS(HOMING_FEEDRATE_Z),
  115. #else
  116. MMM_TO_MMS(HOMING_FEEDRATE_XY), MMM_TO_MMS(HOMING_FEEDRATE_XY),
  117. #endif
  118. MMM_TO_MMS(HOMING_FEEDRATE_Z)
  119. };
  120. // Cartesian conversion result goes here:
  121. float cartes[XYZ];
  122. #if IS_KINEMATIC
  123. float delta[ABC];
  124. #if HAS_SCARA_OFFSET
  125. float scara_home_offset[ABC];
  126. #endif
  127. #if HAS_SOFTWARE_ENDSTOPS
  128. float delta_max_radius, delta_max_radius_2;
  129. #elif IS_SCARA
  130. constexpr float delta_max_radius = SCARA_PRINTABLE_RADIUS,
  131. delta_max_radius_2 = sq(SCARA_PRINTABLE_RADIUS);
  132. #else // DELTA
  133. constexpr float delta_max_radius = DELTA_PRINTABLE_RADIUS,
  134. delta_max_radius_2 = sq(DELTA_PRINTABLE_RADIUS);
  135. #endif
  136. #endif
  137. /**
  138. * The workspace can be offset by some commands, or
  139. * these offsets may be omitted to save on computation.
  140. */
  141. #if HAS_POSITION_SHIFT
  142. // The distance that XYZ has been offset by G92. Reset by G28.
  143. float position_shift[XYZ] = { 0 };
  144. #endif
  145. #if HAS_HOME_OFFSET
  146. // This offset is added to the configured home position.
  147. // Set by M206, M428, or menu item. Saved to EEPROM.
  148. float home_offset[XYZ] = { 0 };
  149. #endif
  150. #if HAS_HOME_OFFSET && HAS_POSITION_SHIFT
  151. // The above two are combined to save on computes
  152. float workspace_offset[XYZ] = { 0 };
  153. #endif
  154. #if HAS_ABL_NOT_UBL
  155. float xy_probe_feedrate_mm_s = MMM_TO_MMS(XY_PROBE_SPEED);
  156. #endif
  157. /**
  158. * Output the current position to serial
  159. */
  160. void report_current_position() {
  161. SERIAL_ECHOPAIR("X:", LOGICAL_X_POSITION(current_position[X_AXIS]));
  162. SERIAL_ECHOPAIR(" Y:", LOGICAL_Y_POSITION(current_position[Y_AXIS]));
  163. SERIAL_ECHOPAIR(" Z:", LOGICAL_Z_POSITION(current_position[Z_AXIS]));
  164. SERIAL_ECHOPAIR(" E:", current_position[E_AXIS]);
  165. stepper.report_positions();
  166. #if IS_SCARA
  167. scara_report_positions();
  168. #endif
  169. }
  170. /**
  171. * sync_plan_position
  172. *
  173. * Set the planner/stepper positions directly from current_position with
  174. * no kinematic translation. Used for homing axes and cartesian/core syncing.
  175. */
  176. void sync_plan_position() {
  177. if (DEBUGGING(LEVELING)) DEBUG_POS("sync_plan_position", current_position);
  178. planner.set_position_mm(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  179. }
  180. void sync_plan_position_e() { planner.set_e_position_mm(current_position[E_AXIS]); }
  181. /**
  182. * Get the stepper positions in the cartes[] array.
  183. * Forward kinematics are applied for DELTA and SCARA.
  184. *
  185. * The result is in the current coordinate space with
  186. * leveling applied. The coordinates need to be run through
  187. * unapply_leveling to obtain the "ideal" coordinates
  188. * suitable for current_position, etc.
  189. */
  190. void get_cartesian_from_steppers() {
  191. #if ENABLED(DELTA)
  192. forward_kinematics_DELTA(
  193. planner.get_axis_position_mm(A_AXIS),
  194. planner.get_axis_position_mm(B_AXIS),
  195. planner.get_axis_position_mm(C_AXIS)
  196. );
  197. #else
  198. #if IS_SCARA
  199. forward_kinematics_SCARA(
  200. planner.get_axis_position_degrees(A_AXIS),
  201. planner.get_axis_position_degrees(B_AXIS)
  202. );
  203. #else
  204. cartes[X_AXIS] = planner.get_axis_position_mm(X_AXIS);
  205. cartes[Y_AXIS] = planner.get_axis_position_mm(Y_AXIS);
  206. #endif
  207. cartes[Z_AXIS] = planner.get_axis_position_mm(Z_AXIS);
  208. #endif
  209. }
  210. /**
  211. * Set the current_position for an axis based on
  212. * the stepper positions, removing any leveling that
  213. * may have been applied.
  214. *
  215. * To prevent small shifts in axis position always call
  216. * sync_plan_position after updating axes with this.
  217. *
  218. * To keep hosts in sync, always call report_current_position
  219. * after updating the current_position.
  220. */
  221. void set_current_from_steppers_for_axis(const AxisEnum axis) {
  222. get_cartesian_from_steppers();
  223. #if HAS_POSITION_MODIFIERS
  224. float pos[XYZE] = { cartes[X_AXIS], cartes[Y_AXIS], cartes[Z_AXIS], current_position[E_AXIS] };
  225. planner.unapply_modifiers(pos
  226. #if HAS_LEVELING
  227. , true
  228. #endif
  229. );
  230. const float (&cartes)[XYZE] = pos;
  231. #endif
  232. if (axis == ALL_AXES)
  233. COPY(current_position, cartes);
  234. else
  235. current_position[axis] = cartes[axis];
  236. }
  237. /**
  238. * Move the planner to the current position from wherever it last moved
  239. * (or from wherever it has been told it is located).
  240. */
  241. void line_to_current_position(const float &fr_mm_s/*=feedrate_mm_s*/) {
  242. planner.buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], fr_mm_s, active_extruder);
  243. }
  244. /**
  245. * Move the planner to the position stored in the destination array, which is
  246. * used by G0/G1/G2/G3/G5 and many other functions to set a destination.
  247. */
  248. void buffer_line_to_destination(const float fr_mm_s) {
  249. planner.buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], fr_mm_s, active_extruder);
  250. }
  251. #if IS_KINEMATIC
  252. /**
  253. * Calculate delta, start a line, and set current_position to destination
  254. */
  255. void prepare_uninterpolated_move_to_destination(const float &fr_mm_s/*=0.0*/) {
  256. if (DEBUGGING(LEVELING)) DEBUG_POS("prepare_uninterpolated_move_to_destination", destination);
  257. #if UBL_SEGMENTED
  258. // ubl segmented line will do z-only moves in single segment
  259. ubl.prepare_segmented_line_to(destination, MMS_SCALED(fr_mm_s ? fr_mm_s : feedrate_mm_s));
  260. #else
  261. if ( current_position[X_AXIS] == destination[X_AXIS]
  262. && current_position[Y_AXIS] == destination[Y_AXIS]
  263. && current_position[Z_AXIS] == destination[Z_AXIS]
  264. && current_position[E_AXIS] == destination[E_AXIS]
  265. ) return;
  266. planner.buffer_line(destination, MMS_SCALED(fr_mm_s ? fr_mm_s : feedrate_mm_s), active_extruder);
  267. #endif
  268. set_current_from_destination();
  269. }
  270. #endif // IS_KINEMATIC
  271. /**
  272. * Plan a move to (X, Y, Z) and set the current_position
  273. */
  274. void do_blocking_move_to(const float rx, const float ry, const float rz, const float &fr_mm_s/*=0.0*/) {
  275. if (DEBUGGING(LEVELING)) DEBUG_XYZ(">>> do_blocking_move_to", rx, ry, rz);
  276. const float z_feedrate = fr_mm_s ? fr_mm_s : homing_feedrate(Z_AXIS),
  277. xy_feedrate = fr_mm_s ? fr_mm_s : XY_PROBE_FEEDRATE_MM_S;
  278. #if ENABLED(DELTA)
  279. if (!position_is_reachable(rx, ry)) return;
  280. REMEMBER(fr, feedrate_mm_s, xy_feedrate);
  281. set_destination_from_current(); // sync destination at the start
  282. if (DEBUGGING(LEVELING)) DEBUG_POS("set_destination_from_current", destination);
  283. // when in the danger zone
  284. if (current_position[Z_AXIS] > delta_clip_start_height) {
  285. if (rz > delta_clip_start_height) { // staying in the danger zone
  286. destination[X_AXIS] = rx; // move directly (uninterpolated)
  287. destination[Y_AXIS] = ry;
  288. destination[Z_AXIS] = rz;
  289. prepare_uninterpolated_move_to_destination(); // set_current_from_destination()
  290. if (DEBUGGING(LEVELING)) DEBUG_POS("danger zone move", current_position);
  291. return;
  292. }
  293. destination[Z_AXIS] = delta_clip_start_height;
  294. prepare_uninterpolated_move_to_destination(); // set_current_from_destination()
  295. if (DEBUGGING(LEVELING)) DEBUG_POS("zone border move", current_position);
  296. }
  297. if (rz > current_position[Z_AXIS]) { // raising?
  298. destination[Z_AXIS] = rz;
  299. prepare_uninterpolated_move_to_destination(z_feedrate); // set_current_from_destination()
  300. if (DEBUGGING(LEVELING)) DEBUG_POS("z raise move", current_position);
  301. }
  302. destination[X_AXIS] = rx;
  303. destination[Y_AXIS] = ry;
  304. prepare_move_to_destination(); // set_current_from_destination()
  305. if (DEBUGGING(LEVELING)) DEBUG_POS("xy move", current_position);
  306. if (rz < current_position[Z_AXIS]) { // lowering?
  307. destination[Z_AXIS] = rz;
  308. prepare_uninterpolated_move_to_destination(z_feedrate); // set_current_from_destination()
  309. if (DEBUGGING(LEVELING)) DEBUG_POS("z lower move", current_position);
  310. }
  311. #elif IS_SCARA
  312. if (!position_is_reachable(rx, ry)) return;
  313. set_destination_from_current();
  314. // If Z needs to raise, do it before moving XY
  315. if (destination[Z_AXIS] < rz) {
  316. destination[Z_AXIS] = rz;
  317. prepare_uninterpolated_move_to_destination(z_feedrate);
  318. }
  319. destination[X_AXIS] = rx;
  320. destination[Y_AXIS] = ry;
  321. prepare_uninterpolated_move_to_destination(xy_feedrate);
  322. // If Z needs to lower, do it after moving XY
  323. if (destination[Z_AXIS] > rz) {
  324. destination[Z_AXIS] = rz;
  325. prepare_uninterpolated_move_to_destination(z_feedrate);
  326. }
  327. #else
  328. // If Z needs to raise, do it before moving XY
  329. if (current_position[Z_AXIS] < rz) {
  330. current_position[Z_AXIS] = rz;
  331. line_to_current_position(z_feedrate);
  332. }
  333. current_position[X_AXIS] = rx;
  334. current_position[Y_AXIS] = ry;
  335. line_to_current_position(xy_feedrate);
  336. // If Z needs to lower, do it after moving XY
  337. if (current_position[Z_AXIS] > rz) {
  338. current_position[Z_AXIS] = rz;
  339. line_to_current_position(z_feedrate);
  340. }
  341. #endif
  342. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< do_blocking_move_to");
  343. planner.synchronize();
  344. }
  345. void do_blocking_move_to_x(const float &rx, const float &fr_mm_s/*=0.0*/) {
  346. do_blocking_move_to(rx, current_position[Y_AXIS], current_position[Z_AXIS], fr_mm_s);
  347. }
  348. void do_blocking_move_to_z(const float &rz, const float &fr_mm_s/*=0.0*/) {
  349. do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], rz, fr_mm_s);
  350. }
  351. void do_blocking_move_to_xy(const float &rx, const float &ry, const float &fr_mm_s/*=0.0*/) {
  352. do_blocking_move_to(rx, ry, current_position[Z_AXIS], fr_mm_s);
  353. }
  354. //
  355. // Prepare to do endstop or probe moves with custom feedrates.
  356. // - Save / restore current feedrate and multiplier
  357. //
  358. static float saved_feedrate_mm_s;
  359. static int16_t saved_feedrate_percentage;
  360. void setup_for_endstop_or_probe_move() {
  361. saved_feedrate_mm_s = feedrate_mm_s;
  362. saved_feedrate_percentage = feedrate_percentage;
  363. feedrate_percentage = 100;
  364. }
  365. void clean_up_after_endstop_or_probe_move() {
  366. feedrate_mm_s = saved_feedrate_mm_s;
  367. feedrate_percentage = saved_feedrate_percentage;
  368. }
  369. #if HAS_SOFTWARE_ENDSTOPS
  370. bool soft_endstops_enabled = true;
  371. // Software Endstops are based on the configured limits.
  372. axis_limits_t soft_endstop[XYZ] = { { X_MIN_BED, X_MAX_BED }, { Y_MIN_BED, Y_MAX_BED }, { Z_MIN_POS, Z_MAX_POS } };
  373. /**
  374. * Software endstops can be used to monitor the open end of
  375. * an axis that has a hardware endstop on the other end. Or
  376. * they can prevent axes from moving past endstops and grinding.
  377. *
  378. * To keep doing their job as the coordinate system changes,
  379. * the software endstop positions must be refreshed to remain
  380. * at the same positions relative to the machine.
  381. */
  382. void update_software_endstops(const AxisEnum axis
  383. #if HAS_HOTEND_OFFSET
  384. , const uint8_t old_tool_index/*=0*/, const uint8_t new_tool_index/*=0*/
  385. #endif
  386. ) {
  387. #if ENABLED(DUAL_X_CARRIAGE)
  388. if (axis == X_AXIS) {
  389. // In Dual X mode hotend_offset[X] is T1's home position
  390. const float dual_max_x = MAX(hotend_offset[X_AXIS][1], X2_MAX_POS);
  391. if (new_tool_index != 0) {
  392. // T1 can move from X2_MIN_POS to X2_MAX_POS or X2 home position (whichever is larger)
  393. soft_endstop[X_AXIS].min = X2_MIN_POS;
  394. soft_endstop[X_AXIS].max = dual_max_x;
  395. }
  396. else if (dxc_is_duplicating()) {
  397. // In Duplication Mode, T0 can move as far left as X1_MIN_POS
  398. // but not so far to the right that T1 would move past the end
  399. soft_endstop[X_AXIS].min = X1_MIN_POS;
  400. soft_endstop[X_AXIS].max = MIN(X1_MAX_POS, dual_max_x - duplicate_extruder_x_offset);
  401. }
  402. else {
  403. // In other modes, T0 can move from X1_MIN_POS to X1_MAX_POS
  404. soft_endstop[X_AXIS].min = X1_MIN_POS;
  405. soft_endstop[X_AXIS].max = X1_MAX_POS;
  406. }
  407. }
  408. #elif ENABLED(DELTA)
  409. soft_endstop[axis].min = base_min_pos(axis);
  410. soft_endstop[axis].max = (axis == Z_AXIS ? delta_height
  411. #if HAS_BED_PROBE
  412. - zprobe_zoffset
  413. #endif
  414. : base_max_pos(axis));
  415. switch (axis) {
  416. case X_AXIS:
  417. case Y_AXIS:
  418. // Get a minimum radius for clamping
  419. delta_max_radius = MIN(ABS(MAX(soft_endstop[X_AXIS].min, soft_endstop[Y_AXIS].min)), soft_endstop[X_AXIS].max, soft_endstop[Y_AXIS].max);
  420. delta_max_radius_2 = sq(delta_max_radius);
  421. break;
  422. case Z_AXIS:
  423. delta_clip_start_height = soft_endstop[axis].max - delta_safe_distance_from_top();
  424. default: break;
  425. }
  426. #elif HAS_HOTEND_OFFSET
  427. // Software endstops are relative to the tool 0 workspace, so
  428. // the movement limits must be shifted by the tool offset to
  429. // retain the same physical limit when other tools are selected.
  430. if (old_tool_index != new_tool_index) {
  431. const float offs = hotend_offset[axis][new_tool_index] - hotend_offset[axis][old_tool_index];
  432. soft_endstop[axis].min += offs;
  433. soft_endstop[axis].max += offs;
  434. }
  435. else {
  436. const float offs = hotend_offset[axis][active_extruder];
  437. soft_endstop[axis].min = base_min_pos(axis) + offs;
  438. soft_endstop[axis].max = base_max_pos(axis) + offs;
  439. }
  440. #else
  441. soft_endstop[axis].min = base_min_pos(axis);
  442. soft_endstop[axis].max = base_max_pos(axis);
  443. #endif
  444. #if ENABLED(DEBUG_LEVELING_FEATURE)
  445. if (DEBUGGING(LEVELING))
  446. SERIAL_ECHOLNPAIR("Axis ", axis_codes[axis], " min:", soft_endstop[axis].min, " max:", soft_endstop[axis].max);
  447. #endif
  448. }
  449. /**
  450. * Constrain the given coordinates to the software endstops.
  451. *
  452. * For DELTA/SCARA the XY constraint is based on the smallest
  453. * radius within the set software endstops.
  454. */
  455. void apply_motion_limits(float target[XYZ]) {
  456. if (!soft_endstops_enabled) return;
  457. #if IS_KINEMATIC
  458. #if HAS_HOTEND_OFFSET && ENABLED(DELTA)
  459. // The effector center position will be the target minus the hotend offset.
  460. const float offx = hotend_offset[X_AXIS][active_extruder], offy = hotend_offset[Y_AXIS][active_extruder];
  461. #else
  462. // SCARA needs to consider the angle of the arm through the entire move, so for now use no tool offset.
  463. constexpr float offx = 0, offy = 0;
  464. #endif
  465. const float dist_2 = HYPOT2(target[X_AXIS] - offx, target[Y_AXIS] - offy);
  466. if (dist_2 > delta_max_radius_2) {
  467. const float ratio = (delta_max_radius) / SQRT(dist_2); // 200 / 300 = 0.66
  468. target[X_AXIS] *= ratio;
  469. target[Y_AXIS] *= ratio;
  470. }
  471. #else
  472. #if !HAS_SOFTWARE_ENDSTOPS || ENABLED(MIN_SOFTWARE_ENDSTOP_X)
  473. NOLESS(target[X_AXIS], soft_endstop[X_AXIS].min);
  474. #endif
  475. #if !HAS_SOFTWARE_ENDSTOPS || ENABLED(MAX_SOFTWARE_ENDSTOP_X)
  476. NOMORE(target[X_AXIS], soft_endstop[X_AXIS].max);
  477. #endif
  478. #if !HAS_SOFTWARE_ENDSTOPS || ENABLED(MIN_SOFTWARE_ENDSTOP_Y)
  479. NOLESS(target[Y_AXIS], soft_endstop[Y_AXIS].min);
  480. #endif
  481. #if !HAS_SOFTWARE_ENDSTOPS || ENABLED(MAX_SOFTWARE_ENDSTOP_Y)
  482. NOMORE(target[Y_AXIS], soft_endstop[Y_AXIS].max);
  483. #endif
  484. #endif
  485. #if !HAS_SOFTWARE_ENDSTOPS || ENABLED(MIN_SOFTWARE_ENDSTOP_Z)
  486. NOLESS(target[Z_AXIS], soft_endstop[Z_AXIS].min);
  487. #endif
  488. #if !HAS_SOFTWARE_ENDSTOPS || ENABLED(MAX_SOFTWARE_ENDSTOP_Z)
  489. NOMORE(target[Z_AXIS], soft_endstop[Z_AXIS].max);
  490. #endif
  491. }
  492. #endif // HAS_SOFTWARE_ENDSTOPS
  493. #if !UBL_SEGMENTED
  494. #if IS_KINEMATIC
  495. #if IS_SCARA
  496. /**
  497. * Before raising this value, use M665 S[seg_per_sec] to decrease
  498. * the number of segments-per-second. Default is 200. Some deltas
  499. * do better with 160 or lower. It would be good to know how many
  500. * segments-per-second are actually possible for SCARA on AVR.
  501. *
  502. * Longer segments result in less kinematic overhead
  503. * but may produce jagged lines. Try 0.5mm, 1.0mm, and 2.0mm
  504. * and compare the difference.
  505. */
  506. #define SCARA_MIN_SEGMENT_LENGTH 0.5f
  507. #endif
  508. /**
  509. * Prepare a linear move in a DELTA or SCARA setup.
  510. *
  511. * Called from prepare_move_to_destination as the
  512. * default Delta/SCARA segmenter.
  513. *
  514. * This calls planner.buffer_line several times, adding
  515. * small incremental moves for DELTA or SCARA.
  516. *
  517. * For Unified Bed Leveling (Delta or Segmented Cartesian)
  518. * the ubl.prepare_segmented_line_to method replaces this.
  519. *
  520. * For Auto Bed Leveling (Bilinear) with SEGMENT_LEVELED_MOVES
  521. * this is replaced by segmented_line_to_destination below.
  522. */
  523. inline bool prepare_kinematic_move_to(const float (&rtarget)[XYZE]) {
  524. // Get the top feedrate of the move in the XY plane
  525. const float _feedrate_mm_s = MMS_SCALED(feedrate_mm_s);
  526. const float xdiff = rtarget[X_AXIS] - current_position[X_AXIS],
  527. ydiff = rtarget[Y_AXIS] - current_position[Y_AXIS];
  528. // If the move is only in Z/E don't split up the move
  529. if (!xdiff && !ydiff) {
  530. planner.buffer_line(rtarget, _feedrate_mm_s, active_extruder);
  531. return false; // caller will update current_position
  532. }
  533. // Fail if attempting move outside printable radius
  534. if (!position_is_reachable(rtarget[X_AXIS], rtarget[Y_AXIS])) return true;
  535. // Remaining cartesian distances
  536. const float zdiff = rtarget[Z_AXIS] - current_position[Z_AXIS],
  537. ediff = rtarget[E_AXIS] - current_position[E_AXIS];
  538. // Get the linear distance in XYZ
  539. float cartesian_mm = SQRT(sq(xdiff) + sq(ydiff) + sq(zdiff));
  540. // If the move is very short, check the E move distance
  541. if (UNEAR_ZERO(cartesian_mm)) cartesian_mm = ABS(ediff);
  542. // No E move either? Game over.
  543. if (UNEAR_ZERO(cartesian_mm)) return true;
  544. // Minimum number of seconds to move the given distance
  545. const float seconds = cartesian_mm / _feedrate_mm_s;
  546. // The number of segments-per-second times the duration
  547. // gives the number of segments
  548. uint16_t segments = delta_segments_per_second * seconds;
  549. // For SCARA enforce a minimum segment size
  550. #if IS_SCARA
  551. NOMORE(segments, cartesian_mm * (1.0f / float(SCARA_MIN_SEGMENT_LENGTH)));
  552. #endif
  553. // At least one segment is required
  554. NOLESS(segments, 1U);
  555. // The approximate length of each segment
  556. const float inv_segments = 1.0f / float(segments),
  557. segment_distance[XYZE] = {
  558. xdiff * inv_segments,
  559. ydiff * inv_segments,
  560. zdiff * inv_segments,
  561. ediff * inv_segments
  562. },
  563. cartesian_segment_mm = cartesian_mm * inv_segments;
  564. #if ENABLED(SCARA_FEEDRATE_SCALING)
  565. const float inv_duration = _feedrate_mm_s / cartesian_segment_mm;
  566. #endif
  567. /*
  568. SERIAL_ECHOPAIR("mm=", cartesian_mm);
  569. SERIAL_ECHOPAIR(" seconds=", seconds);
  570. SERIAL_ECHOPAIR(" segments=", segments);
  571. SERIAL_ECHOPAIR(" segment_mm=", cartesian_segment_mm);
  572. SERIAL_EOL();
  573. //*/
  574. // Get the current position as starting point
  575. float raw[XYZE];
  576. COPY(raw, current_position);
  577. // Calculate and execute the segments
  578. while (--segments) {
  579. static millis_t next_idle_ms = millis() + 200UL;
  580. thermalManager.manage_heater(); // This returns immediately if not really needed.
  581. if (ELAPSED(millis(), next_idle_ms)) {
  582. next_idle_ms = millis() + 200UL;
  583. idle();
  584. }
  585. LOOP_XYZE(i) raw[i] += segment_distance[i];
  586. if (!planner.buffer_line(raw, _feedrate_mm_s, active_extruder, cartesian_segment_mm
  587. #if ENABLED(SCARA_FEEDRATE_SCALING)
  588. , inv_duration
  589. #endif
  590. ))
  591. break;
  592. }
  593. // Ensure last segment arrives at target location.
  594. planner.buffer_line(rtarget, _feedrate_mm_s, active_extruder, cartesian_segment_mm
  595. #if ENABLED(SCARA_FEEDRATE_SCALING)
  596. , inv_duration
  597. #endif
  598. );
  599. return false; // caller will update current_position
  600. }
  601. #else // !IS_KINEMATIC
  602. #if ENABLED(SEGMENT_LEVELED_MOVES)
  603. /**
  604. * Prepare a segmented move on a CARTESIAN setup.
  605. *
  606. * This calls planner.buffer_line several times, adding
  607. * small incremental moves. This allows the planner to
  608. * apply more detailed bed leveling to the full move.
  609. */
  610. inline void segmented_line_to_destination(const float &fr_mm_s, const float segment_size=LEVELED_SEGMENT_LENGTH) {
  611. const float xdiff = destination[X_AXIS] - current_position[X_AXIS],
  612. ydiff = destination[Y_AXIS] - current_position[Y_AXIS];
  613. // If the move is only in Z/E don't split up the move
  614. if (!xdiff && !ydiff) {
  615. planner.buffer_line(destination, fr_mm_s, active_extruder);
  616. return;
  617. }
  618. // Remaining cartesian distances
  619. const float zdiff = destination[Z_AXIS] - current_position[Z_AXIS],
  620. ediff = destination[E_AXIS] - current_position[E_AXIS];
  621. // Get the linear distance in XYZ
  622. // If the move is very short, check the E move distance
  623. // No E move either? Game over.
  624. float cartesian_mm = SQRT(sq(xdiff) + sq(ydiff) + sq(zdiff));
  625. if (UNEAR_ZERO(cartesian_mm)) cartesian_mm = ABS(ediff);
  626. if (UNEAR_ZERO(cartesian_mm)) return;
  627. // The length divided by the segment size
  628. // At least one segment is required
  629. uint16_t segments = cartesian_mm / segment_size;
  630. NOLESS(segments, 1U);
  631. // The approximate length of each segment
  632. const float inv_segments = 1.0f / float(segments),
  633. cartesian_segment_mm = cartesian_mm * inv_segments,
  634. segment_distance[XYZE] = {
  635. xdiff * inv_segments,
  636. ydiff * inv_segments,
  637. zdiff * inv_segments,
  638. ediff * inv_segments
  639. };
  640. #if ENABLED(SCARA_FEEDRATE_SCALING)
  641. const float inv_duration = _feedrate_mm_s / cartesian_segment_mm;
  642. #endif
  643. // SERIAL_ECHOPAIR("mm=", cartesian_mm);
  644. // SERIAL_ECHOLNPAIR(" segments=", segments);
  645. // SERIAL_ECHOLNPAIR(" segment_mm=", cartesian_segment_mm);
  646. // Get the raw current position as starting point
  647. float raw[XYZE];
  648. COPY(raw, current_position);
  649. // Calculate and execute the segments
  650. while (--segments) {
  651. static millis_t next_idle_ms = millis() + 200UL;
  652. thermalManager.manage_heater(); // This returns immediately if not really needed.
  653. if (ELAPSED(millis(), next_idle_ms)) {
  654. next_idle_ms = millis() + 200UL;
  655. idle();
  656. }
  657. LOOP_XYZE(i) raw[i] += segment_distance[i];
  658. if (!planner.buffer_line(raw, fr_mm_s, active_extruder, cartesian_segment_mm
  659. #if ENABLED(SCARA_FEEDRATE_SCALING)
  660. , inv_duration
  661. #endif
  662. ))
  663. break;
  664. }
  665. // Since segment_distance is only approximate,
  666. // the final move must be to the exact destination.
  667. planner.buffer_line(destination, fr_mm_s, active_extruder, cartesian_segment_mm
  668. #if ENABLED(SCARA_FEEDRATE_SCALING)
  669. , inv_duration
  670. #endif
  671. );
  672. }
  673. #endif // SEGMENT_LEVELED_MOVES
  674. /**
  675. * Prepare a linear move in a Cartesian setup.
  676. *
  677. * When a mesh-based leveling system is active, moves are segmented
  678. * according to the configuration of the leveling system.
  679. *
  680. * Returns true if current_position[] was set to destination[]
  681. */
  682. inline bool prepare_move_to_destination_cartesian() {
  683. #if HAS_MESH
  684. if (planner.leveling_active && planner.leveling_active_at_z(destination[Z_AXIS])) {
  685. #if ENABLED(AUTO_BED_LEVELING_UBL)
  686. ubl.line_to_destination_cartesian(MMS_SCALED(feedrate_mm_s), active_extruder); // UBL's motion routine needs to know about
  687. return true; // all moves, including Z-only moves.
  688. #elif ENABLED(SEGMENT_LEVELED_MOVES)
  689. segmented_line_to_destination(MMS_SCALED(feedrate_mm_s));
  690. return false; // caller will update current_position
  691. #else
  692. /**
  693. * For MBL and ABL-BILINEAR only segment moves when X or Y are involved.
  694. * Otherwise fall through to do a direct single move.
  695. */
  696. if (current_position[X_AXIS] != destination[X_AXIS] || current_position[Y_AXIS] != destination[Y_AXIS]) {
  697. #if ENABLED(MESH_BED_LEVELING)
  698. mbl.line_to_destination(MMS_SCALED(feedrate_mm_s));
  699. #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
  700. bilinear_line_to_destination(MMS_SCALED(feedrate_mm_s));
  701. #endif
  702. return true;
  703. }
  704. #endif
  705. }
  706. #endif // HAS_MESH
  707. buffer_line_to_destination(MMS_SCALED(feedrate_mm_s));
  708. return false; // caller will update current_position
  709. }
  710. #endif // !IS_KINEMATIC
  711. #endif // !UBL_SEGMENTED
  712. #if HAS_DUPLICATION_MODE
  713. bool extruder_duplication_enabled,
  714. mirrored_duplication_mode;
  715. #endif
  716. #if ENABLED(MULTI_NOZZLE_DUPLICATION) && HOTENDS > 2
  717. uint8_t duplication_e_mask; // = 0
  718. #endif
  719. #if ENABLED(DUAL_X_CARRIAGE)
  720. DualXMode dual_x_carriage_mode = DEFAULT_DUAL_X_CARRIAGE_MODE;
  721. float inactive_extruder_x_pos = X2_MAX_POS, // used in mode 0 & 1
  722. raised_parked_position[XYZE], // used in mode 1
  723. duplicate_extruder_x_offset = DEFAULT_DUPLICATION_X_OFFSET; // used in mode 2
  724. bool active_extruder_parked = false; // used in mode 1 & 2
  725. millis_t delayed_move_time = 0; // used in mode 1
  726. int16_t duplicate_extruder_temp_offset = 0; // used in mode 2
  727. float x_home_pos(const int extruder) {
  728. if (extruder == 0)
  729. return base_home_pos(X_AXIS);
  730. else
  731. /**
  732. * In dual carriage mode the extruder offset provides an override of the
  733. * second X-carriage position when homed - otherwise X2_HOME_POS is used.
  734. * This allows soft recalibration of the second extruder home position
  735. * without firmware reflash (through the M218 command).
  736. */
  737. return hotend_offset[X_AXIS][1] > 0 ? hotend_offset[X_AXIS][1] : X2_HOME_POS;
  738. }
  739. /**
  740. * Prepare a linear move in a dual X axis setup
  741. *
  742. * Return true if current_position[] was set to destination[]
  743. */
  744. inline bool dual_x_carriage_unpark() {
  745. if (active_extruder_parked) {
  746. switch (dual_x_carriage_mode) {
  747. case DXC_FULL_CONTROL_MODE:
  748. break;
  749. case DXC_AUTO_PARK_MODE:
  750. if (current_position[E_AXIS] == destination[E_AXIS]) {
  751. // This is a travel move (with no extrusion)
  752. // Skip it, but keep track of the current position
  753. // (so it can be used as the start of the next non-travel move)
  754. if (delayed_move_time != 0xFFFFFFFFUL) {
  755. set_current_from_destination();
  756. NOLESS(raised_parked_position[Z_AXIS], destination[Z_AXIS]);
  757. delayed_move_time = millis();
  758. return true;
  759. }
  760. }
  761. // unpark extruder: 1) raise, 2) move into starting XY position, 3) lower
  762. #define CUR_X current_position[X_AXIS]
  763. #define CUR_Y current_position[Y_AXIS]
  764. #define CUR_Z current_position[Z_AXIS]
  765. #define CUR_E current_position[E_AXIS]
  766. #define RAISED_X raised_parked_position[X_AXIS]
  767. #define RAISED_Y raised_parked_position[Y_AXIS]
  768. #define RAISED_Z raised_parked_position[Z_AXIS]
  769. if ( planner.buffer_line(RAISED_X, RAISED_Y, RAISED_Z, CUR_E, planner.settings.max_feedrate_mm_s[Z_AXIS], active_extruder))
  770. if (planner.buffer_line( CUR_X, CUR_Y, RAISED_Z, CUR_E, PLANNER_XY_FEEDRATE(), active_extruder))
  771. planner.buffer_line( CUR_X, CUR_Y, CUR_Z, CUR_E, planner.settings.max_feedrate_mm_s[Z_AXIS], active_extruder);
  772. delayed_move_time = 0;
  773. active_extruder_parked = false;
  774. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Clear active_extruder_parked");
  775. break;
  776. case DXC_MIRRORED_MODE:
  777. case DXC_DUPLICATION_MODE:
  778. if (active_extruder == 0) {
  779. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Set planner X", inactive_extruder_x_pos, " ... Line to X", current_position[X_AXIS] + duplicate_extruder_x_offset);
  780. // move duplicate extruder into correct duplication position.
  781. planner.set_position_mm(inactive_extruder_x_pos, current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  782. if (!planner.buffer_line(
  783. dual_x_carriage_mode == DXC_DUPLICATION_MODE ? duplicate_extruder_x_offset + current_position[X_AXIS] : inactive_extruder_x_pos,
  784. current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS],
  785. planner.settings.max_feedrate_mm_s[X_AXIS], 1
  786. )
  787. ) break;
  788. planner.synchronize();
  789. sync_plan_position();
  790. extruder_duplication_enabled = true;
  791. active_extruder_parked = false;
  792. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Set extruder_duplication_enabled\nClear active_extruder_parked");
  793. }
  794. else if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Active extruder not 0");
  795. break;
  796. }
  797. }
  798. stepper.set_directions();
  799. return false;
  800. }
  801. #endif // DUAL_X_CARRIAGE
  802. /**
  803. * Prepare a single move and get ready for the next one
  804. *
  805. * This may result in several calls to planner.buffer_line to
  806. * do smaller moves for DELTA, SCARA, mesh moves, etc.
  807. *
  808. * Make sure current_position[E] and destination[E] are good
  809. * before calling or cold/lengthy extrusion may get missed.
  810. */
  811. void prepare_move_to_destination() {
  812. apply_motion_limits(destination);
  813. #if ENABLED(PREVENT_COLD_EXTRUSION) || ENABLED(PREVENT_LENGTHY_EXTRUDE)
  814. if (!DEBUGGING(DRYRUN)) {
  815. if (destination[E_AXIS] != current_position[E_AXIS]) {
  816. #if ENABLED(PREVENT_COLD_EXTRUSION)
  817. if (thermalManager.tooColdToExtrude(active_extruder)) {
  818. current_position[E_AXIS] = destination[E_AXIS]; // Behave as if the move really took place, but ignore E part
  819. SERIAL_ECHO_MSG(MSG_ERR_COLD_EXTRUDE_STOP);
  820. }
  821. #endif // PREVENT_COLD_EXTRUSION
  822. #if ENABLED(PREVENT_LENGTHY_EXTRUDE)
  823. if (ABS(destination[E_AXIS] - current_position[E_AXIS]) * planner.e_factor[active_extruder] > (EXTRUDE_MAXLENGTH)) {
  824. current_position[E_AXIS] = destination[E_AXIS]; // Behave as if the move really took place, but ignore E part
  825. SERIAL_ECHO_MSG(MSG_ERR_LONG_EXTRUDE_STOP);
  826. }
  827. #endif // PREVENT_LENGTHY_EXTRUDE
  828. }
  829. }
  830. #endif // PREVENT_COLD_EXTRUSION || PREVENT_LENGTHY_EXTRUDE
  831. #if ENABLED(DUAL_X_CARRIAGE)
  832. if (dual_x_carriage_unpark()) return;
  833. #endif
  834. if (
  835. #if UBL_SEGMENTED
  836. //ubl.prepare_segmented_line_to(destination, MMS_SCALED(feedrate_mm_s)) // This doesn't seem to work correctly on UBL.
  837. #if IS_KINEMATIC // Use Kinematic / Cartesian cases as a workaround for now.
  838. ubl.prepare_segmented_line_to(destination, MMS_SCALED(feedrate_mm_s))
  839. #else
  840. prepare_move_to_destination_cartesian()
  841. #endif
  842. #elif IS_KINEMATIC
  843. prepare_kinematic_move_to(destination)
  844. #else
  845. prepare_move_to_destination_cartesian()
  846. #endif
  847. ) return;
  848. set_current_from_destination();
  849. }
  850. bool axis_unhomed_error(const bool x/*=true*/, const bool y/*=true*/, const bool z/*=true*/) {
  851. #if ENABLED(HOME_AFTER_DEACTIVATE)
  852. const bool xx = x && !TEST(axis_known_position, X_AXIS),
  853. yy = y && !TEST(axis_known_position, Y_AXIS),
  854. zz = z && !TEST(axis_known_position, Z_AXIS);
  855. #else
  856. const bool xx = x && !TEST(axis_homed, X_AXIS),
  857. yy = y && !TEST(axis_homed, Y_AXIS),
  858. zz = z && !TEST(axis_homed, Z_AXIS);
  859. #endif
  860. if (xx || yy || zz) {
  861. SERIAL_ECHO_START();
  862. SERIAL_ECHOPGM(MSG_HOME " ");
  863. if (xx) SERIAL_CHAR('X');
  864. if (yy) SERIAL_CHAR('Y');
  865. if (zz) SERIAL_CHAR('Z');
  866. SERIAL_ECHOLNPGM(" " MSG_FIRST);
  867. #if ENABLED(ULTRA_LCD) || ENABLED(EXTENSIBLE_UI)
  868. ui.status_printf_P(0, PSTR(MSG_HOME " %s%s%s " MSG_FIRST), xx ? MSG_X : "", yy ? MSG_Y : "", zz ? MSG_Z : "");
  869. #endif
  870. return true;
  871. }
  872. return false;
  873. }
  874. /**
  875. * Homing bump feedrate (mm/s)
  876. */
  877. float get_homing_bump_feedrate(const AxisEnum axis) {
  878. #if HOMING_Z_WITH_PROBE
  879. if (axis == Z_AXIS) return MMM_TO_MMS(Z_PROBE_SPEED_SLOW);
  880. #endif
  881. static const uint8_t homing_bump_divisor[] PROGMEM = HOMING_BUMP_DIVISOR;
  882. uint8_t hbd = pgm_read_byte(&homing_bump_divisor[axis]);
  883. if (hbd < 1) {
  884. hbd = 10;
  885. SERIAL_ECHO_MSG("Warning: Homing Bump Divisor < 1");
  886. }
  887. return homing_feedrate(axis) / hbd;
  888. }
  889. #if ENABLED(SENSORLESS_HOMING)
  890. /**
  891. * Set sensorless homing if the axis has it, accounting for Core Kinematics.
  892. */
  893. sensorless_t start_sensorless_homing_per_axis(const AxisEnum axis) {
  894. sensorless_t stealth_states { false, false, false, false, false, false, false };
  895. switch (axis) {
  896. default: break;
  897. #if X_SENSORLESS
  898. case X_AXIS:
  899. stealth_states.x = tmc_enable_stallguard(stepperX);
  900. #if AXIS_HAS_STALLGUARD(X2)
  901. stealth_states.x2 = tmc_enable_stallguard(stepperX2);
  902. #endif
  903. #if CORE_IS_XY && Y_SENSORLESS
  904. stealth_states.y = tmc_enable_stallguard(stepperY);
  905. #elif CORE_IS_XZ && Z_SENSORLESS
  906. stealth_states.z = tmc_enable_stallguard(stepperZ);
  907. #endif
  908. break;
  909. #endif
  910. #if Y_SENSORLESS
  911. case Y_AXIS:
  912. stealth_states.y = tmc_enable_stallguard(stepperY);
  913. #if AXIS_HAS_STALLGUARD(Y2)
  914. stealth_states.y2 = tmc_enable_stallguard(stepperY2);
  915. #endif
  916. #if CORE_IS_XY && X_SENSORLESS
  917. stealth_states.x = tmc_enable_stallguard(stepperX);
  918. #elif CORE_IS_YZ && Z_SENSORLESS
  919. stealth_states.z = tmc_enable_stallguard(stepperZ);
  920. #endif
  921. break;
  922. #endif
  923. #if Z_SENSORLESS
  924. case Z_AXIS:
  925. stealth_states.z = tmc_enable_stallguard(stepperZ);
  926. #if AXIS_HAS_STALLGUARD(Z2)
  927. stealth_states.z2 = tmc_enable_stallguard(stepperZ2);
  928. #endif
  929. #if AXIS_HAS_STALLGUARD(Z3)
  930. stealth_states.z3 = tmc_enable_stallguard(stepperZ3);
  931. #endif
  932. #if CORE_IS_XZ && X_SENSORLESS
  933. stealth_states.x = tmc_enable_stallguard(stepperX);
  934. #elif CORE_IS_YZ && Y_SENSORLESS
  935. stealth_states.y = tmc_enable_stallguard(stepperY);
  936. #endif
  937. break;
  938. #endif
  939. }
  940. return stealth_states;
  941. }
  942. void end_sensorless_homing_per_axis(const AxisEnum axis, sensorless_t enable_stealth) {
  943. switch (axis) {
  944. default: break;
  945. #if X_SENSORLESS
  946. case X_AXIS:
  947. tmc_disable_stallguard(stepperX, enable_stealth.x);
  948. #if AXIS_HAS_STALLGUARD(X2)
  949. tmc_disable_stallguard(stepperX2, enable_stealth.x2);
  950. #endif
  951. #if CORE_IS_XY && Y_SENSORLESS
  952. tmc_disable_stallguard(stepperY, enable_stealth.y);
  953. #elif CORE_IS_XZ && Z_SENSORLESS
  954. tmc_disable_stallguard(stepperZ, enable_stealth.z);
  955. #endif
  956. break;
  957. #endif
  958. #if Y_SENSORLESS
  959. case Y_AXIS:
  960. tmc_disable_stallguard(stepperY, enable_stealth.y);
  961. #if AXIS_HAS_STALLGUARD(Y2)
  962. tmc_disable_stallguard(stepperY2, enable_stealth.y2);
  963. #endif
  964. #if CORE_IS_XY && X_SENSORLESS
  965. tmc_disable_stallguard(stepperX, enable_stealth.x);
  966. #elif CORE_IS_YZ && Z_SENSORLESS
  967. tmc_disable_stallguard(stepperZ, enable_stealth.z);
  968. #endif
  969. break;
  970. #endif
  971. #if Z_SENSORLESS
  972. case Z_AXIS:
  973. tmc_disable_stallguard(stepperZ, enable_stealth.z);
  974. #if AXIS_HAS_STALLGUARD(Z2)
  975. tmc_disable_stallguard(stepperZ2, enable_stealth.z2);
  976. #endif
  977. #if AXIS_HAS_STALLGUARD(Z3)
  978. tmc_disable_stallguard(stepperZ3, enable_stealth.z3);
  979. #endif
  980. #if CORE_IS_XZ && X_SENSORLESS
  981. tmc_disable_stallguard(stepperX, enable_stealth.x);
  982. #elif CORE_IS_YZ && Y_SENSORLESS
  983. tmc_disable_stallguard(stepperY, enable_stealth.y);
  984. #endif
  985. break;
  986. #endif
  987. }
  988. }
  989. #endif // SENSORLESS_HOMING
  990. /**
  991. * Home an individual linear axis
  992. */
  993. void do_homing_move(const AxisEnum axis, const float distance, const float fr_mm_s=0.0) {
  994. if (DEBUGGING(LEVELING)) {
  995. DEBUG_ECHOPAIR(">>> do_homing_move(", axis_codes[axis], ", ", distance, ", ");
  996. if (fr_mm_s)
  997. DEBUG_ECHO(fr_mm_s);
  998. else
  999. DEBUG_ECHOPAIR("[", homing_feedrate(axis), "]");
  1000. DEBUG_ECHOLNPGM(")");
  1001. }
  1002. #if HOMING_Z_WITH_PROBE && HAS_HEATED_BED && ENABLED(WAIT_FOR_BED_HEATER)
  1003. // Wait for bed to heat back up between probing points
  1004. if (axis == Z_AXIS && distance < 0 && thermalManager.isHeatingBed()) {
  1005. serialprintPGM(msg_wait_for_bed_heating);
  1006. LCD_MESSAGEPGM(MSG_BED_HEATING);
  1007. thermalManager.wait_for_bed();
  1008. ui.reset_status();
  1009. }
  1010. #endif
  1011. // Only do some things when moving towards an endstop
  1012. const int8_t axis_home_dir =
  1013. #if ENABLED(DUAL_X_CARRIAGE)
  1014. (axis == X_AXIS) ? x_home_dir(active_extruder) :
  1015. #endif
  1016. home_dir(axis);
  1017. const bool is_home_dir = (axis_home_dir > 0) == (distance > 0);
  1018. #if ENABLED(SENSORLESS_HOMING)
  1019. sensorless_t stealth_states;
  1020. #endif
  1021. if (is_home_dir) {
  1022. #if HOMING_Z_WITH_PROBE && QUIET_PROBING
  1023. if (axis == Z_AXIS) probing_pause(true);
  1024. #endif
  1025. // Disable stealthChop if used. Enable diag1 pin on driver.
  1026. #if ENABLED(SENSORLESS_HOMING)
  1027. stealth_states = start_sensorless_homing_per_axis(axis);
  1028. #endif
  1029. }
  1030. #if IS_SCARA
  1031. // Tell the planner the axis is at 0
  1032. current_position[axis] = 0;
  1033. sync_plan_position();
  1034. current_position[axis] = distance;
  1035. planner.buffer_line(current_position, fr_mm_s ? fr_mm_s : homing_feedrate(axis), active_extruder);
  1036. #else
  1037. float target[ABCE] = { planner.get_axis_position_mm(A_AXIS), planner.get_axis_position_mm(B_AXIS), planner.get_axis_position_mm(C_AXIS), planner.get_axis_position_mm(E_AXIS) };
  1038. target[axis] = 0;
  1039. planner.set_machine_position_mm(target);
  1040. target[axis] = distance;
  1041. #if IS_KINEMATIC && ENABLED(JUNCTION_DEVIATION)
  1042. const float delta_mm_cart[XYZE] = {0, 0, 0, 0};
  1043. #endif
  1044. // Set delta/cartesian axes directly
  1045. planner.buffer_segment(target
  1046. #if IS_KINEMATIC && ENABLED(JUNCTION_DEVIATION)
  1047. , delta_mm_cart
  1048. #endif
  1049. , fr_mm_s ? fr_mm_s : homing_feedrate(axis), active_extruder
  1050. );
  1051. #endif
  1052. planner.synchronize();
  1053. if (is_home_dir) {
  1054. #if HOMING_Z_WITH_PROBE && QUIET_PROBING
  1055. if (axis == Z_AXIS) probing_pause(false);
  1056. #endif
  1057. endstops.validate_homing_move();
  1058. // Re-enable stealthChop if used. Disable diag1 pin on driver.
  1059. #if ENABLED(SENSORLESS_HOMING)
  1060. end_sensorless_homing_per_axis(axis, stealth_states);
  1061. #endif
  1062. }
  1063. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("<<< do_homing_move(", axis_codes[axis], ")");
  1064. }
  1065. /**
  1066. * Set an axis' current position to its home position (after homing).
  1067. *
  1068. * For Core and Cartesian robots this applies one-to-one when an
  1069. * individual axis has been homed.
  1070. *
  1071. * DELTA should wait until all homing is done before setting the XYZ
  1072. * current_position to home, because homing is a single operation.
  1073. * In the case where the axis positions are already known and previously
  1074. * homed, DELTA could home to X or Y individually by moving either one
  1075. * to the center. However, homing Z always homes XY and Z.
  1076. *
  1077. * SCARA should wait until all XY homing is done before setting the XY
  1078. * current_position to home, because neither X nor Y is at home until
  1079. * both are at home. Z can however be homed individually.
  1080. *
  1081. * Callers must sync the planner position after calling this!
  1082. */
  1083. void set_axis_is_at_home(const AxisEnum axis) {
  1084. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR(">>> set_axis_is_at_home(", axis_codes[axis], ")");
  1085. SBI(axis_known_position, axis);
  1086. SBI(axis_homed, axis);
  1087. #if HAS_POSITION_SHIFT
  1088. position_shift[axis] = 0;
  1089. update_workspace_offset(axis);
  1090. #endif
  1091. #if ENABLED(DUAL_X_CARRIAGE)
  1092. if (axis == X_AXIS && (active_extruder == 1 || dual_x_carriage_mode == DXC_DUPLICATION_MODE)) {
  1093. current_position[X_AXIS] = x_home_pos(active_extruder);
  1094. return;
  1095. }
  1096. #endif
  1097. #if ENABLED(MORGAN_SCARA)
  1098. scara_set_axis_is_at_home(axis);
  1099. #elif ENABLED(DELTA)
  1100. current_position[axis] = (axis == Z_AXIS ? delta_height
  1101. #if HAS_BED_PROBE
  1102. - zprobe_zoffset
  1103. #endif
  1104. : base_home_pos(axis));
  1105. #else
  1106. current_position[axis] = base_home_pos(axis);
  1107. #endif
  1108. /**
  1109. * Z Probe Z Homing? Account for the probe's Z offset.
  1110. */
  1111. #if HAS_BED_PROBE && Z_HOME_DIR < 0
  1112. if (axis == Z_AXIS) {
  1113. #if HOMING_Z_WITH_PROBE
  1114. current_position[Z_AXIS] -= zprobe_zoffset;
  1115. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("*** Z HOMED WITH PROBE (Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) ***\n> zprobe_zoffset = ", zprobe_zoffset);
  1116. #else
  1117. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("*** Z HOMED TO ENDSTOP ***");
  1118. #endif
  1119. }
  1120. #endif
  1121. if (DEBUGGING(LEVELING)) {
  1122. #if HAS_HOME_OFFSET
  1123. DEBUG_ECHOLNPAIR("> home_offset[", axis_codes[axis], "] = ", home_offset[axis]);
  1124. #endif
  1125. DEBUG_POS("", current_position);
  1126. DEBUG_ECHOLNPAIR("<<< set_axis_is_at_home(", axis_codes[axis], ")");
  1127. }
  1128. #if ENABLED(I2C_POSITION_ENCODERS)
  1129. I2CPEM.homed(axis);
  1130. #endif
  1131. }
  1132. /**
  1133. * Set an axis' to be unhomed.
  1134. */
  1135. void set_axis_is_not_at_home(const AxisEnum axis) {
  1136. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR(">>> set_axis_is_not_at_home(", axis_codes[axis], ")");
  1137. CBI(axis_known_position, axis);
  1138. CBI(axis_homed, axis);
  1139. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("<<< set_axis_is_not_at_home(", axis_codes[axis], ")");
  1140. #if ENABLED(I2C_POSITION_ENCODERS)
  1141. I2CPEM.unhomed(axis);
  1142. #endif
  1143. }
  1144. /**
  1145. * Home an individual "raw axis" to its endstop.
  1146. * This applies to XYZ on Cartesian and Core robots, and
  1147. * to the individual ABC steppers on DELTA and SCARA.
  1148. *
  1149. * At the end of the procedure the axis is marked as
  1150. * homed and the current position of that axis is updated.
  1151. * Kinematic robots should wait till all axes are homed
  1152. * before updating the current position.
  1153. */
  1154. void homeaxis(const AxisEnum axis) {
  1155. #if IS_SCARA
  1156. // Only Z homing (with probe) is permitted
  1157. if (axis != Z_AXIS) { BUZZ(100, 880); return; }
  1158. #else
  1159. #define CAN_HOME(A) \
  1160. (axis == _AXIS(A) && ((A##_MIN_PIN > -1 && A##_HOME_DIR < 0) || (A##_MAX_PIN > -1 && A##_HOME_DIR > 0)))
  1161. if (!CAN_HOME(X) && !CAN_HOME(Y) && !CAN_HOME(Z)) return;
  1162. #endif
  1163. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR(">>> homeaxis(", axis_codes[axis], ")");
  1164. const int axis_home_dir = (
  1165. #if ENABLED(DUAL_X_CARRIAGE)
  1166. axis == X_AXIS ? x_home_dir(active_extruder) :
  1167. #endif
  1168. home_dir(axis)
  1169. );
  1170. // Homing Z towards the bed? Deploy the Z probe or endstop.
  1171. #if HOMING_Z_WITH_PROBE
  1172. if (axis == Z_AXIS && DEPLOY_PROBE()) return;
  1173. #endif
  1174. // Set flags for X, Y, Z motor locking
  1175. #if HAS_EXTRA_ENDSTOPS
  1176. switch (axis) {
  1177. #if ENABLED(X_DUAL_ENDSTOPS)
  1178. case X_AXIS:
  1179. #endif
  1180. #if ENABLED(Y_DUAL_ENDSTOPS)
  1181. case Y_AXIS:
  1182. #endif
  1183. #if Z_MULTI_ENDSTOPS
  1184. case Z_AXIS:
  1185. #endif
  1186. stepper.set_separate_multi_axis(true);
  1187. default: break;
  1188. }
  1189. #endif
  1190. // Fast move towards endstop until triggered
  1191. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Home 1 Fast:");
  1192. #if HOMING_Z_WITH_PROBE && ENABLED(BLTOUCH)
  1193. // BLTOUCH needs to be deployed every time
  1194. if (axis == Z_AXIS && set_bltouch_deployed(true)) return;
  1195. #endif
  1196. do_homing_move(axis, 1.5f * max_length(
  1197. #if ENABLED(DELTA)
  1198. Z_AXIS
  1199. #else
  1200. axis
  1201. #endif
  1202. ) * axis_home_dir
  1203. );
  1204. #if HOMING_Z_WITH_PROBE && ENABLED(BLTOUCH)
  1205. // BLTOUCH needs to be stowed after trigger to rearm itself
  1206. if (axis == Z_AXIS) set_bltouch_deployed(false);
  1207. #endif
  1208. // When homing Z with probe respect probe clearance
  1209. const float bump = axis_home_dir * (
  1210. #if HOMING_Z_WITH_PROBE
  1211. (axis == Z_AXIS && (Z_HOME_BUMP_MM)) ? MAX(Z_CLEARANCE_BETWEEN_PROBES, Z_HOME_BUMP_MM) :
  1212. #endif
  1213. home_bump_mm(axis)
  1214. );
  1215. // If a second homing move is configured...
  1216. if (bump) {
  1217. // Move away from the endstop by the axis HOME_BUMP_MM
  1218. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Move Away:");
  1219. do_homing_move(axis, -bump
  1220. #if HOMING_Z_WITH_PROBE
  1221. , axis == Z_AXIS ? MMM_TO_MMS(Z_PROBE_SPEED_FAST) : 0.0
  1222. #endif
  1223. );
  1224. // Slow move towards endstop until triggered
  1225. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Home 2 Slow:");
  1226. #if HOMING_Z_WITH_PROBE && ENABLED(BLTOUCH)
  1227. // BLTOUCH needs to be deployed every time
  1228. if (axis == Z_AXIS && set_bltouch_deployed(true)) return;
  1229. #endif
  1230. do_homing_move(axis, 2 * bump, get_homing_bump_feedrate(axis));
  1231. #if HOMING_Z_WITH_PROBE && ENABLED(BLTOUCH)
  1232. // BLTOUCH needs to be stowed after trigger to rearm itself
  1233. if (axis == Z_AXIS) set_bltouch_deployed(false);
  1234. #endif
  1235. }
  1236. #if HAS_EXTRA_ENDSTOPS
  1237. const bool pos_dir = axis_home_dir > 0;
  1238. #if ENABLED(X_DUAL_ENDSTOPS)
  1239. if (axis == X_AXIS) {
  1240. const float adj = ABS(endstops.x2_endstop_adj);
  1241. if (adj) {
  1242. if (pos_dir ? (endstops.x2_endstop_adj > 0) : (endstops.x2_endstop_adj < 0)) stepper.set_x_lock(true); else stepper.set_x2_lock(true);
  1243. do_homing_move(axis, pos_dir ? -adj : adj);
  1244. stepper.set_x_lock(false);
  1245. stepper.set_x2_lock(false);
  1246. }
  1247. }
  1248. #endif
  1249. #if ENABLED(Y_DUAL_ENDSTOPS)
  1250. if (axis == Y_AXIS) {
  1251. const float adj = ABS(endstops.y2_endstop_adj);
  1252. if (adj) {
  1253. if (pos_dir ? (endstops.y2_endstop_adj > 0) : (endstops.y2_endstop_adj < 0)) stepper.set_y_lock(true); else stepper.set_y2_lock(true);
  1254. do_homing_move(axis, pos_dir ? -adj : adj);
  1255. stepper.set_y_lock(false);
  1256. stepper.set_y2_lock(false);
  1257. }
  1258. }
  1259. #endif
  1260. #if ENABLED(Z_DUAL_ENDSTOPS)
  1261. if (axis == Z_AXIS) {
  1262. const float adj = ABS(endstops.z2_endstop_adj);
  1263. if (adj) {
  1264. if (pos_dir ? (endstops.z2_endstop_adj > 0) : (endstops.z2_endstop_adj < 0)) stepper.set_z_lock(true); else stepper.set_z2_lock(true);
  1265. do_homing_move(axis, pos_dir ? -adj : adj);
  1266. stepper.set_z_lock(false);
  1267. stepper.set_z2_lock(false);
  1268. }
  1269. }
  1270. #endif
  1271. #if ENABLED(Z_TRIPLE_ENDSTOPS)
  1272. if (axis == Z_AXIS) {
  1273. // we push the function pointers for the stepper lock function into an array
  1274. void (*lock[3]) (bool)= {&stepper.set_z_lock, &stepper.set_z2_lock, &stepper.set_z3_lock};
  1275. float adj[3] = {0, endstops.z2_endstop_adj, endstops.z3_endstop_adj};
  1276. void (*tempLock) (bool);
  1277. float tempAdj;
  1278. // manual bubble sort by adjust value
  1279. if (adj[1] < adj[0]) {
  1280. tempLock = lock[0], tempAdj = adj[0];
  1281. lock[0] = lock[1], adj[0] = adj[1];
  1282. lock[1] = tempLock, adj[1] = tempAdj;
  1283. }
  1284. if (adj[2] < adj[1]) {
  1285. tempLock = lock[1], tempAdj = adj[1];
  1286. lock[1] = lock[2], adj[1] = adj[2];
  1287. lock[2] = tempLock, adj[2] = tempAdj;
  1288. }
  1289. if (adj[1] < adj[0]) {
  1290. tempLock = lock[0], tempAdj = adj[0];
  1291. lock[0] = lock[1], adj[0] = adj[1];
  1292. lock[1] = tempLock, adj[1] = tempAdj;
  1293. }
  1294. if (pos_dir) {
  1295. // normalize adj to smallest value and do the first move
  1296. (*lock[0])(true);
  1297. do_homing_move(axis, adj[1] - adj[0]);
  1298. // lock the second stepper for the final correction
  1299. (*lock[1])(true);
  1300. do_homing_move(axis, adj[2] - adj[1]);
  1301. }
  1302. else {
  1303. (*lock[2])(true);
  1304. do_homing_move(axis, adj[1] - adj[2]);
  1305. (*lock[1])(true);
  1306. do_homing_move(axis, adj[0] - adj[1]);
  1307. }
  1308. stepper.set_z_lock(false);
  1309. stepper.set_z2_lock(false);
  1310. stepper.set_z3_lock(false);
  1311. }
  1312. #endif
  1313. // Reset flags for X, Y, Z motor locking
  1314. switch (axis) {
  1315. #if ENABLED(X_DUAL_ENDSTOPS)
  1316. case X_AXIS:
  1317. #endif
  1318. #if ENABLED(Y_DUAL_ENDSTOPS)
  1319. case Y_AXIS:
  1320. #endif
  1321. #if Z_MULTI_ENDSTOPS
  1322. case Z_AXIS:
  1323. #endif
  1324. stepper.set_separate_multi_axis(false);
  1325. default: break;
  1326. }
  1327. #endif
  1328. #if IS_SCARA
  1329. set_axis_is_at_home(axis);
  1330. sync_plan_position();
  1331. #elif ENABLED(DELTA)
  1332. // Delta has already moved all three towers up in G28
  1333. // so here it re-homes each tower in turn.
  1334. // Delta homing treats the axes as normal linear axes.
  1335. // retrace by the amount specified in delta_endstop_adj + additional dist in order to have minimum steps
  1336. if (delta_endstop_adj[axis] * Z_HOME_DIR <= 0) {
  1337. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("delta_endstop_adj:");
  1338. do_homing_move(axis, delta_endstop_adj[axis] - (MIN_STEPS_PER_SEGMENT + 1) * planner.steps_to_mm[axis] * Z_HOME_DIR);
  1339. }
  1340. #else // CARTESIAN / CORE
  1341. set_axis_is_at_home(axis);
  1342. sync_plan_position();
  1343. destination[axis] = current_position[axis];
  1344. if (DEBUGGING(LEVELING)) DEBUG_POS("> AFTER set_axis_is_at_home", current_position);
  1345. #endif
  1346. // Put away the Z probe
  1347. #if HOMING_Z_WITH_PROBE
  1348. if (axis == Z_AXIS && STOW_PROBE()) return;
  1349. #endif
  1350. // Clear retracted status if homing the Z axis
  1351. #if ENABLED(FWRETRACT)
  1352. if (axis == Z_AXIS) fwretract.current_hop = 0.0;
  1353. #endif
  1354. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("<<< homeaxis(", axis_codes[axis], ")");
  1355. } // homeaxis()
  1356. #if HAS_WORKSPACE_OFFSET
  1357. void update_workspace_offset(const AxisEnum axis) {
  1358. workspace_offset[axis] = home_offset[axis] + position_shift[axis];
  1359. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Axis ", axis_codes[axis], " home_offset = ", home_offset[axis], " position_shift = ", position_shift[axis]);
  1360. }
  1361. #endif
  1362. #if HAS_M206_COMMAND
  1363. /**
  1364. * Change the home offset for an axis.
  1365. * Also refreshes the workspace offset.
  1366. */
  1367. void set_home_offset(const AxisEnum axis, const float v) {
  1368. home_offset[axis] = v;
  1369. update_workspace_offset(axis);
  1370. }
  1371. #endif // HAS_M206_COMMAND