My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

G425.cpp 21KB

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