Apply loop shorthand macros (#17159)
This commit is contained in:
@ -115,8 +115,8 @@ void extrapolate_unprobed_bed_level() {
|
||||
ylen = ctry1;
|
||||
#endif
|
||||
|
||||
for (uint8_t xo = 0; xo <= xlen; xo++)
|
||||
for (uint8_t yo = 0; yo <= ylen; yo++) {
|
||||
LOOP_LE_N(xo, xlen)
|
||||
LOOP_LE_N(yo, ylen) {
|
||||
uint8_t x2 = ctrx2 + xo, y2 = ctry2 + yo;
|
||||
#ifndef HALF_IN_X
|
||||
const uint8_t x1 = ctrx1 - xo;
|
||||
@ -209,8 +209,8 @@ void print_bilinear_leveling_grid() {
|
||||
|
||||
static float bed_level_virt_2cmr(const uint8_t x, const uint8_t y, const float &tx, const float &ty) {
|
||||
float row[4], column[4];
|
||||
for (uint8_t i = 0; i < 4; i++) {
|
||||
for (uint8_t j = 0; j < 4; j++) {
|
||||
LOOP_L_N(i, 4) {
|
||||
LOOP_L_N(j, 4) {
|
||||
column[j] = bed_level_virt_coord(i + x - 1, j + y - 1);
|
||||
}
|
||||
row[i] = bed_level_virt_cmr(column, 1, ty);
|
||||
@ -221,11 +221,11 @@ void print_bilinear_leveling_grid() {
|
||||
void bed_level_virt_interpolate() {
|
||||
bilinear_grid_spacing_virt = bilinear_grid_spacing / (BILINEAR_SUBDIVISIONS);
|
||||
bilinear_grid_factor_virt = bilinear_grid_spacing_virt.reciprocal();
|
||||
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
|
||||
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
|
||||
for (uint8_t ty = 0; ty < BILINEAR_SUBDIVISIONS; ty++)
|
||||
for (uint8_t tx = 0; tx < BILINEAR_SUBDIVISIONS; tx++) {
|
||||
if ((ty && y == GRID_MAX_POINTS_Y - 1) || (tx && x == GRID_MAX_POINTS_X - 1))
|
||||
LOOP_L_N(y, GRID_MAX_POINTS_Y)
|
||||
LOOP_L_N(x, GRID_MAX_POINTS_X)
|
||||
LOOP_L_N(ty, BILINEAR_SUBDIVISIONS)
|
||||
LOOP_L_N(tx, BILINEAR_SUBDIVISIONS) {
|
||||
if ((ty && y == (GRID_MAX_POINTS_Y) - 1) || (tx && x == (GRID_MAX_POINTS_X) - 1))
|
||||
continue;
|
||||
z_values_virt[x * (BILINEAR_SUBDIVISIONS) + tx][y * (BILINEAR_SUBDIVISIONS) + ty] =
|
||||
bed_level_virt_2cmr(
|
||||
|
@ -143,13 +143,12 @@ void reset_bed_level() {
|
||||
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
||||
bilinear_start.reset();
|
||||
bilinear_grid_spacing.reset();
|
||||
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
|
||||
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) {
|
||||
z_values[x][y] = NAN;
|
||||
#if ENABLED(EXTENSIBLE_UI)
|
||||
ExtUI::onMeshUpdate(x, y, 0);
|
||||
#endif
|
||||
}
|
||||
GRID_LOOP(x, y) {
|
||||
z_values[x][y] = NAN;
|
||||
#if ENABLED(EXTENSIBLE_UI)
|
||||
ExtUI::onMeshUpdate(x, y, 0);
|
||||
#endif
|
||||
}
|
||||
#elif ABL_PLANAR
|
||||
planner.bed_level_matrix.set_to_identity();
|
||||
#endif
|
||||
@ -173,7 +172,7 @@ void reset_bed_level() {
|
||||
*/
|
||||
void print_2d_array(const uint8_t sx, const uint8_t sy, const uint8_t precision, element_2d_fn fn) {
|
||||
#ifndef SCAD_MESH_OUTPUT
|
||||
for (uint8_t x = 0; x < sx; x++) {
|
||||
LOOP_L_N(x, sx) {
|
||||
serial_spaces(precision + (x < 10 ? 3 : 2));
|
||||
SERIAL_ECHO(int(x));
|
||||
}
|
||||
@ -182,14 +181,14 @@ void reset_bed_level() {
|
||||
#ifdef SCAD_MESH_OUTPUT
|
||||
SERIAL_ECHOLNPGM("measured_z = ["); // open 2D array
|
||||
#endif
|
||||
for (uint8_t y = 0; y < sy; y++) {
|
||||
LOOP_L_N(y, sy) {
|
||||
#ifdef SCAD_MESH_OUTPUT
|
||||
SERIAL_ECHOPGM(" ["); // open sub-array
|
||||
#else
|
||||
if (y < 10) SERIAL_CHAR(' ');
|
||||
SERIAL_ECHO(int(y));
|
||||
#endif
|
||||
for (uint8_t x = 0; x < sx; x++) {
|
||||
LOOP_L_N(x, sx) {
|
||||
SERIAL_CHAR(' ');
|
||||
const float offset = fn(x, y);
|
||||
if (!isnan(offset)) {
|
||||
@ -202,7 +201,7 @@ void reset_bed_level() {
|
||||
SERIAL_CHAR(' ');
|
||||
SERIAL_ECHOPGM("NAN");
|
||||
#else
|
||||
for (uint8_t i = 0; i < precision + 3; i++)
|
||||
LOOP_L_N(i, precision + 3)
|
||||
SERIAL_CHAR(i ? '=' : ' ');
|
||||
#endif
|
||||
}
|
||||
|
@ -40,9 +40,9 @@
|
||||
mesh_bed_leveling::index_to_ypos[GRID_MAX_POINTS_Y];
|
||||
|
||||
mesh_bed_leveling::mesh_bed_leveling() {
|
||||
for (uint8_t i = 0; i < GRID_MAX_POINTS_X; ++i)
|
||||
LOOP_L_N(i, GRID_MAX_POINTS_X)
|
||||
index_to_xpos[i] = MESH_MIN_X + i * (MESH_X_DIST);
|
||||
for (uint8_t i = 0; i < GRID_MAX_POINTS_Y; ++i)
|
||||
LOOP_L_N(i, GRID_MAX_POINTS_Y)
|
||||
index_to_ypos[i] = MESH_MIN_Y + i * (MESH_Y_DIST);
|
||||
reset();
|
||||
}
|
||||
@ -51,9 +51,7 @@
|
||||
z_offset = 0;
|
||||
ZERO(z_values);
|
||||
#if ENABLED(EXTENSIBLE_UI)
|
||||
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
|
||||
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
|
||||
ExtUI::onMeshUpdate(x, y, 0);
|
||||
GRID_LOOP(x, y) ExtUI::onMeshUpdate(x, y, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -52,9 +52,7 @@ public:
|
||||
static void reset();
|
||||
|
||||
FORCE_INLINE static bool has_mesh() {
|
||||
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
|
||||
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
|
||||
if (z_values[x][y]) return true;
|
||||
GRID_LOOP(x, y) if (z_values[x][y]) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@
|
||||
void unified_bed_leveling::report_current_mesh() {
|
||||
if (!leveling_is_valid()) return;
|
||||
SERIAL_ECHO_MSG(" G29 I99");
|
||||
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
|
||||
LOOP_L_N(x, GRID_MAX_POINTS_X)
|
||||
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
|
||||
if (!isnan(z_values[x][y])) {
|
||||
SERIAL_ECHO_START();
|
||||
@ -101,9 +101,7 @@
|
||||
storage_slot = -1;
|
||||
ZERO(z_values);
|
||||
#if ENABLED(EXTENSIBLE_UI)
|
||||
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
|
||||
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
|
||||
ExtUI::onMeshUpdate(x, y, 0);
|
||||
GRID_LOOP(x, y) ExtUI::onMeshUpdate(x, y, 0);
|
||||
#endif
|
||||
if (was_enabled) report_current_position();
|
||||
}
|
||||
@ -114,13 +112,11 @@
|
||||
}
|
||||
|
||||
void unified_bed_leveling::set_all_mesh_points_to_value(const float value) {
|
||||
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) {
|
||||
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) {
|
||||
z_values[x][y] = value;
|
||||
#if ENABLED(EXTENSIBLE_UI)
|
||||
ExtUI::onMeshUpdate(x, y, value);
|
||||
#endif
|
||||
}
|
||||
GRID_LOOP(x, y) {
|
||||
z_values[x][y] = value;
|
||||
#if ENABLED(EXTENSIBLE_UI)
|
||||
ExtUI::onMeshUpdate(x, y, value);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -190,7 +186,7 @@
|
||||
}
|
||||
|
||||
// Row Values (I indexes)
|
||||
for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
|
||||
LOOP_L_N(i, GRID_MAX_POINTS_X) {
|
||||
|
||||
// Opening Brace or Space
|
||||
const bool is_current = i == curr.x && j == curr.y;
|
||||
|
@ -298,9 +298,7 @@ class unified_bed_leveling {
|
||||
#endif
|
||||
|
||||
static inline bool mesh_is_valid() {
|
||||
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
|
||||
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
|
||||
if (isnan(z_values[x][y])) return false;
|
||||
GRID_LOOP(x, y) if (isnan(z_values[x][y])) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -365,25 +365,23 @@
|
||||
#endif
|
||||
|
||||
case 0:
|
||||
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) { // Create a bowl shape - similar to
|
||||
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) { // a poorly calibrated Delta.
|
||||
const float p1 = 0.5f * (GRID_MAX_POINTS_X) - x,
|
||||
p2 = 0.5f * (GRID_MAX_POINTS_Y) - y;
|
||||
z_values[x][y] += 2.0f * HYPOT(p1, p2);
|
||||
#if ENABLED(EXTENSIBLE_UI)
|
||||
ExtUI::onMeshUpdate(x, y, z_values[x][y]);
|
||||
#endif
|
||||
}
|
||||
GRID_LOOP(x, y) { // Create a bowl shape similar to a poorly-calibrated Delta
|
||||
const float p1 = 0.5f * (GRID_MAX_POINTS_X) - x,
|
||||
p2 = 0.5f * (GRID_MAX_POINTS_Y) - y;
|
||||
z_values[x][y] += 2.0f * HYPOT(p1, p2);
|
||||
#if ENABLED(EXTENSIBLE_UI)
|
||||
ExtUI::onMeshUpdate(x, y, z_values[x][y]);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) { // Create a diagonal line several Mesh cells thick that is raised
|
||||
LOOP_L_N(x, GRID_MAX_POINTS_X) { // Create a diagonal line several Mesh cells thick that is raised
|
||||
z_values[x][x] += 9.999f;
|
||||
z_values[x][x + (x < GRID_MAX_POINTS_Y - 1) ? 1 : -1] += 9.999f; // We want the altered line several mesh points thick
|
||||
z_values[x][x + (x < (GRID_MAX_POINTS_Y) - 1) ? 1 : -1] += 9.999f; // We want the altered line several mesh points thick
|
||||
#if ENABLED(EXTENSIBLE_UI)
|
||||
ExtUI::onMeshUpdate(x, x, z_values[x][x]);
|
||||
ExtUI::onMeshUpdate(x, (x + (x < GRID_MAX_POINTS_Y - 1) ? 1 : -1), z_values[x][x + (x < GRID_MAX_POINTS_Y - 1) ? 1 : -1]);
|
||||
ExtUI::onMeshUpdate(x, (x + (x < (GRID_MAX_POINTS_Y) - 1) ? 1 : -1), z_values[x][x + (x < (GRID_MAX_POINTS_Y) - 1) ? 1 : -1]);
|
||||
#endif
|
||||
|
||||
}
|
||||
@ -467,7 +465,7 @@
|
||||
//
|
||||
// Manually Probe Mesh in areas that can't be reached by the probe
|
||||
//
|
||||
SERIAL_ECHOLNPGM("Manually probing unreachable mesh locations.");
|
||||
SERIAL_ECHOLNPGM("Manually probing unreachable points.");
|
||||
do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
|
||||
|
||||
if (parser.seen('C') && !xy_seen) {
|
||||
@ -537,9 +535,7 @@
|
||||
if (cpos.x < 0) {
|
||||
// No more REAL INVALID mesh points to populate, so we ASSUME
|
||||
// user meant to populate ALL INVALID mesh points to value
|
||||
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
|
||||
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
|
||||
if (isnan(z_values[x][y])) z_values[x][y] = g29_constant;
|
||||
GRID_LOOP(x, y) if (isnan(z_values[x][y])) z_values[x][y] = g29_constant;
|
||||
break; // No more invalid Mesh Points to populate
|
||||
}
|
||||
else {
|
||||
@ -696,12 +692,11 @@
|
||||
void unified_bed_leveling::adjust_mesh_to_mean(const bool cflag, const float value) {
|
||||
float sum = 0;
|
||||
int n = 0;
|
||||
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
|
||||
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
|
||||
if (!isnan(z_values[x][y])) {
|
||||
sum += z_values[x][y];
|
||||
n++;
|
||||
}
|
||||
GRID_LOOP(x, y)
|
||||
if (!isnan(z_values[x][y])) {
|
||||
sum += z_values[x][y];
|
||||
n++;
|
||||
}
|
||||
|
||||
const float mean = sum / n;
|
||||
|
||||
@ -709,10 +704,9 @@
|
||||
// Sum the squares of difference from mean
|
||||
//
|
||||
float sum_of_diff_squared = 0;
|
||||
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
|
||||
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
|
||||
if (!isnan(z_values[x][y]))
|
||||
sum_of_diff_squared += sq(z_values[x][y] - mean);
|
||||
GRID_LOOP(x, y)
|
||||
if (!isnan(z_values[x][y]))
|
||||
sum_of_diff_squared += sq(z_values[x][y] - mean);
|
||||
|
||||
SERIAL_ECHOLNPAIR("# of samples: ", n);
|
||||
SERIAL_ECHOLNPAIR_F("Mean Mesh Height: ", mean, 6);
|
||||
@ -721,27 +715,25 @@
|
||||
SERIAL_ECHOLNPAIR_F("Standard Deviation: ", sigma, 6);
|
||||
|
||||
if (cflag)
|
||||
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
|
||||
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
|
||||
if (!isnan(z_values[x][y])) {
|
||||
z_values[x][y] -= mean + value;
|
||||
#if ENABLED(EXTENSIBLE_UI)
|
||||
ExtUI::onMeshUpdate(x, y, z_values[x][y]);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void unified_bed_leveling::shift_mesh_height() {
|
||||
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
|
||||
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
|
||||
GRID_LOOP(x, y)
|
||||
if (!isnan(z_values[x][y])) {
|
||||
z_values[x][y] += g29_constant;
|
||||
z_values[x][y] -= mean + value;
|
||||
#if ENABLED(EXTENSIBLE_UI)
|
||||
ExtUI::onMeshUpdate(x, y, z_values[x][y]);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void unified_bed_leveling::shift_mesh_height() {
|
||||
GRID_LOOP(x, y)
|
||||
if (!isnan(z_values[x][y])) {
|
||||
z_values[x][y] += g29_constant;
|
||||
#if ENABLED(EXTENSIBLE_UI)
|
||||
ExtUI::onMeshUpdate(x, y, z_values[x][y]);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#if HAS_BED_PROBE
|
||||
/**
|
||||
* Probe all invalidated locations of the mesh that can be reached by the probe.
|
||||
@ -1243,52 +1235,46 @@
|
||||
|
||||
mesh_index_pair farthest { -1, -1, -99999.99 };
|
||||
|
||||
for (int8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
|
||||
for (int8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
|
||||
GRID_LOOP(i, j) {
|
||||
if (!isnan(z_values[i][j])) continue; // Skip valid mesh points
|
||||
|
||||
if (isnan(z_values[i][j])) { // Invalid mesh point?
|
||||
// Skip unreachable points
|
||||
if (!probe.can_reach(mesh_index_to_xpos(i), mesh_index_to_ypos(j)))
|
||||
continue;
|
||||
|
||||
// Skip points the probe can't reach
|
||||
if (!probe.can_reach(mesh_index_to_xpos(i), mesh_index_to_ypos(j)))
|
||||
continue;
|
||||
found_a_NAN = true;
|
||||
|
||||
found_a_NAN = true;
|
||||
xy_int8_t near { -1, -1 };
|
||||
float d1, d2 = 99999.9f;
|
||||
GRID_LOOP(k, l) {
|
||||
if (isnan(z_values[k][l])) continue;
|
||||
|
||||
xy_int8_t near { -1, -1 };
|
||||
float d1, d2 = 99999.9f;
|
||||
for (int8_t k = 0; k < GRID_MAX_POINTS_X; k++) {
|
||||
for (int8_t l = 0; l < GRID_MAX_POINTS_Y; l++) {
|
||||
if (!isnan(z_values[k][l])) {
|
||||
found_a_real = true;
|
||||
found_a_real = true;
|
||||
|
||||
// Add in a random weighting factor that scrambles the probing of the
|
||||
// last half of the mesh (when every unprobed mesh point is one index
|
||||
// from a probed location).
|
||||
// Add in a random weighting factor that scrambles the probing of the
|
||||
// last half of the mesh (when every unprobed mesh point is one index
|
||||
// from a probed location).
|
||||
|
||||
d1 = HYPOT(i - k, j - l) + (1.0f / ((millis() % 47) + 13));
|
||||
d1 = HYPOT(i - k, j - l) + (1.0f / ((millis() % 47) + 13));
|
||||
|
||||
if (d1 < d2) { // Invalid mesh point (i,j) is closer to the defined point (k,l)
|
||||
d2 = d1;
|
||||
near.set(i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// At this point d2 should have the near defined mesh point to invalid mesh point (i,j)
|
||||
//
|
||||
|
||||
if (found_a_real && near.x >= 0 && d2 > farthest.distance) {
|
||||
farthest.pos = near; // Found an invalid location farther from the defined mesh point
|
||||
farthest.distance = d2;
|
||||
}
|
||||
if (d1 < d2) { // Invalid mesh point (i,j) is closer to the defined point (k,l)
|
||||
d2 = d1;
|
||||
near.set(i, j);
|
||||
}
|
||||
} // for j
|
||||
} // for i
|
||||
}
|
||||
|
||||
//
|
||||
// At this point d2 should have the near defined mesh point to invalid mesh point (i,j)
|
||||
//
|
||||
|
||||
if (found_a_real && near.x >= 0 && d2 > farthest.distance) {
|
||||
farthest.pos = near; // Found an invalid location farther from the defined mesh point
|
||||
farthest.distance = d2;
|
||||
}
|
||||
} // GRID_LOOP
|
||||
|
||||
if (!found_a_real && found_a_NAN) { // if the mesh is totally unpopulated, start the probing
|
||||
farthest.pos.set(GRID_MAX_POINTS_X / 2, GRID_MAX_POINTS_Y / 2);
|
||||
farthest.pos.set((GRID_MAX_POINTS_X) / 2, (GRID_MAX_POINTS_Y) / 2);
|
||||
farthest.distance = 1;
|
||||
}
|
||||
return farthest;
|
||||
@ -1304,36 +1290,34 @@
|
||||
|
||||
float best_so_far = 99999.99f;
|
||||
|
||||
for (int8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
|
||||
for (int8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
|
||||
if ( (type == (isnan(z_values[i][j]) ? INVALID : REAL))
|
||||
|| (type == SET_IN_BITMAP && !done_flags->marked(i, j))
|
||||
) {
|
||||
// Found a Mesh Point of the specified type!
|
||||
const xy_pos_t mpos = { mesh_index_to_xpos(i), mesh_index_to_ypos(j) };
|
||||
GRID_LOOP(i, j) {
|
||||
if ( (type == (isnan(z_values[i][j]) ? INVALID : REAL))
|
||||
|| (type == SET_IN_BITMAP && !done_flags->marked(i, j))
|
||||
) {
|
||||
// Found a Mesh Point of the specified type!
|
||||
const xy_pos_t mpos = { mesh_index_to_xpos(i), mesh_index_to_ypos(j) };
|
||||
|
||||
// If using the probe as the reference there are some unreachable locations.
|
||||
// Also for round beds, there are grid points outside the bed the nozzle can't reach.
|
||||
// Prune them from the list and ignore them till the next Phase (manual nozzle probing).
|
||||
// If using the probe as the reference there are some unreachable locations.
|
||||
// Also for round beds, there are grid points outside the bed the nozzle can't reach.
|
||||
// Prune them from the list and ignore them till the next Phase (manual nozzle probing).
|
||||
|
||||
if (!(probe_relative ? probe.can_reach(mpos) : position_is_reachable(mpos)))
|
||||
continue;
|
||||
if (!(probe_relative ? probe.can_reach(mpos) : position_is_reachable(mpos)))
|
||||
continue;
|
||||
|
||||
// Reachable. Check if it's the best_so_far location to the nozzle.
|
||||
// Reachable. Check if it's the best_so_far location to the nozzle.
|
||||
|
||||
const xy_pos_t diff = current_position - mpos;
|
||||
const float distance = (ref - mpos).magnitude() + diff.magnitude() * 0.1f;
|
||||
const xy_pos_t diff = current_position - mpos;
|
||||
const float distance = (ref - mpos).magnitude() + diff.magnitude() * 0.1f;
|
||||
|
||||
// factor in the distance from the current location for the normal case
|
||||
// so the nozzle isn't running all over the bed.
|
||||
if (distance < best_so_far) {
|
||||
best_so_far = distance; // Found a closer location with the desired value type.
|
||||
closest.pos.set(i, j);
|
||||
closest.distance = best_so_far;
|
||||
}
|
||||
// factor in the distance from the current location for the normal case
|
||||
// so the nozzle isn't running all over the bed.
|
||||
if (distance < best_so_far) {
|
||||
best_so_far = distance; // Found a closer location with the desired value type.
|
||||
closest.pos.set(i, j);
|
||||
closest.distance = best_so_far;
|
||||
}
|
||||
} // for j
|
||||
} // for i
|
||||
}
|
||||
} // GRID_LOOP
|
||||
|
||||
return closest;
|
||||
}
|
||||
@ -1373,7 +1357,7 @@
|
||||
info3 PROGMEM = { GRID_MAX_POINTS_X - 1, 0, 0, GRID_MAX_POINTS_Y, true }; // Right side of the mesh looking left
|
||||
static const smart_fill_info * const info[] PROGMEM = { &info0, &info1, &info2, &info3 };
|
||||
|
||||
for (uint8_t i = 0; i < COUNT(info); ++i) {
|
||||
LOOP_L_N(i, COUNT(info)) {
|
||||
const smart_fill_info *f = (smart_fill_info*)pgm_read_ptr(&info[i]);
|
||||
const int8_t sx = pgm_read_byte(&f->sx), sy = pgm_read_byte(&f->sy),
|
||||
ex = pgm_read_byte(&f->ex), ey = pgm_read_byte(&f->ey);
|
||||
@ -1496,12 +1480,13 @@
|
||||
|
||||
bool zig_zag = false;
|
||||
|
||||
uint16_t total_points = g29_grid_size * g29_grid_size, point_num = 1;
|
||||
const uint16_t total_points = sq(g29_grid_size);
|
||||
uint16_t point_num = 1;
|
||||
|
||||
xy_pos_t rpos;
|
||||
for (uint8_t ix = 0; ix < g29_grid_size; ix++) {
|
||||
LOOP_L_N(ix, g29_grid_size) {
|
||||
rpos.x = x_min + ix * dx;
|
||||
for (int8_t iy = 0; iy < g29_grid_size; iy++) {
|
||||
LOOP_L_N(iy, g29_grid_size) {
|
||||
rpos.y = y_min + dy * (zig_zag ? g29_grid_size - 1 - iy : iy);
|
||||
|
||||
if (!abort_flag) {
|
||||
@ -1569,39 +1554,37 @@
|
||||
|
||||
matrix_3x3 rotation = matrix_3x3::create_look_at(vector_3(lsf_results.A, lsf_results.B, 1));
|
||||
|
||||
for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
|
||||
for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
|
||||
float mx = mesh_index_to_xpos(i),
|
||||
my = mesh_index_to_ypos(j),
|
||||
mz = z_values[i][j];
|
||||
GRID_LOOP(i, j) {
|
||||
float mx = mesh_index_to_xpos(i),
|
||||
my = mesh_index_to_ypos(j),
|
||||
mz = z_values[i][j];
|
||||
|
||||
if (DEBUGGING(LEVELING)) {
|
||||
DEBUG_ECHOPAIR_F("before rotation = [", mx, 7);
|
||||
DEBUG_CHAR(',');
|
||||
DEBUG_ECHO_F(my, 7);
|
||||
DEBUG_CHAR(',');
|
||||
DEBUG_ECHO_F(mz, 7);
|
||||
DEBUG_ECHOPGM("] ---> ");
|
||||
DEBUG_DELAY(20);
|
||||
}
|
||||
|
||||
apply_rotation_xyz(rotation, mx, my, mz);
|
||||
|
||||
if (DEBUGGING(LEVELING)) {
|
||||
DEBUG_ECHOPAIR_F("after rotation = [", mx, 7);
|
||||
DEBUG_CHAR(',');
|
||||
DEBUG_ECHO_F(my, 7);
|
||||
DEBUG_CHAR(',');
|
||||
DEBUG_ECHO_F(mz, 7);
|
||||
DEBUG_ECHOLNPGM("]");
|
||||
DEBUG_DELAY(20);
|
||||
}
|
||||
|
||||
z_values[i][j] = mz - lsf_results.D;
|
||||
#if ENABLED(EXTENSIBLE_UI)
|
||||
ExtUI::onMeshUpdate(i, j, z_values[i][j]);
|
||||
#endif
|
||||
if (DEBUGGING(LEVELING)) {
|
||||
DEBUG_ECHOPAIR_F("before rotation = [", mx, 7);
|
||||
DEBUG_CHAR(',');
|
||||
DEBUG_ECHO_F(my, 7);
|
||||
DEBUG_CHAR(',');
|
||||
DEBUG_ECHO_F(mz, 7);
|
||||
DEBUG_ECHOPGM("] ---> ");
|
||||
DEBUG_DELAY(20);
|
||||
}
|
||||
|
||||
apply_rotation_xyz(rotation, mx, my, mz);
|
||||
|
||||
if (DEBUGGING(LEVELING)) {
|
||||
DEBUG_ECHOPAIR_F("after rotation = [", mx, 7);
|
||||
DEBUG_CHAR(',');
|
||||
DEBUG_ECHO_F(my, 7);
|
||||
DEBUG_CHAR(',');
|
||||
DEBUG_ECHO_F(mz, 7);
|
||||
DEBUG_ECHOLNPGM("]");
|
||||
DEBUG_DELAY(20);
|
||||
}
|
||||
|
||||
z_values[i][j] = mz - lsf_results.D;
|
||||
#if ENABLED(EXTENSIBLE_UI)
|
||||
ExtUI::onMeshUpdate(i, j, z_values[i][j]);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (DEBUGGING(LEVELING)) {
|
||||
@ -1661,7 +1644,7 @@
|
||||
// being extrapolated so that nearby points will have greater influence on
|
||||
// the point being extrapolated. Then extrapolate the mesh point from WLSF.
|
||||
|
||||
static_assert(GRID_MAX_POINTS_Y <= 16, "GRID_MAX_POINTS_Y too big");
|
||||
static_assert((GRID_MAX_POINTS_Y) <= 16, "GRID_MAX_POINTS_Y too big");
|
||||
uint16_t bitmap[GRID_MAX_POINTS_X] = { 0 };
|
||||
struct linear_fit_data lsf_results;
|
||||
|
||||
@ -1669,23 +1652,20 @@
|
||||
|
||||
const float weight_scaled = weight_factor * _MAX(MESH_X_DIST, MESH_Y_DIST);
|
||||
|
||||
for (uint8_t jx = 0; jx < GRID_MAX_POINTS_X; jx++)
|
||||
for (uint8_t jy = 0; jy < GRID_MAX_POINTS_Y; jy++)
|
||||
if (!isnan(z_values[jx][jy]))
|
||||
SBI(bitmap[jx], jy);
|
||||
GRID_LOOP(jx, jy) if (!isnan(z_values[jx][jy])) SBI(bitmap[jx], jy);
|
||||
|
||||
xy_pos_t ppos;
|
||||
for (uint8_t ix = 0; ix < GRID_MAX_POINTS_X; ix++) {
|
||||
LOOP_L_N(ix, GRID_MAX_POINTS_X) {
|
||||
ppos.x = mesh_index_to_xpos(ix);
|
||||
for (uint8_t iy = 0; iy < GRID_MAX_POINTS_Y; iy++) {
|
||||
LOOP_L_N(iy, GRID_MAX_POINTS_Y) {
|
||||
ppos.y = mesh_index_to_ypos(iy);
|
||||
if (isnan(z_values[ix][iy])) {
|
||||
// undefined mesh point at (ppos.x,ppos.y), compute weighted LSF from original valid mesh points.
|
||||
incremental_LSF_reset(&lsf_results);
|
||||
xy_pos_t rpos;
|
||||
for (uint8_t jx = 0; jx < GRID_MAX_POINTS_X; jx++) {
|
||||
LOOP_L_N(jx, GRID_MAX_POINTS_X) {
|
||||
rpos.x = mesh_index_to_xpos(jx);
|
||||
for (uint8_t jy = 0; jy < GRID_MAX_POINTS_Y; jy++) {
|
||||
LOOP_L_N(jy, GRID_MAX_POINTS_Y) {
|
||||
if (TEST(bitmap[jx], jy)) {
|
||||
rpos.y = mesh_index_to_ypos(jy);
|
||||
const float rz = z_values[jx][jy],
|
||||
@ -1747,7 +1727,7 @@
|
||||
SERIAL_ECHOLNPAIR("MESH_Y_DIST ", MESH_Y_DIST); serial_delay(50);
|
||||
|
||||
SERIAL_ECHOPGM("X-Axis Mesh Points at: ");
|
||||
for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
|
||||
LOOP_L_N(i, GRID_MAX_POINTS_X) {
|
||||
SERIAL_ECHO_F(LOGICAL_X_POSITION(mesh_index_to_xpos(i)), 3);
|
||||
SERIAL_ECHOPGM(" ");
|
||||
serial_delay(25);
|
||||
@ -1755,7 +1735,7 @@
|
||||
SERIAL_EOL();
|
||||
|
||||
SERIAL_ECHOPGM("Y-Axis Mesh Points at: ");
|
||||
for (uint8_t i = 0; i < GRID_MAX_POINTS_Y; i++) {
|
||||
LOOP_L_N(i, GRID_MAX_POINTS_Y) {
|
||||
SERIAL_ECHO_F(LOGICAL_Y_POSITION(mesh_index_to_ypos(i)), 3);
|
||||
SERIAL_ECHOPGM(" ");
|
||||
serial_delay(25);
|
||||
@ -1840,13 +1820,12 @@
|
||||
|
||||
SERIAL_ECHOLNPAIR("Subtracting mesh in slot ", g29_storage_slot, " from current mesh.");
|
||||
|
||||
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
|
||||
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) {
|
||||
z_values[x][y] -= tmp_z_values[x][y];
|
||||
#if ENABLED(EXTENSIBLE_UI)
|
||||
ExtUI::onMeshUpdate(x, y, z_values[x][y]);
|
||||
#endif
|
||||
}
|
||||
GRID_LOOP(x, y) {
|
||||
z_values[x][y] -= tmp_z_values[x][y];
|
||||
#if ENABLED(EXTENSIBLE_UI)
|
||||
ExtUI::onMeshUpdate(x, y, z_values[x][y]);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#endif // UBL_DEVEL_DEBUGGING
|
||||
|
Reference in New Issue
Block a user