From dbad0cb1e76c76e3596132ecc5af6013c7186297 Mon Sep 17 00:00:00 2001 From: F0x06 Date: Sun, 9 Dec 2018 16:26:28 +0100 Subject: [PATCH] Hyperfine bed leveling --- Firmware/Marlin_main.cpp | 176 ++++++++++++++++++++++++++++++--------- Firmware/eeprom.h | 7 ++ Firmware/ultralcd.cpp | 96 +++++++++++++++------ lang/config.sh | 0 lang/fw-clean.sh | 0 lang/lang-add.sh | 0 lang/lang-check.sh | 0 lang/lang-clean.sh | 0 lang/lang-export.sh | 0 lang/lang-import.sh | 0 10 files changed, 215 insertions(+), 64 deletions(-) mode change 100644 => 100755 lang/config.sh mode change 100644 => 100755 lang/fw-clean.sh mode change 100644 => 100755 lang/lang-add.sh mode change 100644 => 100755 lang/lang-check.sh mode change 100644 => 100755 lang/lang-clean.sh mode change 100644 => 100755 lang/lang-export.sh mode change 100644 => 100755 lang/lang-import.sh diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 25c005c591..b63eb0e4eb 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -2697,11 +2697,20 @@ void gcode_G28(bool home_x_axis, long home_x_value, bool home_y_axis, long home_ void adjust_bed_reset() { - eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1); - eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_LEFT, 0); - eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, 0); - eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT, 0); - eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR, 0); + // Hyperfine Bed Tuning + eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1); + + eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT_LEFT , 0); + eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT , 0); + eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT_RIGHT , 0); + + eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_LEFT , 0); + eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_RIGHT , 0); + + eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR_LEFT , 0); + eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR , 0); + eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR_RIGHT , 0); + // End Hyperfine Bed Tuning } //! @brief Calibrate XYZ @@ -4557,55 +4566,145 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) } #endif // SUPPORT_VERBOSITY - for (uint8_t i = 0; i < 4; ++i) { - unsigned char codes[4] = { 'L', 'R', 'F', 'B' }; +// Hyperfine Bed Tuning + /*mbl.z_values[2][0] += -0.060f; + mbl.z_values[2][1] += -0.072f; + mbl.z_values[2][2] += 0.070f; + mbl.z_values[1][2] += -0.205f; + mbl.z_values[0][2] += -0.255f; + mbl.z_values[0][1] += -0.202f; + mbl.z_values[0][0] += -0.025f; + mbl.z_values[1][0] += -0.062f;*/ + + + for (uint8_t i = 0; i < 8; ++i) { + unsigned char codes[8] = { 'a', 'b', 'c', 'd' , 'e' , 'f', 'g', 'h'}; long correction = 0; if (code_seen(codes[i])) correction = code_value_long(); else if (eeprom_bed_correction_valid) { - unsigned char *addr = (i < 2) ? - ((i == 0) ? (unsigned char*)EEPROM_BED_CORRECTION_LEFT : (unsigned char*)EEPROM_BED_CORRECTION_RIGHT) : - ((i == 2) ? (unsigned char*)EEPROM_BED_CORRECTION_FRONT : (unsigned char*)EEPROM_BED_CORRECTION_REAR); + switch (i) { + case 0: + {unsigned char *addr = (unsigned char*)EEPROM_BED_CORRECTION_FRONT_LEFT; + correction = eeprom_read_int8(addr); + } + break; + case 1: + {unsigned char *addr = (unsigned char*)EEPROM_BED_CORRECTION_FRONT; + correction = eeprom_read_int8(addr); + } + break; + case 2: + {unsigned char *addr = (unsigned char*)EEPROM_BED_CORRECTION_FRONT_RIGHT; + correction = eeprom_read_int8(addr); + } + break; + case 3: + {unsigned char *addr = (unsigned char*)EEPROM_BED_CORRECTION_LEFT; + correction = eeprom_read_int8(addr); + } + break; + case 4: + {unsigned char *addr = (unsigned char*)EEPROM_BED_CORRECTION_RIGHT; + correction = eeprom_read_int8(addr); + } + break; + case 5: + {unsigned char *addr = (unsigned char*)EEPROM_BED_CORRECTION_REAR_LEFT; + correction = eeprom_read_int8(addr); + } + break; + case 6: + {unsigned char *addr = (unsigned char*)EEPROM_BED_CORRECTION_REAR; + correction = eeprom_read_int8(addr); + } + break; + case 7: + {unsigned char *addr = (unsigned char*)EEPROM_BED_CORRECTION_REAR_RIGHT; correction = eeprom_read_int8(addr); + } + break; } - if (correction == 0) - continue; + } + if (correction == 0) + continue; float offset = float(correction) * 0.001f; - if (fabs(offset) > 0.101f) { + if (fabs(offset) > 0.201f) { SERIAL_ERROR_START; SERIAL_ECHOPGM("Excessive bed leveling correction: "); SERIAL_ECHO(offset); SERIAL_ECHOLNPGM(" microns"); } else { - switch (i) { - case 0: - for (uint8_t row = 0; row < 3; ++row) { - mbl.z_values[row][1] += 0.5f * offset; - mbl.z_values[row][0] += offset; - } - break; - case 1: - for (uint8_t row = 0; row < 3; ++row) { - mbl.z_values[row][1] += 0.5f * offset; - mbl.z_values[row][2] += offset; - } - break; - case 2: - for (uint8_t col = 0; col < 3; ++col) { - mbl.z_values[1][col] += 0.5f * offset; - mbl.z_values[0][col] += offset; - } - break; - case 3: - for (uint8_t col = 0; col < 3; ++col) { - mbl.z_values[1][col] += 0.5f * offset; - mbl.z_values[2][col] += offset; - } - break; + switch (i) { + case 0: + { + mbl.z_values[0][0] += offset; + SERIAL_ECHOPGM("FrontLeft a ="); + SERIAL_ECHO(correction+0); + SERIAL_ECHOLNPGM(" microns."); + } + break; + case 1: + { + mbl.z_values[0][1] += offset; + SERIAL_ECHOPGM("FrontCenter b ="); + SERIAL_ECHO(correction+0); + SERIAL_ECHOLNPGM(" microns."); + } + break; + case 2: + { + mbl.z_values[0][2] += offset; + SERIAL_ECHOPGM("FrontRight c ="); + SERIAL_ECHO(correction+0); + SERIAL_ECHOLNPGM(" microns."); + } + break; + case 3: + { + mbl.z_values[1][0] += offset; + SERIAL_ECHOPGM("MidLeft h ="); + SERIAL_ECHO(correction+0); + SERIAL_ECHOLNPGM(" microns."); + } + break; + case 4: + { + mbl.z_values[1][2] += offset; + SERIAL_ECHOPGM("MidRight d ="); + SERIAL_ECHO(correction+0); + SERIAL_ECHOLNPGM(" microns."); + } + break; + case 5: + { + mbl.z_values[2][0] += offset; + SERIAL_ECHOPGM("RearLeft g ="); + SERIAL_ECHO(correction+0); + SERIAL_ECHOLNPGM(" microns."); + } + break; + case 6: + { + mbl.z_values[2][1] += offset; + SERIAL_ECHOPGM("RearCentr f ="); + SERIAL_ECHO(correction+0); + SERIAL_ECHOLNPGM(" microns."); + } + break; + case 7: + { + mbl.z_values[2][2] += offset; + SERIAL_ECHOPGM("RearRight e ="); + SERIAL_ECHO(correction+0); + SERIAL_ECHOLNPGM(" microns."); } + break; } } + } +// End Hyperfine Bed Tuning // SERIAL_ECHOLNPGM("Bed leveling correction finished"); mbl.upsample_3x3(); //bilinear interpolation from 3x3 to 7x7 points while using the same array z_values[iy][ix] for storing (just coppying measured data to new destination and interpolating between them) // SERIAL_ECHOLNPGM("Upsample finished"); @@ -4642,6 +4741,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) SERIAL_PROTOCOLPGM("\nZ search height: "); SERIAL_PROTOCOL(MESH_HOME_Z_SEARCH); SERIAL_PROTOCOLLNPGM("\nMeasured points:"); + for (int y = MESH_NUM_Y_POINTS-1; y >= 0; y--) { for (int x = 0; x < MESH_NUM_X_POINTS; x++) { SERIAL_PROTOCOLPGM(" "); diff --git a/Firmware/eeprom.h b/Firmware/eeprom.h index da003990fd..b5fe021495 100644 --- a/Firmware/eeprom.h +++ b/Firmware/eeprom.h @@ -152,6 +152,13 @@ // !!!!! this is end of EEPROM section ... all updates MUST BE inserted before this mark !!!!! // !!!!! +// Hyperfine Bed Tuning +#define EEPROM_BED_CORRECTION_FRONT_LEFT (EEPROM_BOARD_TYPE - 1) +#define EEPROM_BED_CORRECTION_FRONT_RIGHT (EEPROM_BED_CORRECTION_FRONT_LEFT - 1) +#define EEPROM_BED_CORRECTION_REAR_RIGHT (EEPROM_BED_CORRECTION_FRONT_RIGHT - 1) +#define EEPROM_BED_CORRECTION_REAR_LEFT (EEPROM_BED_CORRECTION_REAR_RIGHT - 1) +// End Hyperfine Bed Tuning + //TMC2130 configuration #define EEPROM_TMC_AXIS_SIZE //axis configuration block size #define EEPROM_TMC_X (EEPROM_TMC + 0 * EEPROM_TMC_AXIS_SIZE) //X axis configuration blok diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 8e50ead591..3033cf5b34 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -2832,46 +2832,75 @@ static void lcd_babystep_z() } +// Hyperfine Bed Tuning typedef struct { // 12bytes + 9bytes = 21bytes total menu_data_edit_t reserved; //12 bytes reserved for number editing functions int8_t status; // 1byte - int16_t left; // 2byte - int16_t right; // 2byte - int16_t front; // 2byte - int16_t rear; // 2byte + int16_t front_left; // 2byte + int16_t front_center; // 2byte + int16_t front_right; // 2byte + + int16_t mid_left; // 2byte + int16_t mid_right; // 2byte + + int16_t rear_left; // 2byte + int16_t rear_center; // 2byte + int16_t rear_right; // 2byte } _menu_data_adjust_bed_t; static_assert(sizeof(menu_data)>= sizeof(_menu_data_adjust_bed_t),"_menu_data_adjust_bed_t doesn't fit into menu_data"); +// End Hyperfine Bed Tuning void lcd_adjust_bed_reset(void) { - eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1); - eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_LEFT , 0); - eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, 0); - eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT, 0); - eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR , 0); + // Hyperfine Bed Tuning + eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1); + + eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT_LEFT , 0); + eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT , 0); + eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT_RIGHT , 0); + + eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_LEFT , 0); + eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_RIGHT , 0); + + eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR_LEFT , 0); + eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR , 0); + eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR_RIGHT , 0); + // End Hyperfine Bed Tuning + _menu_data_adjust_bed_t* _md = (_menu_data_adjust_bed_t*)&(menu_data[0]); _md->status = 0; } -#define BED_ADJUSTMENT_UM_MAX 50 +#define BED_ADJUSTMENT_UM_MAX 200 void lcd_adjust_bed(void) { _menu_data_adjust_bed_t* _md = (_menu_data_adjust_bed_t*)&(menu_data[0]); if (_md->status == 0) { + // Hyperfine Bed Tuning // Menu was entered. - _md->left = 0; - _md->right = 0; - _md->front = 0; - _md->rear = 0; + _md->front_left = 0; + _md->front_center = 0; + _md->front_right = 0; + _md->mid_left = 0; + _md->mid_right = 0; + _md->rear_left = 0; + _md->rear_center = 0; + _md->rear_right = 0; if (eeprom_read_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID) == 1) { - _md->left = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_LEFT); - _md->right = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_RIGHT); - _md->front = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT); - _md->rear = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR); + _md->front_left = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT_LEFT); + _md->front_center = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT); + _md->front_right = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT_RIGHT); + + _md->mid_left = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_LEFT); + _md->mid_right = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_RIGHT); + + _md->rear_left = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR_LEFT); + _md->rear_center = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR); + _md->rear_right = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR_RIGHT); } _md->status = 1; } @@ -2879,17 +2908,32 @@ void lcd_adjust_bed(void) // leaving menu - this condition must be immediately before MENU_ITEM_BACK_P if (((menu_item == menu_line) && menu_clicked && (lcd_encoder == menu_item)) || menu_leaving) { - eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_LEFT, _md->left); - eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, _md->right); - eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT, _md->front); - eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR, _md->rear); + eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT_LEFT, _md->front_left); + eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT, _md->front_center); + eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT_RIGHT, _md->front_right); + + eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_LEFT, _md->mid_left); + eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, _md->mid_right); + + eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR_LEFT, _md->rear_left); + eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR, _md->rear_center); + eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR_RIGHT, _md->rear_right); + eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1); } MENU_ITEM_BACK_P(_T(MSG_SETTINGS)); - MENU_ITEM_EDIT_int3_P(_i("Left side [um]"), &_md->left, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_LEFT c=14 r=1 - MENU_ITEM_EDIT_int3_P(_i("Right side[um]"), &_md->right, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_RIGHT c=14 r=1 - MENU_ITEM_EDIT_int3_P(_i("Front side[um]"), &_md->front, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_FRONT c=14 r=1 - MENU_ITEM_EDIT_int3_P(_i("Rear side [um]"), &_md->rear, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_REAR c=14 r=1 + MENU_ITEM_EDIT_int3_P(_i("A [um]"), &_md->front_left, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_LEFT c=14 r=1 + MENU_ITEM_EDIT_int3_P(_i("B [um]"), &_md->front_center, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_LEFT c=14 r=1 + MENU_ITEM_EDIT_int3_P(_i("C [um]"), &_md->front_right, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_LEFT c=14 r=1 + + MENU_ITEM_EDIT_int3_P(_i("D [um]"), &_md->mid_right, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_LEFT c=14 r=1 + MENU_ITEM_EDIT_int3_P(_i("E [um]"), &_md->rear_right, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_LEFT c=14 r=1 + MENU_ITEM_EDIT_int3_P(_i("F [um]"), &_md->rear_center, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_LEFT c=14 r=1 + + MENU_ITEM_EDIT_int3_P(_i("G [um]"), &_md->rear_left, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_LEFT c=14 r=1 + MENU_ITEM_EDIT_int3_P(_i("H [um]"), &_md->mid_left, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_LEFT c=14 r=1 + // End Hyperfine Bed Tuning + MENU_ITEM_FUNCTION_P(_i("Reset"), lcd_adjust_bed_reset);////MSG_BED_CORRECTION_RESET c=0 r=0 MENU_END(); } diff --git a/lang/config.sh b/lang/config.sh old mode 100644 new mode 100755 diff --git a/lang/fw-clean.sh b/lang/fw-clean.sh old mode 100644 new mode 100755 diff --git a/lang/lang-add.sh b/lang/lang-add.sh old mode 100644 new mode 100755 diff --git a/lang/lang-check.sh b/lang/lang-check.sh old mode 100644 new mode 100755 diff --git a/lang/lang-clean.sh b/lang/lang-clean.sh old mode 100644 new mode 100755 diff --git a/lang/lang-export.sh b/lang/lang-export.sh old mode 100644 new mode 100755 diff --git a/lang/lang-import.sh b/lang/lang-import.sh old mode 100644 new mode 100755