changed eeprom address for temp shift, verbosity level for mesh bed leveling added, added debuging functions for temp calibration

This commit is contained in:
PavelSindler 2017-03-03 14:12:37 +01:00
parent fd3bb9c7e5
commit d31d73c565
2 changed files with 264 additions and 184 deletions

View File

@ -34,8 +34,6 @@
#define EEPROM_FARM_MODE (EEPROM_BED_CALIBRATION_Z_JITTER-4) #define EEPROM_FARM_MODE (EEPROM_BED_CALIBRATION_Z_JITTER-4)
#define EEPROM_PROBE_TEMP_SHIFT (EEPROM_FARM_MODE - 2*5) //5 x int for storing pinda probe temp shift relative to 50 C; unit: motor steps
// Correction of the bed leveling, in micrometers. // Correction of the bed leveling, in micrometers.
// Maximum 50 micrometers allowed. // Maximum 50 micrometers allowed.
// Bed correction is valid if set to 1. If set to zero or 255, the successive 4 bytes are invalid. // Bed correction is valid if set to 1. If set to zero or 255, the successive 4 bytes are invalid.
@ -46,6 +44,7 @@
#define EEPROM_BED_CORRECTION_REAR (EEPROM_BED_CORRECTION_FRONT-1) #define EEPROM_BED_CORRECTION_REAR (EEPROM_BED_CORRECTION_FRONT-1)
#define EEPROM_TOSHIBA_FLASH_AIR_COMPATIBLITY (EEPROM_BED_CORRECTION_REAR-1) #define EEPROM_TOSHIBA_FLASH_AIR_COMPATIBLITY (EEPROM_BED_CORRECTION_REAR-1)
#define EEPROM_PRINT_FLAG (EEPROM_TOSHIBA_FLASH_AIR_COMPATIBLITY-1) #define EEPROM_PRINT_FLAG (EEPROM_TOSHIBA_FLASH_AIR_COMPATIBLITY-1)
#define EEPROM_PROBE_TEMP_SHIFT (EEPROM_PRINT_FLAG - 2*5) //5 x int for storing pinda probe temp shift relative to 50 C; unit: motor steps
// Currently running firmware, each digit stored as uint16_t. // Currently running firmware, each digit stored as uint16_t.
// The flavor differentiates a dev, alpha, beta, release candidate or a release version. // The flavor differentiates a dev, alpha, beta, release candidate or a release version.

View File

