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