Various improvements - mostly UBL-related (#6607)

UBL Clean up.
This commit is contained in:
bgort 2017-05-06 19:59:16 -04:00 committed by Scott Lahteine
parent c0f1052efb
commit d99794f11d
4 changed files with 35 additions and 40 deletions

View File

@ -4360,7 +4360,7 @@ void home_all_axes() { gcode_G28(); }
verbose_level = code_seen('V') && code_has_value() ? code_value_int() : 0; verbose_level = code_seen('V') && code_has_value() ? code_value_int() : 0;
if (!WITHIN(verbose_level, 0, 4)) { if (!WITHIN(verbose_level, 0, 4)) {
SERIAL_PROTOCOLLNPGM("?(V)erbose Level is implausible (0-4)."); SERIAL_PROTOCOLLNPGM("?(V)erbose level is implausible (0-4).");
return; return;
} }
@ -5081,7 +5081,7 @@ void home_all_axes() { gcode_G28(); }
const int8_t verbose_level = code_seen('V') ? code_value_byte() : 1; const int8_t verbose_level = code_seen('V') ? code_value_byte() : 1;
if (!WITHIN(verbose_level, 0, 2)) { if (!WITHIN(verbose_level, 0, 2)) {
SERIAL_PROTOCOLLNPGM("?(V)erbose Level is implausible (0-2)."); SERIAL_PROTOCOLLNPGM("?(V)erbose level is implausible (0-2).");
return; return;
} }
@ -6183,7 +6183,7 @@ inline void gcode_M42() {
const int8_t verbose_level = code_seen('V') ? code_value_byte() : 1; const int8_t verbose_level = code_seen('V') ? code_value_byte() : 1;
if (!WITHIN(verbose_level, 0, 4)) { if (!WITHIN(verbose_level, 0, 4)) {
SERIAL_PROTOCOLLNPGM("?Verbose Level not plausible (0-4)."); SERIAL_PROTOCOLLNPGM("?(V)erbose level is implausible (0-4).");
return; return;
} }

View File

@ -73,8 +73,9 @@ int finish_incremental_LSF(struct linear_fit_data *lsf) {
lsf->yzbar = lsf->yzbar / N - lsf->ybar * lsf->zbar; lsf->yzbar = lsf->yzbar / N - lsf->ybar * lsf->zbar;
lsf->xzbar = lsf->xzbar / N - lsf->xbar * lsf->zbar; lsf->xzbar = lsf->xzbar / N - lsf->xbar * lsf->zbar;
const float DD = lsf->x2bar * lsf->y2bar - sq(lsf->xybar); const float DD = lsf->x2bar * lsf->y2bar - sq(lsf->xybar);
if (fabs(DD) <= 1e-10 * (lsf->max_absx + lsf->max_absy)) if (fabs(DD) <= 1e-10 * (lsf->max_absx + lsf->max_absy))
return -1; return 1;
lsf->A = (lsf->yzbar * lsf->xybar - lsf->xzbar * lsf->y2bar) / DD; lsf->A = (lsf->yzbar * lsf->xybar - lsf->xzbar * lsf->y2bar) / DD;
lsf->B = (lsf->xzbar * lsf->xybar - lsf->yzbar * lsf->x2bar) / DD; lsf->B = (lsf->xzbar * lsf->xybar - lsf->yzbar * lsf->x2bar) / DD;

18
Marlin/ubl.cpp Executable file → Normal file
View File

@ -50,13 +50,6 @@
safe_delay(10); safe_delay(10);
} }
static void serial_echo_mspaces(const uint8_t cnt) {
for (uint8_t i = GRID_MAX_POINTS_X - 1; --i;) {
SERIAL_ECHO_SP((uint8_t)cnt);
safe_delay(10);
}
}
ubl_state unified_bed_leveling::state; ubl_state unified_bed_leveling::state;
float unified_bed_leveling::z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y], float unified_bed_leveling::z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y],
@ -148,12 +141,11 @@
if (map0) { if (map0) {
SERIAL_PROTOCOLLNPGM("\nBed Topography Report:\n"); SERIAL_PROTOCOLLNPGM("\nBed Topography Report:\n");
serial_echo_xy(0, GRID_MAX_POINTS_Y - 1); serial_echo_xy(0, GRID_MAX_POINTS_Y - 1);
SERIAL_ECHO_SP(3); SERIAL_ECHO_SP(spaces * (GRID_MAX_POINTS_X - 2) + 3);
serial_echo_mspaces(spaces);
serial_echo_xy(GRID_MAX_POINTS_X - 1, GRID_MAX_POINTS_Y - 1); serial_echo_xy(GRID_MAX_POINTS_X - 1, GRID_MAX_POINTS_Y - 1);
SERIAL_EOL; SERIAL_EOL;
serial_echo_xy(UBL_MESH_MIN_X, UBL_MESH_MAX_Y); serial_echo_xy(UBL_MESH_MIN_X, UBL_MESH_MAX_Y);
serial_echo_mspaces(spaces); SERIAL_ECHO_SP(spaces * (GRID_MAX_POINTS_X - 2));
serial_echo_xy(UBL_MESH_MAX_X, UBL_MESH_MAX_Y); serial_echo_xy(UBL_MESH_MAX_X, UBL_MESH_MAX_Y);
SERIAL_EOL; SERIAL_EOL;
} }
@ -198,13 +190,11 @@
if (map0) { if (map0) {
serial_echo_xy(UBL_MESH_MIN_X, UBL_MESH_MIN_Y); serial_echo_xy(UBL_MESH_MIN_X, UBL_MESH_MIN_Y);
SERIAL_ECHO_SP(4); SERIAL_ECHO_SP(spaces * (GRID_MAX_POINTS_X - 2) + 4);
serial_echo_mspaces(spaces);
serial_echo_xy(UBL_MESH_MAX_X, UBL_MESH_MIN_Y); serial_echo_xy(UBL_MESH_MAX_X, UBL_MESH_MIN_Y);
SERIAL_EOL; SERIAL_EOL;
serial_echo_xy(0, 0); serial_echo_xy(0, 0);
SERIAL_ECHO_SP(5); SERIAL_ECHO_SP(spaces * (GRID_MAX_POINTS_X - 2) + 5);
serial_echo_mspaces(spaces);
serial_echo_xy(GRID_MAX_POINTS_X - 1, 0); serial_echo_xy(GRID_MAX_POINTS_X - 1, 0);
SERIAL_EOL; SERIAL_EOL;
} }