@ -27,14 +27,6 @@
http://reprap.org/pipermail/reprap-dev/2011-May/003323.html http://reprap.org/pipermail/reprap-dev/2011-May/003323.html
*/ */
#include "Marlin.h" #include "Marlin.h"
#ifdef ENABLE_AUTO_BED_LEVELING #ifdef ENABLE_AUTO_BED_LEVELING
@ -62,6 +54,7 @@
#include "pins_arduino.h" #include "pins_arduino.h"
#include "math.h" #include "math.h"
#include "util.h" #include "util.h"
//#include "spline.h"
#ifdef BLINKM #ifdef BLINKM
#include "BlinkM.h" #include "BlinkM.h"
@ -2767,6 +2760,25 @@ void process_commands()
* *
*/ */
case 73:
{
int i, read;
for (i = 0; i < 5; i++) {
EEPROM_read_B(EEPROM_PROBE_TEMP_SHIFT + i * 2, &read);
MYSERIAL.print(read);
SERIAL_ECHOLNPGM(" ");
}
}break;
case 74:
{
float result, temp;
if (code_seen('X')) temp = code_value();
result = temp_comp_interpolation(temp);
MYSERIAL.print(result);
}break;
case 76: //PINDA probe temperature compensation case 76: //PINDA probe temperature compensation
{ {
setTargetBed(PINDA_MIN_T); setTargetBed(PINDA_MIN_T);
@ -2847,6 +2859,12 @@ void process_commands()
} }
break; break;
case 75:
{
temp_compensation_start();
}
break;
#ifdef DIS #ifdef DIS
case 77: case 77:
{ {
@ -2877,9 +2895,16 @@ void process_commands()
#endif #endif
case 80: case 80:
case_G80: case_G80:
{ {
int8_t verbosity_level = 0;
if (code_seen('V')) {
// Just 'V' without a number counts as V1.
char c = strchr_pointer[1];
verbosity_level = (c == ' ' || c == '\t' || c == 0) ? 1 : code_value_short();
}
// Firstly check if we know where we are // Firstly check if we know where we are
if (!(axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS])) { if (!(axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS])) {
// We don't know where we are! HOME! // We don't know where we are! HOME!
@ -2889,7 +2914,7 @@ void process_commands()
enquecommand_front_P((PSTR("G28 W0"))); enquecommand_front_P((PSTR("G28 W0")));
break; break;
} }
temp_compensation_start();
// Save custom message state, set a new custom message state to display: Calibrating point 9. // Save custom message state, set a new custom message state to display: Calibrating point 9.
bool custom_message_old = custom_message; bool custom_message_old = custom_message;
unsigned int custom_message_type_old = custom_message_type; unsigned int custom_message_type_old = custom_message_type;
@ -2899,7 +2924,7 @@ void process_commands()
custom_message_state = (MESH_MEAS_NUM_X_POINTS * MESH_MEAS_NUM_Y_POINTS) + 10; custom_message_state = (MESH_MEAS_NUM_X_POINTS * MESH_MEAS_NUM_Y_POINTS) + 10;
lcd_update(1); lcd_update(1);
mbl.reset(); mbl.reset(); //reset mesh bed leveling
// Reset baby stepping to zero, if the babystepping has already been loaded before. The babystepsTodo value will be // Reset baby stepping to zero, if the babystepping has already been loaded before. The babystepsTodo value will be
// consumed during the first movements following this statement. // consumed during the first movements following this statement.
@ -2912,13 +2937,17 @@ void process_commands()
// The move to the first calibration point. // The move to the first calibration point.
current_position[X_AXIS] = pgm_read_float(bed_ref_points); current_position[X_AXIS] = pgm_read_float(bed_ref_points);
current_position[Y_AXIS] = pgm_read_float(bed_ref_points + 1); current_position[Y_AXIS] = pgm_read_float(bed_ref_points + 1);
world2machine_clamp(current_position[X_AXIS], current_position[Y_AXIS]); bool clamped = world2machine_clamp(current_position[X_AXIS], current_position[Y_AXIS]);
if (verbosity_level >= 1) {
clamped ? SERIAL_PROTOCOLPGM("First calibration point clamped.\n") : SERIAL_PROTOCOLPGM("No clamping for first calibration point.\n");
}
// mbl.get_meas_xy(0, 0, current_position[X_AXIS], current_position[Y_AXIS], false); // mbl.get_meas_xy(0, 0, current_position[X_AXIS], current_position[Y_AXIS], false);
plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], homing_feedrate[X_AXIS] / 30, active_extruder); plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], homing_feedrate[X_AXIS] / 30, active_extruder);
// Wait until the move is finished. // Wait until the move is finished.
st_synchronize(); st_synchronize();
int mesh_point = 0; int mesh_point = 0; //index number of calibration point
int ix = 0; int ix = 0;
int iy = 0; int iy = 0;
@ -2926,25 +2955,31 @@ void process_commands()
int XY_AXIS_FEEDRATE = homing_feedrate[X_AXIS] / 20; int XY_AXIS_FEEDRATE = homing_feedrate[X_AXIS] / 20;
int Z_PROBE_FEEDRATE = homing_feedrate[Z_AXIS] / 60; int Z_PROBE_FEEDRATE = homing_feedrate[Z_AXIS] / 60;
int Z_LIFT_FEEDRATE = homing_feedrate[Z_AXIS] / 40; int Z_LIFT_FEEDRATE = homing_feedrate[Z_AXIS] / 40;
bool has_z = is_bed_z_jitter_data_valid(); bool has_z = is_bed_z_jitter_data_valid(); //checks if we have data from Z calibration (offsets of the Z heiths of the 8 calibration points from the first point)
setup_for_endstop_move(false); if (verbosity_level >= 1) {
has_z ? SERIAL_PROTOCOLPGM("Z jitter data from Z cal. valid.\n") : SERIAL_PROTOCOLPGM("Z jitter data from Z cal. not valid.\n");
}
setup_for_endstop_move(false); //save feedrate and feedmultiply, sets feedmultiply to 100
const char *kill_message = NULL; const char *kill_message = NULL;
while (mesh_point != MESH_MEAS_NUM_X_POINTS * MESH_MEAS_NUM_Y_POINTS) { while (mesh_point != MESH_MEAS_NUM_X_POINTS * MESH_MEAS_NUM_Y_POINTS) {
if (verbosity_level >= 1) SERIAL_ECHOLNPGM("");
// Get coords of a measuring point. // Get coords of a measuring point.
ix = mesh_point % MESH_MEAS_NUM_X_POINTS; ix = mesh_point % MESH_MEAS_NUM_X_POINTS; // from 0 to MESH_NUM_X_POINTS - 1
iy = mesh_point / MESH_MEAS_NUM_X_POINTS; iy = mesh_point / MESH_MEAS_NUM_X_POINTS;
if (iy & 1) ix = (MESH_MEAS_NUM_X_POINTS - 1) - ix; // Zig zag if (iy & 1) ix = (MESH_MEAS_NUM_X_POINTS - 1) - ix; // Zig zag
float z0 = 0.f; float z0 = 0.f;
if (has_z && mesh_point > 0) { if (has_z && mesh_point > 0) {
uint16_t z_offset_u = eeprom_read_word((uint16_t*)(EEPROM_BED_CALIBRATION_Z_JITTER + 2 * (ix + iy * 3 - 1))); uint16_t z_offset_u = eeprom_read_word((uint16_t*)(EEPROM_BED_CALIBRATION_Z_JITTER + 2 * (ix + iy * 3 - 1)));
z0 = mbl.z_values[0][0] + *reinterpret_cast<int16_t*>(&z_offset_u) * 0.01; z0 = mbl.z_values[0][0] + *reinterpret_cast<int16_t*>(&z_offset_u) * 0.01;
#if 0 //#if 0
if (verbosity_level >= 1) {
SERIAL_ECHOPGM("Bed leveling, point: "); SERIAL_ECHOPGM("Bed leveling, point: ");
MYSERIAL.print(mesh_point); MYSERIAL.print(mesh_point);
SERIAL_ECHOPGM(", calibration z: "); SERIAL_ECHOPGM(", calibration z: ");
MYSERIAL.print(z0, 5); MYSERIAL.print(z0, 5);
SERIAL_ECHOLNPGM(""); SERIAL_ECHOLNPGM("");
#endif }
//#endif
} }
// Move Z up to MESH_HOME_Z_SEARCH. // Move Z up to MESH_HOME_Z_SEARCH.
@ -2955,13 +2990,23 @@ void process_commands()
// Move to XY position of the sensor point. // Move to XY position of the sensor point.
current_position[X_AXIS] = pgm_read_float(bed_ref_points + 2 * mesh_point); current_position[X_AXIS] = pgm_read_float(bed_ref_points + 2 * mesh_point);
current_position[Y_AXIS] = pgm_read_float(bed_ref_points + 2 * mesh_point + 1); current_position[Y_AXIS] = pgm_read_float(bed_ref_points + 2 * mesh_point + 1);
world2machine_clamp(current_position[X_AXIS], current_position[Y_AXIS]); world2machine_clamp(current_position[X_AXIS], current_position[Y_AXIS]);
if (verbosity_level >= 1) {
SERIAL_PROTOCOL(mesh_point);
clamped ? SERIAL_PROTOCOLPGM(": xy clamped.\n") : SERIAL_PROTOCOLPGM(": no xy clamping\n");
}
plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], XY_AXIS_FEEDRATE, active_extruder); plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], XY_AXIS_FEEDRATE, active_extruder);
st_synchronize(); st_synchronize();
// Go down until endstop is hit // Go down until endstop is hit
const float Z_CALIBRATION_THRESHOLD = 1.f; const float Z_CALIBRATION_THRESHOLD = 1.f;
if (! find_bed_induction_sensor_point_z((has_z && mesh_point > 0) ? z0 - Z_CALIBRATION_THRESHOLD : -10.f)) { if (!find_bed_induction_sensor_point_z((has_z && mesh_point > 0) ? z0 - Z_CALIBRATION_THRESHOLD : -10.f)) { //if we have data from z calibration max allowed difference is 1mm for each point, if we dont have data max difference is 10mm from initial point
kill_message = MSG_BED_LEVELING_FAILED_POINT_LOW; kill_message = MSG_BED_LEVELING_FAILED_POINT_LOW;
break; break;
} }
@ -2969,32 +3014,54 @@ void process_commands()
kill_message = MSG_BED_LEVELING_FAILED_PROBE_DISCONNECTED; kill_message = MSG_BED_LEVELING_FAILED_PROBE_DISCONNECTED;
break; break;
} }
if (has_z && fabs(z0 - current_position[Z_AXIS]) > Z_CALIBRATION_THRESHOLD) { if (has_z && fabs(z0 - current_position[Z_AXIS]) > Z_CALIBRATION_THRESHOLD) { //if we have data from z calibration, max. allowed difference is 1mm for each point
kill_message = MSG_BED_LEVELING_FAILED_POINT_HIGH; kill_message = MSG_BED_LEVELING_FAILED_POINT_HIGH;
break; break;
} }
mbl.set_z(ix, iy, current_position[Z_AXIS]); if (verbosity_level >= 10) {
SERIAL_ECHOPGM("X: ");
MYSERIAL.print(current_position[X_AXIS], 5);
SERIAL_ECHOLNPGM("");
SERIAL_ECHOPGM("Y: ");
MYSERIAL.print(current_position[Y_AXIS], 5);
SERIAL_PROTOCOLPGM("\n");
}
if (verbosity_level >= 1) {
SERIAL_ECHOPGM("mesh bed leveling: ");
MYSERIAL.print(current_position[Z_AXIS], 5);
SERIAL_ECHOLNPGM("");
}
mbl.set_z(ix, iy, current_position[Z_AXIS]); //store measured z values z_values[iy][ix] = z;
custom_message_state--; custom_message_state--;
mesh_point++; mesh_point++;
lcd_update(1); lcd_update(1);
} }
if (verbosity_level >= 20) SERIAL_ECHOLNPGM("Mesh bed leveling while loop finished.");
current_position[Z_AXIS] = MESH_HOME_Z_SEARCH; current_position[Z_AXIS] = MESH_HOME_Z_SEARCH;
if (verbosity_level >= 20) {
SERIAL_ECHOLNPGM("MESH_HOME_Z_SEARCH: ");
MYSERIAL.print(current_position[Z_AXIS], 5);
}
plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], Z_LIFT_FEEDRATE, active_extruder); plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], Z_LIFT_FEEDRATE, active_extruder);
st_synchronize(); st_synchronize();
if (mesh_point != MESH_MEAS_NUM_X_POINTS * MESH_MEAS_NUM_Y_POINTS) { if (mesh_point != MESH_MEAS_NUM_X_POINTS * MESH_MEAS_NUM_Y_POINTS) {
kill(kill_message); kill(kill_message);
SERIAL_ECHOLNPGM("killed");
} }
clean_up_after_endstop_move(); clean_up_after_endstop_move();
SERIAL_ECHOLNPGM("clean up finished ");
temp_compensation_apply(); //apply PINDA temperature compensation temp_compensation_apply(); //apply PINDA temperature compensation
babystep_apply(); // Apply Z height correction aka baby stepping before mesh bed leveing gets activated.
// Apply Z height correction aka baby stepping before mesh bed leveing gets activated. SERIAL_ECHOLNPGM("babystep applied");
babystep_apply();
bool eeprom_bed_correction_valid = eeprom_read_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID) == 1; bool eeprom_bed_correction_valid = eeprom_read_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID) == 1;
if (verbosity_level >= 1) {
eeprom_bed_correction_valid ? SERIAL_PROTOCOLPGM("Bed correction data valid\n") : SERIAL_PROTOCOLPGM("Bed correction data not valid\n");
}
for (uint8_t i = 0; i < 4; ++i) { for (uint8_t i = 0; i < 4; ++i) {
unsigned char codes[4] = { 'L', 'R', 'F', 'B' }; unsigned char codes[4] = { 'L', 'R', 'F', 'B' };
long correction = 0; long correction = 0;
@ -3014,7 +3081,8 @@ void process_commands()
SERIAL_ECHOPGM("Excessive bed leveling correction: "); SERIAL_ECHOPGM("Excessive bed leveling correction: ");
SERIAL_ECHO(offset); SERIAL_ECHO(offset);
SERIAL_ECHOLNPGM(" microns"); SERIAL_ECHOLNPGM(" microns");
} else { }
else {
switch (i) { switch (i) {
case 0: case 0:
for (uint8_t row = 0; row < 3; ++row) { for (uint8_t row = 0; row < 3; ++row) {
@ -3043,11 +3111,13 @@ void process_commands()
} }
} }
} }
SERIAL_ECHOLNPGM("Bed leveling correction finished");
mbl.upsample_3x3(); 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)
mbl.active = 1; SERIAL_ECHOLNPGM("Upsample finished");
mbl.active = 1; //activate mesh bed leveling
SERIAL_ECHOLNPGM("Mesh bed leveling activated");
go_home_with_z_lift(); go_home_with_z_lift();
SERIAL_ECHOLNPGM("Go home finished");
// Restore custom message state // Restore custom message state
custom_message = custom_message_old; custom_message = custom_message_old;
custom_message_type = custom_message_type_old; custom_message_type = custom_message_type_old;
@ -6166,14 +6236,14 @@ void temp_compensation_apply() {
int z_shift = 0; int z_shift = 0;
float z_shift_mm; float z_shift_mm;
if (target_temperature_bed % 10 == 0 && target_temperature_bed >= 60 && target_temperature_bed <= 100) { if (target_temperature_bed % 10 == 0 && target_temperature_bed >= 50 && target_temperature_bed <= 100) {
i_add = (target_temperature_bed - 60) / 10; i_add = (target_temperature_bed - 60) / 10;
EEPROM_read_B(EEPROM_PROBE_TEMP_SHIFT + i_add * 2, &z_shift); EEPROM_read_B(EEPROM_PROBE_TEMP_SHIFT + i_add * 2, &z_shift);
z_shift_mm = z_shift / axis_steps_per_unit[Z_AXIS]; z_shift_mm = z_shift / axis_steps_per_unit[Z_AXIS];
} }
else { else {
//interpolation //interpolation
//z_shift_mm = temp_comp_interpolation(target_temperature_bed) / axis_steps_per_unit[Z_AXIS]; z_shift_mm = temp_comp_interpolation(target_temperature_bed) / axis_steps_per_unit[Z_AXIS];
} }
SERIAL_PROTOCOLPGM("\n"); SERIAL_PROTOCOLPGM("\n");
SERIAL_PROTOCOLPGM("Z shift applied:"); SERIAL_PROTOCOLPGM("Z shift applied:");
@ -6183,6 +6253,12 @@ void temp_compensation_apply() {
plan_set_z_position(current_position[Z_AXIS]); plan_set_z_position(current_position[Z_AXIS]);
} }
/*float temp_comp_interpolation(float temperature) {
}*/
float temp_comp_interpolation(float temperature) { float temp_comp_interpolation(float temperature) {
//cubic spline interpolation //cubic spline interpolation
@ -6196,19 +6272,24 @@ float temp_comp_interpolation(float temperature) {
int n, j, k; int n, j, k;
float h[10], a, b, c, d, sum, s[10] = { 0 }, x[10], F[10], f[10], p, m[10][10] = { 0 }, temp; float h[10], a, b, c, d, sum, s[10] = { 0 }, x[10], F[10], f[10], p, m[10][10] = { 0 }, temp;
/*SERIAL_ECHOLNPGM("Reading shift data:");
for (i = 0; i < 6; i++) { MYSERIAL.print(shift[i]);*/
for (i = 0; i < 5; i++) {
EEPROM_read_B(EEPROM_PROBE_TEMP_SHIFT + i * 2, &shift[i + 1]); //read shift in steps from EEPROM EEPROM_read_B(EEPROM_PROBE_TEMP_SHIFT + i * 2, &shift[i + 1]); //read shift in steps from EEPROM
//SERIAL_ECHOLNPGM(" ");
//MYSERIAL.print(shift[i + 1]);
temp_C[i] = 50 + i * 10; //temperature in C temp_C[i] = 50 + i * 10; //temperature in C
shift_f[i] = (float)shift[i]; shift_f[i] = (float)shift[i];
} }
for (i = 5; i > 0; i--) { for (i = 5; i > 0; i--) {
F[i] = (shift_f[i] - shift_f[i - 1]) / (temp_C[i] - temp_C[i - 1]); F[i] = (shift_f[i] - shift_f[i - 1]) / (temp_C[i] - temp_C[i - 1]);
h[i - 1] = temp_C[i] - temp_C[i - 1]; h[i - 1] = temp_C[i] - temp_C[i - 1];
} }
//*********** formation of h, s , f matrix **************// //*********** formation of h, s , f matrix *************
for (i = 1; i<5; i++) { for (i = 1; i<5; i++) {
m[i][i] = 2 * (h[i - 1] + h[i]); m[i][i] = 2 * (h[i - 1] + h[i]);
if (i != 1) { if (i != 1) {
@ -6217,13 +6298,13 @@ float temp_comp_interpolation(float temperature) {
} }
m[i][5] = 6 * (F[i + 1] - F[i]); m[i][5] = 6 * (F[i + 1] - F[i]);
} }
//*********** forward elimination **************// //*********** forward elimination **************
for (i = 1; i<4; i++) { for (i = 1; i<4; i++) {
temp = (m[i + 1][i] / m[i][i]); temp = (m[i + 1][i] / m[i][i]);
for (j = 1; j <= 5; j++) for (j = 1; j <= 5; j++)
m[i + 1][j] -= temp*m[i][j]; m[i + 1][j] -= temp*m[i][j];
} }
//*********** backward substitution *********// //*********** backward substitution *********
for (i = 4; i>0; i--) { for (i = 4; i>0; i--) {
sum = 0; sum = 0;
for (j = i; j <= 4; j++) for (j = i; j <= 4; j++)