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.

UBL_G29.cpp 63KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 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 "MarlinConfig.h"
  23. #if ENABLED(AUTO_BED_LEVELING_UBL)
  24. //#include "vector_3.h"
  25. //#include "qr_solve.h"
  26. #include "UBL.h"
  27. #include "Marlin.h"
  28. #include "hex_print_routines.h"
  29. #include "configuration_store.h"
  30. #include "planner.h"
  31. #include "ultralcd.h"
  32. #include <avr/io.h>
  33. void lcd_babystep_z();
  34. void lcd_return_to_status();
  35. bool lcd_clicked();
  36. void lcd_implementation_clear();
  37. extern float meshedit_done;
  38. extern long babysteps_done;
  39. extern float code_value_float();
  40. extern bool code_value_bool();
  41. extern bool code_has_value();
  42. extern float probe_pt(float x, float y, bool, int);
  43. extern float zprobe_zoffset;
  44. extern bool set_probe_deployed(bool);
  45. #define DEPLOY_PROBE() set_probe_deployed(true)
  46. #define STOW_PROBE() set_probe_deployed(false)
  47. bool ProbeStay = true;
  48. constexpr float ubl_3_point_1_X = UBL_PROBE_PT_1_X,
  49. ubl_3_point_1_Y = UBL_PROBE_PT_1_Y,
  50. ubl_3_point_2_X = UBL_PROBE_PT_2_X,
  51. ubl_3_point_2_Y = UBL_PROBE_PT_2_Y,
  52. ubl_3_point_3_X = UBL_PROBE_PT_3_X,
  53. ubl_3_point_3_Y = UBL_PROBE_PT_3_Y;
  54. #define SIZE_OF_LITTLE_RAISE 0
  55. #define BIG_RAISE_NOT_NEEDED 0
  56. extern void lcd_quick_feedback();
  57. /**
  58. * G29: Unified Bed Leveling by Roxy
  59. *
  60. * Parameters understood by this leveling system:
  61. *
  62. * A Activate Activate the Unified Bed Leveling system.
  63. *
  64. * B # Business Use the 'Business Card' mode of the Manual Probe subsystem. This is invoked as
  65. * G29 P2 B The mode of G29 P2 allows you to use a bussiness card or recipe card
  66. * as a shim that the nozzle will pinch as it is lowered. The idea is that you
  67. * can easily feel the nozzle getting to the same height by the amount of resistance
  68. * the business card exhibits to movement. You should try to achieve the same amount
  69. * of resistance on each probed point to facilitate accurate and repeatable measurements.
  70. * You should be very careful not to drive the nozzle into the bussiness card with a
  71. * lot of force as it is very possible to cause damage to your printer if your are
  72. * careless. If you use the B option with G29 P2 B you can leave the number parameter off
  73. * on its first use to enable measurement of the business card thickness. Subsequent usage
  74. * of the B parameter can have the number previously measured supplied to the command.
  75. * Incidently, you are much better off using something like a Spark Gap feeler gauge than
  76. * something that compresses like a Business Card.
  77. *
  78. * C Continue Continue, Constant, Current Location. This is not a primary command. C is used to
  79. * further refine the behaviour of several other commands. Issuing a G29 P1 C will
  80. * continue the generation of a partially constructed Mesh without invalidating what has
  81. * been done. Issuing a G29 P2 C will tell the Manual Probe subsystem to use the current
  82. * location in its search for the closest unmeasured Mesh Point. When used with a G29 Z C
  83. * it indicates to use the current location instead of defaulting to the center of the print bed.
  84. *
  85. * D Disable Disable the Unified Bed Leveling system.
  86. *
  87. * E Stow_probe Stow the probe after each sampled point.
  88. *
  89. * F # Fade * Fade the amount of Mesh Based Compensation over a specified height. At the
  90. * specified height, no correction is applied and natural printer kenimatics take over. If no
  91. * number is specified for the command, 10mm is assumed to be reasonable.
  92. *
  93. * G # Grid * Perform a Grid Based Leveling of the current Mesh using a grid with n points on a side.
  94. *
  95. * H # Height Specify the Height to raise the nozzle after each manual probe of the bed. The
  96. * default is 5mm.
  97. *
  98. * I # Invalidate Invalidate specified number of Mesh Points. The nozzle location is used unless
  99. * the X and Y parameter are used. If no number is specified, only the closest Mesh
  100. * point to the location is invalidated. The M parameter is available as well to produce
  101. * a map after the operation. This command is useful to invalidate a portion of the
  102. * Mesh so it can be adjusted using other tools in the Unified Bed Leveling System. When
  103. * attempting to invalidate an isolated bad point in the mesh, the M option will indicate
  104. * where the nozzle is positioned in the Mesh with (#). You can move the nozzle around on
  105. * the bed and use this feature to select the center of the area (or cell) you want to
  106. * invalidate.
  107. *
  108. * K # Kompare Kompare current Mesh with stored Mesh # replacing current Mesh with the result. This
  109. * command literally performs a diff between two Meshes.
  110. *
  111. * L Load * Load Mesh from the previously activated location in the EEPROM.
  112. *
  113. * L # Load * Load Mesh from the specified location in the EEPROM. Set this location as activated
  114. * for subsequent Load and Store operations.
  115. *
  116. * O Map * Display the Mesh Map Topology.
  117. * The parameter can be specified alone (ie. G29 O) or in combination with many of the
  118. * other commands. The Mesh Map option works with all of the Phase
  119. * commands (ie. G29 P4 R 5 X 50 Y100 C -.1 O) The Map parameter can also of a Map Type
  120. * specified. A map type of 0 is the default is user readable. A map type of 1 can
  121. * be specified and is suitable to Cut & Paste into Excel to allow graphing of the user's
  122. * mesh.
  123. *
  124. * N No Home G29 normally insists that a G28 has been performed. You can over rule this with an
  125. * N option. In general, you should not do this. This can only be done safely with
  126. * commands that do not move the nozzle.
  127. *
  128. * The P or Phase commands are used for the bulk of the work to setup a Mesh. In general, your Mesh will
  129. * start off being initialized with a G29 P0 or a G29 P1. Further refinement of the Mesh happens with
  130. * each additional Phase that processes it.
  131. *
  132. * P0 Phase 0 Zero Mesh Data and turn off the Mesh Compensation System. This reverts the
  133. * 3D Printer to the same state it was in before the Unified Bed Leveling Compensation
  134. * was turned on. Setting the entire Mesh to Zero is a special case that allows
  135. * a subsequent G or T leveling operation for backward compatability.
  136. *
  137. * P1 Phase 1 Invalidate entire Mesh and continue with automatic generation of the Mesh data using
  138. * the Z-Probe. Depending upon the values of DELTA_PROBEABLE_RADIUS and
  139. * DELTA_PRINTABLE_RADIUS some area of the bed will not have Mesh Data automatically
  140. * generated. This will be handled in Phase 2. If the Phase 1 command is given the
  141. * C (Continue) parameter it does not invalidate the Mesh prior to automatically
  142. * probing needed locations. This allows you to invalidate portions of the Mesh but still
  143. * use the automatic probing capabilities of the Unified Bed Leveling System. An X and Y
  144. * parameter can be given to prioritize where the command should be trying to measure points.
  145. * If the X and Y parameters are not specified the current probe position is used. Phase 1
  146. * allows you to specify the M (Map) parameter so you can watch the generation of the Mesh.
  147. * Phase 1 also watches for the LCD Panel's Encoder Switch being held in a depressed state.
  148. * It will suspend generation of the Mesh if it sees the user request that. (This check is
  149. * only done between probe points. You will need to press and hold the switch until the
  150. * Phase 1 command can detect it.)
  151. *
  152. * P2 Phase 2 Probe areas of the Mesh that can not be automatically handled. Phase 2 respects an H
  153. * parameter to control the height between Mesh points. The default height for movement
  154. * between Mesh points is 5mm. A smaller number can be used to make this part of the
  155. * calibration less time consuming. You will be running the nozzle down until it just barely
  156. * touches the glass. You should have the nozzle clean with no plastic obstructing your view.
  157. * Use caution and move slowly. It is possible to damage your printer if you are careless.
  158. * Note that this command will use the configuration #define SIZE_OF_LITTLE_RAISE if the
  159. * nozzle is moving a distance of less than BIG_RAISE_NOT_NEEDED.
  160. *
  161. * The H parameter can be set negative if your Mesh dips in a large area. You can press
  162. * and hold the LCD Panel's encoder wheel to terminate the current Phase 2 command. You
  163. * can then re-issue the G29 P 2 command with an H parameter that is more suitable for the
  164. * area you are manually probing. Note that the command tries to start you in a corner
  165. * of the bed where movement will be predictable. You can force the location to be used in
  166. * the distance calculations by using the X and Y parameters. You may find it is helpful to
  167. * print out a Mesh Map (G29 O ) to understand where the mesh is invalidated and where
  168. * the nozzle will need to move in order to complete the command. The C parameter is
  169. * available on the Phase 2 command also and indicates the search for points to measure should
  170. * be done based on the current location of the nozzle.
  171. *
  172. * A B parameter is also available for this command and described up above. It places the
  173. * manual probe subsystem into Business Card mode where the thickness of a business care is
  174. * measured and then used to accurately set the nozzle height in all manual probing for the
  175. * duration of the command. (S for Shim mode would be a better parameter name, but S is needed
  176. * for Save or Store of the Mesh to EEPROM) A Business card can be used, but you will have
  177. * better results if you use a flexible Shim that does not compress very much. That makes it
  178. * easier for you to get the nozzle to press with similar amounts of force against the shim so you
  179. * can get accurate measurements. As you are starting to touch the nozzle against the shim try
  180. * to get it to grasp the shim with the same force as when you measured the thickness of the
  181. * shim at the start of the command.
  182. *
  183. * Phase 2 allows the O (Map) parameter to be specified. This helps the user see the progression
  184. * of the Mesh being built.
  185. *
  186. * P3 Phase 3 Fill the unpopulated regions of the Mesh with a fixed value. The C parameter is
  187. * used to specify the 'constant' value to fill all invalid areas of the Mesh. If no C parameter
  188. * is specified, a value of 0.0 is assumed. The R parameter can be given to specify the number
  189. * of points to set. If the R parameter is specified the current nozzle position is used to
  190. * find the closest points to alter unless the X and Y parameter are used to specify the fill
  191. * location.
  192. *
  193. * P4 Phase 4 Fine tune the Mesh. The Delta Mesh Compensation System assume the existance of
  194. * an LCD Panel. It is possible to fine tune the mesh without the use of an LCD Panel.
  195. * (More work and details on doing this later!)
  196. * The System will search for the closest Mesh Point to the nozzle. It will move the
  197. * nozzle to this location. The user can use the LCD Panel to carefully adjust the nozzle
  198. * so it is just barely touching the bed. When the user clicks the control, the System
  199. * will lock in that height for that point in the Mesh Compensation System.
  200. *
  201. * Phase 4 has several additional parameters that the user may find helpful. Phase 4
  202. * can be started at a specific location by specifying an X and Y parameter. Phase 4
  203. * can be requested to continue the adjustment of Mesh Points by using the R(epeat)
  204. * parameter. If the Repetition count is not specified, it is assumed the user wishes
  205. * to adjust the entire matrix. The nozzle is moved to the Mesh Point being edited.
  206. * The command can be terminated early (or after the area of interest has been edited) by
  207. * pressing and holding the encoder wheel until the system recognizes the exit request.
  208. * Phase 4's general form is G29 P4 [R # of points] [X position] [Y position]
  209. *
  210. * Phase 4 is intended to be used with the G26 Mesh Validation Command. Using the
  211. * information left on the printer's bed from the G26 command it is very straight forward
  212. * and easy to fine tune the Mesh. One concept that is important to remember and that
  213. * will make using the Phase 4 command easy to use is this: You are editing the Mesh Points.
  214. * If you have too little clearance and not much plastic was extruded in an area, you want to
  215. * LOWER the Mesh Point at the location. If you did not get good adheasion, you want to
  216. * RAISE the Mesh Point at that location.
  217. *
  218. *
  219. * P5 Phase 5 Find Mean Mesh Height and Standard Deviation. Typically, it is easier to use and
  220. * work with the Mesh if it is Mean Adjusted. You can specify a C parameter to
  221. * Correct the Mesh to a 0.00 Mean Height. Adding a C parameter will automatically
  222. * execute a G29 P6 C <mean height>.
  223. *
  224. * P6 Phase 6 Shift Mesh height. The entire Mesh's height is adjusted by the height specified
  225. * with the C parameter. Being able to adjust the height of a Mesh is useful tool. It
  226. * can be used to compensate for poorly calibrated Z-Probes and other errors. Ideally,
  227. * you should have the Mesh adjusted for a Mean Height of 0.00 and the Z-Probe measuring
  228. * 0.000 at the Z Home location.
  229. *
  230. * Q Test * Load specified Test Pattern to assist in checking correct operation of system. This
  231. * command is not anticipated to be of much value to the typical user. It is intended
  232. * for developers to help them verify correct operation of the Unified Bed Leveling System.
  233. *
  234. * S Store Store the current Mesh in the Activated area of the EEPROM. It will also store the
  235. * current state of the Unified Bed Leveling system in the EEPROM.
  236. *
  237. * S # Store Store the current Mesh at the specified location in EEPROM. Activate this location
  238. * for subsequent Load and Store operations. It will also store the current state of
  239. * the Unified Bed Leveling system in the EEPROM.
  240. *
  241. * S -1 Store Store the current Mesh as a print out that is suitable to be feed back into
  242. * the system at a later date. The text generated can be saved and later sent by PronterFace or
  243. * Repetier Host to reconstruct the current mesh on another machine.
  244. *
  245. * T 3-Point Perform a 3 Point Bed Leveling on the current Mesh
  246. *
  247. * U Unlevel Perform a probe of the outer perimeter to assist in physically leveling unlevel beds.
  248. * Only used for G29 P1 O U It will speed up the probing of the edge of the bed. This
  249. * is useful when the entire bed does not need to be probed because it will be adjusted.
  250. *
  251. * W What? Display valuable data the Unified Bed Leveling System knows.
  252. *
  253. * X # * * X Location for this line of commands
  254. *
  255. * Y # * * Y Location for this line of commands
  256. *
  257. * Z Zero * Probes to set the Z Height of the nozzle. The entire Mesh can be raised or lowered
  258. * by just doing a G29 Z
  259. *
  260. * Z # Zero * The entire Mesh can be raised or lowered to conform with the specified difference.
  261. * zprobe_zoffset is added to the calculation.
  262. *
  263. *
  264. * Release Notes:
  265. * You MUST do M502, M500 to initialize the storage. Failure to do this will cause all
  266. * kinds of problems. Enabling EEPROM Storage is highly recommended. With EEPROM Storage
  267. * of the mesh, you are limited to 3-Point and Grid Leveling. (G29 P0 T and G29 P0 G
  268. * respectively.)
  269. *
  270. * When you do a G28 and then a G29 P1 to automatically build your first mesh, you are going to notice
  271. * the Unified Bed Leveling probes points further and further away from the starting location. (The
  272. * starting location defaults to the center of the bed.) The original Grid and Mesh leveling used
  273. * a Zig Zag pattern. The new pattern is better, especially for people with Delta printers. This
  274. * allows you to get the center area of the Mesh populated (and edited) quicker. This allows you to
  275. * perform a small print and check out your settings quicker. You do not need to populate the
  276. * entire mesh to use it. (You don't want to spend a lot of time generating a mesh only to realize
  277. * you don't have the resolution or zprobe_zoffset set correctly. The Mesh generation
  278. * gathers points closest to where the nozzle is located unless you specify an (X,Y) coordinate pair.
  279. *
  280. * The Unified Bed Leveling uses a lot of EEPROM storage to hold its data. And it takes some effort
  281. * to get this Mesh data correct for a user's printer. We do not want this data destroyed as
  282. * new versions of Marlin add or subtract to the items stored in EEPROM. So, for the benefit of
  283. * the users, we store the Mesh data at the end of the EEPROM and do not keep it contiguous with the
  284. * other data stored in the EEPROM. (For sure the developers are going to complain about this, but
  285. * this is going to be helpful to the users!)
  286. *
  287. * The foundation of this Bed Leveling System is built on Epatel's Mesh Bed Leveling code. A big
  288. * 'Thanks!' to him and the creators of 3-Point and Grid Based leveling. Combining thier contributions
  289. * we now have the functionality and features of all three systems combined.
  290. */
  291. int ubl_eeprom_start = -1;
  292. bool ubl_has_control_of_lcd_panel = false;
  293. volatile uint8_t ubl_encoderDiff = 0; // Volatile because it's changed by Temperature ISR button update
  294. // The simple parameter flags and values are 'static' so parameter parsing can be in a support routine.
  295. static int g29_verbose_level = 0, phase_value = -1, repetition_cnt = 1,
  296. storage_slot = 0, map_type = 0, test_pattern = 0, unlevel_value = -1;
  297. static bool repeat_flag = UBL_OK, c_flag = false, x_flag = UBL_OK, y_flag = UBL_OK, statistics_flag = UBL_OK, business_card_mode = false;
  298. static float x_pos = 0.0, y_pos = 0.0, height_value = 5.0, measured_z, card_thickness = 0.0, constant = 0.0;
  299. #if ENABLED(ULTRA_LCD)
  300. void lcd_setstatus(const char* message, bool persist);
  301. #endif
  302. void gcode_G29() {
  303. float Z1, Z2, Z3;
  304. g29_verbose_level = 0; // These may change, but let's get some reasonable values into them.
  305. repeat_flag = UBL_OK;
  306. repetition_cnt = 1;
  307. c_flag = false;
  308. SERIAL_PROTOCOLLNPAIR("ubl_eeprom_start=", ubl_eeprom_start);
  309. if (ubl_eeprom_start < 0) {
  310. SERIAL_PROTOCOLLNPGM("?You need to enable your EEPROM and initialize it");
  311. SERIAL_PROTOCOLLNPGM("with M502, M500, M501 in that order.\n");
  312. return;
  313. }
  314. if (!code_seen('N') && axis_unhomed_error(true, true, true)) // Don't allow auto-leveling without homing first
  315. gcode_G28();
  316. if (g29_parameter_parsing()) return; // abort if parsing the simple parameters causes a problem,
  317. // Invalidate Mesh Points. This command is a little bit asymetrical because
  318. // it directly specifies the repetition count and does not use the 'R' parameter.
  319. if (code_seen('I')) {
  320. repetition_cnt = code_has_value() ? code_value_int() : 1;
  321. while (repetition_cnt--) {
  322. const mesh_index_pair location = find_closest_mesh_point_of_type(REAL, x_pos, y_pos, 0, NULL, false); // The '0' says we want to use the nozzle's position
  323. if (location.x_index < 0) {
  324. SERIAL_PROTOCOLLNPGM("Entire Mesh invalidated.\n");
  325. break; // No more invalid Mesh Points to populate
  326. }
  327. z_values[location.x_index][location.y_index] = NAN;
  328. }
  329. SERIAL_PROTOCOLLNPGM("Locations invalidated.\n");
  330. }
  331. if (code_seen('Q')) {
  332. if (code_has_value()) test_pattern = code_value_int();
  333. if (test_pattern < 0 || test_pattern > 4) {
  334. SERIAL_PROTOCOLLNPGM("Invalid test_pattern value. (0-4)\n");
  335. return;
  336. }
  337. SERIAL_PROTOCOLLNPGM("Loading test_pattern values.\n");
  338. switch (test_pattern) {
  339. case 0:
  340. for (uint8_t x = 0; x < UBL_MESH_NUM_X_POINTS; x++) { // Create a bowl shape. This is
  341. for (uint8_t y = 0; y < UBL_MESH_NUM_Y_POINTS; y++) { // similar to what a user would see with
  342. Z1 = 0.5 * (UBL_MESH_NUM_X_POINTS) - x; // a poorly calibrated Delta.
  343. Z2 = 0.5 * (UBL_MESH_NUM_Y_POINTS) - y;
  344. z_values[x][y] += 2.0 * HYPOT(Z1, Z2);
  345. }
  346. }
  347. break;
  348. case 1:
  349. for (uint8_t x = 0; x < UBL_MESH_NUM_X_POINTS; x++) { // Create a diagonal line several Mesh
  350. z_values[x][x] += 9.999; // cells thick that is raised
  351. if (x < UBL_MESH_NUM_Y_POINTS - 1)
  352. z_values[x][x + 1] += 9.999; // We want the altered line several mesh points thick
  353. if (x > 0)
  354. z_values[x][x - 1] += 9.999; // We want the altered line several mesh points thick
  355. }
  356. break;
  357. case 2:
  358. // Allow the user to specify the height because 10mm is
  359. // a little bit extreme in some cases.
  360. for (uint8_t x = (UBL_MESH_NUM_X_POINTS) / 3; x < 2 * (UBL_MESH_NUM_X_POINTS) / 3; x++) // Create a rectangular raised area in
  361. for (uint8_t y = (UBL_MESH_NUM_Y_POINTS) / 3; y < 2 * (UBL_MESH_NUM_Y_POINTS) / 3; y++) // the center of the bed
  362. z_values[x][y] += code_seen('C') ? constant : 9.99;
  363. break;
  364. case 3:
  365. break;
  366. }
  367. }
  368. /*
  369. if (code_seen('U')) {
  370. unlevel_value = code_value_int();
  371. // if (unlevel_value < 0 || unlevel_value > 7) {
  372. // SERIAL_PROTOCOLLNPGM("Invalid Unlevel value. (0-4)\n");
  373. // return;
  374. // }
  375. }
  376. */
  377. if (code_seen('P')) {
  378. phase_value = code_value_int();
  379. if (phase_value < 0 || phase_value > 7) {
  380. SERIAL_PROTOCOLLNPGM("Invalid Phase value. (0-4)\n");
  381. return;
  382. }
  383. switch (phase_value) {
  384. //
  385. // Zero Mesh Data
  386. //
  387. case 0:
  388. ubl.reset();
  389. SERIAL_PROTOCOLLNPGM("Mesh zeroed.\n");
  390. break;
  391. //
  392. // Invalidate Entire Mesh and Automatically Probe Mesh in areas that can be reached by the probe
  393. //
  394. case 1:
  395. if (!code_seen('C') ) {
  396. ubl.invalidate();
  397. SERIAL_PROTOCOLLNPGM("Mesh invalidated. Probing mesh.\n");
  398. }
  399. if (g29_verbose_level > 1) {
  400. SERIAL_ECHOPGM("Probing Mesh Points Closest to (");
  401. SERIAL_ECHO(x_pos);
  402. SERIAL_ECHOPAIR(",", y_pos);
  403. SERIAL_PROTOCOLLNPGM(")\n");
  404. }
  405. probe_entire_mesh(x_pos + X_PROBE_OFFSET_FROM_EXTRUDER, y_pos + Y_PROBE_OFFSET_FROM_EXTRUDER,
  406. code_seen('O') || code_seen('M'), code_seen('E'), code_seen('U'));
  407. break;
  408. //
  409. // Manually Probe Mesh in areas that can not be reached by the probe
  410. //
  411. case 2:
  412. SERIAL_PROTOCOLLNPGM("Manually probing unreachable mesh locations.\n");
  413. do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
  414. if (!x_flag && !y_flag) { // use a good default location for the path
  415. x_pos = X_MIN_POS;
  416. y_pos = Y_MIN_POS;
  417. if (X_PROBE_OFFSET_FROM_EXTRUDER > 0) // The flipped > and < operators on these two comparisons is
  418. x_pos = X_MAX_POS; // intentional. It should cause the probed points to follow a
  419. if (Y_PROBE_OFFSET_FROM_EXTRUDER < 0) // nice path on Cartesian printers. It may make sense to
  420. y_pos = Y_MAX_POS; // have Delta printers default to the center of the bed.
  421. } // For now, until that is decided, it can be forced with the X
  422. // and Y parameters.
  423. if (code_seen('C')) {
  424. x_pos = current_position[X_AXIS];
  425. y_pos = current_position[Y_AXIS];
  426. }
  427. height_value = code_seen('H') && code_has_value() ? code_value_float() : Z_CLEARANCE_BETWEEN_PROBES;
  428. if ((business_card_mode = code_seen('B'))) {
  429. card_thickness = code_has_value() ? code_value_float() : measure_business_card_thickness(height_value);
  430. if (fabs(card_thickness) > 1.5) {
  431. SERIAL_PROTOCOLLNPGM("?Error in Business Card measurment.\n");
  432. return;
  433. }
  434. }
  435. manually_probe_remaining_mesh(x_pos, y_pos, height_value, card_thickness, code_seen('O') || code_seen('M'));
  436. break;
  437. //
  438. // Populate invalid Mesh areas with a constant
  439. //
  440. case 3:
  441. height_value = 0.0; // Assume 0.0 until proven otherwise
  442. if (code_seen('C')) height_value = constant;
  443. // If no repetition is specified, do the whole Mesh
  444. if (!repeat_flag) repetition_cnt = 9999;
  445. while (repetition_cnt--) {
  446. const mesh_index_pair location = find_closest_mesh_point_of_type(INVALID, x_pos, y_pos, 0, NULL, false); // The '0' says we want to use the nozzle's position
  447. if (location.x_index < 0) break; // No more invalid Mesh Points to populate
  448. z_values[location.x_index][location.y_index] = height_value;
  449. }
  450. break;
  451. //
  452. // Fine Tune (Or Edit) the Mesh
  453. //
  454. case 4:
  455. fine_tune_mesh(x_pos, y_pos, code_seen('O') || code_seen('M'));
  456. break;
  457. case 5:
  458. find_mean_mesh_height();
  459. break;
  460. case 6:
  461. shift_mesh_height();
  462. break;
  463. case 10:
  464. // Debug code... Pay no attention to this stuff
  465. // it can be removed soon.
  466. SERIAL_ECHO_START;
  467. SERIAL_ECHOLNPGM("Checking G29 has control of LCD Panel:");
  468. wait_for_user = true;
  469. while (wait_for_user) {
  470. idle();
  471. delay(250);
  472. SERIAL_ECHO((int)ubl_encoderDiff);
  473. ubl_encoderDiff = 0;
  474. SERIAL_EOL;
  475. }
  476. SERIAL_ECHOLNPGM("G29 giving back control of LCD Panel.");
  477. break;
  478. }
  479. }
  480. if (code_seen('T')) {
  481. Z1 = probe_pt(ubl_3_point_1_X, ubl_3_point_1_Y, false /*Stow Flag*/, g29_verbose_level) + zprobe_zoffset;
  482. Z2 = probe_pt(ubl_3_point_2_X, ubl_3_point_2_Y, false /*Stow Flag*/, g29_verbose_level) + zprobe_zoffset;
  483. Z3 = probe_pt(ubl_3_point_3_X, ubl_3_point_3_Y, true /*Stow Flag*/, g29_verbose_level) + zprobe_zoffset;
  484. // We need to adjust Z1, Z2, Z3 by the Mesh Height at these points. Just because they are non-zero doesn't mean
  485. // the Mesh is tilted! (We need to compensate each probe point by what the Mesh says that location's height is)
  486. Z1 -= ubl.get_z_correction(ubl_3_point_1_X, ubl_3_point_1_Y);
  487. Z2 -= ubl.get_z_correction(ubl_3_point_2_X, ubl_3_point_2_Y);
  488. Z3 -= ubl.get_z_correction(ubl_3_point_3_X, ubl_3_point_3_Y);
  489. do_blocking_move_to_xy((X_MAX_POS - (X_MIN_POS)) / 2.0, (Y_MAX_POS - (Y_MIN_POS)) / 2.0);
  490. tilt_mesh_based_on_3pts(Z1, Z2, Z3);
  491. }
  492. //
  493. // Much of the 'What?' command can be eliminated. But until we are fully debugged, it is
  494. // good to have the extra information. Soon... we prune this to just a few items
  495. //
  496. if (code_seen('W')) g29_what_command();
  497. //
  498. // When we are fully debugged, the EEPROM dump command will get deleted also. But
  499. // right now, it is good to have the extra information. Soon... we prune this.
  500. //
  501. if (code_seen('J')) g29_eeprom_dump(); // EEPROM Dump
  502. //
  503. // When we are fully debugged, this may go away. But there are some valid
  504. // use cases for the users. So we can wait and see what to do with it.
  505. //
  506. if (code_seen('K')) // Kompare Current Mesh Data to Specified Stored Mesh
  507. g29_compare_current_mesh_to_stored_mesh();
  508. //
  509. // Load a Mesh from the EEPROM
  510. //
  511. if (code_seen('L')) { // Load Current Mesh Data
  512. storage_slot = code_has_value() ? code_value_int() : ubl.state.eeprom_storage_slot;
  513. const int16_t j = (UBL_LAST_EEPROM_INDEX - ubl_eeprom_start) / sizeof(z_values);
  514. if (storage_slot < 0 || storage_slot >= j || ubl_eeprom_start <= 0) {
  515. SERIAL_PROTOCOLLNPGM("?EEPROM storage not available for use.\n");
  516. return;
  517. }
  518. ubl.load_mesh(storage_slot);
  519. ubl.state.eeprom_storage_slot = storage_slot;
  520. if (storage_slot != ubl.state.eeprom_storage_slot)
  521. ubl.store_state();
  522. SERIAL_PROTOCOLLNPGM("Done.\n");
  523. }
  524. //
  525. // Store a Mesh in the EEPROM
  526. //
  527. if (code_seen('S')) { // Store (or Save) Current Mesh Data
  528. storage_slot = code_has_value() ? code_value_int() : ubl.state.eeprom_storage_slot;
  529. if (storage_slot == -1) { // Special case, we are going to 'Export' the mesh to the
  530. SERIAL_ECHOLNPGM("G29 I 999"); // host in a form it can be reconstructed on a different machine
  531. for (uint8_t x = 0; x < UBL_MESH_NUM_X_POINTS; x++)
  532. for (uint8_t y = 0; y < UBL_MESH_NUM_Y_POINTS; y++)
  533. if (!isnan(z_values[x][y])) {
  534. SERIAL_ECHOPAIR("M421 I ", x);
  535. SERIAL_ECHOPAIR(" J ", y);
  536. SERIAL_ECHOPGM(" Z ");
  537. SERIAL_ECHO_F(z_values[x][y], 6);
  538. SERIAL_EOL;
  539. }
  540. return;
  541. }
  542. const int16_t j = (UBL_LAST_EEPROM_INDEX - ubl_eeprom_start) / sizeof(z_values);
  543. if (storage_slot < 0 || storage_slot >= j || ubl_eeprom_start <= 0) {
  544. SERIAL_PROTOCOLLNPGM("?EEPROM storage not available for use.\n");
  545. SERIAL_PROTOCOLLNPAIR("?Use 0 to ", j - 1);
  546. goto LEAVE;
  547. }
  548. ubl.store_mesh(storage_slot);
  549. ubl.state.eeprom_storage_slot = storage_slot;
  550. //
  551. // if (storage_slot != ubl.state.eeprom_storage_slot)
  552. ubl.store_state(); // Always save an updated copy of the UBL State info
  553. SERIAL_PROTOCOLLNPGM("Done.\n");
  554. }
  555. if (code_seen('O') || code_seen('M'))
  556. ubl.display_map(code_has_value() ? code_value_int() : 0);
  557. if (code_seen('Z')) {
  558. if (code_has_value())
  559. ubl.state.z_offset = code_value_float(); // do the simple case. Just lock in the specified value
  560. else {
  561. save_ubl_active_state_and_disable();
  562. //measured_z = probe_pt(x_pos + X_PROBE_OFFSET_FROM_EXTRUDER, y_pos + Y_PROBE_OFFSET_FROM_EXTRUDER, ProbeDeployAndStow, g29_verbose_level);
  563. ubl_has_control_of_lcd_panel = true;// Grab the LCD Hardware
  564. measured_z = 1.5;
  565. do_blocking_move_to_z(measured_z); // Get close to the bed, but leave some space so we don't damage anything
  566. // The user is not going to be locking in a new Z-Offset very often so
  567. // it won't be that painful to spin the Encoder Wheel for 1.5mm
  568. lcd_implementation_clear();
  569. lcd_z_offset_edit_setup(measured_z);
  570. do {
  571. measured_z = lcd_z_offset_edit();
  572. idle();
  573. do_blocking_move_to_z(measured_z);
  574. } while (!ubl_lcd_clicked());
  575. ubl_has_control_of_lcd_panel++; // There is a race condition for the Encoder Wheel getting clicked.
  576. // It could get detected in lcd_mesh_edit (actually _lcd_mesh_fine_tune)
  577. // or here. So, until we are done looking for a long Encoder Wheel Press,
  578. // we need to take control of the panel
  579. lcd_return_to_status();
  580. const millis_t nxt = millis() + 1500UL;
  581. while (ubl_lcd_clicked()) { // debounce and watch for abort
  582. idle();
  583. if (ELAPSED(millis(), nxt)) {
  584. SERIAL_PROTOCOLLNPGM("\nZ-Offset Adjustment Stopped.");
  585. do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
  586. lcd_setstatus("Z-Offset Stopped", true);
  587. ubl_has_control_of_lcd_panel = false;
  588. restore_ubl_active_state_and_leave();
  589. goto LEAVE;
  590. }
  591. }
  592. ubl_has_control_of_lcd_panel = false;
  593. delay(20); // We don't want any switch noise.
  594. ubl.state.z_offset = measured_z;
  595. lcd_implementation_clear();
  596. restore_ubl_active_state_and_leave();
  597. }
  598. }
  599. LEAVE:
  600. #if ENABLED(ULTRA_LCD)
  601. lcd_setstatus(" ", true);
  602. lcd_quick_feedback();
  603. #endif
  604. ubl_has_control_of_lcd_panel = false;
  605. }
  606. void find_mean_mesh_height() {
  607. uint8_t x, y;
  608. int n;
  609. float sum, sum_of_diff_squared, sigma, difference, mean;
  610. sum = sum_of_diff_squared = 0.0;
  611. n = 0;
  612. for (x = 0; x < UBL_MESH_NUM_X_POINTS; x++)
  613. for (y = 0; y < UBL_MESH_NUM_Y_POINTS; y++)
  614. if (!isnan(z_values[x][y])) {
  615. sum += z_values[x][y];
  616. n++;
  617. }
  618. mean = sum / n;
  619. //
  620. // Now do the sumation of the squares of difference from mean
  621. //
  622. for (x = 0; x < UBL_MESH_NUM_X_POINTS; x++)
  623. for (y = 0; y < UBL_MESH_NUM_Y_POINTS; y++)
  624. if (!isnan(z_values[x][y])) {
  625. difference = (z_values[x][y] - mean);
  626. sum_of_diff_squared += difference * difference;
  627. }
  628. SERIAL_ECHOLNPAIR("# of samples: ", n);
  629. SERIAL_ECHOPGM("Mean Mesh Height: ");
  630. SERIAL_ECHO_F(mean, 6);
  631. SERIAL_EOL;
  632. sigma = sqrt(sum_of_diff_squared / (n + 1));
  633. SERIAL_ECHOPGM("Standard Deviation: ");
  634. SERIAL_ECHO_F(sigma, 6);
  635. SERIAL_EOL;
  636. if (c_flag)
  637. for (x = 0; x < UBL_MESH_NUM_X_POINTS; x++)
  638. for (y = 0; y < UBL_MESH_NUM_Y_POINTS; y++)
  639. if (!isnan(z_values[x][y]))
  640. z_values[x][y] -= mean + constant;
  641. }
  642. void shift_mesh_height() {
  643. for (uint8_t x = 0; x < UBL_MESH_NUM_X_POINTS; x++)
  644. for (uint8_t y = 0; y < UBL_MESH_NUM_Y_POINTS; y++)
  645. if (!isnan(z_values[x][y]))
  646. z_values[x][y] += constant;
  647. }
  648. /**
  649. * Probe all invalidated locations of the mesh that can be reached by the probe.
  650. * This attempts to fill in locations closest to the nozzle's start location first.
  651. */
  652. void probe_entire_mesh(const float &lx, const float &ly, const bool do_ubl_mesh_map, const bool stow_probe, bool do_furthest) {
  653. mesh_index_pair location;
  654. ubl_has_control_of_lcd_panel++;
  655. save_ubl_active_state_and_disable(); // we don't do bed level correction because we want the raw data when we probe
  656. DEPLOY_PROBE();
  657. do {
  658. if (ubl_lcd_clicked()) {
  659. SERIAL_PROTOCOLLNPGM("\nMesh only partially populated.\n");
  660. lcd_quick_feedback();
  661. STOW_PROBE();
  662. while (ubl_lcd_clicked() ) {
  663. idle();
  664. }
  665. ubl_has_control_of_lcd_panel = false;
  666. restore_ubl_active_state_and_leave();
  667. delay(50); // Debounce the Encoder wheel
  668. return;
  669. }
  670. location = find_closest_mesh_point_of_type(INVALID, lx, ly, 1, NULL, do_furthest ); // the '1' says we want the location to be relative to the probe
  671. if (location.x_index >= 0 && location.y_index >= 0) {
  672. const float xProbe = ubl.map_x_index_to_bed_location(location.x_index),
  673. yProbe = ubl.map_y_index_to_bed_location(location.y_index);
  674. if (xProbe < MIN_PROBE_X || xProbe > MAX_PROBE_X || yProbe < MIN_PROBE_Y || yProbe > MAX_PROBE_Y) {
  675. SERIAL_PROTOCOLLNPGM("?Error: Attempt to probe off the bed.");
  676. ubl_has_control_of_lcd_panel = false;
  677. goto LEAVE;
  678. }
  679. const float measured_z = probe_pt(xProbe, yProbe, stow_probe, g29_verbose_level);
  680. z_values[location.x_index][location.y_index] = measured_z + zprobe_zoffset;
  681. }
  682. if (do_ubl_mesh_map) ubl.display_map(map_type);
  683. } while (location.x_index >= 0 && location.y_index >= 0);
  684. LEAVE:
  685. STOW_PROBE();
  686. restore_ubl_active_state_and_leave();
  687. do_blocking_move_to_xy(
  688. constrain(lx - (X_PROBE_OFFSET_FROM_EXTRUDER), X_MIN_POS, X_MAX_POS),
  689. constrain(ly - (Y_PROBE_OFFSET_FROM_EXTRUDER), Y_MIN_POS, Y_MAX_POS)
  690. );
  691. }
  692. vector_3 tilt_mesh_based_on_3pts(const float &pt1, const float &pt2, const float &pt3) {
  693. float c, d, t;
  694. int i, j;
  695. vector_3 v1 = vector_3( (ubl_3_point_1_X - ubl_3_point_2_X),
  696. (ubl_3_point_1_Y - ubl_3_point_2_Y),
  697. (pt1 - pt2) ),
  698. v2 = vector_3( (ubl_3_point_3_X - ubl_3_point_2_X),
  699. (ubl_3_point_3_Y - ubl_3_point_2_Y),
  700. (pt3 - pt2) ),
  701. normal = vector_3::cross(v1, v2);
  702. // printf("[%f,%f,%f] ", normal.x, normal.y, normal.z);
  703. /**
  704. * This code does two things. This vector is normal to the tilted plane.
  705. * However, we don't know its direction. We need it to point up. So if
  706. * Z is negative, we need to invert the sign of all components of the vector
  707. * We also need Z to be unity because we are going to be treating this triangle
  708. * as the sin() and cos() of the bed's tilt
  709. */
  710. const float inv_z = 1.0 / normal.z;
  711. normal.x *= inv_z;
  712. normal.y *= inv_z;
  713. normal.z = 1.0;
  714. //
  715. // All of 3 of these points should give us the same d constant
  716. //
  717. t = normal.x * ubl_3_point_1_X + normal.y * ubl_3_point_1_Y;
  718. d = t + normal.z * pt1;
  719. c = d - t;
  720. SERIAL_ECHOPGM("d from 1st point: ");
  721. SERIAL_ECHO_F(d, 6);
  722. SERIAL_ECHOPGM(" c: ");
  723. SERIAL_ECHO_F(c, 6);
  724. SERIAL_EOL;
  725. t = normal.x * ubl_3_point_2_X + normal.y * ubl_3_point_2_Y;
  726. d = t + normal.z * pt2;
  727. c = d - t;
  728. SERIAL_ECHOPGM("d from 2nd point: ");
  729. SERIAL_ECHO_F(d, 6);
  730. SERIAL_ECHOPGM(" c: ");
  731. SERIAL_ECHO_F(c, 6);
  732. SERIAL_EOL;
  733. t = normal.x * ubl_3_point_3_X + normal.y * ubl_3_point_3_Y;
  734. d = t + normal.z * pt3;
  735. c = d - t;
  736. SERIAL_ECHOPGM("d from 3rd point: ");
  737. SERIAL_ECHO_F(d, 6);
  738. SERIAL_ECHOPGM(" c: ");
  739. SERIAL_ECHO_F(c, 6);
  740. SERIAL_EOL;
  741. for (i = 0; i < UBL_MESH_NUM_X_POINTS; i++) {
  742. for (j = 0; j < UBL_MESH_NUM_Y_POINTS; j++) {
  743. c = -((normal.x * (UBL_MESH_MIN_X + i * (MESH_X_DIST)) + normal.y * (UBL_MESH_MIN_Y + j * (MESH_Y_DIST))) - d);
  744. z_values[i][j] += c;
  745. }
  746. }
  747. return normal;
  748. }
  749. float use_encoder_wheel_to_measure_point() {
  750. while (!ubl_lcd_clicked()) { // we need the loop to move the nozzle based on the encoder wheel here!
  751. idle();
  752. if (ubl_encoderDiff) {
  753. do_blocking_move_to_z(current_position[Z_AXIS] + 0.01 * float(ubl_encoderDiff));
  754. ubl_encoderDiff = 0;
  755. }
  756. }
  757. return current_position[Z_AXIS];
  758. }
  759. float measure_business_card_thickness(const float &height_value) {
  760. ubl_has_control_of_lcd_panel++;
  761. save_ubl_active_state_and_disable(); // we don't do bed level correction because we want the raw data when we probe
  762. SERIAL_PROTOCOLLNPGM("Place Shim Under Nozzle and Perform Measurement.");
  763. do_blocking_move_to_z(height_value);
  764. do_blocking_move_to_xy((float(X_MAX_POS) - float(X_MIN_POS)) / 2.0, (float(Y_MAX_POS) - float(Y_MIN_POS)) / 2.0);
  765. //, min( planner.max_feedrate_mm_s[X_AXIS], planner.max_feedrate_mm_s[Y_AXIS])/2.0);
  766. const float Z1 = use_encoder_wheel_to_measure_point();
  767. do_blocking_move_to_z(current_position[Z_AXIS] + SIZE_OF_LITTLE_RAISE);
  768. ubl_has_control_of_lcd_panel = false;
  769. SERIAL_PROTOCOLLNPGM("Remove Shim and Measure Bed Height.");
  770. const float Z2 = use_encoder_wheel_to_measure_point();
  771. do_blocking_move_to_z(current_position[Z_AXIS] + SIZE_OF_LITTLE_RAISE);
  772. if (g29_verbose_level > 1) {
  773. SERIAL_PROTOCOLPGM("Business Card is: ");
  774. SERIAL_PROTOCOL_F(abs(Z1 - Z2), 6);
  775. SERIAL_PROTOCOLLNPGM("mm thick.");
  776. }
  777. restore_ubl_active_state_and_leave();
  778. return abs(Z1 - Z2);
  779. }
  780. void manually_probe_remaining_mesh(const float &lx, const float &ly, const float &z_clearance, const float &card_thickness, const bool do_ubl_mesh_map) {
  781. ubl_has_control_of_lcd_panel++;
  782. save_ubl_active_state_and_disable(); // we don't do bed level correction because we want the raw data when we probe
  783. do_blocking_move_to_z(z_clearance);
  784. do_blocking_move_to_xy(lx, ly);
  785. float last_x = -9999.99, last_y = -9999.99;
  786. mesh_index_pair location;
  787. do {
  788. if (do_ubl_mesh_map) ubl.display_map(map_type);
  789. location = find_closest_mesh_point_of_type(INVALID, lx, ly, 0, NULL, false); // The '0' says we want to use the nozzle's position
  790. // It doesn't matter if the probe can not reach the
  791. // NAN location. This is a manual probe.
  792. if (location.x_index < 0 && location.y_index < 0) continue;
  793. const float xProbe = ubl.map_x_index_to_bed_location(location.x_index),
  794. yProbe = ubl.map_y_index_to_bed_location(location.y_index);
  795. // Modify to use if (position_is_reachable(pos[XYZ]))
  796. if (xProbe < (X_MIN_POS) || xProbe > (X_MAX_POS) || yProbe < (Y_MIN_POS) || yProbe > (Y_MAX_POS)) {
  797. SERIAL_PROTOCOLLNPGM("?Error: Attempt to probe off the bed.");
  798. ubl_has_control_of_lcd_panel = false;
  799. goto LEAVE;
  800. }
  801. const float dx = xProbe - last_x,
  802. dy = yProbe - last_y;
  803. if (HYPOT(dx, dy) < BIG_RAISE_NOT_NEEDED)
  804. do_blocking_move_to_z(current_position[Z_AXIS] + SIZE_OF_LITTLE_RAISE);
  805. else
  806. do_blocking_move_to_z(z_clearance);
  807. do_blocking_move_to_xy(xProbe, yProbe);
  808. last_x = xProbe;
  809. last_y = yProbe;
  810. ubl_has_control_of_lcd_panel = true;
  811. while (!ubl_lcd_clicked) { // we need the loop to move the nozzle based on the encoder wheel here!
  812. idle();
  813. if (ubl_encoderDiff) {
  814. do_blocking_move_to_z(current_position[Z_AXIS] + float(ubl_encoderDiff) / 100.0);
  815. ubl_encoderDiff = 0;
  816. }
  817. }
  818. const millis_t nxt = millis() + 1500L;
  819. while (ubl_lcd_clicked()) { // debounce and watch for abort
  820. idle();
  821. if (ELAPSED(millis(), nxt)) {
  822. SERIAL_PROTOCOLLNPGM("\nMesh only partially populated.");
  823. do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
  824. lcd_quick_feedback();
  825. while (ubl_lcd_clicked()) idle();
  826. ubl_has_control_of_lcd_panel = false;
  827. restore_ubl_active_state_and_leave();
  828. return;
  829. }
  830. }
  831. z_values[location.x_index][location.y_index] = current_position[Z_AXIS] - card_thickness;
  832. if (g29_verbose_level > 2) {
  833. SERIAL_PROTOCOL("Mesh Point Measured at: ");
  834. SERIAL_PROTOCOL_F(z_values[location.x_index][location.y_index], 6);
  835. SERIAL_EOL;
  836. }
  837. } while (location.x_index >= 0 && location.y_index >= 0);
  838. if (do_ubl_mesh_map) ubl.display_map(map_type);
  839. LEAVE:
  840. restore_ubl_active_state_and_leave();
  841. do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
  842. do_blocking_move_to_xy(lx, ly);
  843. }
  844. bool g29_parameter_parsing() {
  845. #if ENABLED(ULTRA_LCD)
  846. lcd_setstatus("Doing G29 UBL !", true);
  847. lcd_quick_feedback();
  848. #endif
  849. x_pos = current_position[X_AXIS];
  850. y_pos = current_position[Y_AXIS];
  851. x_flag = y_flag = repeat_flag = false;
  852. map_type = 0;
  853. constant = 0.0;
  854. repetition_cnt = 1;
  855. if ((x_flag = code_seen('X'))) {
  856. x_pos = code_value_float();
  857. if (x_pos < X_MIN_POS || x_pos > X_MAX_POS) {
  858. SERIAL_PROTOCOLLNPGM("Invalid X location specified.\n");
  859. return UBL_ERR;
  860. }
  861. }
  862. if ((y_flag = code_seen('Y'))) {
  863. y_pos = code_value_float();
  864. if (y_pos < Y_MIN_POS || y_pos > Y_MAX_POS) {
  865. SERIAL_PROTOCOLLNPGM("Invalid Y location specified.\n");
  866. return UBL_ERR;
  867. }
  868. }
  869. if (x_flag != y_flag) {
  870. SERIAL_PROTOCOLLNPGM("Both X & Y locations must be specified.\n");
  871. return UBL_ERR;
  872. }
  873. g29_verbose_level = 0;
  874. if (code_seen('V')) {
  875. g29_verbose_level = code_value_int();
  876. if (g29_verbose_level < 0 || g29_verbose_level > 4) {
  877. SERIAL_PROTOCOLLNPGM("Invalid Verbose Level specified. (0-4)\n");
  878. return UBL_ERR;
  879. }
  880. }
  881. if (code_seen('A')) { // Activate the Unified Bed Leveling System
  882. ubl.state.active = 1;
  883. SERIAL_PROTOCOLLNPGM("Unified Bed Leveling System activated.\n");
  884. ubl.store_state();
  885. }
  886. if ((c_flag = code_seen('C') && code_has_value()))
  887. constant = code_value_float();
  888. if (code_seen('D')) { // Disable the Unified Bed Leveling System
  889. ubl.state.active = 0;
  890. SERIAL_PROTOCOLLNPGM("Unified Bed Leveling System de-activated.\n");
  891. ubl.store_state();
  892. }
  893. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  894. if (code_seen('F') && code_has_value()) {
  895. const float fh = code_value_float();
  896. if (fh < 0.0 || fh > 100.0) {
  897. SERIAL_PROTOCOLLNPGM("?Bed Level Correction Fade Height Not Plausible.\n");
  898. return UBL_ERR;
  899. }
  900. ubl.state.g29_correction_fade_height = fh;
  901. ubl.state.g29_fade_height_multiplier = 1.0 / fh;
  902. }
  903. #endif
  904. if ((repeat_flag = code_seen('R'))) {
  905. repetition_cnt = code_has_value() ? code_value_int() : 9999;
  906. if (repetition_cnt < 1) {
  907. SERIAL_PROTOCOLLNPGM("Invalid Repetition count.\n");
  908. return UBL_ERR;
  909. }
  910. }
  911. if (code_seen('O')) { // Check if a map type was specified
  912. map_type = code_value_int() ? code_has_value() : 0;
  913. if ( map_type<0 || map_type>1) {
  914. SERIAL_PROTOCOLLNPGM("Invalid map type.\n");
  915. return UBL_ERR;
  916. }
  917. }
  918. if (code_seen('M')) { // Check if a map type was specified
  919. map_type = code_value_int() ? code_has_value() : 0;
  920. if ( map_type<0 || map_type>1) {
  921. SERIAL_PROTOCOLLNPGM("Invalid map type.\n");
  922. return UBL_ERR;
  923. }
  924. }
  925. return UBL_OK;
  926. }
  927. /**
  928. * This function goes away after G29 debug is complete. But for right now, it is a handy
  929. * routine to dump binary data structures.
  930. */
  931. void dump(char * const str, const float &f) {
  932. char *ptr;
  933. SERIAL_PROTOCOL(str);
  934. SERIAL_PROTOCOL_F(f, 8);
  935. SERIAL_PROTOCOL(" ");
  936. ptr = (char*)&f;
  937. for (uint8_t i = 0; i < 4; i++) {
  938. SERIAL_PROTOCOL(" ");
  939. prt_hex_byte(*ptr++);
  940. }
  941. SERIAL_PROTOCOL(" isnan()=");
  942. SERIAL_PROTOCOL(isnan(f));
  943. SERIAL_PROTOCOL(" isinf()=");
  944. SERIAL_PROTOCOL(isinf(f));
  945. constexpr float g = INFINITY;
  946. if (f == -g)
  947. SERIAL_PROTOCOL(" Minus Infinity detected.");
  948. SERIAL_EOL;
  949. }
  950. static int ubl_state_at_invocation = 0,
  951. ubl_state_recursion_chk = 0;
  952. void save_ubl_active_state_and_disable() {
  953. ubl_state_recursion_chk++;
  954. if (ubl_state_recursion_chk != 1) {
  955. SERIAL_ECHOLNPGM("save_ubl_active_state_and_disabled() called multiple times in a row.");
  956. lcd_setstatus("save_UBL_active() error", true);
  957. lcd_quick_feedback();
  958. return;
  959. }
  960. ubl_state_at_invocation = ubl.state.active;
  961. ubl.state.active = 0;
  962. }
  963. void restore_ubl_active_state_and_leave() {
  964. if (--ubl_state_recursion_chk) {
  965. SERIAL_ECHOLNPGM("restore_ubl_active_state_and_leave() called too many times.");
  966. lcd_setstatus("restore_UBL_active() error", true);
  967. lcd_quick_feedback();
  968. return;
  969. }
  970. ubl.state.active = ubl_state_at_invocation;
  971. }
  972. /**
  973. * Much of the 'What?' command can be eliminated. But until we are fully debugged, it is
  974. * good to have the extra information. Soon... we prune this to just a few items
  975. */
  976. void g29_what_command() {
  977. const uint16_t k = E2END - ubl_eeprom_start;
  978. statistics_flag++;
  979. SERIAL_PROTOCOLPGM("Unified Bed Leveling System Version 1.00 ");
  980. if (ubl.state.active)
  981. SERIAL_PROTOCOLCHAR('A');
  982. else
  983. SERIAL_PROTOCOLPGM("In");
  984. SERIAL_PROTOCOLLNPGM("ctive.\n");
  985. delay(50);
  986. if (ubl.state.eeprom_storage_slot == -1)
  987. SERIAL_PROTOCOLPGM("No Mesh Loaded.");
  988. else {
  989. SERIAL_PROTOCOLPGM("Mesh: ");
  990. prt_hex_word(ubl.state.eeprom_storage_slot);
  991. SERIAL_PROTOCOLPGM(" Loaded.");
  992. }
  993. SERIAL_EOL;
  994. delay(50);
  995. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  996. SERIAL_PROTOCOLPAIR("g29_correction_fade_height : ", ubl.state.g29_correction_fade_height);
  997. SERIAL_EOL;
  998. #endif
  999. SERIAL_PROTOCOLPGM("z_offset: ");
  1000. SERIAL_PROTOCOL_F(ubl.state.z_offset, 6);
  1001. SERIAL_EOL;
  1002. delay(50);
  1003. SERIAL_PROTOCOLPGM("X-Axis Mesh Points at: ");
  1004. for (uint8_t i = 0; i < UBL_MESH_NUM_X_POINTS; i++) {
  1005. SERIAL_PROTOCOL_F( ubl.map_x_index_to_bed_location(i), 1);
  1006. SERIAL_PROTOCOLPGM(" ");
  1007. delay(50);
  1008. }
  1009. SERIAL_EOL;
  1010. SERIAL_PROTOCOLPGM("Y-Axis Mesh Points at: ");
  1011. for (uint8_t i = 0; i < UBL_MESH_NUM_Y_POINTS; i++) {
  1012. SERIAL_PROTOCOL_F( ubl.map_y_index_to_bed_location(i), 1);
  1013. SERIAL_PROTOCOLPGM(" ");
  1014. delay(50);
  1015. }
  1016. SERIAL_EOL;
  1017. #if HAS_KILL
  1018. SERIAL_PROTOCOLPAIR("Kill pin on :", KILL_PIN);
  1019. SERIAL_PROTOCOLLNPAIR(" state:", READ(KILL_PIN));
  1020. #endif
  1021. SERIAL_EOL;
  1022. delay(50);
  1023. SERIAL_PROTOCOLLNPAIR("ubl_state_at_invocation :", ubl_state_at_invocation);
  1024. SERIAL_EOL;
  1025. SERIAL_PROTOCOLLNPAIR("ubl_state_recursion_chk :", ubl_state_recursion_chk);
  1026. SERIAL_EOL;
  1027. delay(50);
  1028. SERIAL_PROTOCOLPGM("Free EEPROM space starts at: 0x");
  1029. prt_hex_word(ubl_eeprom_start);
  1030. SERIAL_EOL;
  1031. SERIAL_PROTOCOLPGM("end of EEPROM : ");
  1032. prt_hex_word(E2END);
  1033. SERIAL_EOL;
  1034. delay(50);
  1035. SERIAL_PROTOCOLLNPAIR("sizeof(ubl) : ", (int)sizeof(ubl));
  1036. SERIAL_EOL;
  1037. SERIAL_PROTOCOLLNPAIR("z_value[][] size: ", (int)sizeof(z_values));
  1038. SERIAL_EOL;
  1039. delay(50);
  1040. SERIAL_PROTOCOLPGM("EEPROM free for UBL: 0x");
  1041. prt_hex_word(k);
  1042. SERIAL_EOL;
  1043. delay(50);
  1044. SERIAL_PROTOCOLPGM("EEPROM can hold 0x");
  1045. prt_hex_word(k / sizeof(z_values));
  1046. SERIAL_PROTOCOLLNPGM(" meshes.\n");
  1047. delay(50);
  1048. SERIAL_PROTOCOLPGM("sizeof(ubl.state) :");
  1049. prt_hex_word(sizeof(ubl.state));
  1050. SERIAL_PROTOCOLPAIR("\nUBL_MESH_NUM_X_POINTS ", UBL_MESH_NUM_X_POINTS);
  1051. SERIAL_PROTOCOLPAIR("\nUBL_MESH_NUM_Y_POINTS ", UBL_MESH_NUM_Y_POINTS);
  1052. delay(50);
  1053. SERIAL_PROTOCOLPAIR("\nUBL_MESH_MIN_X ", UBL_MESH_MIN_X);
  1054. SERIAL_PROTOCOLPAIR("\nUBL_MESH_MIN_Y ", UBL_MESH_MIN_Y);
  1055. delay(50);
  1056. SERIAL_PROTOCOLPAIR("\nUBL_MESH_MAX_X ", UBL_MESH_MAX_X);
  1057. SERIAL_PROTOCOLPAIR("\nUBL_MESH_MAX_Y ", UBL_MESH_MAX_Y);
  1058. delay(50);
  1059. SERIAL_PROTOCOLPGM("\nMESH_X_DIST ");
  1060. SERIAL_PROTOCOL_F(MESH_X_DIST, 6);
  1061. SERIAL_PROTOCOLPGM("\nMESH_Y_DIST ");
  1062. SERIAL_PROTOCOL_F(MESH_Y_DIST, 6);
  1063. SERIAL_EOL;
  1064. delay(50);
  1065. if (!ubl.sanity_check())
  1066. SERIAL_PROTOCOLLNPGM("Unified Bed Leveling sanity checks passed.");
  1067. }
  1068. /**
  1069. * When we are fully debugged, the EEPROM dump command will get deleted also. But
  1070. * right now, it is good to have the extra information. Soon... we prune this.
  1071. */
  1072. void g29_eeprom_dump() {
  1073. unsigned char cccc;
  1074. uint16_t kkkk;
  1075. SERIAL_ECHO_START;
  1076. SERIAL_ECHOLNPGM("EEPROM Dump:");
  1077. for (uint16_t i = 0; i < E2END + 1; i += 16) {
  1078. if (!(i & 0x3)) idle();
  1079. prt_hex_word(i);
  1080. SERIAL_ECHOPGM(": ");
  1081. for (uint16_t j = 0; j < 16; j++) {
  1082. kkkk = i + j;
  1083. eeprom_read_block(&cccc, (void *)kkkk, 1);
  1084. prt_hex_byte(cccc);
  1085. SERIAL_ECHO(' ');
  1086. }
  1087. SERIAL_EOL;
  1088. }
  1089. SERIAL_EOL;
  1090. }
  1091. /**
  1092. * When we are fully debugged, this may go away. But there are some valid
  1093. * use cases for the users. So we can wait and see what to do with it.
  1094. */
  1095. void g29_compare_current_mesh_to_stored_mesh() {
  1096. float tmp_z_values[UBL_MESH_NUM_X_POINTS][UBL_MESH_NUM_Y_POINTS];
  1097. if (!code_has_value()) {
  1098. SERIAL_PROTOCOLLNPGM("?Mesh # required.\n");
  1099. return;
  1100. }
  1101. storage_slot = code_value_int();
  1102. int16_t j = (UBL_LAST_EEPROM_INDEX - ubl_eeprom_start) / sizeof(tmp_z_values);
  1103. if (storage_slot < 0 || storage_slot > j || ubl_eeprom_start <= 0) {
  1104. SERIAL_PROTOCOLLNPGM("?EEPROM storage not available for use.\n");
  1105. return;
  1106. }
  1107. j = UBL_LAST_EEPROM_INDEX - (storage_slot + 1) * sizeof(tmp_z_values);
  1108. eeprom_read_block((void *)&tmp_z_values, (void *)j, sizeof(tmp_z_values));
  1109. SERIAL_ECHOPAIR("Subtracting Mesh ", storage_slot);
  1110. SERIAL_PROTOCOLPGM(" loaded from EEPROM address "); // Soon, we can remove the extra clutter of printing
  1111. prt_hex_word(j); // the address in the EEPROM where the Mesh is stored.
  1112. SERIAL_EOL;
  1113. for (uint8_t x = 0; x < UBL_MESH_NUM_X_POINTS; x++)
  1114. for (uint8_t y = 0; y < UBL_MESH_NUM_Y_POINTS; y++)
  1115. z_values[x][y] = z_values[x][y] - tmp_z_values[x][y];
  1116. }
  1117. mesh_index_pair find_closest_mesh_point_of_type(const MeshPointType type, const float &lx, const float &ly, const bool probe_as_reference, unsigned int bits[16], bool far_flag) {
  1118. int i, j, k, l;
  1119. float distance, closest = far_flag ? -99999.99 : 99999.99;
  1120. mesh_index_pair return_val;
  1121. return_val.x_index = return_val.y_index = -1;
  1122. const float current_x = current_position[X_AXIS],
  1123. current_y = current_position[Y_AXIS];
  1124. // Get our reference position. Either the nozzle or probe location.
  1125. const float px = lx - (probe_as_reference ? X_PROBE_OFFSET_FROM_EXTRUDER : 0),
  1126. py = ly - (probe_as_reference ? Y_PROBE_OFFSET_FROM_EXTRUDER : 0);
  1127. for (i = 0; i < UBL_MESH_NUM_X_POINTS; i++) {
  1128. for (j = 0; j < UBL_MESH_NUM_Y_POINTS; j++) {
  1129. if ( (type == INVALID && isnan(z_values[i][j])) // Check to see if this location holds the right thing
  1130. || (type == REAL && !isnan(z_values[i][j]))
  1131. || (type == SET_IN_BITMAP && is_bit_set(bits, i, j))
  1132. ) {
  1133. // We only get here if we found a Mesh Point of the specified type
  1134. const float mx = LOGICAL_X_POSITION(ubl.map_x_index_to_bed_location(i)), // Check if we can probe this mesh location
  1135. my = LOGICAL_Y_POSITION(ubl.map_y_index_to_bed_location(j));
  1136. // If we are using the probe as the reference there are some locations we can't get to.
  1137. // We prune these out of the list and ignore them until the next Phase where we do the
  1138. // manual nozzle probing.
  1139. if (probe_as_reference &&
  1140. (mx < (MIN_PROBE_X) || mx > (MAX_PROBE_X) || my < (MIN_PROBE_Y) || my > (MAX_PROBE_Y))
  1141. ) continue;
  1142. // We can get to it. Let's see if it is the closest location to the nozzle.
  1143. // Add in a weighting factor that considers the current location of the nozzle.
  1144. distance = HYPOT(px - mx, py - my) + HYPOT(current_x - mx, current_y - my) * 0.1;
  1145. if (far_flag) { // If doing the far_flag action, we want to be as far as possible
  1146. for (k = 0; k < UBL_MESH_NUM_X_POINTS; k++) { // from the starting point and from any other probed points. We
  1147. for (l = 0; j < UBL_MESH_NUM_Y_POINTS; l++) { // want the next point spread out and filling in any blank spaces
  1148. if ( !isnan(z_values[k][l])) { // in the mesh. So we add in some of the distance to every probed
  1149. distance += (i-k)*(i-k)*MESH_X_DIST*.05; // point we can find.
  1150. distance += (j-l)*(j-l)*MESH_Y_DIST*.05;
  1151. }
  1152. }
  1153. }
  1154. }
  1155. if ( (!far_flag&&(distance < closest)) || (far_flag&&(distance > closest)) ) { // if far_flag, look for furthest away point
  1156. closest = distance; // We found a closer location with
  1157. return_val.x_index = i; // the specified type of mesh value.
  1158. return_val.y_index = j;
  1159. return_val.distance = closest;
  1160. }
  1161. }
  1162. }
  1163. }
  1164. return return_val;
  1165. }
  1166. void fine_tune_mesh(const float &lx, const float &ly, const bool do_ubl_mesh_map) {
  1167. mesh_index_pair location;
  1168. uint16_t not_done[16];
  1169. int32_t round_off;
  1170. save_ubl_active_state_and_disable();
  1171. memset(not_done, 0xFF, sizeof(not_done));
  1172. #if ENABLED(ULTRA_LCD)
  1173. lcd_setstatus("Fine Tuning Mesh.", true);
  1174. #endif
  1175. do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
  1176. do_blocking_move_to_xy(lx, ly);
  1177. do {
  1178. if (do_ubl_mesh_map) ubl.display_map(map_type);
  1179. location = find_closest_mesh_point_of_type( SET_IN_BITMAP, lx, ly, 0, not_done, false); // The '0' says we want to use the nozzle's position
  1180. // It doesn't matter if the probe can not reach this
  1181. // location. This is a manual edit of the Mesh Point.
  1182. if (location.x_index < 0 && location.y_index < 0) continue; // abort if we can't find any more points.
  1183. bit_clear(not_done, location.x_index, location.y_index); // Mark this location as 'adjusted' so we will find a
  1184. // different location the next time through the loop
  1185. const float xProbe = ubl.map_x_index_to_bed_location(location.x_index),
  1186. yProbe = ubl.map_y_index_to_bed_location(location.y_index);
  1187. if (xProbe < X_MIN_POS || xProbe > X_MAX_POS || yProbe < Y_MIN_POS || yProbe > Y_MAX_POS) { // In theory, we don't need this check.
  1188. SERIAL_PROTOCOLLNPGM("?Error: Attempt to edit off the bed."); // This really can't happen, but for now,
  1189. ubl_has_control_of_lcd_panel = false; // Let's do the check.
  1190. goto FINE_TUNE_EXIT;
  1191. }
  1192. do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE); // Move the nozzle to where we are going to edit
  1193. do_blocking_move_to_xy(xProbe, yProbe);
  1194. float new_z = z_values[location.x_index][location.y_index] + 0.001;
  1195. round_off = (int32_t)(new_z * 1000.0 + 2.5); // we chop off the last digits just to be clean. We are rounding to the
  1196. round_off -= (round_off % 5L); // closest 0 or 5 at the 3rd decimal place.
  1197. new_z = float(round_off) / 1000.0;
  1198. //SERIAL_ECHOPGM("Mesh Point Currently At: ");
  1199. //SERIAL_PROTOCOL_F(new_z, 6);
  1200. //SERIAL_EOL;
  1201. lcd_implementation_clear();
  1202. lcd_mesh_edit_setup(new_z);
  1203. wait_for_user = true;
  1204. do {
  1205. new_z = lcd_mesh_edit();
  1206. idle();
  1207. } while (wait_for_user);
  1208. lcd_return_to_status();
  1209. ubl_has_control_of_lcd_panel++; // There is a race condition for the Encoder Wheel getting clicked.
  1210. // It could get detected in lcd_mesh_edit (actually _lcd_mesh_fine_tune)
  1211. // or here.
  1212. const millis_t nxt = millis() + 1500UL;
  1213. while (ubl_lcd_clicked()) { // debounce and watch for abort
  1214. idle();
  1215. if (ELAPSED(millis(), nxt)) {
  1216. lcd_return_to_status();
  1217. SERIAL_PROTOCOLLNPGM("\nFine Tuning of Mesh Stopped.");
  1218. do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
  1219. lcd_setstatus("Mesh Editing Stopped", true);
  1220. while (ubl_lcd_clicked()) idle();
  1221. ubl_has_control_of_lcd_panel = false;
  1222. goto FINE_TUNE_EXIT;
  1223. }
  1224. }
  1225. delay(20); // We don't want any switch noise.
  1226. z_values[location.x_index][location.y_index] = new_z;
  1227. lcd_implementation_clear();
  1228. } while (location.x_index >= 0 && location.y_index >= 0 && --repetition_cnt);
  1229. FINE_TUNE_EXIT:
  1230. ubl_has_control_of_lcd_panel = false;
  1231. if (do_ubl_mesh_map) ubl.display_map(map_type);
  1232. restore_ubl_active_state_and_leave();
  1233. do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
  1234. do_blocking_move_to_xy(lx, ly);
  1235. #if ENABLED(ULTRA_LCD)
  1236. lcd_setstatus("Done Editing Mesh", true);
  1237. #endif
  1238. SERIAL_ECHOLNPGM("Done Editing Mesh.");
  1239. }
  1240. #endif // AUTO_BED_LEVELING_UBL