|
@@ -225,7 +225,7 @@
|
225
|
225
|
* M406 - Disable Filament Sensor flow control. (Requires FILAMENT_WIDTH_SENSOR)
|
226
|
226
|
* M407 - Display measured filament diameter in millimeters. (Requires FILAMENT_WIDTH_SENSOR)
|
227
|
227
|
* M410 - Quickstop. Abort all planned moves.
|
228
|
|
- * M420 - Enable/Disable Mesh Leveling (with current values) S1=enable S0=disable (Requires MESH_BED_LEVELING)
|
|
228
|
+ * M420 - Enable/Disable Leveling (with current values) S1=enable S0=disable (Requires MESH_BED_LEVELING or ABL)
|
229
|
229
|
* M421 - Set a single Z coordinate in the Mesh Leveling grid. X<units> Y<units> Z<units> (Requires MESH_BED_LEVELING)
|
230
|
230
|
* M428 - Set the home_offset based on the current_position. Nearest edge applies.
|
231
|
231
|
* M500 - Store parameters in EEPROM. (Requires EEPROM_SETTINGS)
|
|
@@ -2027,6 +2027,12 @@ static void clean_up_after_endstop_or_probe_move() {
|
2027
|
2027
|
// Do a first probe at the fast speed
|
2028
|
2028
|
do_probe_move(-(Z_MAX_LENGTH) - 10, Z_PROBE_SPEED_FAST);
|
2029
|
2029
|
|
|
2030
|
+ #if ENABLED(DEBUG_LEVELING_FEATURE)
|
|
2031
|
+ float first_probe_z = current_position[Z_AXIS];
|
|
2032
|
+ if (DEBUGGING(LEVELING))
|
|
2033
|
+ SERIAL_ECHOPAIR("1st Probe Z:", first_probe_z);
|
|
2034
|
+ #endif
|
|
2035
|
+
|
2030
|
2036
|
// move up by the bump distance
|
2031
|
2037
|
do_blocking_move_to_z(current_position[Z_AXIS] + home_bump_mm(Z_AXIS), MMM_TO_MMS(Z_PROBE_SPEED_FAST));
|
2032
|
2038
|
|
|
@@ -2047,6 +2053,13 @@ static void clean_up_after_endstop_or_probe_move() {
|
2047
|
2053
|
if (DEBUGGING(LEVELING)) DEBUG_POS("<<< run_z_probe", current_position);
|
2048
|
2054
|
#endif
|
2049
|
2055
|
|
|
2056
|
+ // Debug: compare probe heights
|
|
2057
|
+ #if ENABLED(PROBE_DOUBLE_TOUCH) && ENABLED(DEBUG_LEVELING_FEATURE)
|
|
2058
|
+ if (DEBUGGING(LEVELING)) {
|
|
2059
|
+ SERIAL_ECHOPAIR("2nd Probe Z:", current_position[Z_AXIS]);
|
|
2060
|
+ SERIAL_ECHOLNPAIR(" Discrepancy:", first_probe_z - current_position[Z_AXIS]);
|
|
2061
|
+ }
|
|
2062
|
+ #endif
|
2050
|
2063
|
return current_position[Z_AXIS];
|
2051
|
2064
|
}
|
2052
|
2065
|
|
|
@@ -2119,30 +2132,69 @@ static void clean_up_after_endstop_or_probe_move() {
|
2119
|
2132
|
|
2120
|
2133
|
#endif // HAS_BED_PROBE
|
2121
|
2134
|
|
2122
|
|
-#if HAS_ABL
|
|
2135
|
+#if PLANNER_LEVELING
|
|
2136
|
+ /**
|
|
2137
|
+ * Turn bed leveling on or off, fixing the current
|
|
2138
|
+ * position as-needed.
|
|
2139
|
+ *
|
|
2140
|
+ * Disable: Current position = physical position
|
|
2141
|
+ * Enable: Current position = "unleveled" physical position
|
|
2142
|
+ */
|
|
2143
|
+ void set_bed_leveling_enabled(bool enable=true) {
|
|
2144
|
+ #if ENABLED(MESH_BED_LEVELING)
|
|
2145
|
+
|
|
2146
|
+ if (!enable && mbl.active())
|
|
2147
|
+ current_position[Z_AXIS] +=
|
|
2148
|
+ mbl.get_z(RAW_CURRENT_POSITION(X_AXIS), RAW_CURRENT_POSITION(Y_AXIS)) - (MESH_HOME_SEARCH_Z);
|
|
2149
|
+
|
|
2150
|
+ mbl.set_active(enable && mbl.has_mesh()); // was set_has_mesh(). Is this not correct?
|
|
2151
|
+
|
|
2152
|
+ #elif HAS_ABL
|
|
2153
|
+
|
|
2154
|
+ if (enable != planner.abl_enabled) {
|
|
2155
|
+ planner.abl_enabled = !planner.abl_enabled;
|
|
2156
|
+ if (!planner.abl_enabled)
|
|
2157
|
+ set_current_from_steppers_for_axis(
|
|
2158
|
+ #if ABL_PLANAR
|
|
2159
|
+ ALL_AXES
|
|
2160
|
+ #else
|
|
2161
|
+ Z_AXIS
|
|
2162
|
+ #endif
|
|
2163
|
+ );
|
|
2164
|
+ else
|
|
2165
|
+ planner.unapply_leveling(current_position);
|
|
2166
|
+ }
|
|
2167
|
+
|
|
2168
|
+ #endif
|
|
2169
|
+ }
|
|
2170
|
+
|
2123
|
2171
|
|
2124
|
2172
|
/**
|
2125
|
2173
|
* Reset calibration results to zero.
|
2126
|
|
- *
|
2127
|
|
- * TODO: Proper functions to disable / enable
|
2128
|
|
- * bed leveling via a flag, correcting the
|
2129
|
|
- * current position in each case.
|
2130
|
2174
|
*/
|
2131
|
2175
|
void reset_bed_level() {
|
2132
|
|
- planner.abl_enabled = false;
|
2133
|
|
- #if ENABLED(DEBUG_LEVELING_FEATURE)
|
2134
|
|
- if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("reset_bed_level");
|
2135
|
|
- #endif
|
2136
|
|
- #if ABL_PLANAR
|
2137
|
|
- planner.bed_level_matrix.set_to_identity();
|
2138
|
|
- #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
2139
|
|
- for (uint8_t x = 0; x < ABL_GRID_POINTS_X; x++)
|
2140
|
|
- for (uint8_t y = 0; y < ABL_GRID_POINTS_Y; y++)
|
2141
|
|
- bed_level_grid[x][y] = 1000.0;
|
|
2176
|
+ #if ENABLED(MESH_BED_LEVELING)
|
|
2177
|
+ if (mbl.has_mesh()) {
|
|
2178
|
+ set_bed_leveling_enabled(false);
|
|
2179
|
+ mbl.reset();
|
|
2180
|
+ mbl.set_has_mesh(false);
|
|
2181
|
+ }
|
|
2182
|
+ #else
|
|
2183
|
+ planner.abl_enabled = false;
|
|
2184
|
+ #if ENABLED(DEBUG_LEVELING_FEATURE)
|
|
2185
|
+ if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("reset_bed_level");
|
|
2186
|
+ #endif
|
|
2187
|
+ #if ABL_PLANAR
|
|
2188
|
+ planner.bed_level_matrix.set_to_identity();
|
|
2189
|
+ #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
|
2190
|
+ for (uint8_t x = 0; x < ABL_GRID_POINTS_X; x++)
|
|
2191
|
+ for (uint8_t y = 0; y < ABL_GRID_POINTS_Y; y++)
|
|
2192
|
+ bed_level_grid[x][y] = 1000.0;
|
|
2193
|
+ #endif
|
2142
|
2194
|
#endif
|
2143
|
2195
|
}
|
2144
|
2196
|
|
2145
|
|
-#endif // HAS_ABL
|
|
2197
|
+#endif // PLANNER_LEVELING
|
2146
|
2198
|
|
2147
|
2199
|
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
2148
|
2200
|
|
|
@@ -2160,7 +2212,7 @@ static void clean_up_after_endstop_or_probe_move() {
|
2160
|
2212
|
if (y < 10) SERIAL_CHAR(' ');
|
2161
|
2213
|
SERIAL_ECHO((int)y);
|
2162
|
2214
|
SERIAL_CHAR(ydir ? (ydir > 0 ? '+' : '-') : ' ');
|
2163
|
|
- SERIAL_CHAR(']');
|
|
2215
|
+ SERIAL_ECHOLN(']');
|
2164
|
2216
|
}
|
2165
|
2217
|
#endif
|
2166
|
2218
|
if (bed_level_grid[x][y] < 999.0) {
|
|
@@ -2247,7 +2299,7 @@ static void clean_up_after_endstop_or_probe_move() {
|
2247
|
2299
|
*/
|
2248
|
2300
|
static void print_bed_level() {
|
2249
|
2301
|
SERIAL_ECHOPGM("Bilinear Leveling Grid:\n ");
|
2250
|
|
- for (uint8_t x = 1; x < ABL_GRID_POINTS_X + 1; x++) {
|
|
2302
|
+ for (uint8_t x = 0; x < ABL_GRID_POINTS_X; x++) {
|
2251
|
2303
|
SERIAL_PROTOCOLPGM(" ");
|
2252
|
2304
|
if (x < 10) SERIAL_PROTOCOLCHAR(' ');
|
2253
|
2305
|
SERIAL_PROTOCOL((int)x);
|
|
@@ -2255,7 +2307,7 @@ static void clean_up_after_endstop_or_probe_move() {
|
2255
|
2307
|
SERIAL_EOL;
|
2256
|
2308
|
for (uint8_t y = 0; y < ABL_GRID_POINTS_Y; y++) {
|
2257
|
2309
|
if (y < 9) SERIAL_PROTOCOLCHAR(' ');
|
2258
|
|
- SERIAL_PROTOCOL(y + 1);
|
|
2310
|
+ SERIAL_PROTOCOL(y);
|
2259
|
2311
|
for (uint8_t x = 0; x < ABL_GRID_POINTS_X; x++) {
|
2260
|
2312
|
SERIAL_PROTOCOLCHAR(' ');
|
2261
|
2313
|
float offset = bed_level_grid[x][y];
|
|
@@ -3583,24 +3635,31 @@ inline void gcode_G28() {
|
3583
|
3635
|
|
3584
|
3636
|
#if ABL_GRID
|
3585
|
3637
|
|
3586
|
|
- #if ABL_PLANAR
|
3587
|
|
- bool do_topography_map = verbose_level > 2 || code_seen('T');
|
3588
|
|
- #endif
|
3589
|
|
-
|
3590
|
3638
|
if (verbose_level > 0) {
|
3591
|
3639
|
SERIAL_PROTOCOLLNPGM("G29 Auto Bed Leveling");
|
3592
|
3640
|
if (dryrun) SERIAL_PROTOCOLLNPGM("Running in DRY-RUN mode");
|
3593
|
3641
|
}
|
3594
|
3642
|
|
3595
|
|
- int abl_grid_points_x = ABL_GRID_POINTS_X,
|
3596
|
|
- abl_grid_points_y = ABL_GRID_POINTS_Y;
|
3597
|
|
-
|
3598
|
3643
|
#if ABL_PLANAR
|
|
3644
|
+
|
|
3645
|
+ bool do_topography_map = verbose_level > 2 || code_seen('T');
|
|
3646
|
+
|
|
3647
|
+ // X and Y specify points in each direction, overriding the default
|
|
3648
|
+ // These values may be saved with the completed mesh
|
|
3649
|
+ int abl_grid_points_x = code_seen('X') ? code_value_int() : ABL_GRID_POINTS_X,
|
|
3650
|
+ abl_grid_points_y = code_seen('Y') ? code_value_int() : ABL_GRID_POINTS_Y;
|
|
3651
|
+
|
3599
|
3652
|
if (code_seen('P')) abl_grid_points_x = abl_grid_points_y = code_value_int();
|
3600
|
|
- if (abl_grid_points_x < 2) {
|
3601
|
|
- SERIAL_PROTOCOLLNPGM("?Number of probed (P)oints is implausible (2 minimum).");
|
|
3653
|
+
|
|
3654
|
+ if (abl_grid_points_x < 2 || abl_grid_points_y < 2) {
|
|
3655
|
+ SERIAL_PROTOCOLLNPGM("?Number of probe points is implausible (2 minimum).");
|
3602
|
3656
|
return;
|
3603
|
3657
|
}
|
|
3658
|
+
|
|
3659
|
+ #else
|
|
3660
|
+
|
|
3661
|
+ const int abl_grid_points_x = ABL_GRID_POINTS_X, abl_grid_points_y = ABL_GRID_POINTS_Y;
|
|
3662
|
+
|
3604
|
3663
|
#endif
|
3605
|
3664
|
|
3606
|
3665
|
xy_probe_feedrate_mm_s = MMM_TO_MMS(code_seen('S') ? code_value_linear_units() : XY_PROBE_SPEED);
|
|
@@ -3651,11 +3710,10 @@ inline void gcode_G28() {
|
3651
|
3710
|
if (!dryrun) {
|
3652
|
3711
|
// Re-orient the current position without leveling
|
3653
|
3712
|
// based on where the steppers are positioned.
|
3654
|
|
- get_cartesian_from_steppers();
|
3655
|
|
- memcpy(current_position, cartes, sizeof(cartes));
|
|
3713
|
+ set_current_from_steppers_for_axis(ALL_AXES);
|
3656
|
3714
|
|
3657
|
|
- // Inform the planner about the new coordinates
|
3658
|
|
- SYNC_PLAN_POSITION_KINEMATIC();
|
|
3715
|
+ // Sync the planner to where the steppers stopped
|
|
3716
|
+ planner.sync_from_steppers();
|
3659
|
3717
|
}
|
3660
|
3718
|
|
3661
|
3719
|
setup_for_endstop_or_probe_move();
|
|
@@ -3713,30 +3771,48 @@ inline void gcode_G28() {
|
3713
|
3771
|
|
3714
|
3772
|
#endif // AUTO_BED_LEVELING_LINEAR
|
3715
|
3773
|
|
3716
|
|
- bool zig = abl_grid_points_y & 1; //always end at [RIGHT_PROBE_BED_POSITION, BACK_PROBE_BED_POSITION]
|
|
3774
|
+ #if ENABLED(PROBE_Y_FIRST)
|
|
3775
|
+ #define PR_OUTER_VAR xCount
|
|
3776
|
+ #define PR_OUTER_END abl_grid_points_x
|
|
3777
|
+ #define PR_INNER_VAR yCount
|
|
3778
|
+ #define PR_INNER_END abl_grid_points_y
|
|
3779
|
+ #else
|
|
3780
|
+ #define PR_OUTER_VAR yCount
|
|
3781
|
+ #define PR_OUTER_END abl_grid_points_y
|
|
3782
|
+ #define PR_INNER_VAR xCount
|
|
3783
|
+ #define PR_INNER_END abl_grid_points_x
|
|
3784
|
+ #endif
|
3717
|
3785
|
|
3718
|
|
- for (uint8_t yCount = 0; yCount < abl_grid_points_y; yCount++) {
|
3719
|
|
- float yBase = front_probe_bed_position + yGridSpacing * yCount;
|
3720
|
|
- yProbe = floor(yBase + (yBase < 0 ? 0 : 0.5));
|
|
3786
|
+ #if ENABLED(MAKERARM_SCARA)
|
|
3787
|
+ bool zig = true;
|
|
3788
|
+ #else
|
|
3789
|
+ bool zig = PR_OUTER_END & 1; //always end at [RIGHT_PROBE_BED_POSITION, BACK_PROBE_BED_POSITION]
|
|
3790
|
+ #endif
|
|
3791
|
+
|
|
3792
|
+ for (uint8_t PR_OUTER_VAR = 0; PR_OUTER_VAR < PR_OUTER_END; PR_OUTER_VAR++) {
|
3721
|
3793
|
|
3722
|
|
- int8_t xStart, xStop, xInc;
|
|
3794
|
+ int8_t inStart, inStop, inInc;
|
3723
|
3795
|
|
3724
|
3796
|
if (zig) {
|
3725
|
|
- xStart = 0;
|
3726
|
|
- xStop = abl_grid_points_x;
|
3727
|
|
- xInc = 1;
|
|
3797
|
+ inStart = 0;
|
|
3798
|
+ inStop = PR_INNER_END;
|
|
3799
|
+ inInc = 1;
|
3728
|
3800
|
}
|
3729
|
3801
|
else {
|
3730
|
|
- xStart = abl_grid_points_x - 1;
|
3731
|
|
- xStop = -1;
|
3732
|
|
- xInc = -1;
|
|
3802
|
+ inStart = PR_INNER_END - 1;
|
|
3803
|
+ inStop = -1;
|
|
3804
|
+ inInc = -1;
|
3733
|
3805
|
}
|
3734
|
3806
|
|
3735
|
3807
|
zig = !zig;
|
3736
|
3808
|
|
3737
|
|
- for (int8_t xCount = xStart; xCount != xStop; xCount += xInc) {
|
3738
|
|
- float xBase = left_probe_bed_position + xGridSpacing * xCount;
|
|
3809
|
+ for (int8_t PR_INNER_VAR = inStart; PR_INNER_VAR != inStop; PR_INNER_VAR += inInc) {
|
|
3810
|
+
|
|
3811
|
+ float xBase = left_probe_bed_position + xGridSpacing * xCount,
|
|
3812
|
+ yBase = front_probe_bed_position + yGridSpacing * yCount;
|
|
3813
|
+
|
3739
|
3814
|
xProbe = floor(xBase + (xBase < 0 ? 0 : 0.5));
|
|
3815
|
+ yProbe = floor(yBase + (yBase < 0 ? 0 : 0.5));
|
3740
|
3816
|
|
3741
|
3817
|
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
|
3742
|
3818
|
indexIntoAB[xCount][yCount] = ++probePointCounter;
|
|
@@ -3992,9 +4068,6 @@ inline void gcode_G28() {
|
3992
|
4068
|
#if ENABLED(DEBUG_LEVELING_FEATURE)
|
3993
|
4069
|
if (DEBUGGING(LEVELING)) DEBUG_POS("G29 corrected XYZ", current_position);
|
3994
|
4070
|
#endif
|
3995
|
|
-
|
3996
|
|
- SYNC_PLAN_POSITION_KINEMATIC();
|
3997
|
|
- abl_should_enable = true;
|
3998
|
4071
|
}
|
3999
|
4072
|
|
4000
|
4073
|
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
|
@@ -4004,14 +4077,13 @@ inline void gcode_G28() {
|
4004
|
4077
|
if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPAIR("G29 uncorrected Z:", current_position[Z_AXIS]);
|
4005
|
4078
|
#endif
|
4006
|
4079
|
|
|
4080
|
+ // Unapply the offset because it is going to be immediately applied
|
|
4081
|
+ // and cause compensation movement in Z
|
4007
|
4082
|
current_position[Z_AXIS] -= bilinear_z_offset(current_position);
|
4008
|
4083
|
|
4009
|
4084
|
#if ENABLED(DEBUG_LEVELING_FEATURE)
|
4010
|
4085
|
if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPAIR(" corrected Z:", current_position[Z_AXIS]);
|
4011
|
4086
|
#endif
|
4012
|
|
-
|
4013
|
|
- SYNC_PLAN_POSITION_KINEMATIC();
|
4014
|
|
- abl_should_enable = true;
|
4015
|
4087
|
}
|
4016
|
4088
|
|
4017
|
4089
|
#endif // ABL_PLANAR
|
|
@@ -4034,6 +4106,9 @@ inline void gcode_G28() {
|
4034
|
4106
|
|
4035
|
4107
|
// Auto Bed Leveling is complete! Enable if possible.
|
4036
|
4108
|
planner.abl_enabled = dryrun ? abl_should_enable : true;
|
|
4109
|
+
|
|
4110
|
+ if (planner.abl_enabled)
|
|
4111
|
+ SYNC_PLAN_POSITION_KINEMATIC();
|
4037
|
4112
|
}
|
4038
|
4113
|
|
4039
|
4114
|
#endif // HAS_ABL
|
|
@@ -4045,13 +4120,13 @@ inline void gcode_G28() {
|
4045
|
4120
|
*/
|
4046
|
4121
|
inline void gcode_G30() {
|
4047
|
4122
|
|
4048
|
|
- #if HAS_ABL
|
4049
|
|
- reset_bed_level();
|
|
4123
|
+ // Disable leveling so the planner won't mess with us
|
|
4124
|
+ #if PLANNER_LEVELING
|
|
4125
|
+ set_bed_leveling_enabled(false);
|
4050
|
4126
|
#endif
|
4051
|
4127
|
|
4052
|
4128
|
setup_for_endstop_or_probe_move();
|
4053
|
4129
|
|
4054
|
|
- // TODO: clear the leveling matrix or the planner will be set incorrectly
|
4055
|
4130
|
float measured_z = probe_pt(current_position[X_AXIS] + X_PROBE_OFFSET_FROM_EXTRUDER,
|
4056
|
4131
|
current_position[Y_AXIS] + Y_PROBE_OFFSET_FROM_EXTRUDER,
|
4057
|
4132
|
true, 1);
|
|
@@ -5380,8 +5455,8 @@ static void report_current_position() {
|
5380
|
5455
|
stepper.report_positions();
|
5381
|
5456
|
|
5382
|
5457
|
#if IS_SCARA
|
5383
|
|
- SERIAL_PROTOCOLPAIR("SCARA Theta:", stepper.get_axis_position_mm(A_AXIS));
|
5384
|
|
- SERIAL_PROTOCOLLNPAIR(" Psi+Theta:", stepper.get_axis_position_mm(B_AXIS));
|
|
5458
|
+ SERIAL_PROTOCOLPAIR("SCARA Theta:", stepper.get_axis_position_degrees(A_AXIS));
|
|
5459
|
+ SERIAL_PROTOCOLLNPAIR(" Psi+Theta:", stepper.get_axis_position_degrees(B_AXIS));
|
5385
|
5460
|
SERIAL_EOL;
|
5386
|
5461
|
#endif
|
5387
|
5462
|
}
|
|
@@ -6260,12 +6335,14 @@ void quickstop_stepper() {
|
6260
|
6335
|
SYNC_PLAN_POSITION_KINEMATIC();
|
6261
|
6336
|
}
|
6262
|
6337
|
|
6263
|
|
-#if ENABLED(MESH_BED_LEVELING)
|
6264
|
|
-
|
|
6338
|
+#if PLANNER_LEVELING
|
6265
|
6339
|
/**
|
6266
|
|
- * M420: Enable/Disable Mesh Bed Leveling
|
|
6340
|
+ * M420: Enable/Disable Bed Leveling
|
6267
|
6341
|
*/
|
6268
|
|
- inline void gcode_M420() { if (code_seen('S')) mbl.set_has_mesh(code_value_bool()); }
|
|
6342
|
+ inline void gcode_M420() { if (code_seen('S')) set_bed_leveling_enabled(code_value_bool()); }
|
|
6343
|
+#endif
|
|
6344
|
+
|
|
6345
|
+#if ENABLED(MESH_BED_LEVELING)
|
6269
|
6346
|
|
6270
|
6347
|
/**
|
6271
|
6348
|
* M421: Set a single Mesh Bed Leveling Z coordinate
|
|
@@ -7291,11 +7368,11 @@ void process_next_command() {
|
7291
|
7368
|
gcode_G28();
|
7292
|
7369
|
break;
|
7293
|
7370
|
|
7294
|
|
- #if HAS_ABL || ENABLED(MESH_BED_LEVELING)
|
|
7371
|
+ #if PLANNER_LEVELING
|
7295
|
7372
|
case 29: // G29 Detailed Z probe, probes the bed at 3 or more points.
|
7296
|
7373
|
gcode_G29();
|
7297
|
7374
|
break;
|
7298
|
|
- #endif // HAS_ABL
|
|
7375
|
+ #endif // PLANNER_LEVELING
|
7299
|
7376
|
|
7300
|
7377
|
#if HAS_BED_PROBE
|
7301
|
7378
|
|
|
@@ -7945,36 +8022,50 @@ void ok_to_send() {
|
7945
|
8022
|
ratio_y = y / bilinear_grid_spacing[Y_AXIS];
|
7946
|
8023
|
|
7947
|
8024
|
// Whole unit is the grid box index
|
7948
|
|
- int gridx = constrain(int(ratio_x), 0, ABL_GRID_POINTS_X - 2),
|
7949
|
|
- gridy = constrain(int(ratio_y), 0, ABL_GRID_POINTS_Y - 2);
|
|
8025
|
+ const int gridx = constrain(floor(ratio_x), 0, ABL_GRID_POINTS_X - 2),
|
|
8026
|
+ gridy = constrain(floor(ratio_y), 0, ABL_GRID_POINTS_Y - 2),
|
|
8027
|
+ nextx = gridx + (x < PROBE_BED_WIDTH ? 1 : 0),
|
|
8028
|
+ nexty = gridy + (y < PROBE_BED_HEIGHT ? 1 : 0);
|
7950
|
8029
|
|
7951
|
8030
|
// Subtract whole to get the ratio within the grid box
|
7952
|
|
- ratio_x -= gridx, ratio_y -= gridy;
|
|
8031
|
+ ratio_x = constrain(ratio_x - gridx, 0.0, 1.0);
|
|
8032
|
+ ratio_y = constrain(ratio_y - gridy, 0.0, 1.0);
|
7953
|
8033
|
|
7954
|
|
- // Z at the box corners
|
7955
|
|
- const float z1 = bed_level_grid[gridx][gridy], // left-front
|
7956
|
|
- z2 = bed_level_grid[gridx][gridy + 1], // left-back
|
7957
|
|
- z3 = bed_level_grid[gridx + 1][gridy], // right-front
|
7958
|
|
- z4 = bed_level_grid[gridx + 1][gridy + 1], // right-back
|
|
8034
|
+ // Z at the box corners
|
|
8035
|
+ const float z1 = bed_level_grid[gridx][gridy], // left-front
|
|
8036
|
+ z2 = bed_level_grid[gridx][nexty], // left-back
|
|
8037
|
+ z3 = bed_level_grid[nextx][gridy], // right-front
|
|
8038
|
+ z4 = bed_level_grid[nextx][nexty], // right-back
|
7959
|
8039
|
|
|
8040
|
+ // Bilinear interpolate
|
7960
|
8041
|
L = z1 + (z2 - z1) * ratio_y, // Linear interp. LF -> LB
|
7961
|
|
- R = z3 + (z4 - z3) * ratio_y; // Linear interp. RF -> RB
|
|
8042
|
+ R = z3 + (z4 - z3) * ratio_y, // Linear interp. RF -> RB
|
|
8043
|
+ offset = L + ratio_x * (R - L);
|
7962
|
8044
|
|
7963
|
8045
|
/*
|
7964
|
|
- SERIAL_ECHOPAIR("gridx=", gridx);
|
7965
|
|
- SERIAL_ECHOPAIR(" gridy=", gridy);
|
|
8046
|
+ static float last_offset = 0;
|
|
8047
|
+ if (fabs(last_offset - offset) > 0.2) {
|
|
8048
|
+ SERIAL_ECHOPGM("Sudden Shift at ");
|
|
8049
|
+ SERIAL_ECHOPAIR("x=", x);
|
|
8050
|
+ SERIAL_ECHOPAIR(" / ", bilinear_grid_spacing[X_AXIS]);
|
|
8051
|
+ SERIAL_ECHOLNPAIR(" -> gridx=", gridx);
|
|
8052
|
+ SERIAL_ECHOPAIR(" y=", y);
|
|
8053
|
+ SERIAL_ECHOPAIR(" / ", bilinear_grid_spacing[Y_AXIS]);
|
|
8054
|
+ SERIAL_ECHOLNPAIR(" -> gridy=", gridy);
|
7966
|
8055
|
SERIAL_ECHOPAIR(" ratio_x=", ratio_x);
|
7967
|
|
- SERIAL_ECHOPAIR(" ratio_y=", ratio_y);
|
|
8056
|
+ SERIAL_ECHOLNPAIR(" ratio_y=", ratio_y);
|
7968
|
8057
|
SERIAL_ECHOPAIR(" z1=", z1);
|
7969
|
8058
|
SERIAL_ECHOPAIR(" z2=", z2);
|
7970
|
8059
|
SERIAL_ECHOPAIR(" z3=", z3);
|
7971
|
|
- SERIAL_ECHOPAIR(" z4=", z4);
|
|
8060
|
+ SERIAL_ECHOLNPAIR(" z4=", z4);
|
7972
|
8061
|
SERIAL_ECHOPAIR(" L=", L);
|
7973
|
8062
|
SERIAL_ECHOPAIR(" R=", R);
|
7974
|
|
- SERIAL_ECHOPAIR(" offset=", L + ratio_x * (R - L));
|
|
8063
|
+ SERIAL_ECHOLNPAIR(" offset=", offset);
|
|
8064
|
+ }
|
|
8065
|
+ last_offset = offset;
|
7975
|
8066
|
//*/
|
7976
|
8067
|
|
7977
|
|
- return L + ratio_x * (R - L);
|
|
8068
|
+ return offset;
|
7978
|
8069
|
}
|
7979
|
8070
|
|
7980
|
8071
|
#endif // AUTO_BED_LEVELING_BILINEAR
|