My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

G76_M871.cpp 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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. /**
  23. * G76_M871.cpp - Temperature calibration/compensation for z-probing
  24. */
  25. #include "../../inc/MarlinConfig.h"
  26. #if ENABLED(PROBE_TEMP_COMPENSATION)
  27. #include "../gcode.h"
  28. #include "../../module/motion.h"
  29. #include "../../module/planner.h"
  30. #include "../../module/probe.h"
  31. #include "../../feature/bedlevel/bedlevel.h"
  32. #include "../../module/temperature.h"
  33. #include "../../module/probe.h"
  34. #include "../../feature/probe_temp_compensation.h"
  35. /**
  36. * G76: calibrate probe and/or bed temperature offsets
  37. * Notes:
  38. * - When calibrating probe, bed temperature is held constant.
  39. * Compensation values are deltas to first probe measurement at probe temp. = 30°C.
  40. * - When calibrating bed, probe temperature is held constant.
  41. * Compensation values are deltas to first probe measurement at bed temp. = 60°C.
  42. * - The hotend will not be heated at any time.
  43. * - On my Prusa MK3S clone I put a piece of paper between the probe and the hotend
  44. * so the hotend fan would not cool my probe constantly. Alternativly you could just
  45. * make sure the fan is not running while running the calibration process.
  46. *
  47. * Probe calibration:
  48. * - Moves probe to cooldown point.
  49. * - Heats up bed to 100°C.
  50. * - Moves probe to probing point (1mm above heatbed).
  51. * - Waits until probe reaches target temperature (30°C).
  52. * - Does a z-probing (=base value) and increases target temperature by 5°C.
  53. * - Waits until probe reaches increased target temperature.
  54. * - Does a z-probing (delta to base value will be a compensation value) and increases target temperature by 5°C.
  55. * - Repeats last two steps until max. temperature reached or timeout (i.e. probe does not heat up any further).
  56. * - Compensation values of higher temperatures will be extrapolated (using linear regression first).
  57. * While this is not exact by any means it is still better than simply using the last compensation value.
  58. *
  59. * Bed calibration:
  60. * - Moves probe to cooldown point.
  61. * - Heats up bed to 60°C.
  62. * - Moves probe to probing point (1mm above heatbed).
  63. * - Waits until probe reaches target temperature (30°C).
  64. * - Does a z-probing (=base value) and increases bed temperature by 5°C.
  65. * - Moves probe to cooldown point.
  66. * - Waits until probe is below 30°C and bed has reached target temperature.
  67. * - Moves probe to probing point and waits until it reaches target temperature (30°C).
  68. * - Does a z-probing (delta to base value will be a compensation value) and increases bed temperature by 5°C.
  69. * - Repeats last four points until max. bed temperature reached (110°C) or timeout.
  70. * - Compensation values of higher temperatures will be extrapolated (using linear regression first).
  71. * While this is not exact by any means it is still better than simply using the last compensation value.
  72. *
  73. * G76 [B | P]
  74. * - no flag - Both calibration procedures will be run.
  75. * - `B` - Run bed temperature calibration.
  76. * - `P` - Run probe temperature calibration.
  77. */
  78. void GcodeSuite::G76() {
  79. // Check if heated bed is available and z-homing is done with probe
  80. #if TEMP_SENSOR_BED == 0 || !(HOMING_Z_WITH_PROBE)
  81. return;
  82. #endif
  83. #if ENABLED(BLTOUCH)
  84. // Make sure any BLTouch error condition is cleared
  85. bltouch_command(BLTOUCH_RESET, BLTOUCH_RESET_DELAY);
  86. set_bltouch_deployed(false);
  87. #endif
  88. bool do_bed_cal = parser.boolval('B'),
  89. do_probe_cal = parser.boolval('P');
  90. if (!do_bed_cal && !do_probe_cal)
  91. do_bed_cal = do_probe_cal = true;
  92. // Synchronize with planner
  93. planner.synchronize();
  94. // Report temperatures every second and handle heating timeouts
  95. millis_t next_temp_report = millis() + 1000;
  96. if (do_bed_cal || do_probe_cal) {
  97. // Ensure park position is reachable
  98. if (!position_is_reachable(ProbeTempComp::park_point.x, ProbeTempComp::park_point.y)
  99. || !(WITHIN(ProbeTempComp::park_point.z, Z_MIN_POS - 0.001f, Z_MAX_POS + 0.001f))
  100. ) {
  101. SERIAL_ECHOLNPGM("!Park position unreachable - aborting.");
  102. return;
  103. }
  104. // Ensure probe position is reachable
  105. destination.set(
  106. temp_comp.measure_point_x - probe_offset.x,
  107. temp_comp.measure_point_y - probe_offset.y
  108. );
  109. if (!position_is_reachable_by_probe(destination)) {
  110. SERIAL_ECHOLNPGM("!Probe position unreachable - aborting.");
  111. return;
  112. }
  113. G28(true);
  114. }
  115. /******************************************
  116. * Calibrate bed temperature offsets
  117. ******************************************/
  118. if (do_bed_cal) {
  119. uint16_t target_bed = temp_comp.cali_info_init[TSI_BED].start_temp,
  120. target_probe = temp_comp.bed_calib_probe_temp;
  121. SERIAL_ECHOLNPGM("Waiting for printer to cool down.");
  122. while (thermalManager.degBed() > target_bed
  123. || thermalManager.degProbe() > target_probe
  124. ) {
  125. idle(
  126. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  127. true
  128. #endif
  129. );
  130. const millis_t ms = millis();
  131. if (ELAPSED(ms, next_temp_report)) {
  132. thermalManager.print_heater_states(active_extruder);
  133. next_temp_report = ms + 1000;
  134. }
  135. }
  136. // Disable leveling so it won't mess with us
  137. #if HAS_LEVELING
  138. set_bed_leveling_enabled(false);
  139. #endif
  140. bool timeout = false;
  141. while (true) {
  142. thermalManager.setTargetBed(target_bed);
  143. SERIAL_ECHOLNPAIR("Target Bed: ", target_bed, "; Probe: ", target_probe);
  144. // Park nozzle
  145. do_blocking_move_to(ProbeTempComp::park_point.x, ProbeTempComp::park_point.y, ProbeTempComp::park_point.z);
  146. // Wait for heatbed to reach target temp and probe to cool below target temp
  147. SERIAL_ECHOLNPGM("Waiting for bed and probe to reach target temp.");
  148. const millis_t probe_timeout_ms = millis() + 900UL * 1000UL;
  149. while (fabs(thermalManager.degBed() - float(target_bed)) > 0.1 || thermalManager.degProbe() > target_probe) {
  150. idle(
  151. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  152. true
  153. #endif
  154. );
  155. const millis_t ms = millis();
  156. if (ELAPSED(ms, next_temp_report)) {
  157. thermalManager.print_heater_states(active_extruder);
  158. next_temp_report = ms + 1000;
  159. }
  160. if (ELAPSED(ms, probe_timeout_ms)) {
  161. SERIAL_ECHOLNPGM("!Bed heating timeout.");
  162. timeout = true;
  163. break;
  164. }
  165. }
  166. if (timeout) break;
  167. // Move probe to probing point and wait for probe to reach target temp
  168. destination.set(temp_comp.measure_point_x, temp_comp.measure_point_y, 0.5);
  169. do_blocking_move_to(destination.x, destination.y, destination.z);
  170. SERIAL_ECHOLNPGM("Waiting for probe heating.");
  171. while (thermalManager.degProbe() < target_probe) {
  172. idle(
  173. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  174. true
  175. #endif
  176. );
  177. const millis_t ms = millis();
  178. if (ELAPSED(ms, next_temp_report)) {
  179. thermalManager.print_heater_states(active_extruder);
  180. next_temp_report = ms + 1000;
  181. }
  182. }
  183. // Raise nozzle before probing
  184. destination.z = 5.0;
  185. do_blocking_move_to_z(destination.z);
  186. // Do a single probe
  187. remember_feedrate_scaling_off();
  188. const float measured_z = probe_at_point(
  189. destination.x + probe_offset.x,
  190. destination.y + probe_offset.y,
  191. PROBE_PT_NONE
  192. );
  193. restore_feedrate_and_scaling();
  194. if (isnan(measured_z)) {
  195. SERIAL_ECHOLNPGM("!Received NAN measurement - aborting.");
  196. break;
  197. }
  198. else
  199. SERIAL_ECHOLNPAIR_F("Measured: ", measured_z);
  200. if (target_bed == temp_comp.cali_info_init[TSI_BED].start_temp)
  201. temp_comp.prepare_new_calibration(measured_z);
  202. else
  203. temp_comp.push_back_new_measurement(TSI_BED, measured_z);
  204. target_bed += temp_comp.cali_info_init[TSI_BED].temp_res;
  205. if (target_bed > temp_comp.max_bed_temp) break;
  206. }
  207. SERIAL_ECHOLNPAIR("Retrieved measurements: ", temp_comp.get_index());
  208. if (temp_comp.finish_calibration(TSI_BED))
  209. SERIAL_ECHOLNPGM("Successfully calibrated bed.");
  210. else
  211. SERIAL_ECHOLNPGM("!Failed to calibrated bed - reset calibration values.");
  212. // Cleanup
  213. thermalManager.setTargetBed(0);
  214. #if HAS_LEVELING
  215. set_bed_leveling_enabled(true);
  216. #endif
  217. } // do_bed_cal
  218. /********************************************
  219. * Calibrate probe temperature offsets
  220. ********************************************/
  221. if (do_probe_cal) {
  222. // Park nozzle
  223. do_blocking_move_to(ProbeTempComp::park_point.x, ProbeTempComp::park_point.y, ProbeTempComp::park_point.z);
  224. // Initialize temperatures
  225. uint16_t target_bed = temp_comp.probe_calib_bed_temp,
  226. target_probe = temp_comp.cali_info_init[TSI_BED].start_temp;
  227. thermalManager.setTargetBed(target_bed);
  228. SERIAL_ECHOLNPGM("Waiting for bed and probe temperature.");
  229. while (fabs(thermalManager.degBed() - float(target_bed)) > 0.1f
  230. || thermalManager.degProbe() > target_probe
  231. ) {
  232. idle(
  233. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  234. true
  235. #endif
  236. );
  237. const millis_t ms = millis();
  238. if (ELAPSED(ms, next_temp_report)) {
  239. thermalManager.print_heater_states(active_extruder);
  240. next_temp_report = ms + 1000;
  241. }
  242. }
  243. // Disable leveling so it won't mess with us
  244. #if HAS_LEVELING
  245. set_bed_leveling_enabled(false);
  246. #endif
  247. bool timeout = false;
  248. while (true) {
  249. // Move probe to probing point and wait for it to reach target temperature
  250. destination.set(temp_comp.measure_point_x, temp_comp.measure_point_y, 0.5);
  251. do_blocking_move_to(destination);
  252. SERIAL_ECHOLNPAIR(
  253. "Bed temp: ", target_bed,
  254. "; Probe temp: ", target_probe,
  255. " Waiting for probe heating."
  256. );
  257. const millis_t probe_timeout_ms = millis() + 900UL * 1000UL;
  258. while (thermalManager.degProbe() < target_probe) {
  259. idle(
  260. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  261. true
  262. #endif
  263. );
  264. const millis_t ms = millis();
  265. if (ELAPSED(ms, next_temp_report)) {
  266. thermalManager.print_heater_states(active_extruder);
  267. next_temp_report = ms + 1000;
  268. }
  269. if (ELAPSED(ms, probe_timeout_ms)) {
  270. SERIAL_ECHOLNPGM("!Probe heating aborted due to timeout.");
  271. timeout = true;
  272. break;
  273. }
  274. }
  275. if (timeout) break;
  276. // Raise nozzle before probing
  277. destination.z = 5.0;
  278. do_blocking_move_to_z(destination.z);
  279. // Do a single probe
  280. remember_feedrate_scaling_off();
  281. const float measured_z = probe_at_point(
  282. destination.x + probe_offset.x,
  283. destination.y + probe_offset.y,
  284. PROBE_PT_NONE
  285. );
  286. restore_feedrate_and_scaling();
  287. if (isnan(measured_z)) {
  288. SERIAL_ECHOLNPGM("!Received NAN measurement - aborting.");
  289. break;
  290. }
  291. else
  292. SERIAL_ECHOLNPAIR_F("Measured: ", measured_z);
  293. if (target_probe == temp_comp.cali_info_init[TSI_BED].start_temp)
  294. temp_comp.prepare_new_calibration(measured_z);
  295. else
  296. temp_comp.push_back_new_measurement(TSI_PROBE, measured_z);
  297. target_probe += temp_comp.cali_info_init[TSI_BED].temp_res;
  298. if (target_probe > temp_comp.cali_info_init[TSI_BED].end_temp) break;
  299. }
  300. SERIAL_ECHOLNPAIR("Retrieved measurements: ", temp_comp.get_index());
  301. if (temp_comp.finish_calibration(TSI_PROBE))
  302. SERIAL_ECHOLNPGM("Successfully calibrated probe.");
  303. else
  304. SERIAL_ECHOLNPGM("!Failed to calibrated probe.");
  305. // Cleanup
  306. thermalManager.setTargetBed(0);
  307. #if HAS_LEVELING
  308. set_bed_leveling_enabled(true);
  309. #endif
  310. SERIAL_ECHOLNPGM("Final compensation values:");
  311. temp_comp.print_offsets();
  312. } // do_probe_cal
  313. }
  314. /**
  315. * M871: Report / reset temperature compensation offsets.
  316. * Note: This does not affect values in EEPROM until M500.
  317. *
  318. * M871 [ R | B | P | E ]
  319. *
  320. * No Parameters - Print current offset values.
  321. *
  322. * Select only one of these flags:
  323. * R - Reset all offsets to zero (i.e., disable compensation).
  324. * B - Manually set offset for bed
  325. * P - Manually set offset for probe
  326. * E - Manually set offset for extruder
  327. *
  328. * With B, P, or E:
  329. * I[index] - Index in the array
  330. * V[value] - Adjustment in µm
  331. */
  332. void GcodeSuite::M871() {
  333. if (parser.seen('R')) {
  334. // Reset z-probe offsets to factory defaults
  335. temp_comp.clear_all_offsets();
  336. SERIAL_ECHOLNPGM("Offsets reset to default.");
  337. }
  338. else if (parser.seen("BPE")) {
  339. if (!parser.seenval('V')) return;
  340. const int16_t val = parser.value_int();
  341. if (!parser.seenval('I')) return;
  342. const int16_t idx = parser.value_int();
  343. const TempSensorID mod = (parser.seen('B') ? TSI_BED :
  344. #if ENABLED(USE_TEMP_EXT_COMPENSATION)
  345. parser.seen('E') ? TSI_EXT :
  346. #endif
  347. TSI_PROBE
  348. );
  349. if (idx > 0 && temp_comp.set_offset(mod, idx - 1, val))
  350. SERIAL_ECHOLNPAIR("Set value: ", val);
  351. else
  352. SERIAL_ECHOLNPGM("!Invalid index. Failed to set value (note: value at index 0 is constant).");
  353. }
  354. else // Print current Z-probe adjustments. Note: Values in EEPROM might differ.
  355. temp_comp.print_offsets();
  356. }
  357. #endif // PROBE_TEMP_COMPENSATION