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_line_to_destination.cpp 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  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 "Marlin.h"
  23. #if ENABLED(AUTO_BED_LEVELING_UBL)
  24. #include "UBL.h"
  25. #include "planner.h"
  26. #include <avr/io.h>
  27. #include <math.h>
  28. extern void set_current_to_destination();
  29. extern bool G26_Debug_flag;
  30. void debug_current_and_destination(char *title);
  31. void wait_for_button_press();
  32. void UBL_line_to_destination(const float &x_end, const float &y_end, const float &z_end, const float &e_end, const float &feed_rate, uint8_t extruder) {
  33. int cell_start_xi, cell_start_yi, cell_dest_xi, cell_dest_yi;
  34. int left_flag, down_flag;
  35. int current_xi, current_yi;
  36. int dxi, dyi, xi_cnt, yi_cnt;
  37. bool use_X_dist, inf_normalized_flag, inf_m_flag;
  38. float x_start, y_start;
  39. float x, y, z1, z2, z0 /*, z_optimized */;
  40. float next_mesh_line_x, next_mesh_line_y, a0ma1diva2ma1;
  41. float on_axis_distance, e_normalized_dist, e_position, e_start, z_normalized_dist, z_position, z_start;
  42. float dx, dy, adx, ady, m, c;
  43. //
  44. // Much of the nozzle movement will be within the same cell. So we will do as little computation
  45. // as possible to determine if this is the case. If this move is within the same cell, we will
  46. // just do the required Z-Height correction, call the Planner's buffer_line() routine, and leave
  47. //
  48. x_start = current_position[X_AXIS];
  49. y_start = current_position[Y_AXIS];
  50. z_start = current_position[Z_AXIS];
  51. e_start = current_position[E_AXIS];
  52. cell_start_xi = blm.get_cell_index_x(x_start);
  53. cell_start_yi = blm.get_cell_index_y(y_start);
  54. cell_dest_xi = blm.get_cell_index_x(x_end);
  55. cell_dest_yi = blm.get_cell_index_y(y_end);
  56. if (G26_Debug_flag!=0) {
  57. SERIAL_ECHOPGM(" UBL_line_to_destination(xe=");
  58. SERIAL_ECHO(x_end);
  59. SERIAL_ECHOPGM(",ye=");
  60. SERIAL_ECHO(y_end);
  61. SERIAL_ECHOPGM(",ze=");
  62. SERIAL_ECHO(z_end);
  63. SERIAL_ECHOPGM(",ee=");
  64. SERIAL_ECHO(e_end);
  65. SERIAL_ECHOPGM(")\n");
  66. debug_current_and_destination( (char *) "Start of UBL_line_to_destination()");
  67. }
  68. if ((cell_start_xi == cell_dest_xi) && (cell_start_yi == cell_dest_yi)) { // if the whole move is within the same cell,
  69. // we don't need to break up the move
  70. //
  71. // If we are moving off the print bed, we are going to allow the move at this level.
  72. // But we detect it and isolate it. For now, we just pass along the request.
  73. //
  74. if (cell_dest_xi<0 || cell_dest_yi<0 || cell_dest_xi >= UBL_MESH_NUM_X_POINTS || cell_dest_yi >= UBL_MESH_NUM_Y_POINTS) {
  75. // Note: There is no Z Correction in this case. We are off the grid and don't know what
  76. // a reasonable correction would be.
  77. planner.buffer_line(x_end, y_end, z_end + blm.state.z_offset, e_end, feed_rate, extruder);
  78. set_current_to_destination();
  79. if (G26_Debug_flag!=0) {
  80. debug_current_and_destination( (char *) "out of bounds in UBL_line_to_destination()");
  81. }
  82. return;
  83. }
  84. // we can optimize some floating point operations here. We could call float get_z_correction(float x0, float y0) to
  85. // generate the correction for us. But we can lighten the load on the CPU by doing a modified version of the function.
  86. // We are going to only calculate the amount we are from the first mesh line towards the second mesh line once.
  87. // We will use this fraction in both of the original two Z Height calculations for the bi-linear interpolation. And,
  88. // instead of doing a generic divide of the distance, we know the distance is MESH_X_DIST so we can use the preprocessor
  89. // to create a 1-over number for us. That will allow us to do a floating point multiply instead of a floating point divide.
  90. FINAL_MOVE:
  91. a0ma1diva2ma1 = (x_end - mesh_index_to_X_location[cell_dest_xi]) * (float) (1.0 / MESH_X_DIST);
  92. z1 = z_values[cell_dest_xi][cell_dest_yi] +
  93. (z_values[cell_dest_xi + 1][cell_dest_yi] - z_values[cell_dest_xi][cell_dest_yi]) * a0ma1diva2ma1;
  94. z2 = z_values[cell_dest_xi][cell_dest_yi+1] +
  95. (z_values[cell_dest_xi+1][cell_dest_yi+1] - z_values[cell_dest_xi][cell_dest_yi+1]) * a0ma1diva2ma1;
  96. // we are done with the fractional X distance into the cell. Now with the two Z-Heights we have calculated, we
  97. // are going to apply the Y-Distance into the cell to interpolate the final Z correction.
  98. a0ma1diva2ma1 = (y_end - mesh_index_to_Y_location[cell_dest_yi]) * (float) (1.0 / MESH_Y_DIST);
  99. z0 = z1 + (z2 - z1) * a0ma1diva2ma1;
  100. // debug code to use non-optimized get_z_correction() and to do a sanity check
  101. // that the correct value is being passed to planner.buffer_line()
  102. //
  103. /*
  104. z_optimized = z0;
  105. z0 = blm.get_z_correction( x_end, y_end);
  106. if ( fabs(z_optimized - z0) > .01 || isnan(z0) || isnan(z_optimized) ) {
  107. debug_current_and_destination( (char *) "FINAL_MOVE: z_correction()");
  108. if ( isnan(z0) ) SERIAL_ECHO(" z0==NAN ");
  109. if ( isnan(z_optimized) ) SERIAL_ECHO(" z_optimized==NAN ");
  110. SERIAL_ECHOPAIR(" x_end=", x_end);
  111. SERIAL_ECHOPAIR(" y_end=", y_end);
  112. SERIAL_ECHOPAIR(" z0=", z0);
  113. SERIAL_ECHOPAIR(" z_optimized=", z_optimized);
  114. SERIAL_ECHOPAIR(" err=",fabs(z_optimized - z0));
  115. SERIAL_EOL;
  116. }
  117. */
  118. z0 = z0 * blm.fade_scaling_factor_for_Z( z_end );
  119. if (isnan(z0)) { // if part of the Mesh is undefined, it will show up as NAN
  120. z0 = 0.0; // in z_values[][] and propagate through the
  121. // calculations. If our correction is NAN, we throw it out
  122. // because part of the Mesh is undefined and we don't have the
  123. // information we need to complete the height correction.
  124. }
  125. planner.buffer_line(x_end, y_end, z_end + z0 + blm.state.z_offset, e_end, feed_rate, extruder);
  126. if (G26_Debug_flag!=0) {
  127. debug_current_and_destination( (char *) "FINAL_MOVE in UBL_line_to_destination()");
  128. }
  129. set_current_to_destination();
  130. return;
  131. }
  132. //
  133. // If we get here, we are processing a move that crosses at least one Mesh Line. We will check
  134. // for the simple case of just crossing X or just crossing Y Mesh Lines after we get all the details
  135. // of the move figured out. We can process the easy case of just crossing an X or Y Mesh Line with less
  136. // computation and in fact most lines are of this nature. We will check for that in the following
  137. // blocks of code:
  138. left_flag = 0;
  139. down_flag = 0;
  140. inf_m_flag = false;
  141. inf_normalized_flag = false;
  142. dx = x_end - x_start;
  143. dy = y_end - y_start;
  144. if (dx<0.0) { // figure out which way we need to move to get to the next cell
  145. dxi = -1;
  146. adx = -dx; // absolute value of dx. We already need to check if dx and dy are negative.
  147. }
  148. else { // We may as well generate the appropriate values for adx and ady right now
  149. dxi = 1; // to save setting up the abs() function call and actually doing the call.
  150. adx = dx;
  151. }
  152. if (dy<0.0) {
  153. dyi = -1;
  154. ady = -dy; // absolute value of dy
  155. }
  156. else {
  157. dyi = 1;
  158. ady = dy;
  159. }
  160. if (dx<0.0) left_flag = 1;
  161. if (dy<0.0) down_flag = 1;
  162. if (cell_start_xi == cell_dest_xi) dxi = 0;
  163. if (cell_start_yi == cell_dest_yi) dyi = 0;
  164. //
  165. // Compute the scaling factor for the extruder for each partial move.
  166. // We need to watch out for zero length moves because it will cause us to
  167. // have an infinate scaling factor. We are stuck doing a floating point
  168. // divide to get our scaling factor, but after that, we just multiply by this
  169. // number. We also pick our scaling factor based on whether the X or Y
  170. // component is larger. We use the biggest of the two to preserve precision.
  171. //
  172. if ( adx > ady ) {
  173. use_X_dist = true;
  174. on_axis_distance = x_end-x_start;
  175. }
  176. else {
  177. use_X_dist = false;
  178. on_axis_distance = y_end-y_start;
  179. }
  180. e_position = e_end - e_start;
  181. e_normalized_dist = e_position / on_axis_distance;
  182. z_position = z_end - z_start;
  183. z_normalized_dist = z_position / on_axis_distance;
  184. if (e_normalized_dist==INFINITY || e_normalized_dist==-INFINITY) {
  185. inf_normalized_flag = true;
  186. }
  187. current_xi = cell_start_xi;
  188. current_yi = cell_start_yi;
  189. m = dy / dx;
  190. c = y_start - m*x_start;
  191. if (m == INFINITY || m == -INFINITY) {
  192. inf_m_flag = true;
  193. }
  194. //
  195. // This block handles vertical lines. These are lines that stay within the same
  196. // X Cell column. They do not need to be perfectly vertical. They just can
  197. // not cross into another X Cell column.
  198. //
  199. if (dxi == 0) { // Check for a vertical line
  200. current_yi += down_flag; // Line is heading down, we just want to go to the bottom
  201. while (current_yi != cell_dest_yi + down_flag) {
  202. current_yi += dyi;
  203. next_mesh_line_y = mesh_index_to_Y_location[current_yi];
  204. if (inf_m_flag) {
  205. x = x_start; // if the slope of the line is infinite, we won't do the calculations
  206. }
  207. // we know the next X is the same so we can recover and continue!
  208. else {
  209. x = (next_mesh_line_y - c) / m; // Calculate X at the next Y mesh line
  210. }
  211. z0 = blm.get_z_correction_along_horizontal_mesh_line_at_specific_X(x, current_xi, current_yi);
  212. //
  213. // debug code to use non-optimized get_z_correction() and to do a sanity check
  214. // that the correct value is being passed to planner.buffer_line()
  215. //
  216. /*
  217. z_optimized = z0;
  218. z0 = blm.get_z_correction( x, next_mesh_line_y);
  219. if ( fabs(z_optimized - z0) > .01 || isnan(z0) || isnan(z_optimized) ) {
  220. debug_current_and_destination( (char *) "VERTICAL z_correction()");
  221. if ( isnan(z0) ) SERIAL_ECHO(" z0==NAN ");
  222. if ( isnan(z_optimized) ) SERIAL_ECHO(" z_optimized==NAN ");
  223. SERIAL_ECHOPAIR(" x=", x);
  224. SERIAL_ECHOPAIR(" next_mesh_line_y=", next_mesh_line_y);
  225. SERIAL_ECHOPAIR(" z0=", z0);
  226. SERIAL_ECHOPAIR(" z_optimized=", z_optimized);
  227. SERIAL_ECHOPAIR(" err=",fabs(z_optimized-z0));
  228. SERIAL_ECHO("\n");
  229. }
  230. */
  231. z0 = z0 * blm.fade_scaling_factor_for_Z( z_end );
  232. if (isnan(z0)) { // if part of the Mesh is undefined, it will show up as NAN
  233. z0 = 0.0; // in z_values[][] and propagate through the
  234. // calculations. If our correction is NAN, we throw it out
  235. // because part of the Mesh is undefined and we don't have the
  236. // information we need to complete the height correction.
  237. }
  238. y = mesh_index_to_Y_location[current_yi];
  239. // Without this check, it is possible for the algorythm to generate a zero length move in the case
  240. // where the line is heading down and it is starting right on a Mesh Line boundary. For how often that
  241. // happens, it might be best to remove the check and always 'schedule' the move because
  242. // the planner.buffer_line() routine will filter it if that happens.
  243. if ( y!=y_start) {
  244. if ( inf_normalized_flag == false ) {
  245. on_axis_distance = y - y_start; // we don't need to check if the extruder position
  246. e_position = e_start + on_axis_distance * e_normalized_dist; // is based on X or Y because this is a vertical move
  247. z_position = z_start + on_axis_distance * z_normalized_dist;
  248. }
  249. else {
  250. e_position = e_start;
  251. z_position = z_start;
  252. }
  253. planner.buffer_line(x, y, z_position + z0 + blm.state.z_offset, e_position, feed_rate, extruder);
  254. } //else printf("FIRST MOVE PRUNED ");
  255. }
  256. //
  257. // Check if we are at the final destination. Usually, we won't be, but if it is on a Y Mesh Line, we are done.
  258. //
  259. if (G26_Debug_flag!=0) {
  260. debug_current_and_destination( (char *) "vertical move done in UBL_line_to_destination()");
  261. }
  262. if (current_position[X_AXIS] != x_end || current_position[Y_AXIS] != y_end) {
  263. goto FINAL_MOVE;
  264. }
  265. set_current_to_destination();
  266. return;
  267. }
  268. //
  269. // This block handles horizontal lines. These are lines that stay within the same
  270. // Y Cell row. They do not need to be perfectly horizontal. They just can
  271. // not cross into another Y Cell row.
  272. //
  273. if (dyi == 0) { // Check for a horiziontal line
  274. current_xi += left_flag; // Line is heading left, we just want to go to the left
  275. // edge of this cell for the first move.
  276. while (current_xi != cell_dest_xi + left_flag) {
  277. current_xi += dxi;
  278. next_mesh_line_x = mesh_index_to_X_location[current_xi];
  279. y = m * next_mesh_line_x + c; // Calculate X at the next Y mesh line
  280. z0 = blm.get_z_correction_along_vertical_mesh_line_at_specific_Y(y, current_xi, current_yi);
  281. //
  282. // debug code to use non-optimized get_z_correction() and to do a sanity check
  283. // that the correct value is being passed to planner.buffer_line()
  284. //
  285. /*
  286. z_optimized = z0;
  287. z0 = blm.get_z_correction( next_mesh_line_x, y);
  288. if ( fabs(z_optimized - z0) > .01 || isnan(z0) || isnan(z_optimized) ) {
  289. debug_current_and_destination( (char *) "HORIZONTAL z_correction()");
  290. if ( isnan(z0) ) SERIAL_ECHO(" z0==NAN ");
  291. if ( isnan(z_optimized) ) SERIAL_ECHO(" z_optimized==NAN ");
  292. SERIAL_ECHOPAIR(" next_mesh_line_x=", next_mesh_line_x);
  293. SERIAL_ECHOPAIR(" y=", y);
  294. SERIAL_ECHOPAIR(" z0=", z0);
  295. SERIAL_ECHOPAIR(" z_optimized=", z_optimized);
  296. SERIAL_ECHOPAIR(" err=",fabs(z_optimized-z0));
  297. SERIAL_ECHO("\n");
  298. }
  299. */
  300. z0 = z0 * blm.fade_scaling_factor_for_Z( z_end );
  301. if (isnan(z0)) { // if part of the Mesh is undefined, it will show up as NAN
  302. z0 = 0.0; // in z_values[][] and propagate through the
  303. // calculations. If our correction is NAN, we throw it out
  304. // because part of the Mesh is undefined and we don't have the
  305. // information we need to complete the height correction.
  306. }
  307. x = mesh_index_to_X_location[current_xi];
  308. // Without this check, it is possible for the algorythm to generate a zero length move in the case
  309. // where the line is heading left and it is starting right on a Mesh Line boundary. For how often
  310. // that happens, it might be best to remove the check and always 'schedule' the move because
  311. // the planner.buffer_line() routine will filter it if that happens.
  312. if ( x!=x_start) {
  313. if ( inf_normalized_flag == false ) {
  314. on_axis_distance = x - x_start; // we don't need to check if the extruder position
  315. e_position = e_start + on_axis_distance * e_normalized_dist; // is based on X or Y because this is a horizontal move
  316. z_position = z_start + on_axis_distance * z_normalized_dist;
  317. }
  318. else {
  319. e_position = e_start;
  320. z_position = z_start;
  321. }
  322. planner.buffer_line(x, y, z_position + z0 + blm.state.z_offset, e_position, feed_rate, extruder);
  323. } //else printf("FIRST MOVE PRUNED ");
  324. }
  325. if (G26_Debug_flag!=0) {
  326. debug_current_and_destination( (char *) "horizontal move done in UBL_line_to_destination()");
  327. }
  328. if (current_position[X_AXIS] != x_end || current_position[Y_AXIS] != y_end) {
  329. goto FINAL_MOVE;
  330. }
  331. set_current_to_destination();
  332. return;
  333. }
  334. //
  335. //
  336. //
  337. //
  338. // This block handles the generic case of a line crossing both X and Y
  339. // Mesh lines.
  340. //
  341. //
  342. //
  343. //
  344. xi_cnt = cell_start_xi - cell_dest_xi;
  345. if ( xi_cnt < 0 ) {
  346. xi_cnt = -xi_cnt;
  347. }
  348. yi_cnt = cell_start_yi - cell_dest_yi;
  349. if ( yi_cnt < 0 ) {
  350. yi_cnt = -yi_cnt;
  351. }
  352. current_xi += left_flag;
  353. current_yi += down_flag;
  354. while ( xi_cnt>0 || yi_cnt>0 ) {
  355. next_mesh_line_x = mesh_index_to_X_location[current_xi + dxi];
  356. next_mesh_line_y = mesh_index_to_Y_location[current_yi + dyi];
  357. y = m * next_mesh_line_x + c; // Calculate Y at the next X mesh line
  358. x = (next_mesh_line_y-c) / m; // Calculate X at the next Y mesh line (we don't have to worry
  359. // about m being equal to 0.0 If this was the case, we would have
  360. // detected this as a vertical line move up above and we wouldn't
  361. // be down here doing a generic type of move.
  362. if ((left_flag && (x>next_mesh_line_x)) || (!left_flag && (x<next_mesh_line_x))) { // Check if we hit the Y line first
  363. //
  364. // Yes! Crossing a Y Mesh Line next
  365. //
  366. z0 = blm.get_z_correction_along_horizontal_mesh_line_at_specific_X(x, current_xi-left_flag, current_yi+dyi);
  367. //
  368. // debug code to use non-optimized get_z_correction() and to do a sanity check
  369. // that the correct value is being passed to planner.buffer_line()
  370. //
  371. /*
  372. z_optimized = z0;
  373. z0 = blm.get_z_correction( x, next_mesh_line_y);
  374. if ( fabs(z_optimized - z0) > .01 || isnan(z0) || isnan(z_optimized) ) {
  375. debug_current_and_destination( (char *) "General_1: z_correction()");
  376. if ( isnan(z0) ) SERIAL_ECHO(" z0==NAN ");
  377. if ( isnan(z_optimized) ) SERIAL_ECHO(" z_optimized==NAN "); {
  378. SERIAL_ECHOPAIR(" x=", x);
  379. }
  380. SERIAL_ECHOPAIR(" next_mesh_line_y=", next_mesh_line_y);
  381. SERIAL_ECHOPAIR(" z0=", z0);
  382. SERIAL_ECHOPAIR(" z_optimized=", z_optimized);
  383. SERIAL_ECHOPAIR(" err=",fabs(z_optimized-z0));
  384. SERIAL_ECHO("\n");
  385. }
  386. */
  387. z0 = z0 * blm.fade_scaling_factor_for_Z( z_end );
  388. if (isnan(z0)) { // if part of the Mesh is undefined, it will show up as NAN
  389. z0 = 0.0; // in z_values[][] and propagate through the
  390. // calculations. If our correction is NAN, we throw it out
  391. // because part of the Mesh is undefined and we don't have the
  392. // information we need to complete the height correction.
  393. }
  394. if ( inf_normalized_flag == false ) {
  395. if ( use_X_dist ) {
  396. on_axis_distance = x - x_start;
  397. }
  398. else {
  399. on_axis_distance = next_mesh_line_y - y_start;
  400. }
  401. e_position = e_start + on_axis_distance * e_normalized_dist;
  402. z_position = z_start + on_axis_distance * z_normalized_dist;
  403. }
  404. else {
  405. e_position = e_start;
  406. z_position = z_start;
  407. }
  408. planner.buffer_line(x, next_mesh_line_y, z_position + z0 + blm.state.z_offset, e_position, feed_rate, extruder);
  409. current_yi += dyi;
  410. yi_cnt--;
  411. }
  412. else {
  413. //
  414. // Yes! Crossing a X Mesh Line next
  415. //
  416. z0 = blm.get_z_correction_along_vertical_mesh_line_at_specific_Y(y, current_xi+dxi, current_yi-down_flag);
  417. //
  418. // debug code to use non-optimized get_z_correction() and to do a sanity check
  419. // that the correct value is being passed to planner.buffer_line()
  420. //
  421. /*
  422. z_optimized = z0;
  423. z0 = blm.get_z_correction( next_mesh_line_x, y);
  424. if ( fabs(z_optimized - z0) > .01 || isnan(z0) || isnan(z_optimized) ) {
  425. debug_current_and_destination( (char *) "General_2: z_correction()");
  426. if ( isnan(z0) ) SERIAL_ECHO(" z0==NAN ");
  427. if ( isnan(z_optimized) ) SERIAL_ECHO(" z_optimized==NAN ");
  428. SERIAL_ECHOPAIR(" next_mesh_line_x=", next_mesh_line_x);
  429. SERIAL_ECHOPAIR(" y=", y);
  430. SERIAL_ECHOPAIR(" z0=", z0);
  431. SERIAL_ECHOPAIR(" z_optimized=", z_optimized);
  432. SERIAL_ECHOPAIR(" err=",fabs(z_optimized-z0));
  433. SERIAL_ECHO("\n");
  434. }
  435. */
  436. z0 = z0 * blm.fade_scaling_factor_for_Z( z_end );
  437. if (isnan(z0)) { // if part of the Mesh is undefined, it will show up as NAN
  438. z0 = 0.0; // in z_values[][] and propagate through the
  439. // calculations. If our correction is NAN, we throw it out
  440. // because part of the Mesh is undefined and we don't have the
  441. // information we need to complete the height correction.
  442. }
  443. if ( inf_normalized_flag == false ) {
  444. if ( use_X_dist ) {
  445. on_axis_distance = next_mesh_line_x - x_start;
  446. }
  447. else {
  448. on_axis_distance = y - y_start;
  449. }
  450. e_position = e_start + on_axis_distance * e_normalized_dist;
  451. z_position = z_start + on_axis_distance * z_normalized_dist;
  452. }
  453. else {
  454. e_position = e_start;
  455. z_position = z_start;
  456. }
  457. planner.buffer_line(next_mesh_line_x, y, z_position + z0 + blm.state.z_offset, e_position, feed_rate, extruder);
  458. current_xi += dxi;
  459. xi_cnt--;
  460. }
  461. }
  462. if (G26_Debug_flag) {
  463. debug_current_and_destination( (char *) "generic move done in UBL_line_to_destination()");
  464. }
  465. if (current_position[0] != x_end || current_position[1] != y_end) {
  466. goto FINAL_MOVE;
  467. }
  468. set_current_to_destination();
  469. return;
  470. }
  471. void wait_for_button_press() {
  472. // if ( !been_to_2_6 )
  473. //return; // bob - I think this should be commented out
  474. SET_INPUT_PULLUP(66); // Roxy's Left Switch is on pin 66. Right Switch is on pin 65
  475. SET_OUTPUT(64);
  476. while (READ(66) & 0x01) idle();
  477. delay(50);
  478. while (!(READ(66) & 0x01)) idle();
  479. delay(50);
  480. }
  481. #endif