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

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