My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

G425.cpp 20KB

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