|
|
@ -36,8 +36,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
#define UBL_G29_P31
|
|
|
|
#define UBL_G29_P31
|
|
|
|
|
|
|
|
|
|
|
|
extern float destination[XYZE];
|
|
|
|
extern float destination[XYZE], current_position[XYZE];
|
|
|
|
extern float current_position[XYZE];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void lcd_return_to_status();
|
|
|
|
void lcd_return_to_status();
|
|
|
|
bool lcd_clicked();
|
|
|
|
bool lcd_clicked();
|
|
|
@ -52,20 +51,31 @@
|
|
|
|
extern uint8_t code_value_byte();
|
|
|
|
extern uint8_t code_value_byte();
|
|
|
|
extern bool code_value_bool();
|
|
|
|
extern bool code_value_bool();
|
|
|
|
extern bool code_has_value();
|
|
|
|
extern bool code_has_value();
|
|
|
|
extern float probe_pt(float x, float y, bool, int);
|
|
|
|
extern float probe_pt(const float &x, const float &y, bool, int);
|
|
|
|
extern bool set_probe_deployed(bool);
|
|
|
|
extern bool set_probe_deployed(bool);
|
|
|
|
void smart_fill_mesh();
|
|
|
|
|
|
|
|
void smart_fill_wlsf(float);
|
|
|
|
|
|
|
|
float measure_business_card_thickness(float &in_height);
|
|
|
|
|
|
|
|
void manually_probe_remaining_mesh(const float&, const float&, const float&, const float&, const bool);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool ProbeStay = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define SIZE_OF_LITTLE_RAISE 1
|
|
|
|
#define SIZE_OF_LITTLE_RAISE 1
|
|
|
|
#define BIG_RAISE_NOT_NEEDED 0
|
|
|
|
#define BIG_RAISE_NOT_NEEDED 0
|
|
|
|
|
|
|
|
|
|
|
|
extern void lcd_status_screen();
|
|
|
|
extern void lcd_status_screen();
|
|
|
|
typedef void (*screenFunc_t)();
|
|
|
|
typedef void (*screenFunc_t)();
|
|
|
|
extern void lcd_goto_screen(screenFunc_t screen, const uint32_t encoder = 0);
|
|
|
|
extern void lcd_goto_screen(screenFunc_t screen, const uint32_t encoder = 0);
|
|
|
|
|
|
|
|
extern void lcd_setstatus(const char* message, const bool persist);
|
|
|
|
|
|
|
|
extern void lcd_setstatuspgm(const char* message, const uint8_t level);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int unified_bed_leveling::g29_verbose_level,
|
|
|
|
|
|
|
|
unified_bed_leveling::g29_phase_value,
|
|
|
|
|
|
|
|
unified_bed_leveling::g29_repetition_cnt,
|
|
|
|
|
|
|
|
unified_bed_leveling::g29_storage_slot = 0,
|
|
|
|
|
|
|
|
unified_bed_leveling::g29_map_type,
|
|
|
|
|
|
|
|
unified_bed_leveling::g29_grid_size;
|
|
|
|
|
|
|
|
bool unified_bed_leveling::g29_c_flag,
|
|
|
|
|
|
|
|
unified_bed_leveling::g29_x_flag,
|
|
|
|
|
|
|
|
unified_bed_leveling::g29_y_flag;
|
|
|
|
|
|
|
|
float unified_bed_leveling::g29_x_pos,
|
|
|
|
|
|
|
|
unified_bed_leveling::g29_y_pos,
|
|
|
|
|
|
|
|
unified_bed_leveling::g29_card_thickness = 0.0,
|
|
|
|
|
|
|
|
unified_bed_leveling::g29_constant = 0.0;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* G29: Unified Bed Leveling by Roxy
|
|
|
|
* G29: Unified Bed Leveling by Roxy
|
|
|
@ -304,16 +314,7 @@
|
|
|
|
* we now have the functionality and features of all three systems combined.
|
|
|
|
* we now have the functionality and features of all three systems combined.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
// The simple parameter flags and values are 'static' so parameter parsing can be in a support routine.
|
|
|
|
void unified_bed_leveling::G29() {
|
|
|
|
static int g29_verbose_level, phase_value, repetition_cnt,
|
|
|
|
|
|
|
|
storage_slot = 0, map_type, grid_size;
|
|
|
|
|
|
|
|
static bool repeat_flag, c_flag, x_flag, y_flag;
|
|
|
|
|
|
|
|
static float x_pos, y_pos, card_thickness = 0.0, ubl_constant = 0.0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extern void lcd_setstatus(const char* message, const bool persist);
|
|
|
|
|
|
|
|
extern void lcd_setstatuspgm(const char* message, const uint8_t level);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void _O0 gcode_G29() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!settings.calc_num_meshes()) {
|
|
|
|
if (!settings.calc_num_meshes()) {
|
|
|
|
SERIAL_PROTOCOLLNPGM("?You need to enable your EEPROM and initialize it");
|
|
|
|
SERIAL_PROTOCOLLNPGM("?You need to enable your EEPROM and initialize it");
|
|
|
@ -340,15 +341,15 @@
|
|
|
|
// it directly specifies the repetition count and does not use the 'R' parameter.
|
|
|
|
// it directly specifies the repetition count and does not use the 'R' parameter.
|
|
|
|
if (code_seen('I')) {
|
|
|
|
if (code_seen('I')) {
|
|
|
|
uint8_t cnt = 0;
|
|
|
|
uint8_t cnt = 0;
|
|
|
|
repetition_cnt = code_has_value() ? code_value_int() : 1;
|
|
|
|
g29_repetition_cnt = code_has_value() ? code_value_int() : 1;
|
|
|
|
while (repetition_cnt--) {
|
|
|
|
while (g29_repetition_cnt--) {
|
|
|
|
if (cnt > 20) { cnt = 0; idle(); }
|
|
|
|
if (cnt > 20) { cnt = 0; idle(); }
|
|
|
|
const mesh_index_pair location = find_closest_mesh_point_of_type(REAL, x_pos, y_pos, USE_NOZZLE_AS_REFERENCE, NULL, false);
|
|
|
|
const mesh_index_pair location = find_closest_mesh_point_of_type(REAL, g29_x_pos, g29_y_pos, USE_NOZZLE_AS_REFERENCE, NULL, false);
|
|
|
|
if (location.x_index < 0) {
|
|
|
|
if (location.x_index < 0) {
|
|
|
|
SERIAL_PROTOCOLLNPGM("Entire Mesh invalidated.\n");
|
|
|
|
SERIAL_PROTOCOLLNPGM("Entire Mesh invalidated.\n");
|
|
|
|
break; // No more invalid Mesh Points to populate
|
|
|
|
break; // No more invalid Mesh Points to populate
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ubl.z_values[location.x_index][location.y_index] = NAN;
|
|
|
|
z_values[location.x_index][location.y_index] = NAN;
|
|
|
|
cnt++;
|
|
|
|
cnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SERIAL_PROTOCOLLNPGM("Locations invalidated.\n");
|
|
|
|
SERIAL_PROTOCOLLNPGM("Locations invalidated.\n");
|
|
|
@ -370,30 +371,30 @@
|
|
|
|
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) { // a poorly calibrated Delta.
|
|
|
|
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) { // a poorly calibrated Delta.
|
|
|
|
const float p1 = 0.5 * (GRID_MAX_POINTS_X) - x,
|
|
|
|
const float p1 = 0.5 * (GRID_MAX_POINTS_X) - x,
|
|
|
|
p2 = 0.5 * (GRID_MAX_POINTS_Y) - y;
|
|
|
|
p2 = 0.5 * (GRID_MAX_POINTS_Y) - y;
|
|
|
|
ubl.z_values[x][y] += 2.0 * HYPOT(p1, p2);
|
|
|
|
z_values[x][y] += 2.0 * HYPOT(p1, p2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
case 1:
|
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) { // Create a diagonal line several Mesh cells thick that is raised
|
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) { // Create a diagonal line several Mesh cells thick that is raised
|
|
|
|
ubl.z_values[x][x] += 9.999;
|
|
|
|
z_values[x][x] += 9.999;
|
|
|
|
ubl.z_values[x][x + (x < GRID_MAX_POINTS_Y - 1) ? 1 : -1] += 9.999; // We want the altered line several mesh points thick
|
|
|
|
z_values[x][x + (x < GRID_MAX_POINTS_Y - 1) ? 1 : -1] += 9.999; // We want the altered line several mesh points thick
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
case 2:
|
|
|
|
// Allow the user to specify the height because 10mm is a little extreme in some cases.
|
|
|
|
// Allow the user to specify the height because 10mm is a little extreme in some cases.
|
|
|
|
for (uint8_t x = (GRID_MAX_POINTS_X) / 3; x < 2 * (GRID_MAX_POINTS_X) / 3; x++) // Create a rectangular raised area in
|
|
|
|
for (uint8_t x = (GRID_MAX_POINTS_X) / 3; x < 2 * (GRID_MAX_POINTS_X) / 3; x++) // Create a rectangular raised area in
|
|
|
|
for (uint8_t y = (GRID_MAX_POINTS_Y) / 3; y < 2 * (GRID_MAX_POINTS_Y) / 3; y++) // the center of the bed
|
|
|
|
for (uint8_t y = (GRID_MAX_POINTS_Y) / 3; y < 2 * (GRID_MAX_POINTS_Y) / 3; y++) // the center of the bed
|
|
|
|
ubl.z_values[x][y] += code_seen('C') ? ubl_constant : 9.99;
|
|
|
|
z_values[x][y] += code_seen('C') ? g29_constant : 9.99;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (code_seen('J')) {
|
|
|
|
if (code_seen('J')) {
|
|
|
|
if (grid_size) { // if not 0 it is a normal n x n grid being probed
|
|
|
|
if (g29_grid_size) { // if not 0 it is a normal n x n grid being probed
|
|
|
|
ubl.save_ubl_active_state_and_disable();
|
|
|
|
save_ubl_active_state_and_disable();
|
|
|
|
ubl.tilt_mesh_based_on_probed_grid(code_seen('T'));
|
|
|
|
tilt_mesh_based_on_probed_grid(code_seen('T'));
|
|
|
|
ubl.restore_ubl_active_state_and_leave();
|
|
|
|
restore_ubl_active_state_and_leave();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // grid_size == 0 : A 3-Point leveling has been requested
|
|
|
|
else { // grid_size == 0 : A 3-Point leveling has been requested
|
|
|
|
float z3, z2, z1 = probe_pt(LOGICAL_X_POSITION(UBL_PROBE_PT_1_X), LOGICAL_Y_POSITION(UBL_PROBE_PT_1_Y), false, g29_verbose_level);
|
|
|
|
float z3, z2, z1 = probe_pt(LOGICAL_X_POSITION(UBL_PROBE_PT_1_X), LOGICAL_Y_POSITION(UBL_PROBE_PT_1_Y), false, g29_verbose_level);
|
|
|
@ -413,29 +414,29 @@
|
|
|
|
// doesn't mean the Mesh is tilted! (Compensate each probe point by what the Mesh says
|
|
|
|
// doesn't mean the Mesh is tilted! (Compensate each probe point by what the Mesh says
|
|
|
|
// its height is.)
|
|
|
|
// its height is.)
|
|
|
|
|
|
|
|
|
|
|
|
ubl.save_ubl_active_state_and_disable();
|
|
|
|
save_ubl_active_state_and_disable();
|
|
|
|
z1 -= ubl.get_z_correction(LOGICAL_X_POSITION(UBL_PROBE_PT_1_X), LOGICAL_Y_POSITION(UBL_PROBE_PT_1_Y)) /* + zprobe_zoffset */ ;
|
|
|
|
z1 -= get_z_correction(LOGICAL_X_POSITION(UBL_PROBE_PT_1_X), LOGICAL_Y_POSITION(UBL_PROBE_PT_1_Y)) /* + zprobe_zoffset */ ;
|
|
|
|
z2 -= ubl.get_z_correction(LOGICAL_X_POSITION(UBL_PROBE_PT_2_X), LOGICAL_Y_POSITION(UBL_PROBE_PT_2_Y)) /* + zprobe_zoffset */ ;
|
|
|
|
z2 -= get_z_correction(LOGICAL_X_POSITION(UBL_PROBE_PT_2_X), LOGICAL_Y_POSITION(UBL_PROBE_PT_2_Y)) /* + zprobe_zoffset */ ;
|
|
|
|
z3 -= ubl.get_z_correction(LOGICAL_X_POSITION(UBL_PROBE_PT_3_X), LOGICAL_Y_POSITION(UBL_PROBE_PT_3_Y)) /* + zprobe_zoffset */ ;
|
|
|
|
z3 -= get_z_correction(LOGICAL_X_POSITION(UBL_PROBE_PT_3_X), LOGICAL_Y_POSITION(UBL_PROBE_PT_3_Y)) /* + zprobe_zoffset */ ;
|
|
|
|
|
|
|
|
|
|
|
|
do_blocking_move_to_xy(0.5 * (UBL_MESH_MAX_X - (UBL_MESH_MIN_X)), 0.5 * (UBL_MESH_MAX_Y - (UBL_MESH_MIN_Y)));
|
|
|
|
do_blocking_move_to_xy(0.5 * (UBL_MESH_MAX_X - (UBL_MESH_MIN_X)), 0.5 * (UBL_MESH_MAX_Y - (UBL_MESH_MIN_Y)));
|
|
|
|
ubl.tilt_mesh_based_on_3pts(z1, z2, z3);
|
|
|
|
tilt_mesh_based_on_3pts(z1, z2, z3);
|
|
|
|
ubl.restore_ubl_active_state_and_leave();
|
|
|
|
restore_ubl_active_state_and_leave();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (code_seen('P')) {
|
|
|
|
if (code_seen('P')) {
|
|
|
|
if (WITHIN(phase_value, 0, 1) && ubl.state.storage_slot == -1) {
|
|
|
|
if (WITHIN(g29_phase_value, 0, 1) && state.storage_slot == -1) {
|
|
|
|
ubl.state.storage_slot = 0;
|
|
|
|
state.storage_slot = 0;
|
|
|
|
SERIAL_PROTOCOLLNPGM("Default storage slot 0 selected.");
|
|
|
|
SERIAL_PROTOCOLLNPGM("Default storage slot 0 selected.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch (phase_value) {
|
|
|
|
switch (g29_phase_value) {
|
|
|
|
case 0:
|
|
|
|
case 0:
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Zero Mesh Data
|
|
|
|
// Zero Mesh Data
|
|
|
|
//
|
|
|
|
//
|
|
|
|
ubl.reset();
|
|
|
|
reset();
|
|
|
|
SERIAL_PROTOCOLLNPGM("Mesh zeroed.");
|
|
|
|
SERIAL_PROTOCOLLNPGM("Mesh zeroed.");
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
@ -444,16 +445,16 @@
|
|
|
|
// Invalidate Entire Mesh and Automatically Probe Mesh in areas that can be reached by the probe
|
|
|
|
// Invalidate Entire Mesh and Automatically Probe Mesh in areas that can be reached by the probe
|
|
|
|
//
|
|
|
|
//
|
|
|
|
if (!code_seen('C')) {
|
|
|
|
if (!code_seen('C')) {
|
|
|
|
ubl.invalidate();
|
|
|
|
invalidate();
|
|
|
|
SERIAL_PROTOCOLLNPGM("Mesh invalidated. Probing mesh.");
|
|
|
|
SERIAL_PROTOCOLLNPGM("Mesh invalidated. Probing mesh.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (g29_verbose_level > 1) {
|
|
|
|
if (g29_verbose_level > 1) {
|
|
|
|
SERIAL_PROTOCOLPAIR("Probing Mesh Points Closest to (", x_pos);
|
|
|
|
SERIAL_PROTOCOLPAIR("Probing Mesh Points Closest to (", g29_x_pos);
|
|
|
|
SERIAL_PROTOCOLCHAR(',');
|
|
|
|
SERIAL_PROTOCOLCHAR(',');
|
|
|
|
SERIAL_PROTOCOL(y_pos);
|
|
|
|
SERIAL_PROTOCOL(g29_y_pos);
|
|
|
|
SERIAL_PROTOCOLLNPGM(").\n");
|
|
|
|
SERIAL_PROTOCOLLNPGM(").\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ubl.probe_entire_mesh(x_pos + X_PROBE_OFFSET_FROM_EXTRUDER, y_pos + Y_PROBE_OFFSET_FROM_EXTRUDER,
|
|
|
|
probe_entire_mesh(g29_x_pos + X_PROBE_OFFSET_FROM_EXTRUDER, g29_y_pos + Y_PROBE_OFFSET_FROM_EXTRUDER,
|
|
|
|
code_seen('T'), code_seen('E'), code_seen('U'));
|
|
|
|
code_seen('T'), code_seen('E'), code_seen('U'));
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
@ -463,7 +464,7 @@
|
|
|
|
//
|
|
|
|
//
|
|
|
|
SERIAL_PROTOCOLLNPGM("Manually probing unreachable mesh locations.");
|
|
|
|
SERIAL_PROTOCOLLNPGM("Manually probing unreachable mesh locations.");
|
|
|
|
do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
|
|
|
|
do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
|
|
|
|
if (!x_flag && !y_flag) {
|
|
|
|
if (!g29_x_flag && !g29_y_flag) {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Use a good default location for the path.
|
|
|
|
* Use a good default location for the path.
|
|
|
|
* The flipped > and < operators in these comparisons is intentional.
|
|
|
|
* The flipped > and < operators in these comparisons is intentional.
|
|
|
@ -472,25 +473,25 @@
|
|
|
|
* Until that is decided, this can be forced with the X and Y parameters.
|
|
|
|
* Until that is decided, this can be forced with the X and Y parameters.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
#if IS_KINEMATIC
|
|
|
|
#if IS_KINEMATIC
|
|
|
|
x_pos = X_HOME_POS;
|
|
|
|
g29_x_pos = X_HOME_POS;
|
|
|
|
y_pos = Y_HOME_POS;
|
|
|
|
g29_y_pos = Y_HOME_POS;
|
|
|
|
#else // cartesian
|
|
|
|
#else // cartesian
|
|
|
|
x_pos = X_PROBE_OFFSET_FROM_EXTRUDER > 0 ? X_MAX_POS : X_MIN_POS;
|
|
|
|
g29_x_pos = X_PROBE_OFFSET_FROM_EXTRUDER > 0 ? X_MAX_POS : X_MIN_POS;
|
|
|
|
y_pos = Y_PROBE_OFFSET_FROM_EXTRUDER < 0 ? Y_MAX_POS : Y_MIN_POS;
|
|
|
|
g29_y_pos = Y_PROBE_OFFSET_FROM_EXTRUDER < 0 ? Y_MAX_POS : Y_MIN_POS;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (code_seen('C')) {
|
|
|
|
if (code_seen('C')) {
|
|
|
|
x_pos = current_position[X_AXIS];
|
|
|
|
g29_x_pos = current_position[X_AXIS];
|
|
|
|
y_pos = current_position[Y_AXIS];
|
|
|
|
g29_y_pos = current_position[Y_AXIS];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
float height = Z_CLEARANCE_BETWEEN_PROBES;
|
|
|
|
float height = Z_CLEARANCE_BETWEEN_PROBES;
|
|
|
|
|
|
|
|
|
|
|
|
if (code_seen('B')) {
|
|
|
|
if (code_seen('B')) {
|
|
|
|
card_thickness = code_has_value() ? code_value_float() : measure_business_card_thickness(height);
|
|
|
|
g29_card_thickness = code_has_value() ? code_value_float() : measure_business_card_thickness(height);
|
|
|
|
|
|
|
|
|
|
|
|
if (fabs(card_thickness) > 1.5) {
|
|
|
|
if (fabs(g29_card_thickness) > 1.5) {
|
|
|
|
SERIAL_PROTOCOLLNPGM("?Error in Business Card measurement.");
|
|
|
|
SERIAL_PROTOCOLLNPGM("?Error in Business Card measurement.");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -498,12 +499,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
if (code_seen('H') && code_has_value()) height = code_value_float();
|
|
|
|
if (code_seen('H') && code_has_value()) height = code_value_float();
|
|
|
|
|
|
|
|
|
|
|
|
if (!position_is_reachable_xy(x_pos, y_pos)) {
|
|
|
|
if (!position_is_reachable_xy(g29_x_pos, g29_y_pos)) {
|
|
|
|
SERIAL_PROTOCOLLNPGM("(X,Y) outside printable radius.");
|
|
|
|
SERIAL_PROTOCOLLNPGM("(X,Y) outside printable radius.");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
manually_probe_remaining_mesh(x_pos, y_pos, height, card_thickness, code_seen('T'));
|
|
|
|
manually_probe_remaining_mesh(g29_x_pos, g29_y_pos, height, g29_card_thickness, code_seen('T'));
|
|
|
|
SERIAL_PROTOCOLLNPGM("G29 P2 finished.");
|
|
|
|
SERIAL_PROTOCOLLNPGM("G29 P2 finished.");
|
|
|
|
} break;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
|
|
|
@ -514,24 +515,24 @@
|
|
|
|
* - Specify a constant with the 'C' parameter.
|
|
|
|
* - Specify a constant with the 'C' parameter.
|
|
|
|
* - Allow 'G29 P3' to choose a 'reasonable' constant.
|
|
|
|
* - Allow 'G29 P3' to choose a 'reasonable' constant.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
if (c_flag) {
|
|
|
|
if (g29_c_flag) {
|
|
|
|
if (repetition_cnt >= GRID_MAX_POINTS) {
|
|
|
|
if (g29_repetition_cnt >= GRID_MAX_POINTS) {
|
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) {
|
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) {
|
|
|
|
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) {
|
|
|
|
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) {
|
|
|
|
ubl.z_values[x][y] = ubl_constant;
|
|
|
|
z_values[x][y] = g29_constant;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
while (repetition_cnt--) { // this only populates reachable mesh points near
|
|
|
|
while (g29_repetition_cnt--) { // this only populates reachable mesh points near
|
|
|
|
const mesh_index_pair location = find_closest_mesh_point_of_type(INVALID, x_pos, y_pos, USE_NOZZLE_AS_REFERENCE, NULL, false);
|
|
|
|
const mesh_index_pair location = find_closest_mesh_point_of_type(INVALID, g29_x_pos, g29_y_pos, USE_NOZZLE_AS_REFERENCE, NULL, false);
|
|
|
|
if (location.x_index < 0) break; // No more reachable invalid Mesh Points to populate
|
|
|
|
if (location.x_index < 0) break; // No more reachable invalid Mesh Points to populate
|
|
|
|
ubl.z_values[location.x_index][location.y_index] = ubl_constant;
|
|
|
|
z_values[location.x_index][location.y_index] = g29_constant;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
const float cvf = code_value_float();
|
|
|
|
const float cvf = code_value_float();
|
|
|
|
switch( (int)truncf( cvf * 10.0 ) - 30 ) { // 3.1 -> 1
|
|
|
|
switch((int)truncf(cvf * 10.0) - 30) { // 3.1 -> 1
|
|
|
|
#if ENABLED(UBL_G29_P31)
|
|
|
|
#if ENABLED(UBL_G29_P31)
|
|
|
|
case 1: {
|
|
|
|
case 1: {
|
|
|
|
|
|
|
|
|
|
|
@ -541,9 +542,9 @@
|
|
|
|
// P3.12 100X distance weighting
|
|
|
|
// P3.12 100X distance weighting
|
|
|
|
// P3.13 1000X distance weighting, approaches simple average of nearest points
|
|
|
|
// P3.13 1000X distance weighting, approaches simple average of nearest points
|
|
|
|
|
|
|
|
|
|
|
|
const float weight_power = (cvf - 3.10) * 100.0; // 3.12345 -> 2.345
|
|
|
|
const float weight_power = (cvf - 3.10) * 100.0, // 3.12345 -> 2.345
|
|
|
|
const float weight_factor = weight_power ? pow( 10.0, weight_power ) : 0;
|
|
|
|
weight_factor = weight_power ? pow(10.0, weight_power) : 0;
|
|
|
|
smart_fill_wlsf( weight_factor );
|
|
|
|
smart_fill_wlsf(weight_factor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
@ -561,13 +562,13 @@
|
|
|
|
// Fine Tune (i.e., Edit) the Mesh
|
|
|
|
// Fine Tune (i.e., Edit) the Mesh
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
fine_tune_mesh(x_pos, y_pos, code_seen('T'));
|
|
|
|
fine_tune_mesh(g29_x_pos, g29_y_pos, code_seen('T'));
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case 5: ubl.find_mean_mesh_height(); break;
|
|
|
|
case 5: find_mean_mesh_height(); break;
|
|
|
|
|
|
|
|
|
|
|
|
case 6: ubl.shift_mesh_height(); break;
|
|
|
|
case 6: shift_mesh_height(); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -575,7 +576,7 @@
|
|
|
|
// Much of the 'What?' command can be eliminated. But until we are fully debugged, it is
|
|
|
|
// Much of the 'What?' command can be eliminated. But until we are fully debugged, it is
|
|
|
|
// good to have the extra information. Soon... we prune this to just a few items
|
|
|
|
// good to have the extra information. Soon... we prune this to just a few items
|
|
|
|
//
|
|
|
|
//
|
|
|
|
if (code_seen('W')) ubl.g29_what_command();
|
|
|
|
if (code_seen('W')) g29_what_command();
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// When we are fully debugged, this may go away. But there are some valid
|
|
|
|
// When we are fully debugged, this may go away. But there are some valid
|
|
|
@ -590,7 +591,7 @@
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
if (code_seen('L')) { // Load Current Mesh Data
|
|
|
|
if (code_seen('L')) { // Load Current Mesh Data
|
|
|
|
storage_slot = code_has_value() ? code_value_int() : ubl.state.storage_slot;
|
|
|
|
g29_storage_slot = code_has_value() ? code_value_int() : state.storage_slot;
|
|
|
|
|
|
|
|
|
|
|
|
int16_t a = settings.calc_num_meshes();
|
|
|
|
int16_t a = settings.calc_num_meshes();
|
|
|
|
|
|
|
|
|
|
|
@ -599,14 +600,14 @@
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!WITHIN(storage_slot, 0, a - 1)) {
|
|
|
|
if (!WITHIN(g29_storage_slot, 0, a - 1)) {
|
|
|
|
SERIAL_PROTOCOLLNPGM("?Invalid storage slot.");
|
|
|
|
SERIAL_PROTOCOLLNPGM("?Invalid storage slot.");
|
|
|
|
SERIAL_PROTOCOLLNPAIR("?Use 0 to ", a - 1);
|
|
|
|
SERIAL_PROTOCOLLNPAIR("?Use 0 to ", a - 1);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
settings.load_mesh(storage_slot);
|
|
|
|
settings.load_mesh(g29_storage_slot);
|
|
|
|
ubl.state.storage_slot = storage_slot;
|
|
|
|
state.storage_slot = g29_storage_slot;
|
|
|
|
|
|
|
|
|
|
|
|
SERIAL_PROTOCOLLNPGM("Done.");
|
|
|
|
SERIAL_PROTOCOLLNPGM("Done.");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -616,19 +617,19 @@
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
if (code_seen('S')) { // Store (or Save) Current Mesh Data
|
|
|
|
if (code_seen('S')) { // Store (or Save) Current Mesh Data
|
|
|
|
storage_slot = code_has_value() ? code_value_int() : ubl.state.storage_slot;
|
|
|
|
g29_storage_slot = code_has_value() ? code_value_int() : state.storage_slot;
|
|
|
|
|
|
|
|
|
|
|
|
if (storage_slot == -1) { // Special case, we are going to 'Export' the mesh to the
|
|
|
|
if (g29_storage_slot == -1) { // Special case, we are going to 'Export' the mesh to the
|
|
|
|
SERIAL_ECHOLNPGM("G29 I 999"); // host in a form it can be reconstructed on a different machine
|
|
|
|
SERIAL_ECHOLNPGM("G29 I 999"); // host in a form it can be reconstructed on a different machine
|
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
|
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
|
|
|
|
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
|
|
|
|
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
|
|
|
|
if (!isnan(ubl.z_values[x][y])) {
|
|
|
|
if (!isnan(z_values[x][y])) {
|
|
|
|
SERIAL_ECHOPAIR("M421 I ", x);
|
|
|
|
SERIAL_ECHOPAIR("M421 I ", x);
|
|
|
|
SERIAL_ECHOPAIR(" J ", y);
|
|
|
|
SERIAL_ECHOPAIR(" J ", y);
|
|
|
|
SERIAL_ECHOPGM(" Z ");
|
|
|
|
SERIAL_ECHOPGM(" Z ");
|
|
|
|
SERIAL_ECHO_F(ubl.z_values[x][y], 6);
|
|
|
|
SERIAL_ECHO_F(z_values[x][y], 6);
|
|
|
|
SERIAL_ECHOPAIR(" ; X ", LOGICAL_X_POSITION(pgm_read_float(&ubl.mesh_index_to_xpos[x])));
|
|
|
|
SERIAL_ECHOPAIR(" ; X ", LOGICAL_X_POSITION(mesh_index_to_xpos(x)));
|
|
|
|
SERIAL_ECHOPAIR(", Y ", LOGICAL_Y_POSITION(pgm_read_float(&ubl.mesh_index_to_ypos[y])));
|
|
|
|
SERIAL_ECHOPAIR(", Y ", LOGICAL_Y_POSITION(mesh_index_to_ypos(y)));
|
|
|
|
SERIAL_EOL;
|
|
|
|
SERIAL_EOL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
return;
|
|
|
@ -641,32 +642,32 @@
|
|
|
|
goto LEAVE;
|
|
|
|
goto LEAVE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!WITHIN(storage_slot, 0, a - 1)) {
|
|
|
|
if (!WITHIN(g29_storage_slot, 0, a - 1)) {
|
|
|
|
SERIAL_PROTOCOLLNPGM("?Invalid storage slot.");
|
|
|
|
SERIAL_PROTOCOLLNPGM("?Invalid storage slot.");
|
|
|
|
SERIAL_PROTOCOLLNPAIR("?Use 0 to ", a - 1);
|
|
|
|
SERIAL_PROTOCOLLNPAIR("?Use 0 to ", a - 1);
|
|
|
|
goto LEAVE;
|
|
|
|
goto LEAVE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
settings.store_mesh(storage_slot);
|
|
|
|
settings.store_mesh(g29_storage_slot);
|
|
|
|
ubl.state.storage_slot = storage_slot;
|
|
|
|
state.storage_slot = g29_storage_slot;
|
|
|
|
|
|
|
|
|
|
|
|
SERIAL_PROTOCOLLNPGM("Done.");
|
|
|
|
SERIAL_PROTOCOLLNPGM("Done.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (code_seen('T'))
|
|
|
|
if (code_seen('T'))
|
|
|
|
ubl.display_map(code_has_value() ? code_value_int() : 0);
|
|
|
|
display_map(code_has_value() ? code_value_int() : 0);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* This code may not be needed... Prepare for its removal...
|
|
|
|
* This code may not be needed... Prepare for its removal...
|
|
|
|
*
|
|
|
|
*
|
|
|
|
if (code_seen('Z')) {
|
|
|
|
if (code_seen('Z')) {
|
|
|
|
if (code_has_value())
|
|
|
|
if (code_has_value())
|
|
|
|
ubl.state.z_offset = code_value_float(); // do the simple case. Just lock in the specified value
|
|
|
|
state.z_offset = code_value_float(); // do the simple case. Just lock in the specified value
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
ubl.save_ubl_active_state_and_disable();
|
|
|
|
save_ubl_active_state_and_disable();
|
|
|
|
//float measured_z = probe_pt(x_pos + X_PROBE_OFFSET_FROM_EXTRUDER, y_pos + Y_PROBE_OFFSET_FROM_EXTRUDER, ProbeDeployAndStow, g29_verbose_level);
|
|
|
|
//float measured_z = probe_pt(g29_x_pos + X_PROBE_OFFSET_FROM_EXTRUDER, g29_y_pos + Y_PROBE_OFFSET_FROM_EXTRUDER, ProbeDeployAndStow, g29_verbose_level);
|
|
|
|
|
|
|
|
|
|
|
|
ubl.has_control_of_lcd_panel = true; // Grab the LCD Hardware
|
|
|
|
has_control_of_lcd_panel = true; // Grab the LCD Hardware
|
|
|
|
float measured_z = 1.5;
|
|
|
|
float measured_z = 1.5;
|
|
|
|
do_blocking_move_to_z(measured_z); // Get close to the bed, but leave some space so we don't damage anything
|
|
|
|
do_blocking_move_to_z(measured_z); // Get close to the bed, but leave some space so we don't damage anything
|
|
|
|
// The user is not going to be locking in a new Z-Offset very often so
|
|
|
|
// The user is not going to be locking in a new Z-Offset very often so
|
|
|
@ -682,7 +683,7 @@
|
|
|
|
do_blocking_move_to_z(measured_z);
|
|
|
|
do_blocking_move_to_z(measured_z);
|
|
|
|
} while (!ubl_lcd_clicked());
|
|
|
|
} while (!ubl_lcd_clicked());
|
|
|
|
|
|
|
|
|
|
|
|
ubl.has_control_of_lcd_panel = true; // There is a race condition for the encoder click.
|
|
|
|
has_control_of_lcd_panel = true; // There is a race condition for the encoder click.
|
|
|
|
// It could get detected in lcd_mesh_edit (actually _lcd_mesh_fine_tune)
|
|
|
|
// It could get detected in lcd_mesh_edit (actually _lcd_mesh_fine_tune)
|
|
|
|
// or here. So, until we are done looking for a long encoder press,
|
|
|
|
// or here. So, until we are done looking for a long encoder press,
|
|
|
|
// we need to take control of the panel
|
|
|
|
// we need to take control of the panel
|
|
|
@ -698,17 +699,17 @@
|
|
|
|
SERIAL_PROTOCOLLNPGM("\nZ-Offset Adjustment Stopped.");
|
|
|
|
SERIAL_PROTOCOLLNPGM("\nZ-Offset Adjustment Stopped.");
|
|
|
|
do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
|
|
|
|
do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
|
|
|
|
LCD_MESSAGEPGM("Z-Offset Stopped"); // TODO: Make translatable string
|
|
|
|
LCD_MESSAGEPGM("Z-Offset Stopped"); // TODO: Make translatable string
|
|
|
|
ubl.restore_ubl_active_state_and_leave();
|
|
|
|
restore_ubl_active_state_and_leave();
|
|
|
|
goto LEAVE;
|
|
|
|
goto LEAVE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ubl.has_control_of_lcd_panel = false;
|
|
|
|
has_control_of_lcd_panel = false;
|
|
|
|
safe_delay(20); // We don't want any switch noise.
|
|
|
|
safe_delay(20); // We don't want any switch noise.
|
|
|
|
|
|
|
|
|
|
|
|
ubl.state.z_offset = measured_z;
|
|
|
|
state.z_offset = measured_z;
|
|
|
|
|
|
|
|
|
|
|
|
lcd_implementation_clear();
|
|
|
|
lcd_implementation_clear();
|
|
|
|
ubl.restore_ubl_active_state_and_leave();
|
|
|
|
restore_ubl_active_state_and_leave();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -719,7 +720,7 @@
|
|
|
|
LCD_MESSAGEPGM("");
|
|
|
|
LCD_MESSAGEPGM("");
|
|
|
|
lcd_quick_feedback();
|
|
|
|
lcd_quick_feedback();
|
|
|
|
|
|
|
|
|
|
|
|
ubl.has_control_of_lcd_panel = false;
|
|
|
|
has_control_of_lcd_panel = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void unified_bed_leveling::find_mean_mesh_height() {
|
|
|
|
void unified_bed_leveling::find_mean_mesh_height() {
|
|
|
@ -727,8 +728,8 @@
|
|
|
|
int n = 0;
|
|
|
|
int n = 0;
|
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
|
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
|
|
|
|
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
|
|
|
|
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
|
|
|
|
if (!isnan(ubl.z_values[x][y])) {
|
|
|
|
if (!isnan(z_values[x][y])) {
|
|
|
|
sum += ubl.z_values[x][y];
|
|
|
|
sum += z_values[x][y];
|
|
|
|
n++;
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -740,8 +741,8 @@
|
|
|
|
float sum_of_diff_squared = 0.0;
|
|
|
|
float sum_of_diff_squared = 0.0;
|
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
|
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
|
|
|
|
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
|
|
|
|
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
|
|
|
|
if (!isnan(ubl.z_values[x][y]))
|
|
|
|
if (!isnan(z_values[x][y]))
|
|
|
|
sum_of_diff_squared += sq(ubl.z_values[x][y] - mean);
|
|
|
|
sum_of_diff_squared += sq(z_values[x][y] - mean);
|
|
|
|
|
|
|
|
|
|
|
|
SERIAL_ECHOLNPAIR("# of samples: ", n);
|
|
|
|
SERIAL_ECHOLNPAIR("# of samples: ", n);
|
|
|
|
SERIAL_ECHOPGM("Mean Mesh Height: ");
|
|
|
|
SERIAL_ECHOPGM("Mean Mesh Height: ");
|
|
|
@ -753,18 +754,18 @@
|
|
|
|
SERIAL_ECHO_F(sigma, 6);
|
|
|
|
SERIAL_ECHO_F(sigma, 6);
|
|
|
|
SERIAL_EOL;
|
|
|
|
SERIAL_EOL;
|
|
|
|
|
|
|
|
|
|
|
|
if (c_flag)
|
|
|
|
if (g29_c_flag)
|
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
|
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
|
|
|
|
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
|
|
|
|
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
|
|
|
|
if (!isnan(ubl.z_values[x][y]))
|
|
|
|
if (!isnan(z_values[x][y]))
|
|
|
|
ubl.z_values[x][y] -= mean + ubl_constant;
|
|
|
|
z_values[x][y] -= mean + g29_constant;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void unified_bed_leveling::shift_mesh_height() {
|
|
|
|
void unified_bed_leveling::shift_mesh_height() {
|
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
|
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
|
|
|
|
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
|
|
|
|
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
|
|
|
|
if (!isnan(ubl.z_values[x][y]))
|
|
|
|
if (!isnan(z_values[x][y]))
|
|
|
|
ubl.z_values[x][y] += ubl_constant;
|
|
|
|
z_values[x][y] += g29_constant;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -774,8 +775,8 @@
|
|
|
|
void unified_bed_leveling::probe_entire_mesh(const float &lx, const float &ly, const bool do_ubl_mesh_map, const bool stow_probe, bool close_or_far) {
|
|
|
|
void unified_bed_leveling::probe_entire_mesh(const float &lx, const float &ly, const bool do_ubl_mesh_map, const bool stow_probe, bool close_or_far) {
|
|
|
|
mesh_index_pair location;
|
|
|
|
mesh_index_pair location;
|
|
|
|
|
|
|
|
|
|
|
|
ubl.has_control_of_lcd_panel = true;
|
|
|
|
has_control_of_lcd_panel = true;
|
|
|
|
ubl.save_ubl_active_state_and_disable(); // we don't do bed level correction because we want the raw data when we probe
|
|
|
|
save_ubl_active_state_and_disable(); // we don't do bed level correction because we want the raw data when we probe
|
|
|
|
DEPLOY_PROBE();
|
|
|
|
DEPLOY_PROBE();
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t max_iterations = GRID_MAX_POINTS;
|
|
|
|
uint16_t max_iterations = GRID_MAX_POINTS;
|
|
|
@ -786,8 +787,8 @@
|
|
|
|
lcd_quick_feedback();
|
|
|
|
lcd_quick_feedback();
|
|
|
|
STOW_PROBE();
|
|
|
|
STOW_PROBE();
|
|
|
|
while (ubl_lcd_clicked()) idle();
|
|
|
|
while (ubl_lcd_clicked()) idle();
|
|
|
|
ubl.has_control_of_lcd_panel = false;
|
|
|
|
has_control_of_lcd_panel = false;
|
|
|
|
ubl.restore_ubl_active_state_and_leave();
|
|
|
|
restore_ubl_active_state_and_leave();
|
|
|
|
safe_delay(50); // Debounce the Encoder wheel
|
|
|
|
safe_delay(50); // Debounce the Encoder wheel
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -795,19 +796,19 @@
|
|
|
|
location = find_closest_mesh_point_of_type(INVALID, lx, ly, USE_PROBE_AS_REFERENCE, NULL, close_or_far);
|
|
|
|
location = find_closest_mesh_point_of_type(INVALID, lx, ly, USE_PROBE_AS_REFERENCE, NULL, close_or_far);
|
|
|
|
|
|
|
|
|
|
|
|
if (location.x_index >= 0) { // mesh point found and is reachable by probe
|
|
|
|
if (location.x_index >= 0) { // mesh point found and is reachable by probe
|
|
|
|
const float rawx = pgm_read_float(&ubl.mesh_index_to_xpos[location.x_index]),
|
|
|
|
const float rawx = mesh_index_to_xpos(location.x_index),
|
|
|
|
rawy = pgm_read_float(&ubl.mesh_index_to_ypos[location.y_index]);
|
|
|
|
rawy = mesh_index_to_ypos(location.y_index);
|
|
|
|
|
|
|
|
|
|
|
|
const float measured_z = probe_pt(LOGICAL_X_POSITION(rawx), LOGICAL_Y_POSITION(rawy), stow_probe, g29_verbose_level); // TODO: Needs error handling
|
|
|
|
const float measured_z = probe_pt(LOGICAL_X_POSITION(rawx), LOGICAL_Y_POSITION(rawy), stow_probe, g29_verbose_level); // TODO: Needs error handling
|
|
|
|
ubl.z_values[location.x_index][location.y_index] = measured_z;
|
|
|
|
z_values[location.x_index][location.y_index] = measured_z;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (do_ubl_mesh_map) ubl.display_map(map_type);
|
|
|
|
if (do_ubl_mesh_map) display_map(g29_map_type);
|
|
|
|
|
|
|
|
|
|
|
|
} while (location.x_index >= 0 && --max_iterations);
|
|
|
|
} while (location.x_index >= 0 && --max_iterations);
|
|
|
|
|
|
|
|
|
|
|
|
STOW_PROBE();
|
|
|
|
STOW_PROBE();
|
|
|
|
ubl.restore_ubl_active_state_and_leave();
|
|
|
|
restore_ubl_active_state_and_leave();
|
|
|
|
|
|
|
|
|
|
|
|
do_blocking_move_to_xy(
|
|
|
|
do_blocking_move_to_xy(
|
|
|
|
constrain(lx - (X_PROBE_OFFSET_FROM_EXTRUDER), UBL_MESH_MIN_X, UBL_MESH_MAX_X),
|
|
|
|
constrain(lx - (X_PROBE_OFFSET_FROM_EXTRUDER), UBL_MESH_MIN_X, UBL_MESH_MAX_X),
|
|
|
@ -886,9 +887,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
|
|
|
|
for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
|
|
|
|
for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
|
|
|
|
for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
|
|
|
|
float x_tmp = pgm_read_float(&ubl.mesh_index_to_xpos[i]),
|
|
|
|
float x_tmp = mesh_index_to_xpos(i),
|
|
|
|
y_tmp = pgm_read_float(&ubl.mesh_index_to_ypos[j]),
|
|
|
|
y_tmp = mesh_index_to_ypos(j),
|
|
|
|
z_tmp = ubl.z_values[i][j];
|
|
|
|
z_tmp = z_values[i][j];
|
|
|
|
#if ENABLED(DEBUG_LEVELING_FEATURE)
|
|
|
|
#if ENABLED(DEBUG_LEVELING_FEATURE)
|
|
|
|
if (DEBUGGING(LEVELING)) {
|
|
|
|
if (DEBUGGING(LEVELING)) {
|
|
|
|
SERIAL_ECHOPGM("before rotation = [");
|
|
|
|
SERIAL_ECHOPGM("before rotation = [");
|
|
|
@ -914,12 +915,12 @@
|
|
|
|
safe_delay(55);
|
|
|
|
safe_delay(55);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
ubl.z_values[i][j] += z_tmp - d;
|
|
|
|
z_values[i][j] += z_tmp - d;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
float use_encoder_wheel_to_measure_point() {
|
|
|
|
float unified_bed_leveling::measure_point_with_encoder() {
|
|
|
|
|
|
|
|
|
|
|
|
while (ubl_lcd_clicked()) delay(50); // wait for user to release encoder wheel
|
|
|
|
while (ubl_lcd_clicked()) delay(50); // wait for user to release encoder wheel
|
|
|
|
delay(50); // debounce
|
|
|
|
delay(50); // debounce
|
|
|
@ -927,22 +928,20 @@
|
|
|
|
KEEPALIVE_STATE(PAUSED_FOR_USER);
|
|
|
|
KEEPALIVE_STATE(PAUSED_FOR_USER);
|
|
|
|
while (!ubl_lcd_clicked()) { // we need the loop to move the nozzle based on the encoder wheel here!
|
|
|
|
while (!ubl_lcd_clicked()) { // we need the loop to move the nozzle based on the encoder wheel here!
|
|
|
|
idle();
|
|
|
|
idle();
|
|
|
|
if (ubl.encoder_diff) {
|
|
|
|
if (encoder_diff) {
|
|
|
|
do_blocking_move_to_z(current_position[Z_AXIS] + 0.01 * float(ubl.encoder_diff));
|
|
|
|
do_blocking_move_to_z(current_position[Z_AXIS] + 0.01 * float(encoder_diff));
|
|
|
|
ubl.encoder_diff = 0;
|
|
|
|
encoder_diff = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
KEEPALIVE_STATE(IN_HANDLER);
|
|
|
|
KEEPALIVE_STATE(IN_HANDLER);
|
|
|
|
return current_position[Z_AXIS];
|
|
|
|
return current_position[Z_AXIS];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void echo_and_take_a_measurement() {
|
|
|
|
static void echo_and_take_a_measurement() { SERIAL_PROTOCOLLNPGM(" and take a measurement."); }
|
|
|
|
SERIAL_PROTOCOLLNPGM(" and take a measurement.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float measure_business_card_thickness(float &in_height) {
|
|
|
|
float unified_bed_leveling::measure_business_card_thickness(float &in_height) {
|
|
|
|
ubl.has_control_of_lcd_panel = true;
|
|
|
|
has_control_of_lcd_panel = true;
|
|
|
|
ubl.save_ubl_active_state_and_disable(); // Disable bed level correction for probing
|
|
|
|
save_ubl_active_state_and_disable(); // Disable bed level correction for probing
|
|
|
|
|
|
|
|
|
|
|
|
do_blocking_move_to_z(in_height);
|
|
|
|
do_blocking_move_to_z(in_height);
|
|
|
|
do_blocking_move_to_xy(0.5 * (UBL_MESH_MAX_X - (UBL_MESH_MIN_X)), 0.5 * (UBL_MESH_MAX_Y - (UBL_MESH_MIN_Y)));
|
|
|
|
do_blocking_move_to_xy(0.5 * (UBL_MESH_MAX_X - (UBL_MESH_MIN_X)), 0.5 * (UBL_MESH_MAX_Y - (UBL_MESH_MIN_Y)));
|
|
|
@ -954,7 +953,7 @@
|
|
|
|
lcd_goto_screen(lcd_status_screen);
|
|
|
|
lcd_goto_screen(lcd_status_screen);
|
|
|
|
echo_and_take_a_measurement();
|
|
|
|
echo_and_take_a_measurement();
|
|
|
|
|
|
|
|
|
|
|
|
const float z1 = use_encoder_wheel_to_measure_point();
|
|
|
|
const float z1 = measure_point_with_encoder();
|
|
|
|
do_blocking_move_to_z(current_position[Z_AXIS] + SIZE_OF_LITTLE_RAISE);
|
|
|
|
do_blocking_move_to_z(current_position[Z_AXIS] + SIZE_OF_LITTLE_RAISE);
|
|
|
|
stepper.synchronize();
|
|
|
|
stepper.synchronize();
|
|
|
|
|
|
|
|
|
|
|
@ -962,7 +961,7 @@
|
|
|
|
LCD_MESSAGEPGM("Remove & measure bed"); // TODO: Make translatable string
|
|
|
|
LCD_MESSAGEPGM("Remove & measure bed"); // TODO: Make translatable string
|
|
|
|
echo_and_take_a_measurement();
|
|
|
|
echo_and_take_a_measurement();
|
|
|
|
|
|
|
|
|
|
|
|
const float z2 = use_encoder_wheel_to_measure_point();
|
|
|
|
const float z2 = measure_point_with_encoder();
|
|
|
|
|
|
|
|
|
|
|
|
do_blocking_move_to_z(current_position[Z_AXIS] + Z_CLEARANCE_BETWEEN_PROBES);
|
|
|
|
do_blocking_move_to_z(current_position[Z_AXIS] + Z_CLEARANCE_BETWEEN_PROBES);
|
|
|
|
|
|
|
|
|
|
|
@ -976,17 +975,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
in_height = current_position[Z_AXIS]; // do manual probing at lower height
|
|
|
|
in_height = current_position[Z_AXIS]; // do manual probing at lower height
|
|
|
|
|
|
|
|
|
|
|
|
ubl.has_control_of_lcd_panel = false;
|
|
|
|
has_control_of_lcd_panel = false;
|
|
|
|
|
|
|
|
|
|
|
|
ubl.restore_ubl_active_state_and_leave();
|
|
|
|
restore_ubl_active_state_and_leave();
|
|
|
|
|
|
|
|
|
|
|
|
return thickness;
|
|
|
|
return thickness;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void manually_probe_remaining_mesh(const float &lx, const float &ly, const float &z_clearance, const float &card_thickness, const bool do_ubl_mesh_map) {
|
|
|
|
void unified_bed_leveling::manually_probe_remaining_mesh(const float &lx, const float &ly, const float &z_clearance, const float &thick, const bool do_ubl_mesh_map) {
|
|
|
|
|
|
|
|
|
|
|
|
ubl.has_control_of_lcd_panel = true;
|
|
|
|
has_control_of_lcd_panel = true;
|
|
|
|
ubl.save_ubl_active_state_and_disable(); // we don't do bed level correction because we want the raw data when we probe
|
|
|
|
save_ubl_active_state_and_disable(); // we don't do bed level correction because we want the raw data when we probe
|
|
|
|
do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
|
|
|
|
do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
|
|
|
|
do_blocking_move_to_xy(lx, ly);
|
|
|
|
do_blocking_move_to_xy(lx, ly);
|
|
|
|
|
|
|
|
|
|
|
@ -997,8 +996,8 @@
|
|
|
|
// It doesn't matter if the probe can't reach the NAN location. This is a manual probe.
|
|
|
|
// It doesn't matter if the probe can't reach the NAN location. This is a manual probe.
|
|
|
|
if (location.x_index < 0 && location.y_index < 0) continue;
|
|
|
|
if (location.x_index < 0 && location.y_index < 0) continue;
|
|
|
|
|
|
|
|
|
|
|
|
const float rawx = pgm_read_float(&ubl.mesh_index_to_xpos[location.x_index]),
|
|
|
|
const float rawx = mesh_index_to_xpos(location.x_index),
|
|
|
|
rawy = pgm_read_float(&ubl.mesh_index_to_ypos[location.y_index]),
|
|
|
|
rawy = mesh_index_to_ypos(location.y_index),
|
|
|
|
xProbe = LOGICAL_X_POSITION(rawx),
|
|
|
|
xProbe = LOGICAL_X_POSITION(rawx),
|
|
|
|
yProbe = LOGICAL_Y_POSITION(rawy);
|
|
|
|
yProbe = LOGICAL_Y_POSITION(rawy);
|
|
|
|
|
|
|
|
|
|
|
@ -1012,9 +1011,9 @@
|
|
|
|
do_blocking_move_to_z(z_clearance);
|
|
|
|
do_blocking_move_to_z(z_clearance);
|
|
|
|
|
|
|
|
|
|
|
|
KEEPALIVE_STATE(PAUSED_FOR_USER);
|
|
|
|
KEEPALIVE_STATE(PAUSED_FOR_USER);
|
|
|
|
ubl.has_control_of_lcd_panel = true;
|
|
|
|
has_control_of_lcd_panel = true;
|
|
|
|
|
|
|
|
|
|
|
|
if (do_ubl_mesh_map) ubl.display_map(map_type); // show user where we're probing
|
|
|
|
if (do_ubl_mesh_map) display_map(g29_map_type); // show user where we're probing
|
|
|
|
|
|
|
|
|
|
|
|
if (code_seen('B'))
|
|
|
|
if (code_seen('B'))
|
|
|
|
LCD_MESSAGEPGM("Place shim & measure"); // TODO: Make translatable string
|
|
|
|
LCD_MESSAGEPGM("Place shim & measure"); // TODO: Make translatable string
|
|
|
@ -1025,9 +1024,9 @@
|
|
|
|
delay(50); // debounce
|
|
|
|
delay(50); // debounce
|
|
|
|
while (!ubl_lcd_clicked()) { // we need the loop to move the nozzle based on the encoder wheel here!
|
|
|
|
while (!ubl_lcd_clicked()) { // we need the loop to move the nozzle based on the encoder wheel here!
|
|
|
|
idle();
|
|
|
|
idle();
|
|
|
|
if (ubl.encoder_diff) {
|
|
|
|
if (encoder_diff) {
|
|
|
|
do_blocking_move_to_z(current_position[Z_AXIS] + float(ubl.encoder_diff) / 100.0);
|
|
|
|
do_blocking_move_to_z(current_position[Z_AXIS] + float(encoder_diff) / 100.0);
|
|
|
|
ubl.encoder_diff = 0;
|
|
|
|
encoder_diff = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1042,48 +1041,47 @@
|
|
|
|
do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
|
|
|
|
do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
|
|
|
|
lcd_quick_feedback();
|
|
|
|
lcd_quick_feedback();
|
|
|
|
while (ubl_lcd_clicked()) idle();
|
|
|
|
while (ubl_lcd_clicked()) idle();
|
|
|
|
ubl.has_control_of_lcd_panel = false;
|
|
|
|
has_control_of_lcd_panel = false;
|
|
|
|
KEEPALIVE_STATE(IN_HANDLER);
|
|
|
|
KEEPALIVE_STATE(IN_HANDLER);
|
|
|
|
ubl.restore_ubl_active_state_and_leave();
|
|
|
|
restore_ubl_active_state_and_leave();
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ubl.z_values[location.x_index][location.y_index] = current_position[Z_AXIS] - card_thickness;
|
|
|
|
z_values[location.x_index][location.y_index] = current_position[Z_AXIS] - thick;
|
|
|
|
if (g29_verbose_level > 2) {
|
|
|
|
if (g29_verbose_level > 2) {
|
|
|
|
SERIAL_PROTOCOLPGM("Mesh Point Measured at: ");
|
|
|
|
SERIAL_PROTOCOLPGM("Mesh Point Measured at: ");
|
|
|
|
SERIAL_PROTOCOL_F(ubl.z_values[location.x_index][location.y_index], 6);
|
|
|
|
SERIAL_PROTOCOL_F(z_values[location.x_index][location.y_index], 6);
|
|
|
|
SERIAL_EOL;
|
|
|
|
SERIAL_EOL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (location.x_index >= 0 && location.y_index >= 0);
|
|
|
|
} while (location.x_index >= 0 && location.y_index >= 0);
|
|
|
|
|
|
|
|
|
|
|
|
if (do_ubl_mesh_map) ubl.display_map(map_type);
|
|
|
|
if (do_ubl_mesh_map) display_map(g29_map_type);
|
|
|
|
|
|
|
|
|
|
|
|
ubl.restore_ubl_active_state_and_leave();
|
|
|
|
restore_ubl_active_state_and_leave();
|
|
|
|
KEEPALIVE_STATE(IN_HANDLER);
|
|
|
|
KEEPALIVE_STATE(IN_HANDLER);
|
|
|
|
do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
|
|
|
|
do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
|
|
|
|
do_blocking_move_to_xy(lx, ly);
|
|
|
|
do_blocking_move_to_xy(lx, ly);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool g29_parameter_parsing() {
|
|
|
|
bool unified_bed_leveling::g29_parameter_parsing() {
|
|
|
|
bool err_flag = false;
|
|
|
|
bool err_flag = false;
|
|
|
|
|
|
|
|
|
|
|
|
LCD_MESSAGEPGM("Doing G29 UBL!"); // TODO: Make translatable string
|
|
|
|
LCD_MESSAGEPGM("Doing G29 UBL!"); // TODO: Make translatable string
|
|
|
|
lcd_quick_feedback();
|
|
|
|
lcd_quick_feedback();
|
|
|
|
|
|
|
|
|
|
|
|
ubl_constant = 0.0;
|
|
|
|
g29_constant = 0.0;
|
|
|
|
repetition_cnt = 0;
|
|
|
|
g29_repetition_cnt = 0;
|
|
|
|
|
|
|
|
|
|
|
|
x_flag = code_seen('X') && code_has_value();
|
|
|
|
g29_x_flag = code_seen('X') && code_has_value();
|
|
|
|
x_pos = x_flag ? code_value_float() : current_position[X_AXIS];
|
|
|
|
g29_x_pos = g29_x_flag ? code_value_float() : current_position[X_AXIS];
|
|
|
|
y_flag = code_seen('Y') && code_has_value();
|
|
|
|
g29_y_flag = code_seen('Y') && code_has_value();
|
|
|
|
y_pos = y_flag ? code_value_float() : current_position[Y_AXIS];
|
|
|
|
g29_y_pos = g29_y_flag ? code_value_float() : current_position[Y_AXIS];
|
|
|
|
|
|
|
|
|
|
|
|
repeat_flag = code_seen('R');
|
|
|
|
if (code_seen('R')) {
|
|
|
|
if (repeat_flag) {
|
|
|
|
g29_repetition_cnt = code_has_value() ? code_value_int() : GRID_MAX_POINTS;
|
|
|
|
repetition_cnt = code_has_value() ? code_value_int() : GRID_MAX_POINTS;
|
|
|
|
NOMORE(g29_repetition_cnt, GRID_MAX_POINTS);
|
|
|
|
NOMORE(repetition_cnt, GRID_MAX_POINTS);
|
|
|
|
if (g29_repetition_cnt < 1) {
|
|
|
|
if (repetition_cnt < 1) {
|
|
|
|
|
|
|
|
SERIAL_PROTOCOLLNPGM("?(R)epetition count invalid (1+).\n");
|
|
|
|
SERIAL_PROTOCOLLNPGM("?(R)epetition count invalid (1+).\n");
|
|
|
|
return UBL_ERR;
|
|
|
|
return UBL_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1096,31 +1094,31 @@
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (code_seen('P')) {
|
|
|
|
if (code_seen('P')) {
|
|
|
|
phase_value = code_value_int();
|
|
|
|
g29_phase_value = code_value_int();
|
|
|
|
if (!WITHIN(phase_value, 0, 6)) {
|
|
|
|
if (!WITHIN(g29_phase_value, 0, 6)) {
|
|
|
|
SERIAL_PROTOCOLLNPGM("?(P)hase value invalid (0-6).\n");
|
|
|
|
SERIAL_PROTOCOLLNPGM("?(P)hase value invalid (0-6).\n");
|
|
|
|
err_flag = true;
|
|
|
|
err_flag = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (code_seen('J')) {
|
|
|
|
if (code_seen('J')) {
|
|
|
|
grid_size = code_has_value() ? code_value_int() : 0;
|
|
|
|
g29_grid_size = code_has_value() ? code_value_int() : 0;
|
|
|
|
if (grid_size!=0 && !WITHIN(grid_size, 2, 9)) {
|
|
|
|
if (g29_grid_size && !WITHIN(g29_grid_size, 2, 9)) {
|
|
|
|
SERIAL_PROTOCOLLNPGM("?Invalid grid size (J) specified (2-9).\n");
|
|
|
|
SERIAL_PROTOCOLLNPGM("?Invalid grid size (J) specified (2-9).\n");
|
|
|
|
err_flag = true;
|
|
|
|
err_flag = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (x_flag != y_flag) {
|
|
|
|
if (g29_x_flag != g29_y_flag) {
|
|
|
|
SERIAL_PROTOCOLLNPGM("Both X & Y locations must be specified.\n");
|
|
|
|
SERIAL_PROTOCOLLNPGM("Both X & Y locations must be specified.\n");
|
|
|
|
err_flag = true;
|
|
|
|
err_flag = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!WITHIN(RAW_X_POSITION(x_pos), X_MIN_POS, X_MAX_POS)) {
|
|
|
|
if (!WITHIN(RAW_X_POSITION(g29_x_pos), X_MIN_POS, X_MAX_POS)) {
|
|
|
|
SERIAL_PROTOCOLLNPGM("Invalid X location specified.\n");
|
|
|
|
SERIAL_PROTOCOLLNPGM("Invalid X location specified.\n");
|
|
|
|
err_flag = true;
|
|
|
|
err_flag = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!WITHIN(RAW_Y_POSITION(y_pos), Y_MIN_POS, Y_MAX_POS)) {
|
|
|
|
if (!WITHIN(RAW_Y_POSITION(g29_y_pos), Y_MIN_POS, Y_MAX_POS)) {
|
|
|
|
SERIAL_PROTOCOLLNPGM("Invalid Y location specified.\n");
|
|
|
|
SERIAL_PROTOCOLLNPGM("Invalid Y location specified.\n");
|
|
|
|
err_flag = true;
|
|
|
|
err_flag = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1133,17 +1131,17 @@
|
|
|
|
SERIAL_PROTOCOLLNPGM("?Can't activate and deactivate at the same time.\n");
|
|
|
|
SERIAL_PROTOCOLLNPGM("?Can't activate and deactivate at the same time.\n");
|
|
|
|
return UBL_ERR;
|
|
|
|
return UBL_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ubl.state.active = true;
|
|
|
|
state.active = true;
|
|
|
|
ubl.report_state();
|
|
|
|
report_state();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (code_seen('D')) {
|
|
|
|
else if (code_seen('D')) {
|
|
|
|
ubl.state.active = false;
|
|
|
|
state.active = false;
|
|
|
|
ubl.report_state();
|
|
|
|
report_state();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Set global 'C' flag and its value
|
|
|
|
// Set global 'C' flag and its value
|
|
|
|
if ((c_flag = code_seen('C')))
|
|
|
|
if ((g29_c_flag = code_seen('C')))
|
|
|
|
ubl_constant = code_value_float();
|
|
|
|
g29_constant = code_value_float();
|
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
|
|
|
|
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
|
|
|
|
if (code_seen('F') && code_has_value()) {
|
|
|
|
if (code_seen('F') && code_has_value()) {
|
|
|
@ -1156,8 +1154,8 @@
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
map_type = code_seen('T') && code_has_value() ? code_value_int() : 0;
|
|
|
|
g29_map_type = code_seen('T') && code_has_value() ? code_value_int() : 0;
|
|
|
|
if (!WITHIN(map_type, 0, 1)) {
|
|
|
|
if (!WITHIN(g29_map_type, 0, 1)) {
|
|
|
|
SERIAL_PROTOCOLLNPGM("Invalid map type.\n");
|
|
|
|
SERIAL_PROTOCOLLNPGM("Invalid map type.\n");
|
|
|
|
return UBL_ERR;
|
|
|
|
return UBL_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1175,8 +1173,8 @@
|
|
|
|
lcd_quick_feedback();
|
|
|
|
lcd_quick_feedback();
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ubl_state_at_invocation = ubl.state.active;
|
|
|
|
ubl_state_at_invocation = state.active;
|
|
|
|
ubl.state.active = 0;
|
|
|
|
state.active = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void unified_bed_leveling::restore_ubl_active_state_and_leave() {
|
|
|
|
void unified_bed_leveling::restore_ubl_active_state_and_leave() {
|
|
|
@ -1186,7 +1184,7 @@
|
|
|
|
lcd_quick_feedback();
|
|
|
|
lcd_quick_feedback();
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ubl.state.active = ubl_state_at_invocation;
|
|
|
|
state.active = ubl_state_at_invocation;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -1234,7 +1232,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
SERIAL_PROTOCOLPGM("X-Axis Mesh Points at: ");
|
|
|
|
SERIAL_PROTOCOLPGM("X-Axis Mesh Points at: ");
|
|
|
|
for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
|
|
|
|
for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
|
|
|
|
SERIAL_PROTOCOL_F(LOGICAL_X_POSITION(pgm_read_float(&mesh_index_to_xpos[i])), 3);
|
|
|
|
SERIAL_PROTOCOL_F(LOGICAL_X_POSITION(mesh_index_to_xpos(i)), 3);
|
|
|
|
SERIAL_PROTOCOLPGM(" ");
|
|
|
|
SERIAL_PROTOCOLPGM(" ");
|
|
|
|
safe_delay(25);
|
|
|
|
safe_delay(25);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1242,7 +1240,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
SERIAL_PROTOCOLPGM("Y-Axis Mesh Points at: ");
|
|
|
|
SERIAL_PROTOCOLPGM("Y-Axis Mesh Points at: ");
|
|
|
|
for (uint8_t i = 0; i < GRID_MAX_POINTS_Y; i++) {
|
|
|
|
for (uint8_t i = 0; i < GRID_MAX_POINTS_Y; i++) {
|
|
|
|
SERIAL_PROTOCOL_F(LOGICAL_Y_POSITION(pgm_read_float(&mesh_index_to_ypos[i])), 3);
|
|
|
|
SERIAL_PROTOCOL_F(LOGICAL_Y_POSITION(mesh_index_to_ypos(i)), 3);
|
|
|
|
SERIAL_PROTOCOLPGM(" ");
|
|
|
|
SERIAL_PROTOCOLPGM(" ");
|
|
|
|
safe_delay(25);
|
|
|
|
safe_delay(25);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1288,7 +1286,7 @@
|
|
|
|
* When we are fully debugged, the EEPROM dump command will get deleted also. But
|
|
|
|
* When we are fully debugged, the EEPROM dump command will get deleted also. But
|
|
|
|
* right now, it is good to have the extra information. Soon... we prune this.
|
|
|
|
* right now, it is good to have the extra information. Soon... we prune this.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
void g29_eeprom_dump() {
|
|
|
|
void unified_bed_leveling::g29_eeprom_dump() {
|
|
|
|
unsigned char cccc;
|
|
|
|
unsigned char cccc;
|
|
|
|
uint16_t kkkk;
|
|
|
|
uint16_t kkkk;
|
|
|
|
|
|
|
|
|
|
|
@ -1313,7 +1311,7 @@
|
|
|
|
* When we are fully debugged, this may go away. But there are some valid
|
|
|
|
* When we are fully debugged, this may go away. But there are some valid
|
|
|
|
* use cases for the users. So we can wait and see what to do with it.
|
|
|
|
* use cases for the users. So we can wait and see what to do with it.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
void g29_compare_current_mesh_to_stored_mesh() {
|
|
|
|
void unified_bed_leveling::g29_compare_current_mesh_to_stored_mesh() {
|
|
|
|
int16_t a = settings.calc_num_meshes();
|
|
|
|
int16_t a = settings.calc_num_meshes();
|
|
|
|
|
|
|
|
|
|
|
|
if (!a) {
|
|
|
|
if (!a) {
|
|
|
@ -1327,26 +1325,26 @@
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
storage_slot = code_value_int();
|
|
|
|
g29_storage_slot = code_value_int();
|
|
|
|
|
|
|
|
|
|
|
|
if (!WITHIN(storage_slot, 0, a - 1)) {
|
|
|
|
if (!WITHIN(g29_storage_slot, 0, a - 1)) {
|
|
|
|
SERIAL_PROTOCOLLNPGM("?Invalid storage slot.");
|
|
|
|
SERIAL_PROTOCOLLNPGM("?Invalid storage slot.");
|
|
|
|
SERIAL_PROTOCOLLNPAIR("?Use 0 to ", a - 1);
|
|
|
|
SERIAL_PROTOCOLLNPAIR("?Use 0 to ", a - 1);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
float tmp_z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
|
|
|
|
float tmp_z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
|
|
|
|
settings.load_mesh(storage_slot, &tmp_z_values);
|
|
|
|
settings.load_mesh(g29_storage_slot, &tmp_z_values);
|
|
|
|
|
|
|
|
|
|
|
|
SERIAL_PROTOCOLPAIR("Subtracting mesh in slot ", storage_slot);
|
|
|
|
SERIAL_PROTOCOLPAIR("Subtracting mesh in slot ", g29_storage_slot);
|
|
|
|
SERIAL_PROTOCOLLNPGM(" from current mesh.");
|
|
|
|
SERIAL_PROTOCOLLNPGM(" from current mesh.");
|
|
|
|
|
|
|
|
|
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
|
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
|
|
|
|
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
|
|
|
|
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
|
|
|
|
ubl.z_values[x][y] -= tmp_z_values[x][y];
|
|
|
|
z_values[x][y] -= tmp_z_values[x][y];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mesh_index_pair find_closest_mesh_point_of_type(const MeshPointType type, const float &lx, const float &ly, const bool probe_as_reference, unsigned int bits[16], const bool far_flag) {
|
|
|
|
mesh_index_pair unified_bed_leveling::find_closest_mesh_point_of_type(const MeshPointType type, const float &lx, const float &ly, const bool probe_as_reference, unsigned int bits[16], const bool far_flag) {
|
|
|
|
mesh_index_pair out_mesh;
|
|
|
|
mesh_index_pair out_mesh;
|
|
|
|
out_mesh.x_index = out_mesh.y_index = -1;
|
|
|
|
out_mesh.x_index = out_mesh.y_index = -1;
|
|
|
|
|
|
|
|
|
|
|
@ -1359,15 +1357,15 @@
|
|
|
|
for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
|
|
|
|
for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
|
|
|
|
for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
|
|
|
|
for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
|
|
|
|
|
|
|
|
|
|
|
|
if ( (type == INVALID && isnan(ubl.z_values[i][j])) // Check to see if this location holds the right thing
|
|
|
|
if ( (type == INVALID && isnan(z_values[i][j])) // Check to see if this location holds the right thing
|
|
|
|
|| (type == REAL && !isnan(ubl.z_values[i][j]))
|
|
|
|
|| (type == REAL && !isnan(z_values[i][j]))
|
|
|
|
|| (type == SET_IN_BITMAP && is_bit_set(bits, i, j))
|
|
|
|
|| (type == SET_IN_BITMAP && is_bit_set(bits, i, j))
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
// We only get here if we found a Mesh Point of the specified type
|
|
|
|
// We only get here if we found a Mesh Point of the specified type
|
|
|
|
|
|
|
|
|
|
|
|
float raw_x = RAW_CURRENT_POSITION(X), raw_y = RAW_CURRENT_POSITION(Y);
|
|
|
|
float raw_x = RAW_CURRENT_POSITION(X), raw_y = RAW_CURRENT_POSITION(Y);
|
|
|
|
const float mx = pgm_read_float(&ubl.mesh_index_to_xpos[i]),
|
|
|
|
const float mx = mesh_index_to_xpos(i),
|
|
|
|
my = pgm_read_float(&ubl.mesh_index_to_ypos[j]);
|
|
|
|
my = mesh_index_to_ypos(j);
|
|
|
|
|
|
|
|
|
|
|
|
// If using the probe as the reference there are some unreachable locations.
|
|
|
|
// 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.
|
|
|
|
// Also for round beds, there are grid points outside the bed the nozzle can't reach.
|
|
|
@ -1391,9 +1389,9 @@
|
|
|
|
if (far_flag) {
|
|
|
|
if (far_flag) {
|
|
|
|
for (uint8_t k = 0; k < GRID_MAX_POINTS_X; k++) {
|
|
|
|
for (uint8_t k = 0; k < GRID_MAX_POINTS_X; k++) {
|
|
|
|
for (uint8_t l = 0; l < GRID_MAX_POINTS_Y; l++) {
|
|
|
|
for (uint8_t l = 0; l < GRID_MAX_POINTS_Y; l++) {
|
|
|
|
if (i != k && j != l && !isnan(ubl.z_values[k][l])) {
|
|
|
|
if (i != k && j != l && !isnan(z_values[k][l])) {
|
|
|
|
// distance += pow((float) abs(i - k) * (MESH_X_DIST), 2) + pow((float) abs(j - l) * (MESH_Y_DIST), 2); // working here
|
|
|
|
//distance += pow((float) abs(i - k) * (MESH_X_DIST), 2) + pow((float) abs(j - l) * (MESH_Y_DIST), 2); // working here
|
|
|
|
distance += HYPOT((MESH_X_DIST),(MESH_Y_DIST)) / log(HYPOT((i - k) * (MESH_X_DIST)+.001, (j - l) * (MESH_Y_DIST))+.001);
|
|
|
|
distance += HYPOT(MESH_X_DIST, MESH_Y_DIST) / log(HYPOT((i - k) * (MESH_X_DIST) + .001, (j - l) * (MESH_Y_DIST)) + .001);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1417,20 +1415,19 @@
|
|
|
|
return out_mesh;
|
|
|
|
return out_mesh;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void fine_tune_mesh(const float &lx, const float &ly, const bool do_ubl_mesh_map) {
|
|
|
|
void unified_bed_leveling::fine_tune_mesh(const float &lx, const float &ly, const bool do_ubl_mesh_map) {
|
|
|
|
if (!code_seen('R')) // fine_tune_mesh() is special. If no repetition count flag is specified
|
|
|
|
if (!code_seen('R')) // fine_tune_mesh() is special. If no repetition count flag is specified
|
|
|
|
repetition_cnt = 1; // do exactly one mesh location. Otherwise use what the parser decided.
|
|
|
|
g29_repetition_cnt = 1; // do exactly one mesh location. Otherwise use what the parser decided.
|
|
|
|
|
|
|
|
|
|
|
|
mesh_index_pair location;
|
|
|
|
mesh_index_pair location;
|
|
|
|
uint16_t not_done[16];
|
|
|
|
uint16_t not_done[16];
|
|
|
|
int32_t round_off;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!position_is_reachable_xy(lx, ly)) {
|
|
|
|
if (!position_is_reachable_xy(lx, ly)) {
|
|
|
|
SERIAL_PROTOCOLLNPGM("(X,Y) outside printable radius.");
|
|
|
|
SERIAL_PROTOCOLLNPGM("(X,Y) outside printable radius.");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ubl.save_ubl_active_state_and_disable();
|
|
|
|
save_ubl_active_state_and_disable();
|
|
|
|
|
|
|
|
|
|
|
|
memset(not_done, 0xFF, sizeof(not_done));
|
|
|
|
memset(not_done, 0xFF, sizeof(not_done));
|
|
|
|
|
|
|
|
|
|
|
@ -1446,13 +1443,13 @@
|
|
|
|
bit_clear(not_done, location.x_index, location.y_index); // Mark this location as 'adjusted' so we will find a
|
|
|
|
bit_clear(not_done, location.x_index, location.y_index); // Mark this location as 'adjusted' so we will find a
|
|
|
|
// different location the next time through the loop
|
|
|
|
// different location the next time through the loop
|
|
|
|
|
|
|
|
|
|
|
|
const float rawx = pgm_read_float(&ubl.mesh_index_to_xpos[location.x_index]),
|
|
|
|
const float rawx = mesh_index_to_xpos(location.x_index),
|
|
|
|
rawy = pgm_read_float(&ubl.mesh_index_to_ypos[location.y_index]);
|
|
|
|
rawy = mesh_index_to_ypos(location.y_index);
|
|
|
|
|
|
|
|
|
|
|
|
if (!position_is_reachable_raw_xy(rawx, rawy)) // SHOULD NOT OCCUR because find_closest_mesh_point_of_type will only return reachable
|
|
|
|
if (!position_is_reachable_raw_xy(rawx, rawy)) // SHOULD NOT OCCUR because find_closest_mesh_point_of_type will only return reachable
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
float new_z = ubl.z_values[location.x_index][location.y_index];
|
|
|
|
float new_z = z_values[location.x_index][location.y_index];
|
|
|
|
|
|
|
|
|
|
|
|
if (isnan(new_z)) // if the mesh point is invalid, set it to 0.0 so it can be edited
|
|
|
|
if (isnan(new_z)) // if the mesh point is invalid, set it to 0.0 so it can be edited
|
|
|
|
new_z = 0.0;
|
|
|
|
new_z = 0.0;
|
|
|
@ -1463,9 +1460,9 @@
|
|
|
|
new_z = floor(new_z * 1000.0) * 0.001; // Chop off digits after the 1000ths place
|
|
|
|
new_z = floor(new_z * 1000.0) * 0.001; // Chop off digits after the 1000ths place
|
|
|
|
|
|
|
|
|
|
|
|
KEEPALIVE_STATE(PAUSED_FOR_USER);
|
|
|
|
KEEPALIVE_STATE(PAUSED_FOR_USER);
|
|
|
|
ubl.has_control_of_lcd_panel = true;
|
|
|
|
has_control_of_lcd_panel = true;
|
|
|
|
|
|
|
|
|
|
|
|
if (do_ubl_mesh_map) ubl.display_map(map_type); // show the user which point is being adjusted
|
|
|
|
if (do_ubl_mesh_map) display_map(g29_map_type); // show the user which point is being adjusted
|
|
|
|
|
|
|
|
|
|
|
|
lcd_implementation_clear();
|
|
|
|
lcd_implementation_clear();
|
|
|
|
|
|
|
|
|
|
|
@ -1474,7 +1471,7 @@
|
|
|
|
do {
|
|
|
|
do {
|
|
|
|
new_z = lcd_mesh_edit();
|
|
|
|
new_z = lcd_mesh_edit();
|
|
|
|
#ifdef UBL_MESH_EDIT_MOVES_Z
|
|
|
|
#ifdef UBL_MESH_EDIT_MOVES_Z
|
|
|
|
do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES+new_z); // Move the nozzle as the point is edited
|
|
|
|
do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES + new_z); // Move the nozzle as the point is edited
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
idle();
|
|
|
|
idle();
|
|
|
|
} while (!ubl_lcd_clicked());
|
|
|
|
} while (!ubl_lcd_clicked());
|
|
|
@ -1484,7 +1481,7 @@
|
|
|
|
// The technique used here generates a race condition for the encoder click.
|
|
|
|
// The technique used here generates a race condition for the encoder click.
|
|
|
|
// It could get detected in lcd_mesh_edit (actually _lcd_mesh_fine_tune) or here.
|
|
|
|
// It could get detected in lcd_mesh_edit (actually _lcd_mesh_fine_tune) or here.
|
|
|
|
// Let's work on specifying a proper API for the LCD ASAP, OK?
|
|
|
|
// Let's work on specifying a proper API for the LCD ASAP, OK?
|
|
|
|
ubl.has_control_of_lcd_panel = true;
|
|
|
|
has_control_of_lcd_panel = true;
|
|
|
|
|
|
|
|
|
|
|
|
// this sequence to detect an ubl_lcd_clicked() debounce it and leave if it is
|
|
|
|
// this sequence to detect an ubl_lcd_clicked() debounce it and leave if it is
|
|
|
|
// a Press and Hold is repeated in a lot of places (including G26_Mesh_Validation.cpp). This
|
|
|
|
// a Press and Hold is repeated in a lot of places (including G26_Mesh_Validation.cpp). This
|
|
|
@ -1506,19 +1503,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
safe_delay(20); // We don't want any switch noise.
|
|
|
|
safe_delay(20); // We don't want any switch noise.
|
|
|
|
|
|
|
|
|
|
|
|
ubl.z_values[location.x_index][location.y_index] = new_z;
|
|
|
|
z_values[location.x_index][location.y_index] = new_z;
|
|
|
|
|
|
|
|
|
|
|
|
lcd_implementation_clear();
|
|
|
|
lcd_implementation_clear();
|
|
|
|
|
|
|
|
|
|
|
|
} while (location.x_index >= 0 && --repetition_cnt > 0);
|
|
|
|
} while (location.x_index >= 0 && --g29_repetition_cnt > 0);
|
|
|
|
|
|
|
|
|
|
|
|
FINE_TUNE_EXIT:
|
|
|
|
FINE_TUNE_EXIT:
|
|
|
|
|
|
|
|
|
|
|
|
ubl.has_control_of_lcd_panel = false;
|
|
|
|
has_control_of_lcd_panel = false;
|
|
|
|
KEEPALIVE_STATE(IN_HANDLER);
|
|
|
|
KEEPALIVE_STATE(IN_HANDLER);
|
|
|
|
|
|
|
|
|
|
|
|
if (do_ubl_mesh_map) ubl.display_map(map_type);
|
|
|
|
if (do_ubl_mesh_map) display_map(g29_map_type);
|
|
|
|
ubl.restore_ubl_active_state_and_leave();
|
|
|
|
restore_ubl_active_state_and_leave();
|
|
|
|
do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
|
|
|
|
do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
|
|
|
|
|
|
|
|
|
|
|
|
do_blocking_move_to_xy(lx, ly);
|
|
|
|
do_blocking_move_to_xy(lx, ly);
|
|
|
@ -1533,15 +1530,15 @@
|
|
|
|
* calculate a 'reasonable' value for the unprobed mesh point.
|
|
|
|
* calculate a 'reasonable' value for the unprobed mesh point.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
bool smart_fill_one(const uint8_t x, const uint8_t y, const int8_t xdir, const int8_t ydir) {
|
|
|
|
bool unified_bed_leveling::smart_fill_one(const uint8_t x, const uint8_t y, const int8_t xdir, const int8_t ydir) {
|
|
|
|
const int8_t x1 = x + xdir, x2 = x1 + xdir,
|
|
|
|
const int8_t x1 = x + xdir, x2 = x1 + xdir,
|
|
|
|
y1 = y + ydir, y2 = y1 + ydir;
|
|
|
|
y1 = y + ydir, y2 = y1 + ydir;
|
|
|
|
// A NAN next to a pair of real values?
|
|
|
|
// A NAN next to a pair of real values?
|
|
|
|
if (isnan(ubl.z_values[x][y]) && !isnan(ubl.z_values[x1][y1]) && !isnan(ubl.z_values[x2][y2])) {
|
|
|
|
if (isnan(z_values[x][y]) && !isnan(z_values[x1][y1]) && !isnan(z_values[x2][y2])) {
|
|
|
|
if (ubl.z_values[x1][y1] < ubl.z_values[x2][y2]) // Angled downward?
|
|
|
|
if (z_values[x1][y1] < z_values[x2][y2]) // Angled downward?
|
|
|
|
ubl.z_values[x][y] = ubl.z_values[x1][y1]; // Use nearest (maybe a little too high.)
|
|
|
|
z_values[x][y] = z_values[x1][y1]; // Use nearest (maybe a little too high.)
|
|
|
|
else
|
|
|
|
else
|
|
|
|
ubl.z_values[x][y] = 2.0 * ubl.z_values[x1][y1] - ubl.z_values[x2][y2]; // Angled upward...
|
|
|
|
z_values[x][y] = 2.0 * z_values[x1][y1] - z_values[x2][y2]; // Angled upward...
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
@ -1549,7 +1546,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct { uint8_t sx, ex, sy, ey; bool yfirst; } smart_fill_info;
|
|
|
|
typedef struct { uint8_t sx, ex, sy, ey; bool yfirst; } smart_fill_info;
|
|
|
|
|
|
|
|
|
|
|
|
void smart_fill_mesh() {
|
|
|
|
void unified_bed_leveling::smart_fill_mesh() {
|
|
|
|
const smart_fill_info info[] = {
|
|
|
|
const smart_fill_info info[] = {
|
|
|
|
{ 0, GRID_MAX_POINTS_X, 0, GRID_MAX_POINTS_Y - 2, false }, // Bottom of the mesh looking up
|
|
|
|
{ 0, GRID_MAX_POINTS_X, 0, GRID_MAX_POINTS_Y - 2, false }, // Bottom of the mesh looking up
|
|
|
|
{ 0, GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y - 1, 0, false }, // Top of the mesh looking down
|
|
|
|
{ 0, GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y - 1, 0, false }, // Top of the mesh looking down
|
|
|
@ -1579,17 +1576,17 @@
|
|
|
|
y_min = max(MIN_PROBE_Y, UBL_MESH_MIN_Y),
|
|
|
|
y_min = max(MIN_PROBE_Y, UBL_MESH_MIN_Y),
|
|
|
|
y_max = min(MAX_PROBE_Y, UBL_MESH_MAX_Y);
|
|
|
|
y_max = min(MAX_PROBE_Y, UBL_MESH_MAX_Y);
|
|
|
|
|
|
|
|
|
|
|
|
const float dx = float(x_max - x_min) / (grid_size - 1.0),
|
|
|
|
const float dx = float(x_max - x_min) / (g29_grid_size - 1.0),
|
|
|
|
dy = float(y_max - y_min) / (grid_size - 1.0);
|
|
|
|
dy = float(y_max - y_min) / (g29_grid_size - 1.0);
|
|
|
|
|
|
|
|
|
|
|
|
struct linear_fit_data lsf_results;
|
|
|
|
struct linear_fit_data lsf_results;
|
|
|
|
incremental_LSF_reset(&lsf_results);
|
|
|
|
incremental_LSF_reset(&lsf_results);
|
|
|
|
|
|
|
|
|
|
|
|
bool zig_zag = false;
|
|
|
|
bool zig_zag = false;
|
|
|
|
for (uint8_t ix = 0; ix < grid_size; ix++) {
|
|
|
|
for (uint8_t ix = 0; ix < g29_grid_size; ix++) {
|
|
|
|
const float x = float(x_min) + ix * dx;
|
|
|
|
const float x = float(x_min) + ix * dx;
|
|
|
|
for (int8_t iy = 0; iy < grid_size; iy++) {
|
|
|
|
for (int8_t iy = 0; iy < g29_grid_size; iy++) {
|
|
|
|
const float y = float(y_min) + dy * (zig_zag ? grid_size - 1 - iy : iy);
|
|
|
|
const float y = float(y_min) + dy * (zig_zag ? g29_grid_size - 1 - iy : iy);
|
|
|
|
float measured_z = probe_pt(LOGICAL_X_POSITION(x), LOGICAL_Y_POSITION(y), code_seen('E'), g29_verbose_level); // TODO: Needs error handling
|
|
|
|
float measured_z = probe_pt(LOGICAL_X_POSITION(x), LOGICAL_Y_POSITION(y), code_seen('E'), g29_verbose_level); // TODO: Needs error handling
|
|
|
|
#if ENABLED(DEBUG_LEVELING_FEATURE)
|
|
|
|
#if ENABLED(DEBUG_LEVELING_FEATURE)
|
|
|
|
if (DEBUGGING(LEVELING)) {
|
|
|
|
if (DEBUGGING(LEVELING)) {
|
|
|
@ -1656,8 +1653,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
|
|
|
|
for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
|
|
|
|
for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
|
|
|
|
for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
|
|
|
|
float x_tmp = pgm_read_float(&mesh_index_to_xpos[i]),
|
|
|
|
float x_tmp = mesh_index_to_xpos(i),
|
|
|
|
y_tmp = pgm_read_float(&mesh_index_to_ypos[j]),
|
|
|
|
y_tmp = mesh_index_to_ypos(j),
|
|
|
|
z_tmp = z_values[i][j];
|
|
|
|
z_tmp = z_values[i][j];
|
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(DEBUG_LEVELING_FEATURE)
|
|
|
|
#if ENABLED(DEBUG_LEVELING_FEATURE)
|
|
|
@ -1717,47 +1714,40 @@
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(UBL_G29_P31)
|
|
|
|
#if ENABLED(UBL_G29_P31)
|
|
|
|
|
|
|
|
void unified_bed_leveling::smart_fill_wlsf(const float &weight_factor) {
|
|
|
|
// Note: using optimize("O2") for this routine results in smaller
|
|
|
|
|
|
|
|
// codegen than default optimize("Os") on A2560.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void _O2 smart_fill_wlsf( float weight_factor ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// For each undefined mesh point, compute a distance-weighted least squares fit
|
|
|
|
// For each undefined mesh point, compute a distance-weighted least squares fit
|
|
|
|
// from all the originally populated mesh points, weighted toward the point
|
|
|
|
// from all the originally populated mesh points, weighted toward the point
|
|
|
|
// being extrapolated so that nearby points will have greater influence on
|
|
|
|
// being extrapolated so that nearby points will have greater influence on
|
|
|
|
// the point being extrapolated. Then extrapolate the mesh point from WLSF.
|
|
|
|
// 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};
|
|
|
|
uint16_t bitmap[GRID_MAX_POINTS_X] = { 0 };
|
|
|
|
struct linear_fit_data lsf_results;
|
|
|
|
struct linear_fit_data lsf_results;
|
|
|
|
|
|
|
|
|
|
|
|
SERIAL_ECHOPGM("Extrapolating mesh...");
|
|
|
|
SERIAL_ECHOPGM("Extrapolating mesh...");
|
|
|
|
|
|
|
|
|
|
|
|
const float weight_scaled = weight_factor * max(MESH_X_DIST, MESH_Y_DIST);
|
|
|
|
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 jx = 0; jx < GRID_MAX_POINTS_X; jx++)
|
|
|
|
for (uint8_t jy = 0; jy < GRID_MAX_POINTS_Y; jy++) {
|
|
|
|
for (uint8_t jy = 0; jy < GRID_MAX_POINTS_Y; jy++)
|
|
|
|
if ( !isnan( ubl.z_values[jx][jy] )) {
|
|
|
|
if (!isnan(z_values[jx][jy]))
|
|
|
|
bitmap[jx] |= (uint16_t)1 << jy;
|
|
|
|
SBI(bitmap[jx], jy);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (uint8_t ix = 0; ix < GRID_MAX_POINTS_X; ix++) {
|
|
|
|
for (uint8_t ix = 0; ix < GRID_MAX_POINTS_X; ix++) {
|
|
|
|
const float px = pgm_read_float(&(ubl.mesh_index_to_xpos[ix]));
|
|
|
|
const float px = mesh_index_to_xpos(ix);
|
|
|
|
for (uint8_t iy = 0; iy < GRID_MAX_POINTS_Y; iy++) {
|
|
|
|
for (uint8_t iy = 0; iy < GRID_MAX_POINTS_Y; iy++) {
|
|
|
|
const float py = pgm_read_float(&(ubl.mesh_index_to_ypos[iy]));
|
|
|
|
const float py = mesh_index_to_ypos(iy);
|
|
|
|
if ( isnan( ubl.z_values[ix][iy] )) {
|
|
|
|
if (isnan(z_values[ix][iy])) {
|
|
|
|
// undefined mesh point at (px,py), compute weighted LSF from original valid mesh points.
|
|
|
|
// undefined mesh point at (px,py), compute weighted LSF from original valid mesh points.
|
|
|
|
incremental_LSF_reset(&lsf_results);
|
|
|
|
incremental_LSF_reset(&lsf_results);
|
|
|
|
for (uint8_t jx = 0; jx < GRID_MAX_POINTS_X; jx++) {
|
|
|
|
for (uint8_t jx = 0; jx < GRID_MAX_POINTS_X; jx++) {
|
|
|
|
const float rx = pgm_read_float(&(ubl.mesh_index_to_xpos[jx]));
|
|
|
|
const float rx = mesh_index_to_xpos(jx);
|
|
|
|
for (uint8_t jy = 0; jy < GRID_MAX_POINTS_Y; jy++) {
|
|
|
|
for (uint8_t jy = 0; jy < GRID_MAX_POINTS_Y; jy++) {
|
|
|
|
if ( bitmap[jx] & (uint16_t)1 << jy ) {
|
|
|
|
if (TEST(bitmap[jx], jy)) {
|
|
|
|
const float ry = pgm_read_float(&(ubl.mesh_index_to_ypos[jy]));
|
|
|
|
const float ry = mesh_index_to_ypos(jy),
|
|
|
|
const float rz = ubl.z_values[jx][jy];
|
|
|
|
rz = z_values[jx][jy],
|
|
|
|
const float w = 1.0 + weight_scaled / HYPOT((rx - px),(ry - py));
|
|
|
|
w = 1.0 + weight_scaled / HYPOT((rx - px), (ry - py));
|
|
|
|
incremental_WLSF(&lsf_results, rx, ry, rz, w);
|
|
|
|
incremental_WLSF(&lsf_results, rx, ry, rz, w);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1767,7 +1757,7 @@
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const float ez = -lsf_results.D - lsf_results.A * px - lsf_results.B * py;
|
|
|
|
const float ez = -lsf_results.D - lsf_results.A * px - lsf_results.B * py;
|
|
|
|
ubl.z_values[ix][iy] = ez;
|
|
|
|
z_values[ix][iy] = ez;
|
|
|
|
idle(); // housekeeping
|
|
|
|
idle(); // housekeeping
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1777,5 +1767,4 @@
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // UBL_G29_P31
|
|
|
|
#endif // UBL_G29_P31
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif // AUTO_BED_LEVELING_UBL
|
|
|
|
#endif // AUTO_BED_LEVELING_UBL
|
|
|
|