View File

@ -311,7 +311,7 @@
#define USE_PROBE_AS_REFERENCE 1 #define USE_PROBE_AS_REFERENCE 1
// The simple parameter flags and values are 'static' so parameter parsing can be in a support routine. // The simple parameter flags and values are 'static' so parameter parsing can be in a support routine.
static int g29_verbose_level, phase_value = -1, repetition_cnt, static int g29_verbose_level, phase_value, repetition_cnt,
storage_slot = 0, map_type, grid_size; storage_slot = 0, map_type, grid_size;
static bool repeat_flag, c_flag, x_flag, y_flag; static bool repeat_flag, c_flag, x_flag, y_flag;
static float x_pos, y_pos, measured_z, card_thickness = 0.0, ubl_constant = 0.0; static float x_pos, y_pos, measured_z, card_thickness = 0.0, ubl_constant = 0.0;
@ -321,7 +321,6 @@
void __attribute__((optimize("O0"))) gcode_G29() { void __attribute__((optimize("O0"))) gcode_G29() {
if (ubl.eeprom_start < 0) { if (ubl.eeprom_start < 0) {
SERIAL_PROTOCOLLNPGM("?You need to enable your EEPROM and initialize it"); SERIAL_PROTOCOLLNPGM("?You need to enable your EEPROM and initialize it");
SERIAL_PROTOCOLLNPGM("with M502, M500, M501 in that order.\n"); SERIAL_PROTOCOLLNPGM("with M502, M500, M501 in that order.\n");
@ -384,21 +383,17 @@
} }
if (code_seen('J')) { if (code_seen('J')) {
if (!WITHIN(grid_size, 2, 9)) {
SERIAL_PROTOCOLLNPGM("ERROR - grid size must be between 2 and 9");
return;
}
ubl.save_ubl_active_state_and_disable(); ubl.save_ubl_active_state_and_disable();
ubl.tilt_mesh_based_on_probed_grid(code_seen('O') || code_seen('M')); ubl.tilt_mesh_based_on_probed_grid(code_seen('O') || code_seen('M'));
ubl.restore_ubl_active_state_and_leave(); ubl.restore_ubl_active_state_and_leave();
} }
if (code_seen('P')) { if (code_seen('P')) {
phase_value = code_value_int(); if (WITHIN(phase_value,0,1) && ubl.state.eeprom_storage_slot==-1) {
if (!WITHIN(phase_value, 0, 7)) { ubl.state.eeprom_storage_slot=0;
SERIAL_PROTOCOLLNPGM("Invalid Phase value. (0-4)\n"); SERIAL_PROTOCOLLNPGM("Default storage slot 0 selected.\n");
return;
} }
switch (phase_value) { switch (phase_value) {
case 0: case 0:
// //
@ -420,7 +415,7 @@
SERIAL_PROTOCOLPAIR("Probing Mesh Points Closest to (", x_pos); SERIAL_PROTOCOLPAIR("Probing Mesh Points Closest to (", x_pos);
SERIAL_PROTOCOLCHAR(','); SERIAL_PROTOCOLCHAR(',');
SERIAL_PROTOCOL(y_pos); SERIAL_PROTOCOL(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, ubl.probe_entire_mesh(x_pos + X_PROBE_OFFSET_FROM_EXTRUDER, y_pos + Y_PROBE_OFFSET_FROM_EXTRUDER,
code_seen('O') || code_seen('M'), code_seen('E'), code_seen('U')); code_seen('O') || code_seen('M'), code_seen('E'), code_seen('U'));
@ -460,7 +455,7 @@
} }
} }
manually_probe_remaining_mesh(x_pos, y_pos, height, card_thickness, code_seen('O') || code_seen('M')); manually_probe_remaining_mesh(x_pos, y_pos, height, card_thickness, code_seen('O') || code_seen('M'));
SERIAL_PROTOCOLLNPGM("G29 P2 finished"); SERIAL_PROTOCOLLNPGM("G29 P2 finished.");
} break; } break;
@ -757,8 +752,6 @@
} }
void unified_bed_leveling::tilt_mesh_based_on_3pts(const float &z1, const float &z2, const float &z3) { void unified_bed_leveling::tilt_mesh_based_on_3pts(const float &z1, const float &z2, const float &z3) {
int i, j;
matrix_3x3 rotation; matrix_3x3 rotation;
vector_3 v1 = vector_3( (UBL_PROBE_PT_1_X - UBL_PROBE_PT_2_X), vector_3 v1 = vector_3( (UBL_PROBE_PT_1_X - UBL_PROBE_PT_2_X),
(UBL_PROBE_PT_1_Y - UBL_PROBE_PT_2_Y), (UBL_PROBE_PT_1_Y - UBL_PROBE_PT_2_Y),
@ -892,14 +885,14 @@
//, min(planner.max_feedrate_mm_s[X_AXIS], planner.max_feedrate_mm_s[Y_AXIS]) / 2.0); //, min(planner.max_feedrate_mm_s[X_AXIS], planner.max_feedrate_mm_s[Y_AXIS]) / 2.0);
stepper.synchronize(); stepper.synchronize();
SERIAL_PROTOCOLPGM("Place shim under nozzle"); SERIAL_PROTOCOLPGM("Place shim under nozzle.");
say_and_take_a_measurement(); say_and_take_a_measurement();
const float z1 = use_encoder_wheel_to_measure_point(); const float z1 = use_encoder_wheel_to_measure_point();
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();
SERIAL_PROTOCOLPGM("Remove shim"); SERIAL_PROTOCOLPGM("Remove shim.");
say_and_take_a_measurement(); say_and_take_a_measurement();
const float z2 = use_encoder_wheel_to_measure_point(); const float z2 = use_encoder_wheel_to_measure_point();
@ -1039,14 +1032,22 @@
g29_verbose_level = code_seen('V') ? code_value_int() : 0; g29_verbose_level = code_seen('V') ? code_value_int() : 0;
if (!WITHIN(g29_verbose_level, 0, 4)) { if (!WITHIN(g29_verbose_level, 0, 4)) {
SERIAL_PROTOCOLLNPGM("?(V)erbose Level is implausible (0-4)\n"); SERIAL_PROTOCOLLNPGM("?(V)erbose level is implausible (0-4).\n");
err_flag = true; err_flag = true;
} }
if (code_seen('P')) {
phase_value = code_value_int();
if (!WITHIN(phase_value, 0, 6)) {
SERIAL_PROTOCOLLNPGM("?(P)hase value invalid (0-6).\n");
err_flag = true;
}
}
if (code_seen('J')) { if (code_seen('J')) {
grid_size = code_has_value() ? code_value_int() : 3; grid_size = code_has_value() ? code_value_int() : 3;
if (!WITHIN(grid_size, 2, 5)) { if (!WITHIN(grid_size, 2, 9)) {
SERIAL_PROTOCOLLNPGM("Invalid grid probe points specified.\n"); SERIAL_PROTOCOLLNPGM("?Invalid grid size (J) specified (2-9).\n");
err_flag = true; err_flag = true;
} }
} }
@ -1607,7 +1608,10 @@
zig_zag ^= true; zig_zag ^= true;
} }
const int status = finish_incremental_LSF(&lsf_results); if (finish_incremental_LSF(&lsf_results)) {
SERIAL_ECHOPGM("Could not complete LSF!");
return;
}
if (g29_verbose_level > 3) { if (g29_verbose_level > 3) {
SERIAL_ECHOPGM("LSF Results A="); SERIAL_ECHOPGM("LSF Results A=");