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.

G425.cpp 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "../../MarlinCore.h"
  23. #if ENABLED(CALIBRATION_GCODE)
  24. #include "../gcode.h"
  25. #if ENABLED(BACKLASH_GCODE)
  26. #include "../../feature/backlash.h"
  27. #endif
  28. #include "../../lcd/ultralcd.h"
  29. #include "../../module/motion.h"
  30. #include "../../module/planner.h"
  31. #include "../../module/tool_change.h"
  32. #include "../../module/endstops.h"
  33. #include "../../feature/bedlevel/bedlevel.h"
  34. /**
  35. * G425 backs away from the calibration object by various distances
  36. * depending on the confidence level:
  37. *
  38. * UNKNOWN - No real notion on where the calibration object is on the bed
  39. * UNCERTAIN - Measurement may be uncertain due to backlash
  40. * CERTAIN - Measurement obtained with backlash compensation
  41. */
  42. #ifndef CALIBRATION_MEASUREMENT_UNKNOWN
  43. #define CALIBRATION_MEASUREMENT_UNKNOWN 5.0 // mm
  44. #endif
  45. #ifndef CALIBRATION_MEASUREMENT_UNCERTAIN
  46. #define CALIBRATION_MEASUREMENT_UNCERTAIN 1.0 // mm
  47. #endif
  48. #ifndef CALIBRATION_MEASUREMENT_CERTAIN
  49. #define CALIBRATION_MEASUREMENT_CERTAIN 0.5 // mm
  50. #endif
  51. #if BOTH(CALIBRATION_MEASURE_LEFT, CALIBRATION_MEASURE_RIGHT)
  52. #define HAS_X_CENTER 1
  53. #endif
  54. #if BOTH(CALIBRATION_MEASURE_FRONT, CALIBRATION_MEASURE_BACK)
  55. #define HAS_Y_CENTER 1
  56. #endif
  57. enum side_t : uint8_t { TOP, RIGHT, FRONT, LEFT, BACK, NUM_SIDES };
  58. static constexpr xyz_pos_t true_center CALIBRATION_OBJECT_CENTER;
  59. static constexpr xyz_float_t dimensions CALIBRATION_OBJECT_DIMENSIONS;
  60. static constexpr xy_float_t nod = { CALIBRATION_NOZZLE_OUTER_DIAMETER, CALIBRATION_NOZZLE_OUTER_DIAMETER };
  61. struct measurements_t {
  62. xyz_pos_t obj_center = true_center; // Non-static must be assigned from xyz_pos_t
  63. float obj_side[NUM_SIDES], backlash[NUM_SIDES];
  64. xyz_float_t pos_error;
  65. xy_float_t nozzle_outer_dimension = nod;
  66. };
  67. #define TEMPORARY_SOFT_ENDSTOP_STATE(enable) REMEMBER(tes, soft_endstops_enabled, enable);
  68. #if ENABLED(BACKLASH_GCODE)
  69. #define TEMPORARY_BACKLASH_CORRECTION(value) REMEMBER(tbst, backlash.correction, value)
  70. #else
  71. #define TEMPORARY_BACKLASH_CORRECTION(value)
  72. #endif
  73. #if ENABLED(BACKLASH_GCODE) && defined(BACKLASH_SMOOTHING_MM)
  74. #define TEMPORARY_BACKLASH_SMOOTHING(value) REMEMBER(tbsm, backlash.smoothing_mm, value)
  75. #else
  76. #define TEMPORARY_BACKLASH_SMOOTHING(value)
  77. #endif
  78. inline void calibration_move() {
  79. do_blocking_move_to(current_position, MMM_TO_MMS(CALIBRATION_FEEDRATE_TRAVEL));
  80. }
  81. /**
  82. * Move to the exact center above the calibration object
  83. *
  84. * m in - Measurement record
  85. * uncertainty in - How far away from the object top to park
  86. */
  87. inline void park_above_object(measurements_t &m, const float uncertainty) {
  88. // Move to safe distance above calibration object
  89. current_position.z = m.obj_center.z + dimensions.z / 2 + uncertainty;
  90. calibration_move();
  91. // Move to center of calibration object in XY
  92. current_position = xy_pos_t(m.obj_center);
  93. calibration_move();
  94. }
  95. #if HOTENDS > 1
  96. inline void set_nozzle(measurements_t &m, const uint8_t extruder) {
  97. if (extruder != active_extruder) {
  98. park_above_object(m, CALIBRATION_MEASUREMENT_UNKNOWN);
  99. tool_change(extruder);
  100. }
  101. }
  102. #endif
  103. #if HAS_HOTEND_OFFSET
  104. inline void normalize_hotend_offsets() {
  105. LOOP_S_L_N(e, 1, HOTENDS)
  106. hotend_offset[e] -= hotend_offset[0];
  107. hotend_offset[0].reset();
  108. }
  109. #endif
  110. inline bool read_calibration_pin() {
  111. return (
  112. #if PIN_EXISTS(CALIBRATION)
  113. READ(CALIBRATION_PIN) != CALIBRATION_PIN_INVERTING
  114. #elif HAS_CUSTOM_PROBE_PIN
  115. READ(Z_MIN_PROBE_PIN) != Z_MIN_PROBE_ENDSTOP_INVERTING
  116. #else
  117. READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING
  118. #endif
  119. );
  120. }
  121. /**
  122. * Move along axis in the specified dir until the probe value becomes stop_state,
  123. * then return the axis value.
  124. *
  125. * axis in - Axis along which the measurement will take place
  126. * dir in - Direction along that axis (-1 or 1)
  127. * stop_state in - Move until probe pin becomes this value
  128. * fast in - Fast vs. precise measurement
  129. */
  130. float measuring_movement(const AxisEnum axis, const int dir, const bool stop_state, const bool fast) {
  131. const float step = fast ? 0.25 : CALIBRATION_MEASUREMENT_RESOLUTION;
  132. const feedRate_t mms = fast ? MMM_TO_MMS(CALIBRATION_FEEDRATE_FAST) : MMM_TO_MMS(CALIBRATION_FEEDRATE_SLOW);
  133. const float limit = fast ? 50 : 5;
  134. destination = current_position;
  135. for (float travel = 0; travel < limit; travel += step) {
  136. destination[axis] += dir * step;
  137. do_blocking_move_to(destination, mms);
  138. planner.synchronize();
  139. if (read_calibration_pin() == stop_state) break;
  140. }
  141. return destination[axis];
  142. }
  143. /**
  144. * Move along axis until the probe is triggered. Move toolhead to its starting
  145. * point and return the measured value.
  146. *
  147. * axis in - Axis along which the measurement will take place
  148. * dir in - Direction along that axis (-1 or 1)
  149. * stop_state in - Move until probe pin becomes this value
  150. * backlash_ptr in/out - When not nullptr, measure and record axis backlash
  151. * uncertainty in - If uncertainty is CALIBRATION_MEASUREMENT_UNKNOWN, do a fast probe.
  152. */
  153. inline float measure(const AxisEnum axis, const int dir, const bool stop_state, float * const backlash_ptr, const float uncertainty) {
  154. const bool fast = uncertainty == CALIBRATION_MEASUREMENT_UNKNOWN;
  155. // Save position
  156. destination = current_position;
  157. const float start_pos = destination[axis];
  158. const float measured_pos = measuring_movement(axis, dir, stop_state, fast);
  159. // Measure backlash
  160. if (backlash_ptr && !fast) {
  161. const float release_pos = measuring_movement(axis, -dir, !stop_state, fast);
  162. *backlash_ptr = ABS(release_pos - measured_pos);
  163. }
  164. // Return to starting position
  165. destination[axis] = start_pos;
  166. do_blocking_move_to(destination, MMM_TO_MMS(CALIBRATION_FEEDRATE_TRAVEL));
  167. return measured_pos;
  168. }
  169. /**
  170. * Probe one side of the calibration object
  171. *
  172. * m in/out - Measurement record, m.obj_center and m.obj_side will be updated.
  173. * uncertainty in - How far away from the calibration object to begin probing
  174. * side in - Side of probe where probe will occur
  175. * probe_top_at_edge in - When probing sides, probe top of calibration object nearest edge
  176. * to find out height of edge
  177. */
  178. inline void probe_side(measurements_t &m, const float uncertainty, const side_t side, const bool probe_top_at_edge=false) {
  179. const xyz_float_t dimensions = CALIBRATION_OBJECT_DIMENSIONS;
  180. AxisEnum axis;
  181. float dir;
  182. park_above_object(m, uncertainty);
  183. switch (side) {
  184. case TOP: {
  185. const float measurement = measure(Z_AXIS, -1, true, &m.backlash[TOP], uncertainty);
  186. m.obj_center.z = measurement - dimensions.z / 2;
  187. m.obj_side[TOP] = measurement;
  188. return;
  189. }
  190. case RIGHT: axis = X_AXIS; dir = -1; break;
  191. case FRONT: axis = Y_AXIS; dir = 1; break;
  192. case LEFT: axis = X_AXIS; dir = 1; break;
  193. case BACK: axis = Y_AXIS; dir = -1; break;
  194. default: return;
  195. }
  196. if (probe_top_at_edge) {
  197. // Probe top nearest the side we are probing
  198. current_position[axis] = m.obj_center[axis] + (-dir) * (dimensions[axis] / 2 - m.nozzle_outer_dimension[axis]);
  199. calibration_move();
  200. m.obj_side[TOP] = measure(Z_AXIS, -1, true, &m.backlash[TOP], uncertainty);
  201. m.obj_center.z = m.obj_side[TOP] - dimensions.z / 2;
  202. }
  203. // Move to safe distance to the side of the calibration object
  204. current_position[axis] = m.obj_center[axis] + (-dir) * (dimensions[axis] / 2 + m.nozzle_outer_dimension[axis] / 2 + uncertainty);
  205. calibration_move();
  206. // Plunge below the side of the calibration object and measure
  207. current_position.z = m.obj_side[TOP] - CALIBRATION_NOZZLE_TIP_HEIGHT * 0.7;
  208. calibration_move();
  209. const float measurement = measure(axis, dir, true, &m.backlash[side], uncertainty);
  210. m.obj_center[axis] = measurement + dir * (dimensions[axis] / 2 + m.nozzle_outer_dimension[axis] / 2);
  211. m.obj_side[side] = measurement;
  212. }
  213. /**
  214. * Probe all sides of the calibration calibration object
  215. *
  216. * m in/out - Measurement record: center, backlash and error values be updated.
  217. * uncertainty in - How far away from the calibration object to begin probing
  218. */
  219. inline void probe_sides(measurements_t &m, const float uncertainty) {
  220. #ifdef CALIBRATION_MEASURE_AT_TOP_EDGES
  221. constexpr bool probe_top_at_edge = true;
  222. #else
  223. // Probing at the exact center only works if the center is flat. Probing on a washer
  224. // or bolt will require probing the top near the side edges, away from the center.
  225. constexpr bool probe_top_at_edge = false;
  226. probe_side(m, uncertainty, TOP);
  227. #endif
  228. #ifdef CALIBRATION_MEASURE_RIGHT
  229. probe_side(m, uncertainty, RIGHT, probe_top_at_edge);
  230. #endif
  231. #ifdef CALIBRATION_MEASURE_FRONT
  232. probe_side(m, uncertainty, FRONT, probe_top_at_edge);
  233. #endif
  234. #ifdef CALIBRATION_MEASURE_LEFT
  235. probe_side(m, uncertainty, LEFT, probe_top_at_edge);
  236. #endif
  237. #ifdef CALIBRATION_MEASURE_BACK
  238. probe_side(m, uncertainty, BACK, probe_top_at_edge);
  239. #endif
  240. // Compute the measured center of the calibration object.
  241. #if HAS_X_CENTER
  242. m.obj_center.x = (m.obj_side[LEFT] + m.obj_side[RIGHT]) / 2;
  243. #endif
  244. #if HAS_Y_CENTER
  245. m.obj_center.y = (m.obj_side[FRONT] + m.obj_side[BACK]) / 2;
  246. #endif
  247. // Compute the outside diameter of the nozzle at the height
  248. // at which it makes contact with the calibration object
  249. #if HAS_X_CENTER
  250. m.nozzle_outer_dimension.x = m.obj_side[RIGHT] - m.obj_side[LEFT] - dimensions.x;
  251. #endif
  252. #if HAS_Y_CENTER
  253. m.nozzle_outer_dimension.y = m.obj_side[BACK] - m.obj_side[FRONT] - dimensions.y;
  254. #endif
  255. park_above_object(m, uncertainty);
  256. // The difference between the known and the measured location
  257. // of the calibration object is the positional error
  258. m.pos_error.x = (0
  259. #if HAS_X_CENTER
  260. + true_center.x - m.obj_center.x
  261. #endif
  262. );
  263. m.pos_error.y = (0
  264. #if HAS_Y_CENTER
  265. + true_center.y - m.obj_center.y
  266. #endif
  267. );
  268. m.pos_error.z = true_center.z - m.obj_center.z;
  269. }
  270. #if ENABLED(CALIBRATION_REPORTING)
  271. inline void report_measured_faces(const measurements_t &m) {
  272. SERIAL_ECHOLNPGM("Sides:");
  273. SERIAL_ECHOLNPAIR(" Top: ", m.obj_side[TOP]);
  274. #if ENABLED(CALIBRATION_MEASURE_LEFT)
  275. SERIAL_ECHOLNPAIR(" Left: ", m.obj_side[LEFT]);
  276. #endif
  277. #if ENABLED(CALIBRATION_MEASURE_RIGHT)
  278. SERIAL_ECHOLNPAIR(" Right: ", m.obj_side[RIGHT]);
  279. #endif
  280. #if ENABLED(CALIBRATION_MEASURE_FRONT)
  281. SERIAL_ECHOLNPAIR(" Front: ", m.obj_side[FRONT]);
  282. #endif
  283. #if ENABLED(CALIBRATION_MEASURE_BACK)
  284. SERIAL_ECHOLNPAIR(" Back: ", m.obj_side[BACK]);
  285. #endif
  286. SERIAL_EOL();
  287. }
  288. inline void report_measured_center(const measurements_t &m) {
  289. SERIAL_ECHOLNPGM("Center:");
  290. #if HAS_X_CENTER
  291. SERIAL_ECHOLNPAIR_P(SP_X_STR, m.obj_center.x);
  292. #endif
  293. #if HAS_Y_CENTER
  294. SERIAL_ECHOLNPAIR_P(SP_Y_STR, m.obj_center.y);
  295. #endif
  296. SERIAL_ECHOLNPAIR_P(SP_Z_STR, m.obj_center.z);
  297. SERIAL_EOL();
  298. }
  299. inline void report_measured_backlash(const measurements_t &m) {
  300. SERIAL_ECHOLNPGM("Backlash:");
  301. #if ENABLED(CALIBRATION_MEASURE_LEFT)
  302. SERIAL_ECHOLNPAIR(" Left: ", m.backlash[LEFT]);
  303. #endif
  304. #if ENABLED(CALIBRATION_MEASURE_RIGHT)
  305. SERIAL_ECHOLNPAIR(" Right: ", m.backlash[RIGHT]);
  306. #endif
  307. #if ENABLED(CALIBRATION_MEASURE_FRONT)
  308. SERIAL_ECHOLNPAIR(" Front: ", m.backlash[FRONT]);
  309. #endif
  310. #if ENABLED(CALIBRATION_MEASURE_BACK)
  311. SERIAL_ECHOLNPAIR(" Back: ", m.backlash[BACK]);
  312. #endif
  313. SERIAL_ECHOLNPAIR(" Top: ", m.backlash[TOP]);
  314. SERIAL_EOL();
  315. }
  316. inline void report_measured_positional_error(const measurements_t &m) {
  317. SERIAL_CHAR('T');
  318. SERIAL_ECHO(int(active_extruder));
  319. SERIAL_ECHOLNPGM(" Positional Error:");
  320. #if HAS_X_CENTER
  321. SERIAL_ECHOLNPAIR_P(SP_X_STR, m.pos_error.x);
  322. #endif
  323. #if HAS_Y_CENTER
  324. SERIAL_ECHOLNPAIR_P(SP_Y_STR, m.pos_error.y);
  325. #endif
  326. SERIAL_ECHOLNPAIR_P(SP_Z_STR, m.pos_error.z);
  327. SERIAL_EOL();
  328. }
  329. inline void report_measured_nozzle_dimensions(const measurements_t &m) {
  330. SERIAL_ECHOLNPGM("Nozzle Tip Outer Dimensions:");
  331. #if HAS_X_CENTER || HAS_Y_CENTER
  332. #if HAS_X_CENTER
  333. SERIAL_ECHOLNPAIR_P(SP_X_STR, m.nozzle_outer_dimension.x);
  334. #endif
  335. #if HAS_Y_CENTER
  336. SERIAL_ECHOLNPAIR_P(SP_Y_STR, m.nozzle_outer_dimension.y);
  337. #endif
  338. #else
  339. UNUSED(m);
  340. #endif
  341. SERIAL_EOL();
  342. }
  343. #if HAS_HOTEND_OFFSET
  344. //
  345. // This function requires normalize_hotend_offsets() to be called
  346. //
  347. inline void report_hotend_offsets() {
  348. LOOP_S_L_N(e, 1, HOTENDS)
  349. SERIAL_ECHOLNPAIR_P(PSTR("T"), int(e), PSTR(" Hotend Offset X"), hotend_offset[e].x, SP_Y_STR, hotend_offset[e].y, SP_Z_STR, hotend_offset[e].z);
  350. }
  351. #endif
  352. #endif // CALIBRATION_REPORTING
  353. /**
  354. * Probe around the calibration object to measure backlash
  355. *
  356. * m in/out - Measurement record, updated with new readings
  357. * uncertainty in - How far away from the object to begin probing
  358. */
  359. inline void calibrate_backlash(measurements_t &m, const float uncertainty) {
  360. // Backlash compensation should be off while measuring backlash
  361. {
  362. // New scope for TEMPORARY_BACKLASH_CORRECTION
  363. TEMPORARY_BACKLASH_CORRECTION(all_off);
  364. TEMPORARY_BACKLASH_SMOOTHING(0.0f);
  365. probe_sides(m, uncertainty);
  366. #if ENABLED(BACKLASH_GCODE)
  367. #if HAS_X_CENTER
  368. backlash.distance_mm.x = (m.backlash[LEFT] + m.backlash[RIGHT]) / 2;
  369. #elif ENABLED(CALIBRATION_MEASURE_LEFT)
  370. backlash.distance_mm.x = m.backlash[LEFT];
  371. #elif ENABLED(CALIBRATION_MEASURE_RIGHT)
  372. backlash.distance_mm.x = m.backlash[RIGHT];
  373. #endif
  374. #if HAS_Y_CENTER
  375. backlash.distance_mm.y = (m.backlash[FRONT] + m.backlash[BACK]) / 2;
  376. #elif ENABLED(CALIBRATION_MEASURE_FRONT)
  377. backlash.distance_mm.y = m.backlash[FRONT];
  378. #elif ENABLED(CALIBRATION_MEASURE_BACK)
  379. backlash.distance_mm.y = m.backlash[BACK];
  380. #endif
  381. backlash.distance_mm.z = m.backlash[TOP];
  382. #endif
  383. }
  384. #if ENABLED(BACKLASH_GCODE)
  385. // Turn on backlash compensation and move in all
  386. // directions to take up any backlash
  387. {
  388. // New scope for TEMPORARY_BACKLASH_CORRECTION
  389. TEMPORARY_BACKLASH_CORRECTION(all_on);
  390. TEMPORARY_BACKLASH_SMOOTHING(0.0f);
  391. const xyz_float_t move = { 3, 3, 3 };
  392. current_position += move; calibration_move();
  393. current_position -= move; calibration_move();
  394. }
  395. #endif
  396. }
  397. inline void update_measurements(measurements_t &m, const AxisEnum axis) {
  398. current_position[axis] += m.pos_error[axis];
  399. m.obj_center[axis] = true_center[axis];
  400. m.pos_error[axis] = 0;
  401. }
  402. /**
  403. * Probe around the calibration object. Adjust the position and toolhead offset
  404. * using the deviation from the known position of the calibration object.
  405. *
  406. * m in/out - Measurement record, updated with new readings
  407. * uncertainty in - How far away from the object to begin probing
  408. * extruder in - What extruder to probe
  409. *
  410. * Prerequisites:
  411. * - Call calibrate_backlash() beforehand for best accuracy
  412. */
  413. inline void calibrate_toolhead(measurements_t &m, const float uncertainty, const uint8_t extruder) {
  414. TEMPORARY_BACKLASH_CORRECTION(all_on);
  415. TEMPORARY_BACKLASH_SMOOTHING(0.0f);
  416. #if HOTENDS > 1
  417. set_nozzle(m, extruder);
  418. #else
  419. UNUSED(extruder);
  420. #endif
  421. probe_sides(m, uncertainty);
  422. // Adjust the hotend offset
  423. #if HAS_HOTEND_OFFSET
  424. #if HAS_X_CENTER
  425. hotend_offset[extruder].x += m.pos_error.x;
  426. #endif
  427. #if HAS_Y_CENTER
  428. hotend_offset[extruder].y += m.pos_error.y;
  429. #endif
  430. hotend_offset[extruder].z += m.pos_error.z;
  431. normalize_hotend_offsets();
  432. #endif
  433. // Correct for positional error, so the object
  434. // is at the known actual spot
  435. planner.synchronize();
  436. #if HAS_X_CENTER
  437. update_measurements(m, X_AXIS);
  438. #endif
  439. #if HAS_Y_CENTER
  440. update_measurements(m, Y_AXIS);
  441. #endif
  442. update_measurements(m, Z_AXIS);
  443. sync_plan_position();
  444. }
  445. /**
  446. * Probe around the calibration object for all toolheads, adjusting the coordinate
  447. * system for the first nozzle and the nozzle offset for subsequent nozzles.
  448. *
  449. * m in/out - Measurement record, updated with new readings
  450. * uncertainty in - How far away from the object to begin probing
  451. */
  452. inline void calibrate_all_toolheads(measurements_t &m, const float uncertainty) {
  453. TEMPORARY_BACKLASH_CORRECTION(all_on);
  454. TEMPORARY_BACKLASH_SMOOTHING(0.0f);
  455. HOTEND_LOOP() calibrate_toolhead(m, uncertainty, e);
  456. #if HAS_HOTEND_OFFSET
  457. normalize_hotend_offsets();
  458. #endif
  459. #if HOTENDS > 1
  460. set_nozzle(m, 0);
  461. #endif
  462. }
  463. /**
  464. * Perform a full auto-calibration routine:
  465. *
  466. * 1) For each nozzle, touch top and sides of object to determine object position and
  467. * nozzle offsets. Do a fast but rough search over a wider area.
  468. * 2) With the first nozzle, touch top and sides of object to determine backlash values
  469. * for all axis (if BACKLASH_GCODE is enabled)
  470. * 3) For each nozzle, touch top and sides of object slowly to determine precise
  471. * position of object. Adjust coordinate system and nozzle offsets so probed object
  472. * location corresponds to known object location with a high degree of precision.
  473. */
  474. inline void calibrate_all() {
  475. measurements_t m;
  476. #if HAS_HOTEND_OFFSET
  477. reset_hotend_offsets();
  478. #endif
  479. TEMPORARY_BACKLASH_CORRECTION(all_on);
  480. TEMPORARY_BACKLASH_SMOOTHING(0.0f);
  481. // Do a fast and rough calibration of the toolheads
  482. calibrate_all_toolheads(m, CALIBRATION_MEASUREMENT_UNKNOWN);
  483. #if ENABLED(BACKLASH_GCODE)
  484. calibrate_backlash(m, CALIBRATION_MEASUREMENT_UNCERTAIN);
  485. #endif
  486. // Cycle the toolheads so the servos settle into their "natural" positions
  487. #if HOTENDS > 1
  488. HOTEND_LOOP() set_nozzle(m, e);
  489. #endif
  490. // Do a slow and precise calibration of the toolheads
  491. calibrate_all_toolheads(m, CALIBRATION_MEASUREMENT_UNCERTAIN);
  492. current_position.x = X_CENTER;
  493. calibration_move(); // Park nozzle away from calibration object
  494. }
  495. /**
  496. * G425: Perform calibration with calibration object.
  497. *
  498. * B - Perform calibration of backlash only.
  499. * T<extruder> - Perform calibration of toolhead only.
  500. * V - Probe object and print position, error, backlash and hotend offset.
  501. * U - Uncertainty, how far to start probe away from the object (mm)
  502. *
  503. * no args - Perform entire calibration sequence (backlash + position on all toolheads)
  504. */
  505. void GcodeSuite::G425() {
  506. TEMPORARY_SOFT_ENDSTOP_STATE(false);
  507. TEMPORARY_BED_LEVELING_STATE(false);
  508. if (axis_unhomed_error()) return;
  509. measurements_t m;
  510. float uncertainty = parser.seenval('U') ? parser.value_float() : CALIBRATION_MEASUREMENT_UNCERTAIN;
  511. if (parser.seen('B'))
  512. calibrate_backlash(m, uncertainty);
  513. else if (parser.seen('T'))
  514. calibrate_toolhead(m, uncertainty, parser.has_value() ? parser.value_int() : active_extruder);
  515. #if ENABLED(CALIBRATION_REPORTING)
  516. else if (parser.seen('V')) {
  517. probe_sides(m, uncertainty);
  518. SERIAL_EOL();
  519. report_measured_faces(m);
  520. report_measured_center(m);
  521. report_measured_backlash(m);
  522. report_measured_nozzle_dimensions(m);
  523. report_measured_positional_error(m);
  524. #if HAS_HOTEND_OFFSET
  525. normalize_hotend_offsets();
  526. report_hotend_offsets();
  527. #endif
  528. }
  529. #endif
  530. else
  531. calibrate_all();
  532. }
  533. #endif // CALIBRATION_GCODE