From 96b5da71983adffa86dffa5961da78aa24183fb4 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 25 Mar 2015 20:36:24 -0700 Subject: [PATCH 01/14] Fix up bed leveling code - Init `zprobe_zoffset` - Remove `current_position[Z_AXIS] = zprobe_zoffset` lines from the `set_bed_level_equation_*` functions - Apply standards to `mesh_bed_leveling` files - Document `MESH_BED_LEVELING` --- Marlin/ConfigurationStore.cpp | 2 +- Marlin/Marlin_main.cpp | 271 +++++++++++++++++----------------- Marlin/mesh_bed_leveling.cpp | 22 ++- Marlin/mesh_bed_leveling.h | 62 ++++---- 4 files changed, 173 insertions(+), 184 deletions(-) diff --git a/Marlin/ConfigurationStore.cpp b/Marlin/ConfigurationStore.cpp index fc485e226..a0be20276 100644 --- a/Marlin/ConfigurationStore.cpp +++ b/Marlin/ConfigurationStore.cpp @@ -11,7 +11,7 @@ * max_acceleration_units_per_sq_second (x4) * acceleration * retract_acceleration - * travel_aceeleration + * travel_acceleration * minimumfeedrate * mintravelfeedrate * minsegmenttime diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index b3235f559..ff6e96499 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -255,7 +255,7 @@ float home_offset[3] = { 0, 0, 0 }; float min_pos[3] = { X_MIN_POS, Y_MIN_POS, Z_MIN_POS }; float max_pos[3] = { X_MAX_POS, Y_MAX_POS, Z_MAX_POS }; bool axis_known_position[3] = { false, false, false }; -float zprobe_zoffset; +float zprobe_zoffset = -Z_PROBE_OFFSET_FROM_EXTRUDER; // Extruder offset #if EXTRUDERS > 1 @@ -1092,9 +1092,6 @@ static void set_bed_level_equation_lsq(double *plane_equation_coefficients) current_position[Y_AXIS] = corrected_position.y; current_position[Z_AXIS] = corrected_position.z; - // put the bed at 0 so we don't go below it. - current_position[Z_AXIS] = zprobe_zoffset; // in the lsq we reach here after raising the extruder due to the loop structure - plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); } #endif @@ -1121,9 +1118,6 @@ static void set_bed_level_equation_3pts(float z_at_pt_1, float z_at_pt_2, float current_position[Y_AXIS] = corrected_position.y; current_position[Z_AXIS] = corrected_position.z; - // put the bed at 0 so we don't go below it. - current_position[Z_AXIS] = zprobe_zoffset; - plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); } @@ -2010,8 +2004,19 @@ inline void gcode_G28() { endstops_hit_on_purpose(); } -#if defined(MESH_BED_LEVELING) +#ifdef MESH_BED_LEVELING + /** + * G29: Mesh-based Z-Probe, probes a grid and produces a + * mesh to compensate for variable bed height + * + * Parameters With MESH_BED_LEVELING: + * + * S0 Produce a mesh report + * S1 Start probing mesh points + * S2 Probe the next mesh point + * + */ inline void gcode_G29() { static int probe_point = -1; int state = 0; @@ -2053,7 +2058,7 @@ inline void gcode_G28() { } else if (state == 2) { // Goto next point if (probe_point < 0) { - SERIAL_PROTOCOLPGM("Mesh probing not started.\n"); + SERIAL_PROTOCOLPGM("Start mesh probing with \"G29 S1\" first.\n"); return; } int ix, iy; @@ -2063,16 +2068,14 @@ inline void gcode_G28() { } else { ix = (probe_point-1) % MESH_NUM_X_POINTS; iy = (probe_point-1) / MESH_NUM_X_POINTS; - if (iy&1) { // Zig zag - ix = (MESH_NUM_X_POINTS - 1) - ix; - } + if (iy & 1) ix = (MESH_NUM_X_POINTS - 1) - ix; // zig-zag mbl.set_z(ix, iy, current_position[Z_AXIS]); current_position[Z_AXIS] = MESH_HOME_SEARCH_Z; plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], homing_feedrate[X_AXIS]/60, active_extruder); st_synchronize(); } - if (probe_point == MESH_NUM_X_POINTS*MESH_NUM_Y_POINTS) { - SERIAL_PROTOCOLPGM("Mesh done.\n"); + if (probe_point == MESH_NUM_X_POINTS * MESH_NUM_Y_POINTS) { + SERIAL_PROTOCOLPGM("Mesh probing done.\n"); probe_point = -1; mbl.active = 1; enquecommands_P(PSTR("G28")); @@ -2080,9 +2083,7 @@ inline void gcode_G28() { } ix = probe_point % MESH_NUM_X_POINTS; iy = probe_point / MESH_NUM_X_POINTS; - if (iy&1) { // Zig zag - ix = (MESH_NUM_X_POINTS - 1) - ix; - } + if (iy & 1) ix = (MESH_NUM_X_POINTS - 1) - ix; // zig-zag current_position[X_AXIS] = mbl.get_x(ix); current_position[Y_AXIS] = mbl.get_y(iy); plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], homing_feedrate[X_AXIS]/60, active_extruder); @@ -2091,9 +2092,7 @@ inline void gcode_G28() { } } -#endif - -#ifdef ENABLE_AUTO_BED_LEVELING +#elif defined(ENABLE_AUTO_BED_LEVELING) /** * G29: Detailed Z-Probe, probes the bed at 3 or more points. @@ -2154,9 +2153,9 @@ inline void gcode_G28() { #ifdef AUTO_BED_LEVELING_GRID - #ifndef DELTA - bool do_topography_map = verbose_level > 2 || code_seen('T') || code_seen('t'); - #endif + #ifndef DELTA + bool do_topography_map = verbose_level > 2 || code_seen('T') || code_seen('t'); + #endif if (verbose_level > 0) SERIAL_PROTOCOLPGM("G29 Auto Bed Leveling\n"); @@ -2210,7 +2209,7 @@ inline void gcode_G28() { #ifdef Z_PROBE_SLED dock_sled(false); // engage (un-dock) the probe - #elif defined(Z_PROBE_ALLEN_KEY) + #elif defined(Z_PROBE_ALLEN_KEY) //|| defined(SERVO_LEVELING) engage_z_probe(); #endif @@ -2218,19 +2217,18 @@ inline void gcode_G28() { #ifdef DELTA reset_bed_level(); - #else - - // make sure the bed_level_rotation_matrix is identity or the planner will get it incorectly - //vector_3 corrected_position = plan_get_position_mm(); - //corrected_position.debug("position before G29"); - plan_bed_level_matrix.set_to_identity(); - vector_3 uncorrected_position = plan_get_position(); - //uncorrected_position.debug("position during G29"); - current_position[X_AXIS] = uncorrected_position.x; - current_position[Y_AXIS] = uncorrected_position.y; - current_position[Z_AXIS] = uncorrected_position.z; - plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); - #endif + #else //!DELTA + // make sure the bed_level_rotation_matrix is identity or the planner will get it wrong + //vector_3 corrected_position = plan_get_position_mm(); + //corrected_position.debug("position before G29"); + plan_bed_level_matrix.set_to_identity(); + vector_3 uncorrected_position = plan_get_position(); + //uncorrected_position.debug("position during G29"); + current_position[X_AXIS] = uncorrected_position.x; + current_position[Y_AXIS] = uncorrected_position.y; + current_position[Z_AXIS] = uncorrected_position.z; + plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); + #endif //!DELTA setup_for_endstop_move(); @@ -2242,26 +2240,24 @@ inline void gcode_G28() { const int xGridSpacing = (right_probe_bed_position - left_probe_bed_position) / (auto_bed_leveling_grid_points-1); const int yGridSpacing = (back_probe_bed_position - front_probe_bed_position) / (auto_bed_leveling_grid_points-1); - #ifndef DELTA - // solve the plane equation ax + by + d = z - // A is the matrix with rows [x y 1] for all the probed points - // B is the vector of the Z positions - // the normal vector to the plane is formed by the coefficients of the plane equation in the standard form, which is Vx*x+Vy*y+Vz*z+d = 0 - // so Vx = -a Vy = -b Vz = 1 (we want the vector facing towards positive Z + #ifdef DELTA + delta_grid_spacing[0] = xGridSpacing; + delta_grid_spacing[1] = yGridSpacing; + float z_offset = Z_PROBE_OFFSET_FROM_EXTRUDER; + if (code_seen(axis_codes[Z_AXIS])) z_offset += code_value(); + #else // !DELTA + // solve the plane equation ax + by + d = z + // A is the matrix with rows [x y 1] for all the probed points + // B is the vector of the Z positions + // the normal vector to the plane is formed by the coefficients of the plane equation in the standard form, which is Vx*x+Vy*y+Vz*z+d = 0 + // so Vx = -a Vy = -b Vz = 1 (we want the vector facing towards positive Z - int abl2 = auto_bed_leveling_grid_points * auto_bed_leveling_grid_points; + int abl2 = auto_bed_leveling_grid_points * auto_bed_leveling_grid_points; - double eqnAMatrix[abl2 * 3], // "A" matrix of the linear system of equations - eqnBVector[abl2], // "B" vector of Z points - mean = 0.0; - - #else - delta_grid_spacing[0] = xGridSpacing; - delta_grid_spacing[1] = yGridSpacing; - - float z_offset = Z_PROBE_OFFSET_FROM_EXTRUDER; - if (code_seen(axis_codes[Z_AXIS])) z_offset += code_value(); - #endif + double eqnAMatrix[abl2 * 3], // "A" matrix of the linear system of equations + eqnBVector[abl2], // "B" vector of Z points + mean = 0.0; + #endif // !DELTA int probePointCounter = 0; bool zig = true; @@ -2294,12 +2290,12 @@ inline void gcode_G28() { float measured_z, z_before = probePointCounter == 0 ? Z_RAISE_BEFORE_PROBING : current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS; - #ifdef DELTA - // Avoid probing the corners (outside the round or hexagon print surface) on a delta printer. - float distance_from_center = sqrt(xProbe*xProbe + yProbe*yProbe); - if (distance_from_center > DELTA_PROBABLE_RADIUS) - continue; - #endif //DELTA + #ifdef DELTA + // Avoid probing the corners (outside the round or hexagon print surface) on a delta printer. + float distance_from_center = sqrt(xProbe*xProbe + yProbe*yProbe); + if (distance_from_center > DELTA_PROBABLE_RADIUS) + continue; + #endif //DELTA // Enhanced G29 - Do not retract servo between probes ProbeAction act; @@ -2316,16 +2312,16 @@ inline void gcode_G28() { measured_z = probe_pt(xProbe, yProbe, z_before, act, verbose_level); - #ifndef DELTA - mean += measured_z; + #ifndef DELTA + mean += measured_z; - eqnBVector[probePointCounter] = measured_z; - eqnAMatrix[probePointCounter + 0 * abl2] = xProbe; - eqnAMatrix[probePointCounter + 1 * abl2] = yProbe; - eqnAMatrix[probePointCounter + 2 * abl2] = 1; - #else - bed_level[xCount][yCount] = measured_z + z_offset; - #endif + eqnBVector[probePointCounter] = measured_z; + eqnAMatrix[probePointCounter + 0 * abl2] = xProbe; + eqnAMatrix[probePointCounter + 1 * abl2] = yProbe; + eqnAMatrix[probePointCounter + 2 * abl2] = 1; + #else + bed_level[xCount][yCount] = measured_z + z_offset; + #endif probePointCounter++; } //xProbe @@ -2333,60 +2329,61 @@ inline void gcode_G28() { clean_up_after_endstop_move(); - #ifndef DELTA - // solve lsq problem - double *plane_equation_coefficients = qr_solve(abl2, 3, eqnAMatrix, eqnBVector); + #ifdef DELTA + extrapolate_unprobed_bed_level(); + print_bed_level(); + #else // !DELTA + // solve lsq problem + double *plane_equation_coefficients = qr_solve(abl2, 3, eqnAMatrix, eqnBVector); - mean /= abl2; + mean /= abl2; - if (verbose_level) { - SERIAL_PROTOCOLPGM("Eqn coefficients: a: "); - SERIAL_PROTOCOL_F(plane_equation_coefficients[0], 8); - SERIAL_PROTOCOLPGM(" b: "); - SERIAL_PROTOCOL_F(plane_equation_coefficients[1], 8); - SERIAL_PROTOCOLPGM(" d: "); - SERIAL_PROTOCOL_F(plane_equation_coefficients[2], 8); - SERIAL_EOL; - if (verbose_level > 2) { - SERIAL_PROTOCOLPGM("Mean of sampled points: "); - SERIAL_PROTOCOL_F(mean, 8); + if (verbose_level) { + SERIAL_PROTOCOLPGM("Eqn coefficients: a: "); + SERIAL_PROTOCOL_F(plane_equation_coefficients[0], 8); + SERIAL_PROTOCOLPGM(" b: "); + SERIAL_PROTOCOL_F(plane_equation_coefficients[1], 8); + SERIAL_PROTOCOLPGM(" d: "); + SERIAL_PROTOCOL_F(plane_equation_coefficients[2], 8); SERIAL_EOL; + if (verbose_level > 2) { + SERIAL_PROTOCOLPGM("Mean of sampled points: "); + SERIAL_PROTOCOL_F(mean, 8); + SERIAL_EOL; + } } - } - // Show the Topography map if enabled - if (do_topography_map) { + // Show the Topography map if enabled + if (do_topography_map) { - SERIAL_PROTOCOLPGM(" \nBed Height Topography: \n"); - SERIAL_PROTOCOLPGM("+-----------+\n"); - SERIAL_PROTOCOLPGM("|...Back....|\n"); - SERIAL_PROTOCOLPGM("|Left..Right|\n"); - SERIAL_PROTOCOLPGM("|...Front...|\n"); - SERIAL_PROTOCOLPGM("+-----------+\n"); + SERIAL_PROTOCOLPGM(" \nBed Height Topography: \n"); + SERIAL_PROTOCOLPGM("+-----------+\n"); + SERIAL_PROTOCOLPGM("|...Back....|\n"); + SERIAL_PROTOCOLPGM("|Left..Right|\n"); + SERIAL_PROTOCOLPGM("|...Front...|\n"); + SERIAL_PROTOCOLPGM("+-----------+\n"); - for (int yy = auto_bed_leveling_grid_points - 1; yy >= 0; yy--) { - for (int xx = 0; xx < auto_bed_leveling_grid_points; xx++) { - int ind = yy * auto_bed_leveling_grid_points + xx; - float diff = eqnBVector[ind] - mean; - if (diff >= 0.0) - SERIAL_PROTOCOLPGM(" +"); // Include + for column alignment - else - SERIAL_PROTOCOLPGM(" "); - SERIAL_PROTOCOL_F(diff, 5); - } // xx + for (int yy = auto_bed_leveling_grid_points - 1; yy >= 0; yy--) { + for (int xx = 0; xx < auto_bed_leveling_grid_points; xx++) { + int ind = yy * auto_bed_leveling_grid_points + xx; + float diff = eqnBVector[ind] - mean; + if (diff >= 0.0) + SERIAL_PROTOCOLPGM(" +"); // Include + for column alignment + else + SERIAL_PROTOCOLPGM(" "); + SERIAL_PROTOCOL_F(diff, 5); + } // xx + SERIAL_EOL; + } // yy SERIAL_EOL; - } // yy - SERIAL_EOL; - } //do_topography_map + } //do_topography_map - set_bed_level_equation_lsq(plane_equation_coefficients); - free(plane_equation_coefficients); - #else - extrapolate_unprobed_bed_level(); - print_bed_level(); - #endif + set_bed_level_equation_lsq(plane_equation_coefficients); + free(plane_equation_coefficients); + + #endif // !DELTA #else // !AUTO_BED_LEVELING_GRID @@ -2409,33 +2406,33 @@ inline void gcode_G28() { #endif // !AUTO_BED_LEVELING_GRID - #ifndef DELTA - if (verbose_level > 0) - plan_bed_level_matrix.debug(" \n\nBed Level Correction Matrix:"); + #ifndef DELTA + if (verbose_level > 0) + plan_bed_level_matrix.debug(" \n\nBed Level Correction Matrix:"); - // Correct the Z height difference from z-probe position and hotend tip position. - // The Z height on homing is measured by Z-Probe, but the probe is quite far from the hotend. - // When the bed is uneven, this height must be corrected. - real_z = float(st_get_position(Z_AXIS)) / axis_steps_per_unit[Z_AXIS]; //get the real Z (since the auto bed leveling is already correcting the plane) - x_tmp = current_position[X_AXIS] + X_PROBE_OFFSET_FROM_EXTRUDER; - y_tmp = current_position[Y_AXIS] + Y_PROBE_OFFSET_FROM_EXTRUDER; - z_tmp = current_position[Z_AXIS]; + // Correct the Z height difference from z-probe position and hotend tip position. + // The Z height on homing is measured by Z-Probe, but the probe is quite far from the hotend. + // When the bed is uneven, this height must be corrected. + real_z = float(st_get_position(Z_AXIS)) / axis_steps_per_unit[Z_AXIS]; //get the real Z (since the auto bed leveling is already correcting the plane) + x_tmp = current_position[X_AXIS] + X_PROBE_OFFSET_FROM_EXTRUDER; + y_tmp = current_position[Y_AXIS] + Y_PROBE_OFFSET_FROM_EXTRUDER; + z_tmp = current_position[Z_AXIS]; - apply_rotation_xyz(plan_bed_level_matrix, x_tmp, y_tmp, z_tmp); //Apply the correction sending the probe offset - current_position[Z_AXIS] = z_tmp - real_z + current_position[Z_AXIS]; //The difference is added to current position and sent to planner. - plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); - #endif + apply_rotation_xyz(plan_bed_level_matrix, x_tmp, y_tmp, z_tmp); //Apply the correction sending the probe offset + current_position[Z_AXIS] = z_tmp - real_z + current_position[Z_AXIS]; //The difference is added to current position and sent to planner. + plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); + #endif - #ifdef Z_PROBE_SLED - dock_sled(true, -SLED_DOCKING_OFFSET); // dock the probe, correcting for over-travel - #elif defined(Z_PROBE_ALLEN_KEY) - retract_z_probe(); - #endif - - #ifdef Z_PROBE_END_SCRIPT - enquecommands_P(PSTR(Z_PROBE_END_SCRIPT)); - st_synchronize(); - #endif + #ifdef Z_PROBE_SLED + dock_sled(true, -SLED_DOCKING_OFFSET); // dock the probe, correcting for over-travel + #elif defined(Z_PROBE_ALLEN_KEY) //|| defined(SERVO_LEVELING) + retract_z_probe(); + #endif + + #ifdef Z_PROBE_END_SCRIPT + enquecommands_P(PSTR(Z_PROBE_END_SCRIPT)); + st_synchronize(); + #endif } #ifndef Z_PROBE_SLED diff --git a/Marlin/mesh_bed_leveling.cpp b/Marlin/mesh_bed_leveling.cpp index b383fe589..a48a6e619 100644 --- a/Marlin/mesh_bed_leveling.cpp +++ b/Marlin/mesh_bed_leveling.cpp @@ -1,20 +1,16 @@ #include "mesh_bed_leveling.h" -#if defined(MESH_BED_LEVELING) +#ifdef MESH_BED_LEVELING -mesh_bed_leveling mbl; + mesh_bed_leveling mbl; -mesh_bed_leveling::mesh_bed_leveling() { - reset(); -} - -void mesh_bed_leveling::reset() { - for (int y=0; y get_x(i) && i < MESH_NUM_X_POINTS-1) { - i++; - } - return i-1; + int i = 1; + while (x > get_x(i) && i < MESH_NUM_X_POINTS-1) i++; + return i - 1; } int select_y_index(float y) { - int i = 1; - while (y > get_y(i) && i < MESH_NUM_Y_POINTS-1) { - i++; - } - return i-1; + int i = 1; + while (y > get_y(i) && i < MESH_NUM_Y_POINTS - 1) i++; + return i - 1; } float calc_z0(float a0, float a1, float z1, float a2, float z2) { - float delta_z = (z2 - z1)/(a2 - a1); - float delta_a = a0 - a1; - return z1 + delta_a * delta_z; + float delta_z = (z2 - z1)/(a2 - a1); + float delta_a = a0 - a1; + return z1 + delta_a * delta_z; } float get_z(float x0, float y0) { - int x_index = select_x_index(x0); - int y_index = select_y_index(y0); - float z1 = calc_z0(x0, - get_x(x_index), z_values[y_index][x_index], - get_x(x_index+1), z_values[y_index][x_index+1]); - float z2 = calc_z0(x0, - get_x(x_index), z_values[y_index+1][x_index], - get_x(x_index+1), z_values[y_index+1][x_index+1]); - float z0 = calc_z0(y0, - get_y(y_index), z1, - get_y(y_index+1), z2); - return z0; + int x_index = select_x_index(x0); + int y_index = select_y_index(y0); + float z1 = calc_z0(x0, + get_x(x_index), z_values[y_index][x_index], + get_x(x_index+1), z_values[y_index][x_index+1]); + float z2 = calc_z0(x0, + get_x(x_index), z_values[y_index+1][x_index], + get_x(x_index+1), z_values[y_index+1][x_index+1]); + float z0 = calc_z0(y0, + get_y(y_index), z1, + get_y(y_index+1), z2); + return z0; } -}; + }; -extern mesh_bed_leveling mbl; + extern mesh_bed_leveling mbl; #endif // MESH_BED_LEVELING From 5261d35737f4a129327de8c5b9ed7e7f4cccbe30 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 25 Mar 2015 21:20:50 -0700 Subject: [PATCH 02/14] Fix custom m-code behavior MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Don’t set CUSTOM_M_CODE_SET_Z_PROBE_OFFSET if there’s no Z probe --- Marlin/Configuration.h | 8 +++++--- Marlin/configurator/config/Configuration.h | 8 +++++--- Marlin/example_configurations/Felix/Configuration.h | 8 +++++--- Marlin/example_configurations/Felix/Configuration_DUAL.h | 8 +++++--- Marlin/example_configurations/Hephestos/Configuration.h | 8 +++++--- Marlin/example_configurations/K8200/Configuration.h | 8 +++++--- Marlin/example_configurations/SCARA/Configuration.h | 8 +++++--- Marlin/example_configurations/WITBOX/Configuration.h | 8 +++++--- .../example_configurations/delta/generic/Configuration.h | 8 +++++--- .../delta/kossel_mini/Configuration.h | 8 +++++--- Marlin/example_configurations/makibox/Configuration.h | 8 +++++--- .../example_configurations/tvrrug/Round2/Configuration.h | 8 +++++--- 12 files changed, 60 insertions(+), 36 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index f5a36e6b9..cb46c530e 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -533,9 +533,11 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o // Custom M code points #define CUSTOM_M_CODES #ifdef CUSTOM_M_CODES - #define CUSTOM_M_CODE_SET_Z_PROBE_OFFSET 851 - #define Z_PROBE_OFFSET_RANGE_MIN -15 - #define Z_PROBE_OFFSET_RANGE_MAX -5 + #ifdef ENABLE_AUTO_BED_LEVELING + #define CUSTOM_M_CODE_SET_Z_PROBE_OFFSET 851 + #define Z_PROBE_OFFSET_RANGE_MIN -15 + #define Z_PROBE_OFFSET_RANGE_MAX -5 + #endif #endif diff --git a/Marlin/configurator/config/Configuration.h b/Marlin/configurator/config/Configuration.h index 71cbdebae..78c40b2e9 100644 --- a/Marlin/configurator/config/Configuration.h +++ b/Marlin/configurator/config/Configuration.h @@ -570,9 +570,11 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of // Custom M code points #define CUSTOM_M_CODES #ifdef CUSTOM_M_CODES - #define CUSTOM_M_CODE_SET_Z_PROBE_OFFSET 851 - #define Z_PROBE_OFFSET_RANGE_MIN -15 - #define Z_PROBE_OFFSET_RANGE_MAX -5 + #ifdef ENABLE_AUTO_BED_LEVELING + #define CUSTOM_M_CODE_SET_Z_PROBE_OFFSET 851 + #define Z_PROBE_OFFSET_RANGE_MIN -15 + #define Z_PROBE_OFFSET_RANGE_MAX -5 + #endif #endif // @section extras diff --git a/Marlin/example_configurations/Felix/Configuration.h b/Marlin/example_configurations/Felix/Configuration.h index e9801813f..17631860c 100644 --- a/Marlin/example_configurations/Felix/Configuration.h +++ b/Marlin/example_configurations/Felix/Configuration.h @@ -512,9 +512,11 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of // Custom M code points #define CUSTOM_M_CODES #ifdef CUSTOM_M_CODES - #define CUSTOM_M_CODE_SET_Z_PROBE_OFFSET 851 - #define Z_PROBE_OFFSET_RANGE_MIN -15 - #define Z_PROBE_OFFSET_RANGE_MAX -5 + #ifdef ENABLE_AUTO_BED_LEVELING + #define CUSTOM_M_CODE_SET_Z_PROBE_OFFSET 851 + #define Z_PROBE_OFFSET_RANGE_MIN -15 + #define Z_PROBE_OFFSET_RANGE_MAX -5 + #endif #endif diff --git a/Marlin/example_configurations/Felix/Configuration_DUAL.h b/Marlin/example_configurations/Felix/Configuration_DUAL.h index e9e4623ca..e72277417 100644 --- a/Marlin/example_configurations/Felix/Configuration_DUAL.h +++ b/Marlin/example_configurations/Felix/Configuration_DUAL.h @@ -512,9 +512,11 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of // Custom M code points #define CUSTOM_M_CODES #ifdef CUSTOM_M_CODES - #define CUSTOM_M_CODE_SET_Z_PROBE_OFFSET 851 - #define Z_PROBE_OFFSET_RANGE_MIN -15 - #define Z_PROBE_OFFSET_RANGE_MAX -5 + #ifdef ENABLE_AUTO_BED_LEVELING + #define CUSTOM_M_CODE_SET_Z_PROBE_OFFSET 851 + #define Z_PROBE_OFFSET_RANGE_MIN -15 + #define Z_PROBE_OFFSET_RANGE_MAX -5 + #endif #endif diff --git a/Marlin/example_configurations/Hephestos/Configuration.h b/Marlin/example_configurations/Hephestos/Configuration.h index c5b0243d5..1e726a0b7 100644 --- a/Marlin/example_configurations/Hephestos/Configuration.h +++ b/Marlin/example_configurations/Hephestos/Configuration.h @@ -540,9 +540,11 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of // Custom M code points #define CUSTOM_M_CODES #ifdef CUSTOM_M_CODES - #define CUSTOM_M_CODE_SET_Z_PROBE_OFFSET 851 - #define Z_PROBE_OFFSET_RANGE_MIN -15 - #define Z_PROBE_OFFSET_RANGE_MAX -5 + #ifdef ENABLE_AUTO_BED_LEVELING + #define CUSTOM_M_CODE_SET_Z_PROBE_OFFSET 851 + #define Z_PROBE_OFFSET_RANGE_MIN -15 + #define Z_PROBE_OFFSET_RANGE_MAX -5 + #endif #endif diff --git a/Marlin/example_configurations/K8200/Configuration.h b/Marlin/example_configurations/K8200/Configuration.h index bc0f3e5df..edb026b7a 100644 --- a/Marlin/example_configurations/K8200/Configuration.h +++ b/Marlin/example_configurations/K8200/Configuration.h @@ -544,9 +544,11 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of // Custom M code points #define CUSTOM_M_CODES #ifdef CUSTOM_M_CODES - #define CUSTOM_M_CODE_SET_Z_PROBE_OFFSET 851 - #define Z_PROBE_OFFSET_RANGE_MIN -15 - #define Z_PROBE_OFFSET_RANGE_MAX -5 + #ifdef ENABLE_AUTO_BED_LEVELING + #define CUSTOM_M_CODE_SET_Z_PROBE_OFFSET 851 + #define Z_PROBE_OFFSET_RANGE_MIN -15 + #define Z_PROBE_OFFSET_RANGE_MAX -5 + #endif #endif diff --git a/Marlin/example_configurations/SCARA/Configuration.h b/Marlin/example_configurations/SCARA/Configuration.h index d42bebe3a..79b3ded98 100644 --- a/Marlin/example_configurations/SCARA/Configuration.h +++ b/Marlin/example_configurations/SCARA/Configuration.h @@ -570,9 +570,11 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of // Custom M code points //#define CUSTOM_M_CODES #ifdef CUSTOM_M_CODES - #define CUSTOM_M_CODE_SET_Z_PROBE_OFFSET 851 - #define Z_PROBE_OFFSET_RANGE_MIN -15 - #define Z_PROBE_OFFSET_RANGE_MAX -5 + #ifdef ENABLE_AUTO_BED_LEVELING + #define CUSTOM_M_CODE_SET_Z_PROBE_OFFSET 851 + #define Z_PROBE_OFFSET_RANGE_MIN -15 + #define Z_PROBE_OFFSET_RANGE_MAX -5 + #endif #endif diff --git a/Marlin/example_configurations/WITBOX/Configuration.h b/Marlin/example_configurations/WITBOX/Configuration.h index 481b59125..6362bb997 100644 --- a/Marlin/example_configurations/WITBOX/Configuration.h +++ b/Marlin/example_configurations/WITBOX/Configuration.h @@ -537,9 +537,11 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of // Custom M code points #define CUSTOM_M_CODES #ifdef CUSTOM_M_CODES - #define CUSTOM_M_CODE_SET_Z_PROBE_OFFSET 851 - #define Z_PROBE_OFFSET_RANGE_MIN -15 - #define Z_PROBE_OFFSET_RANGE_MAX -5 + #ifdef ENABLE_AUTO_BED_LEVELING + #define CUSTOM_M_CODE_SET_Z_PROBE_OFFSET 851 + #define Z_PROBE_OFFSET_RANGE_MIN -15 + #define Z_PROBE_OFFSET_RANGE_MAX -5 + #endif #endif diff --git a/Marlin/example_configurations/delta/generic/Configuration.h b/Marlin/example_configurations/delta/generic/Configuration.h index 0baf7de1c..9a4165605 100644 --- a/Marlin/example_configurations/delta/generic/Configuration.h +++ b/Marlin/example_configurations/delta/generic/Configuration.h @@ -553,9 +553,11 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of // Custom M code points #define CUSTOM_M_CODES #ifdef CUSTOM_M_CODES - #define CUSTOM_M_CODE_SET_Z_PROBE_OFFSET 851 - #define Z_PROBE_OFFSET_RANGE_MIN -15 - #define Z_PROBE_OFFSET_RANGE_MAX -5 + #ifdef ENABLE_AUTO_BED_LEVELING + #define CUSTOM_M_CODE_SET_Z_PROBE_OFFSET 851 + #define Z_PROBE_OFFSET_RANGE_MIN -15 + #define Z_PROBE_OFFSET_RANGE_MAX -5 + #endif #endif diff --git a/Marlin/example_configurations/delta/kossel_mini/Configuration.h b/Marlin/example_configurations/delta/kossel_mini/Configuration.h index 9f5f89ca5..ca77c3984 100644 --- a/Marlin/example_configurations/delta/kossel_mini/Configuration.h +++ b/Marlin/example_configurations/delta/kossel_mini/Configuration.h @@ -555,9 +555,11 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o // Custom M code points #define CUSTOM_M_CODES #ifdef CUSTOM_M_CODES - #define CUSTOM_M_CODE_SET_Z_PROBE_OFFSET 851 - #define Z_PROBE_OFFSET_RANGE_MIN -15 - #define Z_PROBE_OFFSET_RANGE_MAX -5 + #ifdef ENABLE_AUTO_BED_LEVELING + #define CUSTOM_M_CODE_SET_Z_PROBE_OFFSET 851 + #define Z_PROBE_OFFSET_RANGE_MIN -15 + #define Z_PROBE_OFFSET_RANGE_MAX -5 + #endif #endif diff --git a/Marlin/example_configurations/makibox/Configuration.h b/Marlin/example_configurations/makibox/Configuration.h index f6561b3af..341ac6034 100644 --- a/Marlin/example_configurations/makibox/Configuration.h +++ b/Marlin/example_configurations/makibox/Configuration.h @@ -535,9 +535,11 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of // Custom M code points #define CUSTOM_M_CODES #ifdef CUSTOM_M_CODES - #define CUSTOM_M_CODE_SET_Z_PROBE_OFFSET 851 - #define Z_PROBE_OFFSET_RANGE_MIN -15 - #define Z_PROBE_OFFSET_RANGE_MAX -5 + #ifdef ENABLE_AUTO_BED_LEVELING + #define CUSTOM_M_CODE_SET_Z_PROBE_OFFSET 851 + #define Z_PROBE_OFFSET_RANGE_MIN -15 + #define Z_PROBE_OFFSET_RANGE_MAX -5 + #endif #endif diff --git a/Marlin/example_configurations/tvrrug/Round2/Configuration.h b/Marlin/example_configurations/tvrrug/Round2/Configuration.h index 17928b536..da82ccd63 100644 --- a/Marlin/example_configurations/tvrrug/Round2/Configuration.h +++ b/Marlin/example_configurations/tvrrug/Round2/Configuration.h @@ -542,9 +542,11 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of // Custom M code points #define CUSTOM_M_CODES #ifdef CUSTOM_M_CODES - #define CUSTOM_M_CODE_SET_Z_PROBE_OFFSET 851 - #define Z_PROBE_OFFSET_RANGE_MIN -15 - #define Z_PROBE_OFFSET_RANGE_MAX -5 + #ifdef ENABLE_AUTO_BED_LEVELING + #define CUSTOM_M_CODE_SET_Z_PROBE_OFFSET 851 + #define Z_PROBE_OFFSET_RANGE_MIN -15 + #define Z_PROBE_OFFSET_RANGE_MAX -5 + #endif #endif From 32331faee49b426bf5966816687dc56fd0aa8ea7 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 25 Mar 2015 22:13:59 -0700 Subject: [PATCH 03/14] Prettify Bed Level Correction Matrix - Put + in front of positive values in the output --- Marlin/vector_3.cpp | 84 ++++++++++++++++----------------------------- 1 file changed, 30 insertions(+), 54 deletions(-) diff --git a/Marlin/vector_3.cpp b/Marlin/vector_3.cpp index 2e42da553..681eceec2 100644 --- a/Marlin/vector_3.cpp +++ b/Marlin/vector_3.cpp @@ -26,57 +26,40 @@ vector_3::vector_3() : x(0), y(0), z(0) { } vector_3::vector_3(float x_, float y_, float z_) : x(x_), y(y_), z(z_) { } -vector_3 vector_3::cross(vector_3 left, vector_3 right) -{ +vector_3 vector_3::cross(vector_3 left, vector_3 right) { return vector_3(left.y * right.z - left.z * right.y, left.z * right.x - left.x * right.z, left.x * right.y - left.y * right.x); } -vector_3 vector_3::operator+(vector_3 v) -{ - return vector_3((x + v.x), (y + v.y), (z + v.z)); -} +vector_3 vector_3::operator+(vector_3 v) { return vector_3((x + v.x), (y + v.y), (z + v.z)); } +vector_3 vector_3::operator-(vector_3 v) { return vector_3((x - v.x), (y - v.y), (z - v.z)); } -vector_3 vector_3::operator-(vector_3 v) -{ - return vector_3((x - v.x), (y - v.y), (z - v.z)); -} - -vector_3 vector_3::get_normal() -{ +vector_3 vector_3::get_normal() { vector_3 normalized = vector_3(x, y, z); normalized.normalize(); return normalized; } -float vector_3::get_length() -{ - float length = sqrt((x * x) + (y * y) + (z * z)); - return length; -} - -void vector_3::normalize() -{ +float vector_3::get_length() { return sqrt((x * x) + (y * y) + (z * z)); } + +void vector_3::normalize() { float length = get_length(); x /= length; y /= length; z /= length; } -void vector_3::apply_rotation(matrix_3x3 matrix) -{ +void vector_3::apply_rotation(matrix_3x3 matrix) { float resultX = x * matrix.matrix[3*0+0] + y * matrix.matrix[3*1+0] + z * matrix.matrix[3*2+0]; float resultY = x * matrix.matrix[3*0+1] + y * matrix.matrix[3*1+1] + z * matrix.matrix[3*2+1]; float resultZ = x * matrix.matrix[3*0+2] + y * matrix.matrix[3*1+2] + z * matrix.matrix[3*2+2]; - x = resultX; y = resultY; z = resultZ; } -void vector_3::debug(char* title) -{ +void vector_3::debug(char* title) { SERIAL_PROTOCOL(title); SERIAL_PROTOCOLPGM(" x: "); SERIAL_PROTOCOL_F(x, 6); @@ -87,8 +70,7 @@ void vector_3::debug(char* title) SERIAL_EOL; } -void apply_rotation_xyz(matrix_3x3 matrix, float &x, float& y, float& z) -{ +void apply_rotation_xyz(matrix_3x3 matrix, float &x, float& y, float& z) { vector_3 vector = vector_3(x, y, z); vector.apply_rotation(matrix); x = vector.x; @@ -96,48 +78,41 @@ void apply_rotation_xyz(matrix_3x3 matrix, float &x, float& y, float& z) z = vector.z; } -matrix_3x3 matrix_3x3::create_from_rows(vector_3 row_0, vector_3 row_1, vector_3 row_2) -{ - //row_0.debug("row_0"); - //row_1.debug("row_1"); - //row_2.debug("row_2"); +matrix_3x3 matrix_3x3::create_from_rows(vector_3 row_0, vector_3 row_1, vector_3 row_2) { + //row_0.debug("row_0"); + //row_1.debug("row_1"); + //row_2.debug("row_2"); matrix_3x3 new_matrix; new_matrix.matrix[0] = row_0.x; new_matrix.matrix[1] = row_0.y; new_matrix.matrix[2] = row_0.z; new_matrix.matrix[3] = row_1.x; new_matrix.matrix[4] = row_1.y; new_matrix.matrix[5] = row_1.z; new_matrix.matrix[6] = row_2.x; new_matrix.matrix[7] = row_2.y; new_matrix.matrix[8] = row_2.z; - //new_matrix.debug("new_matrix"); - + //new_matrix.debug("new_matrix"); return new_matrix; } -void matrix_3x3::set_to_identity() -{ +void matrix_3x3::set_to_identity() { matrix[0] = 1; matrix[1] = 0; matrix[2] = 0; matrix[3] = 0; matrix[4] = 1; matrix[5] = 0; matrix[6] = 0; matrix[7] = 0; matrix[8] = 1; } -matrix_3x3 matrix_3x3::create_look_at(vector_3 target) -{ - vector_3 z_row = target.get_normal(); - vector_3 x_row = vector_3(1, 0, -target.x/target.z).get_normal(); - vector_3 y_row = vector_3::cross(z_row, x_row).get_normal(); +matrix_3x3 matrix_3x3::create_look_at(vector_3 target) { + vector_3 z_row = target.get_normal(); + vector_3 x_row = vector_3(1, 0, -target.x/target.z).get_normal(); + vector_3 y_row = vector_3::cross(z_row, x_row).get_normal(); - // x_row.debug("x_row"); - // y_row.debug("y_row"); - // z_row.debug("z_row"); + // x_row.debug("x_row"); + // y_row.debug("y_row"); + // z_row.debug("z_row"); - - // create the matrix already correctly transposed - matrix_3x3 rot = matrix_3x3::create_from_rows(x_row, y_row, z_row); + // create the matrix already correctly transposed + matrix_3x3 rot = matrix_3x3::create_from_rows(x_row, y_row, z_row); - // rot.debug("rot"); - return rot; + // rot.debug("rot"); + return rot; } - -matrix_3x3 matrix_3x3::transpose(matrix_3x3 original) -{ +matrix_3x3 matrix_3x3::transpose(matrix_3x3 original) { matrix_3x3 new_matrix; new_matrix.matrix[0] = original.matrix[0]; new_matrix.matrix[1] = original.matrix[3]; new_matrix.matrix[2] = original.matrix[6]; new_matrix.matrix[3] = original.matrix[1]; new_matrix.matrix[4] = original.matrix[4]; new_matrix.matrix[5] = original.matrix[7]; @@ -150,6 +125,7 @@ void matrix_3x3::debug(char* title) { int count = 0; for(int i=0; i<3; i++) { for(int j=0; j<3; j++) { + if (matrix[count] >= 0.0) SERIAL_PROTOCOLPGM("+"); SERIAL_PROTOCOL_F(matrix[count], 6); SERIAL_PROTOCOLPGM(" "); count++; @@ -158,5 +134,5 @@ void matrix_3x3::debug(char* title) { } } -#endif // #ifdef ENABLE_AUTO_BED_LEVELING +#endif // ENABLE_AUTO_BED_LEVELING From abadeac08dd19739d30ef5d5c54086772ca7f022 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 25 Mar 2015 23:06:33 -0700 Subject: [PATCH 04/14] Group zprobe_zoffset with bed leveling --- Marlin/ConfigurationStore.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Marlin/ConfigurationStore.cpp b/Marlin/ConfigurationStore.cpp index ac41d7b65..2ae1e19a8 100644 --- a/Marlin/ConfigurationStore.cpp +++ b/Marlin/ConfigurationStore.cpp @@ -470,9 +470,13 @@ void Config_ResetDefault() { max_e_jerk = DEFAULT_EJERK; home_offset[X_AXIS] = home_offset[Y_AXIS] = home_offset[Z_AXIS] = 0; - #if defined(MESH_BED_LEVELING) + #ifdef MESH_BED_LEVELING mbl.active = 0; - #endif // MESH_BED_LEVELING + #endif + + #ifdef ENABLE_AUTO_BED_LEVELING + zprobe_zoffset = -Z_PROBE_OFFSET_FROM_EXTRUDER; + #endif #ifdef DELTA endstop_adj[X_AXIS] = endstop_adj[Y_AXIS] = endstop_adj[Z_AXIS] = 0; @@ -493,10 +497,6 @@ void Config_ResetDefault() { absPreheatFanSpeed = ABS_PREHEAT_FAN_SPEED; #endif - #ifdef ENABLE_AUTO_BED_LEVELING - zprobe_zoffset = -Z_PROBE_OFFSET_FROM_EXTRUDER; - #endif - #ifdef DOGLCD lcd_contrast = DEFAULT_LCD_CONTRAST; #endif From 78090275a9999f8fd4a335576891f7087a2c304b Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 26 Mar 2015 13:52:48 -0700 Subject: [PATCH 05/14] Fix probe range editing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Increase the probe offset range to -20…20 - Apply the range limits to the menu item --- Marlin/Configuration.h | 4 ++-- Marlin/ultralcd.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index d191ead2a..760c3f260 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -534,8 +534,8 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o #ifdef CUSTOM_M_CODES #ifdef ENABLE_AUTO_BED_LEVELING #define CUSTOM_M_CODE_SET_Z_PROBE_OFFSET 851 - #define Z_PROBE_OFFSET_RANGE_MIN -15 - #define Z_PROBE_OFFSET_RANGE_MAX -5 + #define Z_PROBE_OFFSET_RANGE_MIN -20 + #define Z_PROBE_OFFSET_RANGE_MAX 20 #endif #endif diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index f6af156d5..623327181 100644 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -911,7 +911,7 @@ static void lcd_control_motion_menu() { START_MENU(); MENU_ITEM(back, MSG_CONTROL, lcd_control_menu); #ifdef ENABLE_AUTO_BED_LEVELING - MENU_ITEM_EDIT(float32, MSG_ZPROBE_ZOFFSET, &zprobe_zoffset, 0.0, 50); + MENU_ITEM_EDIT(float32, MSG_ZPROBE_ZOFFSET, &zprobe_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX); #endif MENU_ITEM_EDIT(float5, MSG_ACC, &acceleration, 10, 99000); MENU_ITEM_EDIT(float3, MSG_VXY_JERK, &max_xy_jerk, 1, 990); From 04328d7537807ebfe0520927aaf686a4b3a6969e Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 26 Mar 2015 15:29:16 -0700 Subject: [PATCH 06/14] Add zprobe_zoffset in set_bed_level_equation_* - Also a small tweak to SanityCheck.h --- Marlin/Marlin_main.cpp | 5 ++--- Marlin/SanityCheck.h | 8 ++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 8b4472ab7..19d07cbe7 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1090,7 +1090,7 @@ static void set_bed_level_equation_lsq(double *plane_equation_coefficients) // corrected_position.debug("position after"); current_position[X_AXIS] = corrected_position.x; current_position[Y_AXIS] = corrected_position.y; - current_position[Z_AXIS] = corrected_position.z; + current_position[Z_AXIS] = corrected_position.z + zprobe_zoffset; plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); } @@ -1116,10 +1116,9 @@ static void set_bed_level_equation_3pts(float z_at_pt_1, float z_at_pt_2, float vector_3 corrected_position = plan_get_position(); current_position[X_AXIS] = corrected_position.x; current_position[Y_AXIS] = corrected_position.y; - current_position[Z_AXIS] = corrected_position.z; + current_position[Z_AXIS] = corrected_position.z + zprobe_zoffset; plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); - } #endif // AUTO_BED_LEVELING_GRID diff --git a/Marlin/SanityCheck.h b/Marlin/SanityCheck.h index a8937b44b..d5183abba 100644 --- a/Marlin/SanityCheck.h +++ b/Marlin/SanityCheck.h @@ -104,13 +104,13 @@ // Make sure probing points are reachable #if LEFT_PROBE_BED_POSITION < MIN_PROBE_X - #error The given LEFT_PROBE_BED_POSITION can't be reached by the probe. + #error "The given LEFT_PROBE_BED_POSITION can't be reached by the probe." #elif RIGHT_PROBE_BED_POSITION > MAX_PROBE_X - #error The given RIGHT_PROBE_BED_POSITION can't be reached by the probe. + #error "The given RIGHT_PROBE_BED_POSITION can't be reached by the probe." #elif FRONT_PROBE_BED_POSITION < MIN_PROBE_Y - #error The given FRONT_PROBE_BED_POSITION can't be reached by the probe. + #error "The given FRONT_PROBE_BED_POSITION can't be reached by the probe." #elif BACK_PROBE_BED_POSITION > MAX_PROBE_Y - #error The given BACK_PROBE_BED_POSITION can't be reached by the probe. + #error "The given BACK_PROBE_BED_POSITION can't be reached by the probe." #endif #define PROBE_SIZE_X (X_PROBE_OFFSET_FROM_EXTRUDER * (AUTO_BED_LEVELING_GRID_POINTS-1)) From 53169d96e8f2df88b8bd0bd45234235c65dc78aa Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 26 Mar 2015 16:02:15 -0700 Subject: [PATCH 07/14] Set temp_meas_ready in set_current_temp_raw --- Marlin/temperature.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index cb7001324..0450d1ccd 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -226,7 +226,7 @@ void PID_autotune(float temp, int extruder, int ncycles) unsigned long ms = millis(); - if (temp_meas_ready == true) { // temp sample ready + if (temp_meas_ready) { // temp sample ready updateTemperaturesFromRawValues(); input = (extruder<0)?current_temperature_bed:current_temperature[extruder]; @@ -1198,6 +1198,7 @@ static void set_current_temp_raw() { redundant_temperature_raw = raw_temp_value[1]; #endif current_temperature_bed_raw = raw_temp_bed_value; + temp_meas_ready = true; } // @@ -1507,16 +1508,14 @@ ISR(TIMER0_COMPB_vect) { } // switch(temp_state) if (temp_count >= OVERSAMPLENR) { // 10 * 16 * 1/(16000000/64/256) = 164ms. - if (!temp_meas_ready) { //Only update the raw values if they have been read. Else we could be updating them during reading. - set_current_temp_raw(); - } //!temp_meas_ready + // Update the raw values if they've been read. Else we could be updating them during reading. + if (!temp_meas_ready) set_current_temp_raw(); // Filament Sensor - can be read any time since IIR filtering is used #if HAS_FILAMENT_SENSOR current_raw_filwidth = raw_filwidth_value >> 10; // Divide to get to 0-16384 range since we used 1/128 IIR filter approach #endif - temp_meas_ready = true; temp_count = 0; for (int i = 0; i < TEMP_SENSOR_COUNT; i++) raw_temp_value[i] = 0; raw_temp_bed_value = 0; From 0b3243155109c9c946ddc818919efb9099aa9ff6 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 26 Mar 2015 16:20:23 -0700 Subject: [PATCH 08/14] Remove abs() from planeNormal.z --- Marlin/Marlin_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 36156a3d2..47a4a7908 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1114,7 +1114,7 @@ static void set_bed_level_equation_3pts(float z_at_pt_1, float z_at_pt_2, float vector_3 from_2_to_1 = (pt1 - pt2).get_normal(); vector_3 from_2_to_3 = (pt3 - pt2).get_normal(); vector_3 planeNormal = vector_3::cross(from_2_to_1, from_2_to_3).get_normal(); - planeNormal = vector_3(planeNormal.x, planeNormal.y, abs(planeNormal.z)); + planeNormal = vector_3(planeNormal.x, planeNormal.y, planeNormal.z); plan_bed_level_matrix = matrix_3x3::create_look_at(planeNormal); From b76a352d41a2483409dfd471457d0db4fc0b9231 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 26 Mar 2015 17:14:07 -0700 Subject: [PATCH 09/14] Fix the planeNormal calculation --- Marlin/Marlin_main.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 47a4a7908..f1667cbf8 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1110,11 +1110,13 @@ static void set_bed_level_equation_3pts(float z_at_pt_1, float z_at_pt_2, float vector_3 pt1 = vector_3(ABL_PROBE_PT_1_X, ABL_PROBE_PT_1_Y, z_at_pt_1); vector_3 pt2 = vector_3(ABL_PROBE_PT_2_X, ABL_PROBE_PT_2_Y, z_at_pt_2); vector_3 pt3 = vector_3(ABL_PROBE_PT_3_X, ABL_PROBE_PT_3_Y, z_at_pt_3); + vector_3 planeNormal = vector_3::cross(pt1 - pt2, pt3 - pt2).get_normal(); - vector_3 from_2_to_1 = (pt1 - pt2).get_normal(); - vector_3 from_2_to_3 = (pt3 - pt2).get_normal(); - vector_3 planeNormal = vector_3::cross(from_2_to_1, from_2_to_3).get_normal(); - planeNormal = vector_3(planeNormal.x, planeNormal.y, planeNormal.z); + if (planeNormal.z < 0) { + planeNormal.x = -planeNormal.x; + planeNormal.y = -planeNormal.y; + planeNormal.z = -planeNormal.z; + } plan_bed_level_matrix = matrix_3x3::create_look_at(planeNormal); From 267d6bef15f7014b16f3fa093dc4a4f1fef621c3 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 26 Mar 2015 20:07:17 -0700 Subject: [PATCH 10/14] Eliminate most warnings - Fix a bug reading `code_value` for `M503 Sn` - Hide and remove unused variables --- Marlin/Marlin_main.cpp | 36 +++++++++++++++++++++--------------- Marlin/stepper.cpp | 6 +++--- Marlin/temperature.cpp | 2 +- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index f1667cbf8..ee620bfbb 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -3548,7 +3548,6 @@ inline void gcode_M200() { } } - float area = .0; if (code_seen('D')) { float diameter = code_value(); // setting any extruder filament size disables volumetric on the assumption that @@ -4286,7 +4285,7 @@ inline void gcode_M502() { * M503: print settings currently in memory */ inline void gcode_M503() { - Config_PrintSettings(code_seen('S') && code_value == 0); + Config_PrintSettings(code_seen('S') && code_value() == 0); } #ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED @@ -4583,9 +4582,14 @@ inline void gcode_T() { SERIAL_ECHOLN(MSG_INVALID_EXTRUDER); } else { - boolean make_move = false; + #if EXTRUDERS > 1 + bool make_move = false; + #endif + if (code_seen('F')) { - make_move = true; + #if EXTRUDERS > 1 + make_move = true; + #endif next_feedrate = code_value(); if (next_feedrate > 0.0) feedrate = next_feedrate; } @@ -5182,20 +5186,22 @@ void ClearToSend() SERIAL_PROTOCOLLNPGM(MSG_OK); } -void get_coordinates() -{ - bool seen[4]={false,false,false,false}; - for(int8_t i=0; i < NUM_AXIS; i++) { - if(code_seen(axis_codes[i])) - { - destination[i] = (float)code_value() + (axis_relative_modes[i] || relative_mode)*current_position[i]; - seen[i]=true; +void get_coordinates() { + for (int i = 0; i < NUM_AXIS; i++) { + float dest; + if (code_seen(axis_codes[i])) { + dest = code_value(); + if (axis_relative_modes[i] || relative_mode) + dest += current_position[i]; } - else destination[i] = current_position[i]; //Are these else lines really needed? + else + dest = current_position[i]; + + destination[i] = dest; } - if(code_seen('F')) { + if (code_seen('F')) { next_feedrate = code_value(); - if(next_feedrate > 0.0) feedrate = next_feedrate; + if (next_feedrate > 0.0) feedrate = next_feedrate; } } diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index 8be4b98af..8d55d7ba3 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -1176,8 +1176,6 @@ void digipot_current(uint8_t driver, int current) { } void microstep_init() { - const uint8_t microstep_modes[] = MICROSTEP_MODES; - #if defined(E1_MS1_PIN) && E1_MS1_PIN >= 0 pinMode(E1_MS1_PIN,OUTPUT); pinMode(E1_MS2_PIN,OUTPUT); @@ -1192,7 +1190,9 @@ void microstep_init() { pinMode(Z_MS2_PIN,OUTPUT); pinMode(E0_MS1_PIN,OUTPUT); pinMode(E0_MS2_PIN,OUTPUT); - for (int i = 0; i <= 4; i++) microstep_mode(i, microstep_modes[i]); + const uint8_t microstep_modes[] = MICROSTEP_MODES; + for (int i = 0; i < sizeof(microstep_modes) / sizeof(microstep_modes[0]); i++) + microstep_mode(i, microstep_modes[i]); #endif } diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index 4a5f7a7e5..6b26b0b5c 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -55,7 +55,7 @@ int target_temperature[EXTRUDERS] = { 0 }; int target_temperature_bed = 0; -int current_temperature_raw[EXTRUDERS] = { 0 }; +int current_temperature_raw[4] = { 0 }; float current_temperature[EXTRUDERS] = { 0.0 }; int current_temperature_bed_raw = 0; float current_temperature_bed = 0.0; From b2496533c6a5e632ec2fd537dac4ccfbbd53b4a9 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 26 Mar 2015 20:30:14 -0700 Subject: [PATCH 11/14] Put " M" into pmem --- Marlin/ConfigurationStore.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Marlin/ConfigurationStore.cpp b/Marlin/ConfigurationStore.cpp index 2ae1e19a8..939d83f9e 100644 --- a/Marlin/ConfigurationStore.cpp +++ b/Marlin/ConfigurationStore.cpp @@ -754,8 +754,7 @@ void Config_PrintSettings(bool forReplay) { SERIAL_ECHOLNPGM("Z-Probe Offset (mm):"); SERIAL_ECHO_START; } - SERIAL_ECHO(" M"); - SERIAL_ECHO(CUSTOM_M_CODE_SET_Z_PROBE_OFFSET); + SERIAL_ECHOPAIR(" M", CUSTOM_M_CODE_SET_Z_PROBE_OFFSET); SERIAL_ECHOPAIR(" Z", -zprobe_zoffset); #else if (!forReplay) { From 460f73056bd20458380c17fedaa5204e9b912570 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 27 Mar 2015 00:46:39 -0700 Subject: [PATCH 12/14] Fix ECHOPAIR ambiguity - Also patch up some warnings --- Marlin/ConfigurationStore.cpp | 2 +- Marlin/Marlin_main.cpp | 2 +- Marlin/vector_3.cpp | 4 ++-- Marlin/vector_3.h | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Marlin/ConfigurationStore.cpp b/Marlin/ConfigurationStore.cpp index 939d83f9e..3872b505d 100644 --- a/Marlin/ConfigurationStore.cpp +++ b/Marlin/ConfigurationStore.cpp @@ -754,7 +754,7 @@ void Config_PrintSettings(bool forReplay) { SERIAL_ECHOLNPGM("Z-Probe Offset (mm):"); SERIAL_ECHO_START; } - SERIAL_ECHOPAIR(" M", CUSTOM_M_CODE_SET_Z_PROBE_OFFSET); + SERIAL_ECHOPAIR(" M", (unsigned long)CUSTOM_M_CODE_SET_Z_PROBE_OFFSET); SERIAL_ECHOPAIR(" Z", -zprobe_zoffset); #else if (!forReplay) { diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index ee620bfbb..70fd46957 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -2922,7 +2922,7 @@ inline void gcode_M42() { do_blocking_move_to( X_probe_location, Y_probe_location, Z_start_location); // Make sure we are at the probe location if (n_legs) { - double radius=0.0, theta=0.0, x_sweep, y_sweep; + double radius=0.0, theta=0.0; int l; int rotational_direction = (unsigned long) millis() & 0x0001; // clockwise or counter clockwise radius = (unsigned long)millis() % (long)(X_MAX_LENGTH / 4); // limit how far out to go diff --git a/Marlin/vector_3.cpp b/Marlin/vector_3.cpp index 681eceec2..243f0838f 100644 --- a/Marlin/vector_3.cpp +++ b/Marlin/vector_3.cpp @@ -59,7 +59,7 @@ void vector_3::apply_rotation(matrix_3x3 matrix) { z = resultZ; } -void vector_3::debug(char* title) { +void vector_3::debug(const char title[]) { SERIAL_PROTOCOL(title); SERIAL_PROTOCOLPGM(" x: "); SERIAL_PROTOCOL_F(x, 6); @@ -120,7 +120,7 @@ matrix_3x3 matrix_3x3::transpose(matrix_3x3 original) { return new_matrix; } -void matrix_3x3::debug(char* title) { +void matrix_3x3::debug(const char title[]) { SERIAL_PROTOCOLLN(title); int count = 0; for(int i=0; i<3; i++) { diff --git a/Marlin/vector_3.h b/Marlin/vector_3.h index 0b9decafa..0c5938bac 100644 --- a/Marlin/vector_3.h +++ b/Marlin/vector_3.h @@ -37,7 +37,7 @@ struct vector_3 float get_length(); vector_3 get_normal(); - void debug(char* title); + void debug(const char title[]); void apply_rotation(matrix_3x3 matrix); }; @@ -52,7 +52,7 @@ struct matrix_3x3 void set_to_identity(); - void debug(char* title); + void debug(const char title[]); }; From fe29bdd72b899c5a236617a82c79cad18f41ab5b Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 27 Mar 2015 16:26:07 -0700 Subject: [PATCH 13/14] Also fix temperature externs --- Marlin/temperature.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Marlin/temperature.h b/Marlin/temperature.h index b29fc2b57..853179be5 100644 --- a/Marlin/temperature.h +++ b/Marlin/temperature.h @@ -41,10 +41,10 @@ void manage_heater(); //it is critical that this is called periodically. // low level conversion routines // do not use these routines and variables outside of temperature.cpp -extern int target_temperature[EXTRUDERS]; -extern float current_temperature[EXTRUDERS]; +extern int target_temperature[4]; +extern float current_temperature[4]; #ifdef SHOW_TEMP_ADC_VALUES - extern int current_temperature_raw[EXTRUDERS]; + extern int current_temperature_raw[4]; extern int current_temperature_bed_raw; #endif extern int target_temperature_bed; From df02b992b0879fd04ed4143f7c4be98cbe6c5a09 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 27 Mar 2015 16:37:22 -0700 Subject: [PATCH 14/14] Fix redundant_temperatrure_raw setting --- Marlin/temperature.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index 8f43aab08..7b7eceaf7 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -1181,9 +1181,10 @@ static void set_current_temp_raw() { #endif #if HAS_TEMP_1 #ifdef TEMP_SENSOR_1_AS_REDUNDANT - redundant_temperature_raw = + redundant_temperature_raw = raw_temp_value[1]; + #else + current_temperature_raw[1] = raw_temp_value[1]; #endif - current_temperature_raw[1] = raw_temp_value[1]; #if HAS_TEMP_2 current_temperature_raw[2] = raw_temp_value[2]; #if HAS_TEMP_3