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

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