My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

motion.cpp 52KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604
  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. /**
  59. * axis_homed
  60. * Flags that each linear axis was homed.
  61. * XYZ on cartesian, ABC on delta, ABZ on SCARA.
  62. *
  63. * axis_known_position
  64. * Flags that the position is known in each linear axis. Set when homed.
  65. * Cleared whenever a stepper powers off, potentially losing its position.
  66. */
  67. uint8_t axis_homed, axis_known_position; // = 0
  68. // Relative Mode. Enable with G91, disable with G90.
  69. bool relative_mode; // = false;
  70. /**
  71. * Cartesian Current Position
  72. * Used to track the native machine position as moves are queued.
  73. * Used by 'buffer_line_to_current_position' to do a move after changing it.
  74. * Used by 'sync_plan_position' to update 'planner.position'.
  75. */
  76. float current_position[XYZE] = { 0 };
  77. /**
  78. * Cartesian Destination
  79. * The destination for a move, filled in by G-code movement commands,
  80. * and expected by functions like 'prepare_move_to_destination'.
  81. * Set with 'get_destination_from_command' or 'set_destination_from_current'.
  82. */
  83. float destination[XYZE] = { 0 };
  84. // The active extruder (tool). Set with T<extruder> command.
  85. #if EXTRUDERS > 1
  86. uint8_t active_extruder; // = 0
  87. #endif
  88. // Extruder offsets
  89. #if HAS_HOTEND_OFFSET
  90. float hotend_offset[XYZ][HOTENDS]; // Initialized by settings.load()
  91. #endif
  92. // The feedrate for the current move, often used as the default if
  93. // no other feedrate is specified. Overridden for special moves.
  94. // Set by the last G0 through G5 command's "F" parameter.
  95. // Functions that override this for custom moves *must always* restore it!
  96. float feedrate_mm_s = MMM_TO_MMS(1500.0f);
  97. int16_t feedrate_percentage = 100;
  98. // Homing feedrate is const progmem - compare to constexpr in the header
  99. const float homing_feedrate_mm_s[4] PROGMEM = {
  100. #if ENABLED(DELTA)
  101. MMM_TO_MMS(HOMING_FEEDRATE_Z), MMM_TO_MMS(HOMING_FEEDRATE_Z),
  102. #else
  103. MMM_TO_MMS(HOMING_FEEDRATE_XY), MMM_TO_MMS(HOMING_FEEDRATE_XY),
  104. #endif
  105. MMM_TO_MMS(HOMING_FEEDRATE_Z), 0
  106. };
  107. // Cartesian conversion result goes here:
  108. float cartes[XYZ];
  109. #if IS_KINEMATIC
  110. float delta[ABC];
  111. #endif
  112. #if HAS_SCARA_OFFSET
  113. float scara_home_offset[ABC];
  114. #endif
  115. /**
  116. * The workspace can be offset by some commands, or
  117. * these offsets may be omitted to save on computation.
  118. */
  119. #if HAS_POSITION_SHIFT
  120. // The distance that XYZ has been offset by G92. Reset by G28.
  121. float position_shift[XYZ] = { 0 };
  122. #endif
  123. #if HAS_HOME_OFFSET
  124. // This offset is added to the configured home position.
  125. // Set by M206, M428, or menu item. Saved to EEPROM.
  126. float home_offset[XYZ] = { 0 };
  127. #endif
  128. #if HAS_HOME_OFFSET && HAS_POSITION_SHIFT
  129. // The above two are combined to save on computes
  130. float workspace_offset[XYZ] = { 0 };
  131. #endif
  132. #if OLDSCHOOL_ABL
  133. float xy_probe_feedrate_mm_s = MMM_TO_MMS(XY_PROBE_SPEED);
  134. #endif
  135. /**
  136. * Output the current position to serial
  137. */
  138. void report_current_position() {
  139. SERIAL_PROTOCOLPGM("X:");
  140. SERIAL_PROTOCOL(LOGICAL_X_POSITION(current_position[X_AXIS]));
  141. SERIAL_PROTOCOLPGM(" Y:");
  142. SERIAL_PROTOCOL(LOGICAL_Y_POSITION(current_position[Y_AXIS]));
  143. SERIAL_PROTOCOLPGM(" Z:");
  144. SERIAL_PROTOCOL(LOGICAL_Z_POSITION(current_position[Z_AXIS]));
  145. SERIAL_PROTOCOLPGM(" E:");
  146. SERIAL_PROTOCOL(current_position[E_AXIS]);
  147. stepper.report_positions();
  148. #if IS_SCARA
  149. scara_report_positions();
  150. #endif
  151. }
  152. /**
  153. * sync_plan_position
  154. *
  155. * Set the planner/stepper positions directly from current_position with
  156. * no kinematic translation. Used for homing axes and cartesian/core syncing.
  157. */
  158. void sync_plan_position() {
  159. #if ENABLED(DEBUG_LEVELING_FEATURE)
  160. if (DEBUGGING(LEVELING)) DEBUG_POS("sync_plan_position", current_position);
  161. #endif
  162. planner.set_position_mm(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  163. }
  164. void sync_plan_position_e() { planner.set_e_position_mm(current_position[E_AXIS]); }
  165. /**
  166. * Get the stepper positions in the cartes[] array.
  167. * Forward kinematics are applied for DELTA and SCARA.
  168. *
  169. * The result is in the current coordinate space with
  170. * leveling applied. The coordinates need to be run through
  171. * unapply_leveling to obtain the "ideal" coordinates
  172. * suitable for current_position, etc.
  173. */
  174. void get_cartesian_from_steppers() {
  175. #if ENABLED(DELTA)
  176. forward_kinematics_DELTA(
  177. planner.get_axis_position_mm(A_AXIS),
  178. planner.get_axis_position_mm(B_AXIS),
  179. planner.get_axis_position_mm(C_AXIS)
  180. );
  181. #else
  182. #if IS_SCARA
  183. forward_kinematics_SCARA(
  184. planner.get_axis_position_degrees(A_AXIS),
  185. planner.get_axis_position_degrees(B_AXIS)
  186. );
  187. #else
  188. cartes[X_AXIS] = planner.get_axis_position_mm(X_AXIS);
  189. cartes[Y_AXIS] = planner.get_axis_position_mm(Y_AXIS);
  190. #endif
  191. cartes[Z_AXIS] = planner.get_axis_position_mm(Z_AXIS);
  192. #endif
  193. }
  194. /**
  195. * Set the current_position for an axis based on
  196. * the stepper positions, removing any leveling that
  197. * may have been applied.
  198. *
  199. * To prevent small shifts in axis position always call
  200. * sync_plan_position after updating axes with this.
  201. *
  202. * To keep hosts in sync, always call report_current_position
  203. * after updating the current_position.
  204. */
  205. void set_current_from_steppers_for_axis(const AxisEnum axis) {
  206. get_cartesian_from_steppers();
  207. #if HAS_POSITION_MODIFIERS
  208. float pos[XYZE] = { cartes[X_AXIS], cartes[Y_AXIS], cartes[Z_AXIS], current_position[E_AXIS] };
  209. planner.unapply_modifiers(pos
  210. #if HAS_LEVELING
  211. , true
  212. #endif
  213. );
  214. const float (&cartes)[XYZE] = pos;
  215. #endif
  216. if (axis == ALL_AXES)
  217. COPY(current_position, cartes);
  218. else
  219. current_position[axis] = cartes[axis];
  220. }
  221. /**
  222. * Move the planner to the current position from wherever it last moved
  223. * (or from wherever it has been told it is located).
  224. */
  225. void line_to_current_position() {
  226. planner.buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate_mm_s, active_extruder);
  227. }
  228. /**
  229. * Move the planner to the position stored in the destination array, which is
  230. * used by G0/G1/G2/G3/G5 and many other functions to set a destination.
  231. */
  232. void buffer_line_to_destination(const float fr_mm_s) {
  233. planner.buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], fr_mm_s, active_extruder);
  234. }
  235. #if IS_KINEMATIC
  236. /**
  237. * Calculate delta, start a line, and set current_position to destination
  238. */
  239. void prepare_uninterpolated_move_to_destination(const float fr_mm_s/*=0.0*/) {
  240. #if ENABLED(DEBUG_LEVELING_FEATURE)
  241. if (DEBUGGING(LEVELING)) DEBUG_POS("prepare_uninterpolated_move_to_destination", destination);
  242. #endif
  243. #if UBL_SEGMENTED
  244. // ubl segmented line will do z-only moves in single segment
  245. ubl.prepare_segmented_line_to(destination, MMS_SCALED(fr_mm_s ? fr_mm_s : feedrate_mm_s));
  246. #else
  247. if ( current_position[X_AXIS] == destination[X_AXIS]
  248. && current_position[Y_AXIS] == destination[Y_AXIS]
  249. && current_position[Z_AXIS] == destination[Z_AXIS]
  250. && current_position[E_AXIS] == destination[E_AXIS]
  251. ) return;
  252. planner.buffer_line(destination, MMS_SCALED(fr_mm_s ? fr_mm_s : feedrate_mm_s), active_extruder);
  253. #endif
  254. set_current_from_destination();
  255. }
  256. #endif // IS_KINEMATIC
  257. /**
  258. * Plan a move to (X, Y, Z) and set the current_position
  259. */
  260. void do_blocking_move_to(const float rx, const float ry, const float rz, const float &fr_mm_s/*=0.0*/) {
  261. const float old_feedrate_mm_s = feedrate_mm_s;
  262. #if ENABLED(DEBUG_LEVELING_FEATURE)
  263. if (DEBUGGING(LEVELING)) print_xyz(PSTR(">>> do_blocking_move_to"), NULL, rx, ry, rz);
  264. #endif
  265. const float z_feedrate = fr_mm_s ? fr_mm_s : homing_feedrate(Z_AXIS);
  266. #if ENABLED(DELTA)
  267. if (!position_is_reachable(rx, ry)) return;
  268. feedrate_mm_s = fr_mm_s ? fr_mm_s : XY_PROBE_FEEDRATE_MM_S;
  269. set_destination_from_current(); // sync destination at the start
  270. #if ENABLED(DEBUG_LEVELING_FEATURE)
  271. if (DEBUGGING(LEVELING)) DEBUG_POS("set_destination_from_current", destination);
  272. #endif
  273. // when in the danger zone
  274. if (current_position[Z_AXIS] > delta_clip_start_height) {
  275. if (rz > delta_clip_start_height) { // staying in the danger zone
  276. destination[X_AXIS] = rx; // move directly (uninterpolated)
  277. destination[Y_AXIS] = ry;
  278. destination[Z_AXIS] = rz;
  279. prepare_uninterpolated_move_to_destination(); // set_current_from_destination()
  280. #if ENABLED(DEBUG_LEVELING_FEATURE)
  281. if (DEBUGGING(LEVELING)) DEBUG_POS("danger zone move", current_position);
  282. #endif
  283. return;
  284. }
  285. destination[Z_AXIS] = delta_clip_start_height;
  286. prepare_uninterpolated_move_to_destination(); // set_current_from_destination()
  287. #if ENABLED(DEBUG_LEVELING_FEATURE)
  288. if (DEBUGGING(LEVELING)) DEBUG_POS("zone border move", current_position);
  289. #endif
  290. }
  291. if (rz > current_position[Z_AXIS]) { // raising?
  292. destination[Z_AXIS] = rz;
  293. prepare_uninterpolated_move_to_destination(z_feedrate); // set_current_from_destination()
  294. #if ENABLED(DEBUG_LEVELING_FEATURE)
  295. if (DEBUGGING(LEVELING)) DEBUG_POS("z raise move", current_position);
  296. #endif
  297. }
  298. destination[X_AXIS] = rx;
  299. destination[Y_AXIS] = ry;
  300. prepare_move_to_destination(); // set_current_from_destination()
  301. #if ENABLED(DEBUG_LEVELING_FEATURE)
  302. if (DEBUGGING(LEVELING)) DEBUG_POS("xy move", current_position);
  303. #endif
  304. if (rz < current_position[Z_AXIS]) { // lowering?
  305. destination[Z_AXIS] = rz;
  306. prepare_uninterpolated_move_to_destination(z_feedrate); // set_current_from_destination()
  307. #if ENABLED(DEBUG_LEVELING_FEATURE)
  308. if (DEBUGGING(LEVELING)) DEBUG_POS("z lower move", current_position);
  309. #endif
  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(fr_mm_s ? fr_mm_s : XY_PROBE_FEEDRATE_MM_S);
  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. feedrate_mm_s = z_feedrate;
  331. current_position[Z_AXIS] = rz;
  332. line_to_current_position();
  333. }
  334. feedrate_mm_s = fr_mm_s ? fr_mm_s : XY_PROBE_FEEDRATE_MM_S;
  335. current_position[X_AXIS] = rx;
  336. current_position[Y_AXIS] = ry;
  337. line_to_current_position();
  338. // If Z needs to lower, do it after moving XY
  339. if (current_position[Z_AXIS] > rz) {
  340. feedrate_mm_s = z_feedrate;
  341. current_position[Z_AXIS] = rz;
  342. line_to_current_position();
  343. }
  344. #endif
  345. feedrate_mm_s = old_feedrate_mm_s;
  346. #if ENABLED(DEBUG_LEVELING_FEATURE)
  347. if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("<<< do_blocking_move_to");
  348. #endif
  349. planner.synchronize();
  350. }
  351. void do_blocking_move_to_x(const float &rx, const float &fr_mm_s/*=0.0*/) {
  352. do_blocking_move_to(rx, current_position[Y_AXIS], current_position[Z_AXIS], fr_mm_s);
  353. }
  354. void do_blocking_move_to_z(const float &rz, const float &fr_mm_s/*=0.0*/) {
  355. do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], rz, fr_mm_s);
  356. }
  357. void do_blocking_move_to_xy(const float &rx, const float &ry, const float &fr_mm_s/*=0.0*/) {
  358. do_blocking_move_to(rx, ry, current_position[Z_AXIS], fr_mm_s);
  359. }
  360. //
  361. // Prepare to do endstop or probe moves
  362. // with custom feedrates.
  363. //
  364. // - Save current feedrates
  365. // - Reset the rate multiplier
  366. // - Reset the command timeout
  367. // - Enable the endstops (for endstop moves)
  368. //
  369. void bracket_probe_move(const bool before) {
  370. static float saved_feedrate_mm_s;
  371. static int16_t saved_feedrate_percentage;
  372. #if ENABLED(DEBUG_LEVELING_FEATURE)
  373. if (DEBUGGING(LEVELING)) DEBUG_POS("bracket_probe_move", current_position);
  374. #endif
  375. if (before) {
  376. saved_feedrate_mm_s = feedrate_mm_s;
  377. saved_feedrate_percentage = feedrate_percentage;
  378. feedrate_percentage = 100;
  379. }
  380. else {
  381. feedrate_mm_s = saved_feedrate_mm_s;
  382. feedrate_percentage = saved_feedrate_percentage;
  383. }
  384. }
  385. void setup_for_endstop_or_probe_move() { bracket_probe_move(true); }
  386. void clean_up_after_endstop_or_probe_move() { bracket_probe_move(false); }
  387. #if HAS_SOFTWARE_ENDSTOPS
  388. bool soft_endstops_enabled = true;
  389. // Software Endstops are based on the configured limits.
  390. float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS },
  391. soft_endstop_max[XYZ] = { X_MAX_BED, Y_MAX_BED, Z_MAX_POS };
  392. #if IS_KINEMATIC
  393. float soft_endstop_radius, soft_endstop_radius_2;
  394. #endif
  395. /**
  396. * Constrain the given coordinates to the software endstops.
  397. *
  398. * For DELTA/SCARA the XY constraint is based on the smallest
  399. * radius within the set software endstops.
  400. */
  401. void clamp_to_software_endstops(float target[XYZ]) {
  402. if (!soft_endstops_enabled) return;
  403. #if IS_KINEMATIC
  404. const float dist_2 = HYPOT2(target[X_AXIS], target[Y_AXIS]);
  405. if (dist_2 > soft_endstop_radius_2) {
  406. const float ratio = soft_endstop_radius / SQRT(dist_2); // 200 / 300 = 0.66
  407. target[X_AXIS] *= ratio;
  408. target[Y_AXIS] *= ratio;
  409. }
  410. #else
  411. #if ENABLED(MIN_SOFTWARE_ENDSTOP_X)
  412. NOLESS(target[X_AXIS], soft_endstop_min[X_AXIS]);
  413. #endif
  414. #if ENABLED(MIN_SOFTWARE_ENDSTOP_Y)
  415. NOLESS(target[Y_AXIS], soft_endstop_min[Y_AXIS]);
  416. #endif
  417. #if ENABLED(MAX_SOFTWARE_ENDSTOP_X)
  418. NOMORE(target[X_AXIS], soft_endstop_max[X_AXIS]);
  419. #endif
  420. #if ENABLED(MAX_SOFTWARE_ENDSTOP_Y)
  421. NOMORE(target[Y_AXIS], soft_endstop_max[Y_AXIS]);
  422. #endif
  423. #endif
  424. #if ENABLED(MIN_SOFTWARE_ENDSTOP_Z)
  425. NOLESS(target[Z_AXIS], soft_endstop_min[Z_AXIS]);
  426. #endif
  427. #if ENABLED(MAX_SOFTWARE_ENDSTOP_Z)
  428. NOMORE(target[Z_AXIS], soft_endstop_max[Z_AXIS]);
  429. #endif
  430. }
  431. /**
  432. * Software endstops can be used to monitor the open end of
  433. * an axis that has a hardware endstop on the other end. Or
  434. * they can prevent axes from moving past endstops and grinding.
  435. *
  436. * To keep doing their job as the coordinate system changes,
  437. * the software endstop positions must be refreshed to remain
  438. * at the same positions relative to the machine.
  439. */
  440. void update_software_endstops(const AxisEnum axis) {
  441. #if ENABLED(DUAL_X_CARRIAGE)
  442. if (axis == X_AXIS) {
  443. // In Dual X mode hotend_offset[X] is T1's home position
  444. const float dual_max_x = MAX(hotend_offset[X_AXIS][1], X2_MAX_POS);
  445. if (active_extruder != 0) {
  446. // T1 can move from X2_MIN_POS to X2_MAX_POS or X2 home position (whichever is larger)
  447. soft_endstop_min[X_AXIS] = X2_MIN_POS;
  448. soft_endstop_max[X_AXIS] = dual_max_x;
  449. }
  450. else if (dxc_is_duplicating()) {
  451. // In Duplication Mode, T0 can move as far left as X1_MIN_POS
  452. // but not so far to the right that T1 would move past the end
  453. soft_endstop_min[X_AXIS] = X1_MIN_POS;
  454. soft_endstop_max[X_AXIS] = MIN(X1_MAX_POS, dual_max_x - duplicate_extruder_x_offset);
  455. }
  456. else {
  457. // In other modes, T0 can move from X1_MIN_POS to X1_MAX_POS
  458. soft_endstop_min[X_AXIS] = X1_MIN_POS;
  459. soft_endstop_max[X_AXIS] = X1_MAX_POS;
  460. }
  461. }
  462. #elif ENABLED(DELTA)
  463. soft_endstop_min[axis] = base_min_pos(axis);
  464. soft_endstop_max[axis] = (axis == Z_AXIS ? delta_height
  465. #if HAS_BED_PROBE
  466. - zprobe_zoffset + Z_PROBE_OFFSET_FROM_EXTRUDER
  467. #endif
  468. : base_max_pos(axis));
  469. switch (axis) {
  470. case X_AXIS:
  471. case Y_AXIS:
  472. // Get a minimum radius for clamping
  473. soft_endstop_radius = MIN(ABS(MAX(soft_endstop_min[X_AXIS], soft_endstop_min[Y_AXIS])), soft_endstop_max[X_AXIS], soft_endstop_max[Y_AXIS]);
  474. soft_endstop_radius_2 = sq(soft_endstop_radius);
  475. break;
  476. case Z_AXIS:
  477. delta_clip_start_height = soft_endstop_max[axis] - delta_safe_distance_from_top();
  478. default: break;
  479. }
  480. #else
  481. soft_endstop_min[axis] = base_min_pos(axis);
  482. soft_endstop_max[axis] = base_max_pos(axis);
  483. #endif
  484. #if ENABLED(DEBUG_LEVELING_FEATURE)
  485. if (DEBUGGING(LEVELING)) {
  486. SERIAL_ECHOPAIR("For ", axis_codes[axis]);
  487. SERIAL_ECHOPAIR(" axis:\n soft_endstop_min = ", soft_endstop_min[axis]);
  488. SERIAL_ECHOLNPAIR("\n soft_endstop_max = ", soft_endstop_max[axis]);
  489. }
  490. #endif
  491. }
  492. #endif
  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 ENABLED(DUAL_X_CARRIAGE) || ENABLED(DUAL_NOZZLE_DUPLICATION_MODE)
  713. bool extruder_duplication_enabled = false, // Used in Dual X mode 2 & 3
  714. scaled_duplication_mode = false; // Used in Dual X mode 2 & 3
  715. #endif
  716. #if ENABLED(DUAL_X_CARRIAGE)
  717. DualXMode dual_x_carriage_mode = DEFAULT_DUAL_X_CARRIAGE_MODE;
  718. float inactive_extruder_x_pos = X2_MAX_POS, // used in mode 0 & 1
  719. raised_parked_position[XYZE], // used in mode 1
  720. duplicate_extruder_x_offset = DEFAULT_DUPLICATION_X_OFFSET; // used in mode 2
  721. bool active_extruder_parked = false; // used in mode 1 & 2
  722. millis_t delayed_move_time = 0; // used in mode 1
  723. int16_t duplicate_extruder_temp_offset = 0; // used in mode 2
  724. float x_home_pos(const int extruder) {
  725. if (extruder == 0)
  726. return base_home_pos(X_AXIS);
  727. else
  728. /**
  729. * In dual carriage mode the extruder offset provides an override of the
  730. * second X-carriage position when homed - otherwise X2_HOME_POS is used.
  731. * This allows soft recalibration of the second extruder home position
  732. * without firmware reflash (through the M218 command).
  733. */
  734. return hotend_offset[X_AXIS][1] > 0 ? hotend_offset[X_AXIS][1] : X2_HOME_POS;
  735. }
  736. /**
  737. * Prepare a linear move in a dual X axis setup
  738. *
  739. * Return true if current_position[] was set to destination[]
  740. */
  741. inline bool dual_x_carriage_unpark() {
  742. if (active_extruder_parked) {
  743. switch (dual_x_carriage_mode) {
  744. case DXC_FULL_CONTROL_MODE:
  745. break;
  746. case DXC_AUTO_PARK_MODE:
  747. if (current_position[E_AXIS] == destination[E_AXIS]) {
  748. // This is a travel move (with no extrusion)
  749. // Skip it, but keep track of the current position
  750. // (so it can be used as the start of the next non-travel move)
  751. if (delayed_move_time != 0xFFFFFFFFUL) {
  752. set_current_from_destination();
  753. NOLESS(raised_parked_position[Z_AXIS], destination[Z_AXIS]);
  754. delayed_move_time = millis();
  755. return true;
  756. }
  757. }
  758. // unpark extruder: 1) raise, 2) move into starting XY position, 3) lower
  759. #define CUR_X current_position[X_AXIS]
  760. #define CUR_Y current_position[Y_AXIS]
  761. #define CUR_Z current_position[Z_AXIS]
  762. #define CUR_E current_position[E_AXIS]
  763. #define RAISED_X raised_parked_position[X_AXIS]
  764. #define RAISED_Y raised_parked_position[Y_AXIS]
  765. #define RAISED_Z raised_parked_position[Z_AXIS]
  766. if ( planner.buffer_line(RAISED_X, RAISED_Y, RAISED_Z, CUR_E, planner.settings.max_feedrate_mm_s[Z_AXIS], active_extruder))
  767. if (planner.buffer_line( CUR_X, CUR_Y, RAISED_Z, CUR_E, PLANNER_XY_FEEDRATE(), active_extruder))
  768. planner.buffer_line( CUR_X, CUR_Y, CUR_Z, CUR_E, planner.settings.max_feedrate_mm_s[Z_AXIS], active_extruder);
  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_SCALED_DUPLICATION_MODE:
  776. case DXC_DUPLICATION_MODE:
  777. if (active_extruder == 0) {
  778. #if ENABLED(DEBUG_LEVELING_FEATURE)
  779. if (DEBUGGING(LEVELING)) {
  780. SERIAL_ECHOPAIR("Set planner X", inactive_extruder_x_pos);
  781. SERIAL_ECHOLNPAIR(" ... Line to X", current_position[X_AXIS] + duplicate_extruder_x_offset);
  782. }
  783. #endif
  784. // move duplicate extruder into correct duplication position.
  785. planner.set_position_mm(inactive_extruder_x_pos, current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  786. if (!planner.buffer_line(
  787. dual_x_carriage_mode == DXC_DUPLICATION_MODE ? duplicate_extruder_x_offset + current_position[X_AXIS] : inactive_extruder_x_pos,
  788. current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS],
  789. planner.settings.max_feedrate_mm_s[X_AXIS], 1
  790. )
  791. ) break;
  792. planner.synchronize();
  793. sync_plan_position();
  794. extruder_duplication_enabled = true;
  795. active_extruder_parked = false;
  796. #if ENABLED(DEBUG_LEVELING_FEATURE)
  797. if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("Set extruder_duplication_enabled\nClear active_extruder_parked");
  798. #endif
  799. }
  800. else {
  801. #if ENABLED(DEBUG_LEVELING_FEATURE)
  802. if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("Active extruder not 0");
  803. #endif
  804. }
  805. break;
  806. }
  807. }
  808. stepper.set_directions();
  809. return false;
  810. }
  811. #endif // DUAL_X_CARRIAGE
  812. /**
  813. * Prepare a single move and get ready for the next one
  814. *
  815. * This may result in several calls to planner.buffer_line to
  816. * do smaller moves for DELTA, SCARA, mesh moves, etc.
  817. *
  818. * Make sure current_position[E] and destination[E] are good
  819. * before calling or cold/lengthy extrusion may get missed.
  820. */
  821. void prepare_move_to_destination() {
  822. clamp_to_software_endstops(destination);
  823. #if ENABLED(PREVENT_COLD_EXTRUSION) || ENABLED(PREVENT_LENGTHY_EXTRUDE)
  824. if (!DEBUGGING(DRYRUN)) {
  825. if (destination[E_AXIS] != current_position[E_AXIS]) {
  826. #if ENABLED(PREVENT_COLD_EXTRUSION)
  827. if (thermalManager.tooColdToExtrude(active_extruder)) {
  828. current_position[E_AXIS] = destination[E_AXIS]; // Behave as if the move really took place, but ignore E part
  829. SERIAL_ECHO_START();
  830. SERIAL_ECHOLNPGM(MSG_ERR_COLD_EXTRUDE_STOP);
  831. }
  832. #endif // PREVENT_COLD_EXTRUSION
  833. #if ENABLED(PREVENT_LENGTHY_EXTRUDE)
  834. if (ABS(destination[E_AXIS] - current_position[E_AXIS]) * planner.e_factor[active_extruder] > (EXTRUDE_MAXLENGTH)) {
  835. current_position[E_AXIS] = destination[E_AXIS]; // Behave as if the move really took place, but ignore E part
  836. SERIAL_ECHO_START();
  837. SERIAL_ECHOLNPGM(MSG_ERR_LONG_EXTRUDE_STOP);
  838. }
  839. #endif // PREVENT_LENGTHY_EXTRUDE
  840. }
  841. }
  842. #endif // PREVENT_COLD_EXTRUSION || PREVENT_LENGTHY_EXTRUDE
  843. #if ENABLED(DUAL_X_CARRIAGE)
  844. if (dual_x_carriage_unpark()) return;
  845. #endif
  846. if (
  847. #if UBL_SEGMENTED
  848. //ubl.prepare_segmented_line_to(destination, MMS_SCALED(feedrate_mm_s)) // This doesn't seem to work correctly on UBL.
  849. #if IS_KINEMATIC // Use Kinematic / Cartesian cases as a workaround for now.
  850. ubl.prepare_segmented_line_to(destination, MMS_SCALED(feedrate_mm_s))
  851. #else
  852. prepare_move_to_destination_cartesian()
  853. #endif
  854. #elif IS_KINEMATIC
  855. prepare_kinematic_move_to(destination)
  856. #else
  857. prepare_move_to_destination_cartesian()
  858. #endif
  859. ) return;
  860. set_current_from_destination();
  861. }
  862. #if HAS_AXIS_UNHOMED_ERR
  863. bool axis_unhomed_error(const bool x/*=true*/, const bool y/*=true*/, const bool z/*=true*/) {
  864. #if ENABLED(HOME_AFTER_DEACTIVATE)
  865. const bool xx = x && !TEST(axis_known_position, X_AXIS),
  866. yy = y && !TEST(axis_known_position, Y_AXIS),
  867. zz = z && !TEST(axis_known_position, Z_AXIS);
  868. #else
  869. const bool xx = x && !TEST(axis_homed, X_AXIS),
  870. yy = y && !TEST(axis_homed, Y_AXIS),
  871. zz = z && !TEST(axis_homed, Z_AXIS);
  872. #endif
  873. if (xx || yy || zz) {
  874. SERIAL_ECHO_START();
  875. SERIAL_ECHOPGM(MSG_HOME " ");
  876. if (xx) SERIAL_ECHOPGM(MSG_X);
  877. if (yy) SERIAL_ECHOPGM(MSG_Y);
  878. if (zz) SERIAL_ECHOPGM(MSG_Z);
  879. SERIAL_ECHOLNPGM(" " MSG_FIRST);
  880. #if ENABLED(ULTRA_LCD)
  881. lcd_status_printf_P(0, PSTR(MSG_HOME " %s%s%s " MSG_FIRST), xx ? MSG_X : "", yy ? MSG_Y : "", zz ? MSG_Z : "");
  882. #endif
  883. return true;
  884. }
  885. return false;
  886. }
  887. #endif // HAS_AXIS_UNHOMED_ERR
  888. /**
  889. * Homing bump feedrate (mm/s)
  890. */
  891. inline float get_homing_bump_feedrate(const AxisEnum axis) {
  892. #if HOMING_Z_WITH_PROBE
  893. if (axis == Z_AXIS) return MMM_TO_MMS(Z_PROBE_SPEED_SLOW);
  894. #endif
  895. static const uint8_t homing_bump_divisor[] PROGMEM = HOMING_BUMP_DIVISOR;
  896. uint8_t hbd = pgm_read_byte(&homing_bump_divisor[axis]);
  897. if (hbd < 1) {
  898. hbd = 10;
  899. SERIAL_ECHO_START();
  900. SERIAL_ECHOLNPGM("Warning: Homing Bump Divisor < 1");
  901. }
  902. return homing_feedrate(axis) / hbd;
  903. }
  904. #if ENABLED(SENSORLESS_HOMING)
  905. /**
  906. * Set sensorless homing if the axis has it, accounting for Core Kinematics.
  907. */
  908. void sensorless_homing_per_axis(const AxisEnum axis, const bool enable/*=true*/) {
  909. switch (axis) {
  910. default: break;
  911. #if X_SENSORLESS
  912. case X_AXIS:
  913. tmc_stallguard(stepperX, enable);
  914. #if CORE_IS_XY && Y_SENSORLESS
  915. tmc_stallguard(stepperY, enable);
  916. #elif CORE_IS_XZ && Z_SENSORLESS
  917. tmc_stallguard(stepperZ, enable);
  918. #endif
  919. break;
  920. #endif
  921. #if Y_SENSORLESS
  922. case Y_AXIS:
  923. tmc_stallguard(stepperY, enable);
  924. #if CORE_IS_XY && X_SENSORLESS
  925. tmc_stallguard(stepperX, enable);
  926. #elif CORE_IS_YZ && Z_SENSORLESS
  927. tmc_stallguard(stepperZ, enable);
  928. #endif
  929. break;
  930. #endif
  931. #if Z_SENSORLESS
  932. case Z_AXIS:
  933. tmc_stallguard(stepperZ, enable);
  934. #if CORE_IS_XZ && X_SENSORLESS
  935. tmc_stallguard(stepperX, enable);
  936. #elif CORE_IS_YZ && Y_SENSORLESS
  937. tmc_stallguard(stepperY, enable);
  938. #endif
  939. break;
  940. #endif
  941. }
  942. }
  943. #endif // SENSORLESS_HOMING
  944. /**
  945. * Home an individual linear axis
  946. */
  947. void do_homing_move(const AxisEnum axis, const float distance, const float fr_mm_s=0.0) {
  948. #if ENABLED(DEBUG_LEVELING_FEATURE)
  949. if (DEBUGGING(LEVELING)) {
  950. SERIAL_ECHOPAIR(">>> do_homing_move(", axis_codes[axis]);
  951. SERIAL_ECHOPAIR(", ", distance);
  952. SERIAL_ECHOPGM(", ");
  953. if (fr_mm_s)
  954. SERIAL_ECHO(fr_mm_s);
  955. else {
  956. SERIAL_ECHOPAIR("[", homing_feedrate(axis));
  957. SERIAL_CHAR(']');
  958. }
  959. SERIAL_ECHOLNPGM(")");
  960. }
  961. #endif
  962. #if HOMING_Z_WITH_PROBE && HAS_HEATED_BED && ENABLED(WAIT_FOR_BED_HEATER)
  963. // Wait for bed to heat back up between probing points
  964. if (axis == Z_AXIS && distance < 0 && thermalManager.isHeatingBed()) {
  965. serialprintPGM(msg_wait_for_bed_heating);
  966. LCD_MESSAGEPGM(MSG_BED_HEATING);
  967. while (thermalManager.isHeatingBed()) safe_delay(200);
  968. lcd_reset_status();
  969. }
  970. #endif
  971. // Only do some things when moving towards an endstop
  972. const int8_t axis_home_dir =
  973. #if ENABLED(DUAL_X_CARRIAGE)
  974. (axis == X_AXIS) ? x_home_dir(active_extruder) :
  975. #endif
  976. home_dir(axis);
  977. const bool is_home_dir = (axis_home_dir > 0) == (distance > 0);
  978. if (is_home_dir) {
  979. #if HOMING_Z_WITH_PROBE && QUIET_PROBING
  980. if (axis == Z_AXIS) probing_pause(true);
  981. #endif
  982. // Disable stealthChop if used. Enable diag1 pin on driver.
  983. #if ENABLED(SENSORLESS_HOMING)
  984. sensorless_homing_per_axis(axis);
  985. #endif
  986. }
  987. #if IS_SCARA
  988. // Tell the planner the axis is at 0
  989. current_position[axis] = 0;
  990. sync_plan_position();
  991. current_position[axis] = distance;
  992. planner.buffer_line(current_position, fr_mm_s ? fr_mm_s : homing_feedrate(axis), active_extruder);
  993. #else
  994. 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) };
  995. target[axis] = 0;
  996. planner.set_machine_position_mm(target);
  997. target[axis] = distance;
  998. #if IS_KINEMATIC && ENABLED(JUNCTION_DEVIATION)
  999. const float delta_mm_cart[XYZE] = {0, 0, 0, 0};
  1000. #endif
  1001. // Set delta/cartesian axes directly
  1002. planner.buffer_segment(target
  1003. #if IS_KINEMATIC && ENABLED(JUNCTION_DEVIATION)
  1004. , delta_mm_cart
  1005. #endif
  1006. , fr_mm_s ? fr_mm_s : homing_feedrate(axis), active_extruder
  1007. );
  1008. #endif
  1009. planner.synchronize();
  1010. if (is_home_dir) {
  1011. #if HOMING_Z_WITH_PROBE && QUIET_PROBING
  1012. if (axis == Z_AXIS) probing_pause(false);
  1013. #endif
  1014. endstops.validate_homing_move();
  1015. // Re-enable stealthChop if used. Disable diag1 pin on driver.
  1016. #if ENABLED(SENSORLESS_HOMING)
  1017. sensorless_homing_per_axis(axis, false);
  1018. #endif
  1019. }
  1020. #if ENABLED(DEBUG_LEVELING_FEATURE)
  1021. if (DEBUGGING(LEVELING)) {
  1022. SERIAL_ECHOPAIR("<<< do_homing_move(", axis_codes[axis]);
  1023. SERIAL_CHAR(')');
  1024. SERIAL_EOL();
  1025. }
  1026. #endif
  1027. }
  1028. /**
  1029. * Set an axis' current position to its home position (after homing).
  1030. *
  1031. * For Core and Cartesian robots this applies one-to-one when an
  1032. * individual axis has been homed.
  1033. *
  1034. * DELTA should wait until all homing is done before setting the XYZ
  1035. * current_position to home, because homing is a single operation.
  1036. * In the case where the axis positions are already known and previously
  1037. * homed, DELTA could home to X or Y individually by moving either one
  1038. * to the center. However, homing Z always homes XY and Z.
  1039. *
  1040. * SCARA should wait until all XY homing is done before setting the XY
  1041. * current_position to home, because neither X nor Y is at home until
  1042. * both are at home. Z can however be homed individually.
  1043. *
  1044. * Callers must sync the planner position after calling this!
  1045. */
  1046. void set_axis_is_at_home(const AxisEnum axis) {
  1047. #if ENABLED(DEBUG_LEVELING_FEATURE)
  1048. if (DEBUGGING(LEVELING)) {
  1049. SERIAL_ECHOPAIR(">>> set_axis_is_at_home(", axis_codes[axis]);
  1050. SERIAL_CHAR(')');
  1051. SERIAL_EOL();
  1052. }
  1053. #endif
  1054. SBI(axis_known_position, axis);
  1055. SBI(axis_homed, axis);
  1056. #if HAS_POSITION_SHIFT
  1057. position_shift[axis] = 0;
  1058. update_workspace_offset(axis);
  1059. #endif
  1060. #if ENABLED(DUAL_X_CARRIAGE)
  1061. if (axis == X_AXIS && (active_extruder == 1 || dual_x_carriage_mode == DXC_DUPLICATION_MODE)) {
  1062. current_position[X_AXIS] = x_home_pos(active_extruder);
  1063. return;
  1064. }
  1065. #endif
  1066. #if ENABLED(MORGAN_SCARA)
  1067. scara_set_axis_is_at_home(axis);
  1068. #elif ENABLED(DELTA)
  1069. current_position[axis] = (axis == Z_AXIS ? delta_height
  1070. #if HAS_BED_PROBE
  1071. - zprobe_zoffset + Z_PROBE_OFFSET_FROM_EXTRUDER
  1072. #endif
  1073. : base_home_pos(axis));
  1074. #else
  1075. current_position[axis] = base_home_pos(axis);
  1076. #endif
  1077. /**
  1078. * Z Probe Z Homing? Account for the probe's Z offset.
  1079. */
  1080. #if HAS_BED_PROBE && Z_HOME_DIR < 0
  1081. if (axis == Z_AXIS) {
  1082. #if HOMING_Z_WITH_PROBE
  1083. current_position[Z_AXIS] -= zprobe_zoffset;
  1084. #if ENABLED(DEBUG_LEVELING_FEATURE)
  1085. if (DEBUGGING(LEVELING)) {
  1086. SERIAL_ECHOLNPGM("*** Z HOMED WITH PROBE (Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) ***");
  1087. SERIAL_ECHOLNPAIR("> zprobe_zoffset = ", zprobe_zoffset);
  1088. }
  1089. #endif
  1090. #elif ENABLED(DEBUG_LEVELING_FEATURE)
  1091. if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("*** Z HOMED TO ENDSTOP (Z_MIN_PROBE_ENDSTOP) ***");
  1092. #endif
  1093. }
  1094. #endif
  1095. #if ENABLED(DEBUG_LEVELING_FEATURE)
  1096. if (DEBUGGING(LEVELING)) {
  1097. #if HAS_HOME_OFFSET
  1098. SERIAL_ECHOPAIR("> home_offset[", axis_codes[axis]);
  1099. SERIAL_ECHOLNPAIR("] = ", home_offset[axis]);
  1100. #endif
  1101. DEBUG_POS("", current_position);
  1102. SERIAL_ECHOPAIR("<<< set_axis_is_at_home(", axis_codes[axis]);
  1103. SERIAL_CHAR(')');
  1104. SERIAL_EOL();
  1105. }
  1106. #endif
  1107. #if ENABLED(I2C_POSITION_ENCODERS)
  1108. I2CPEM.homed(axis);
  1109. #endif
  1110. }
  1111. /**
  1112. * Set an axis' to be unhomed.
  1113. */
  1114. void set_axis_is_not_at_home(const AxisEnum axis) {
  1115. #if ENABLED(DEBUG_LEVELING_FEATURE)
  1116. if (DEBUGGING(LEVELING)) {
  1117. SERIAL_ECHOPAIR(">>> set_axis_is_not_at_home(", axis_codes[axis]);
  1118. SERIAL_CHAR(')');
  1119. SERIAL_EOL();
  1120. }
  1121. #endif
  1122. CBI(axis_known_position, axis);
  1123. CBI(axis_homed, axis);
  1124. #if ENABLED(DEBUG_LEVELING_FEATURE)
  1125. if (DEBUGGING(LEVELING)) {
  1126. SERIAL_ECHOPAIR("<<< set_axis_is_not_at_home(", axis_codes[axis]);
  1127. SERIAL_CHAR(')');
  1128. SERIAL_EOL();
  1129. }
  1130. #endif
  1131. #if ENABLED(I2C_POSITION_ENCODERS)
  1132. I2CPEM.unhomed(axis);
  1133. #endif
  1134. }
  1135. /**
  1136. * Home an individual "raw axis" to its endstop.
  1137. * This applies to XYZ on Cartesian and Core robots, and
  1138. * to the individual ABC steppers on DELTA and SCARA.
  1139. *
  1140. * At the end of the procedure the axis is marked as
  1141. * homed and the current position of that axis is updated.
  1142. * Kinematic robots should wait till all axes are homed
  1143. * before updating the current position.
  1144. */
  1145. void homeaxis(const AxisEnum axis) {
  1146. #if IS_SCARA
  1147. // Only Z homing (with probe) is permitted
  1148. if (axis != Z_AXIS) { BUZZ(100, 880); return; }
  1149. #else
  1150. #define CAN_HOME(A) \
  1151. (axis == _AXIS(A) && ((A##_MIN_PIN > -1 && A##_HOME_DIR < 0) || (A##_MAX_PIN > -1 && A##_HOME_DIR > 0)))
  1152. if (!CAN_HOME(X) && !CAN_HOME(Y) && !CAN_HOME(Z)) return;
  1153. #endif
  1154. #if ENABLED(DEBUG_LEVELING_FEATURE)
  1155. if (DEBUGGING(LEVELING)) {
  1156. SERIAL_ECHOPAIR(">>> homeaxis(", axis_codes[axis]);
  1157. SERIAL_CHAR(')');
  1158. SERIAL_EOL();
  1159. }
  1160. #endif
  1161. const int axis_home_dir = (
  1162. #if ENABLED(DUAL_X_CARRIAGE)
  1163. axis == X_AXIS ? x_home_dir(active_extruder) :
  1164. #endif
  1165. home_dir(axis)
  1166. );
  1167. // Homing Z towards the bed? Deploy the Z probe or endstop.
  1168. #if HOMING_Z_WITH_PROBE
  1169. if (axis == Z_AXIS && DEPLOY_PROBE()) return;
  1170. #endif
  1171. // Set flags for X, Y, Z motor locking
  1172. #if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || Z_MULTI_ENDSTOPS
  1173. switch (axis) {
  1174. #if ENABLED(X_DUAL_ENDSTOPS)
  1175. case X_AXIS:
  1176. #endif
  1177. #if ENABLED(Y_DUAL_ENDSTOPS)
  1178. case Y_AXIS:
  1179. #endif
  1180. #if Z_MULTI_ENDSTOPS
  1181. case Z_AXIS:
  1182. #endif
  1183. stepper.set_separate_multi_axis(true);
  1184. default: break;
  1185. }
  1186. #endif
  1187. // Fast move towards endstop until triggered
  1188. #if ENABLED(DEBUG_LEVELING_FEATURE)
  1189. if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("Home 1 Fast:");
  1190. #endif
  1191. #if HOMING_Z_WITH_PROBE && ENABLED(BLTOUCH)
  1192. // BLTOUCH needs to be deployed every time
  1193. if (axis == Z_AXIS && set_bltouch_deployed(true)) return;
  1194. #endif
  1195. do_homing_move(axis, 1.5f * max_length(
  1196. #if ENABLED(DELTA)
  1197. Z_AXIS
  1198. #else
  1199. axis
  1200. #endif
  1201. ) * axis_home_dir
  1202. );
  1203. #if HOMING_Z_WITH_PROBE && ENABLED(BLTOUCH)
  1204. // BLTOUCH needs to be stowed after trigger to rearm itself
  1205. if (axis == Z_AXIS) set_bltouch_deployed(false);
  1206. #endif
  1207. // When homing Z with probe respect probe clearance
  1208. const float bump = axis_home_dir * (
  1209. #if HOMING_Z_WITH_PROBE
  1210. (axis == Z_AXIS && (Z_HOME_BUMP_MM)) ? MAX(Z_CLEARANCE_BETWEEN_PROBES, Z_HOME_BUMP_MM) :
  1211. #endif
  1212. home_bump_mm(axis)
  1213. );
  1214. // If a second homing move is configured...
  1215. if (bump) {
  1216. // Move away from the endstop by the axis HOME_BUMP_MM
  1217. #if ENABLED(DEBUG_LEVELING_FEATURE)
  1218. if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("Move Away:");
  1219. #endif
  1220. do_homing_move(axis, -bump
  1221. #if HOMING_Z_WITH_PROBE
  1222. , axis == Z_AXIS ? MMM_TO_MMS(Z_PROBE_SPEED_FAST) : 0.0
  1223. #endif
  1224. );
  1225. // Slow move towards endstop until triggered
  1226. #if ENABLED(DEBUG_LEVELING_FEATURE)
  1227. if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("Home 2 Slow:");
  1228. #endif
  1229. #if HOMING_Z_WITH_PROBE && ENABLED(BLTOUCH)
  1230. // BLTOUCH needs to be deployed every time
  1231. if (axis == Z_AXIS && set_bltouch_deployed(true)) return;
  1232. #endif
  1233. do_homing_move(axis, 2 * bump, get_homing_bump_feedrate(axis));
  1234. #if HOMING_Z_WITH_PROBE && ENABLED(BLTOUCH)
  1235. // BLTOUCH needs to be stowed after trigger to rearm itself
  1236. if (axis == Z_AXIS) set_bltouch_deployed(false);
  1237. #endif
  1238. }
  1239. #if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || Z_MULTI_ENDSTOPS
  1240. const bool pos_dir = axis_home_dir > 0;
  1241. #if ENABLED(X_DUAL_ENDSTOPS)
  1242. if (axis == X_AXIS) {
  1243. const float adj = ABS(endstops.x2_endstop_adj);
  1244. if (adj) {
  1245. if (pos_dir ? (endstops.x2_endstop_adj > 0) : (endstops.x2_endstop_adj < 0)) stepper.set_x_lock(true); else stepper.set_x2_lock(true);
  1246. do_homing_move(axis, pos_dir ? -adj : adj);
  1247. stepper.set_x_lock(false);
  1248. stepper.set_x2_lock(false);
  1249. }
  1250. }
  1251. #endif
  1252. #if ENABLED(Y_DUAL_ENDSTOPS)
  1253. if (axis == Y_AXIS) {
  1254. const float adj = ABS(endstops.y2_endstop_adj);
  1255. if (adj) {
  1256. if (pos_dir ? (endstops.y2_endstop_adj > 0) : (endstops.y2_endstop_adj < 0)) stepper.set_y_lock(true); else stepper.set_y2_lock(true);
  1257. do_homing_move(axis, pos_dir ? -adj : adj);
  1258. stepper.set_y_lock(false);
  1259. stepper.set_y2_lock(false);
  1260. }
  1261. }
  1262. #endif
  1263. #if ENABLED(Z_DUAL_ENDSTOPS)
  1264. if (axis == Z_AXIS) {
  1265. const float adj = ABS(endstops.z2_endstop_adj);
  1266. if (adj) {
  1267. if (pos_dir ? (endstops.z2_endstop_adj > 0) : (endstops.z2_endstop_adj < 0)) stepper.set_z_lock(true); else stepper.set_z2_lock(true);
  1268. do_homing_move(axis, pos_dir ? -adj : adj);
  1269. stepper.set_z_lock(false);
  1270. stepper.set_z2_lock(false);
  1271. }
  1272. }
  1273. #endif
  1274. #if ENABLED(Z_TRIPLE_ENDSTOPS)
  1275. if (axis == Z_AXIS) {
  1276. // we push the function pointers for the stepper lock function into an array
  1277. void (*lock[3]) (bool)= {&stepper.set_z_lock, &stepper.set_z2_lock, &stepper.set_z3_lock};
  1278. float adj[3] = {0, endstops.z2_endstop_adj, endstops.z3_endstop_adj};
  1279. void (*tempLock) (bool);
  1280. float tempAdj;
  1281. // manual bubble sort by adjust value
  1282. if (adj[1] < adj[0]) {
  1283. tempLock = lock[0], tempAdj = adj[0];
  1284. lock[0] = lock[1], adj[0] = adj[1];
  1285. lock[1] = tempLock, adj[1] = tempAdj;
  1286. }
  1287. if (adj[2] < adj[1]) {
  1288. tempLock = lock[1], tempAdj = adj[1];
  1289. lock[1] = lock[2], adj[1] = adj[2];
  1290. lock[2] = tempLock, adj[2] = tempAdj;
  1291. }
  1292. if (adj[1] < adj[0]) {
  1293. tempLock = lock[0], tempAdj = adj[0];
  1294. lock[0] = lock[1], adj[0] = adj[1];
  1295. lock[1] = tempLock, adj[1] = tempAdj;
  1296. }
  1297. if (pos_dir) {
  1298. // normalize adj to smallest value and do the first move
  1299. (*lock[0])(true);
  1300. do_homing_move(axis, adj[1] - adj[0]);
  1301. // lock the second stepper for the final correction
  1302. (*lock[1])(true);
  1303. do_homing_move(axis, adj[2] - adj[1]);
  1304. }
  1305. else {
  1306. (*lock[2])(true);
  1307. do_homing_move(axis, adj[1] - adj[2]);
  1308. (*lock[1])(true);
  1309. do_homing_move(axis, adj[0] - adj[1]);
  1310. }
  1311. stepper.set_z_lock(false);
  1312. stepper.set_z2_lock(false);
  1313. stepper.set_z3_lock(false);
  1314. }
  1315. #endif
  1316. #endif
  1317. #if IS_SCARA
  1318. set_axis_is_at_home(axis);
  1319. sync_plan_position();
  1320. #elif ENABLED(DELTA)
  1321. // Delta has already moved all three towers up in G28
  1322. // so here it re-homes each tower in turn.
  1323. // Delta homing treats the axes as normal linear axes.
  1324. // retrace by the amount specified in delta_endstop_adj + additional dist in order to have minimum steps
  1325. if (delta_endstop_adj[axis] * Z_HOME_DIR <= 0) {
  1326. #if ENABLED(DEBUG_LEVELING_FEATURE)
  1327. if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("delta_endstop_adj:");
  1328. #endif
  1329. do_homing_move(axis, delta_endstop_adj[axis] - (MIN_STEPS_PER_SEGMENT + 1) * planner.steps_to_mm[axis] * Z_HOME_DIR);
  1330. }
  1331. #else
  1332. // For cartesian/core machines,
  1333. // set the axis to its home position
  1334. set_axis_is_at_home(axis);
  1335. sync_plan_position();
  1336. destination[axis] = current_position[axis];
  1337. #if ENABLED(DEBUG_LEVELING_FEATURE)
  1338. if (DEBUGGING(LEVELING)) DEBUG_POS("> AFTER set_axis_is_at_home", current_position);
  1339. #endif
  1340. #endif
  1341. // Put away the Z probe
  1342. #if HOMING_Z_WITH_PROBE
  1343. if (axis == Z_AXIS && STOW_PROBE()) return;
  1344. #endif
  1345. // Clear retracted status if homing the Z axis
  1346. #if ENABLED(FWRETRACT)
  1347. if (axis == Z_AXIS) fwretract.current_hop = 0.0;
  1348. #endif
  1349. #if ENABLED(DEBUG_LEVELING_FEATURE)
  1350. if (DEBUGGING(LEVELING)) {
  1351. SERIAL_ECHOPAIR("<<< homeaxis(", axis_codes[axis]);
  1352. SERIAL_CHAR(')');
  1353. SERIAL_EOL();
  1354. }
  1355. #endif
  1356. } // homeaxis()
  1357. #if HAS_WORKSPACE_OFFSET
  1358. void update_workspace_offset(const AxisEnum axis) {
  1359. workspace_offset[axis] = home_offset[axis] + position_shift[axis];
  1360. #if ENABLED(DEBUG_LEVELING_FEATURE)
  1361. if (DEBUGGING(LEVELING)) {
  1362. SERIAL_ECHOPAIR("For ", axis_codes[axis]);
  1363. SERIAL_ECHOPAIR(" axis:\n home_offset = ", home_offset[axis]);
  1364. SERIAL_ECHOLNPAIR("\n position_shift = ", position_shift[axis]);
  1365. }
  1366. #endif
  1367. }
  1368. #endif
  1369. #if HAS_M206_COMMAND
  1370. /**
  1371. * Change the home offset for an axis.
  1372. * Also refreshes the workspace offset.
  1373. */
  1374. void set_home_offset(const AxisEnum axis, const float v) {
  1375. home_offset[axis] = v;
  1376. update_workspace_offset(axis);
  1377. }
  1378. #endif // HAS_M206_COMMAND