Merge pull request #4310 from thinkyhead/rc_mbl_position_shift

Fix position shift with MBL
This commit is contained in:
Scott Lahteine 2016-07-17 18:31:25 -07:00 committed by GitHub
commit 3422103863
3 changed files with 50 additions and 65 deletions

View file

@ -7831,76 +7831,59 @@ void clamp_to_software_endstops(float target[3]) {
#if ENABLED(MESH_BED_LEVELING) #if ENABLED(MESH_BED_LEVELING)
// This function is used to split lines on mesh borders so each segment is only part of one mesh area // This function is used to split lines on mesh borders so each segment is only part of one mesh area
void mesh_buffer_line(float x, float y, float z, const float e, float fr_mm_s, const uint8_t& extruder, uint8_t x_splits = 0xff, uint8_t y_splits = 0xff) { void mesh_line_to_destination(float fr_mm_m, uint8_t x_splits = 0xff, uint8_t y_splits = 0xff) {
if (!mbl.active()) { int cx1 = mbl.cell_index_x(RAW_CURRENT_POSITION(X_AXIS)),
planner.buffer_line(x, y, z, e, fr_mm_s, extruder); cy1 = mbl.cell_index_y(RAW_CURRENT_POSITION(Y_AXIS)),
set_current_to_destination(); cx2 = mbl.cell_index_x(RAW_POSITION(destination[X_AXIS], X_AXIS)),
return; cy2 = mbl.cell_index_y(RAW_POSITION(destination[Y_AXIS], Y_AXIS));
} NOMORE(cx1, MESH_NUM_X_POINTS - 2);
int pcx = mbl.cell_index_x(RAW_CURRENT_POSITION(X_AXIS)), NOMORE(cy1, MESH_NUM_Y_POINTS - 2);
pcy = mbl.cell_index_y(RAW_CURRENT_POSITION(Y_AXIS)), NOMORE(cx2, MESH_NUM_X_POINTS - 2);
cx = mbl.cell_index_x(RAW_POSITION(x, X_AXIS)), NOMORE(cy2, MESH_NUM_Y_POINTS - 2);
cy = mbl.cell_index_y(RAW_POSITION(y, Y_AXIS));
NOMORE(pcx, MESH_NUM_X_POINTS - 2); if (cx1 == cx2 && cy1 == cy2) {
NOMORE(pcy, MESH_NUM_Y_POINTS - 2);
NOMORE(cx, MESH_NUM_X_POINTS - 2);
NOMORE(cy, MESH_NUM_Y_POINTS - 2);
if (pcx == cx && pcy == cy) {
// Start and end on same mesh square // Start and end on same mesh square
planner.buffer_line(x, y, z, e, fr_mm_s, extruder); line_to_destination(fr_mm_m);
set_current_to_destination(); set_current_to_destination();
return; return;
} }
float nx, ny, nz, ne, normalized_dist;
if (cx > pcx && TEST(x_splits, cx)) { #define MBL_SEGMENT_END(A) (current_position[A ##_AXIS] + (destination[A ##_AXIS] - current_position[A ##_AXIS]) * normalized_dist)
nx = mbl.get_probe_x(cx) + home_offset[X_AXIS];
normalized_dist = (nx - current_position[X_AXIS]) / (x - current_position[X_AXIS]); float normalized_dist, end[NUM_AXIS];
ny = current_position[Y_AXIS] + (y - current_position[Y_AXIS]) * normalized_dist;
nz = current_position[Z_AXIS] + (z - current_position[Z_AXIS]) * normalized_dist; // Split at the left/front border of the right/top square
ne = current_position[E_AXIS] + (e - current_position[E_AXIS]) * normalized_dist; int8_t gcx = max(cx1, cx2), gcy = max(cy1, cy2);
CBI(x_splits, cx); if (cx2 != cx1 && TEST(x_splits, gcx)) {
memcpy(end, destination, sizeof(end));
destination[X_AXIS] = mbl.get_probe_x(gcx) + home_offset[X_AXIS] + position_shift[X_AXIS];
normalized_dist = (destination[X_AXIS] - current_position[X_AXIS]) / (end[X_AXIS] - current_position[X_AXIS]);
destination[Y_AXIS] = MBL_SEGMENT_END(Y);
CBI(x_splits, gcx);
} }
else if (cx < pcx && TEST(x_splits, pcx)) { else if (cy2 != cy1 && TEST(y_splits, gcy)) {
nx = mbl.get_probe_x(pcx) + home_offset[X_AXIS]; memcpy(end, destination, sizeof(end));
normalized_dist = (nx - current_position[X_AXIS]) / (x - current_position[X_AXIS]); destination[Y_AXIS] = mbl.get_probe_y(gcy) + home_offset[Y_AXIS] + position_shift[Y_AXIS];
ny = current_position[Y_AXIS] + (y - current_position[Y_AXIS]) * normalized_dist; normalized_dist = (destination[Y_AXIS] - current_position[Y_AXIS]) / (end[Y_AXIS] - current_position[Y_AXIS]);
nz = current_position[Z_AXIS] + (z - current_position[Z_AXIS]) * normalized_dist; destination[X_AXIS] = MBL_SEGMENT_END(X);
ne = current_position[E_AXIS] + (e - current_position[E_AXIS]) * normalized_dist; CBI(y_splits, gcy);
CBI(x_splits, pcx);
}
else if (cy > pcy && TEST(y_splits, cy)) {
ny = mbl.get_probe_y(cy) + home_offset[Y_AXIS];
normalized_dist = (ny - current_position[Y_AXIS]) / (y - current_position[Y_AXIS]);
nx = current_position[X_AXIS] + (x - current_position[X_AXIS]) * normalized_dist;
nz = current_position[Z_AXIS] + (z - current_position[Z_AXIS]) * normalized_dist;
ne = current_position[E_AXIS] + (e - current_position[E_AXIS]) * normalized_dist;
CBI(y_splits, cy);
}
else if (cy < pcy && TEST(y_splits, pcy)) {
ny = mbl.get_probe_y(pcy) + home_offset[Y_AXIS];
normalized_dist = (ny - current_position[Y_AXIS]) / (y - current_position[Y_AXIS]);
nx = current_position[X_AXIS] + (x - current_position[X_AXIS]) * normalized_dist;
nz = current_position[Z_AXIS] + (z - current_position[Z_AXIS]) * normalized_dist;
ne = current_position[E_AXIS] + (e - current_position[E_AXIS]) * normalized_dist;
CBI(y_splits, pcy);
} }
else { else {
// Already split on a border // Already split on a border
planner.buffer_line(x, y, z, e, fr_mm_s, extruder); line_to_destination(fr_mm_m);
set_current_to_destination(); set_current_to_destination();
return; return;
} }
destination[Z_AXIS] = MBL_SEGMENT_END(Z);
destination[E_AXIS] = MBL_SEGMENT_END(E);
// Do the split and look for more borders // Do the split and look for more borders
destination[X_AXIS] = nx; mesh_line_to_destination(fr_mm_m, x_splits, y_splits);
destination[Y_AXIS] = ny;
destination[Z_AXIS] = nz; // Restore destination from stack
destination[E_AXIS] = ne; memcpy(destination, end, sizeof(end));
mesh_buffer_line(nx, ny, nz, ne, fr_mm_s, extruder, x_splits, y_splits); mesh_line_to_destination(fr_mm_m, x_splits, y_splits);
destination[X_AXIS] = x;
destination[Y_AXIS] = y;
destination[Z_AXIS] = z;
destination[E_AXIS] = e;
mesh_buffer_line(x, y, z, e, fr_mm_s, extruder, x_splits, y_splits);
} }
#endif // MESH_BED_LEVELING #endif // MESH_BED_LEVELING
@ -7997,11 +7980,13 @@ void mesh_buffer_line(float x, float y, float z, const float e, float fr_mm_s, c
} }
else { else {
#if ENABLED(MESH_BED_LEVELING) #if ENABLED(MESH_BED_LEVELING)
mesh_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], MMM_TO_MMS_SCALED(feedrate_mm_m), active_extruder); if (mbl.active()) {
return false; mesh_line_to_destination(MMM_SCALED(feedrate_mm_m));
#else return false;
line_to_destination(MMM_SCALED(feedrate_mm_m)); }
else
#endif #endif
line_to_destination(MMM_SCALED(feedrate_mm_m));
} }
return true; return true;
} }

View file

@ -238,8 +238,8 @@
#error "MESH_BED_LEVELING does not yet support DELTA printers." #error "MESH_BED_LEVELING does not yet support DELTA printers."
#elif ENABLED(AUTO_BED_LEVELING_FEATURE) #elif ENABLED(AUTO_BED_LEVELING_FEATURE)
#error "Select AUTO_BED_LEVELING_FEATURE or MESH_BED_LEVELING, not both." #error "Select AUTO_BED_LEVELING_FEATURE or MESH_BED_LEVELING, not both."
#elif MESH_NUM_X_POINTS > 7 || MESH_NUM_Y_POINTS > 7 #elif MESH_NUM_X_POINTS > 9 || MESH_NUM_Y_POINTS > 9
#error "MESH_NUM_X_POINTS and MESH_NUM_Y_POINTS need to be less than 8." #error "MESH_NUM_X_POINTS and MESH_NUM_Y_POINTS must be less than 10."
#endif #endif
#elif ENABLED(MANUAL_BED_LEVELING) #elif ENABLED(MANUAL_BED_LEVELING)
#error "MESH_BED_LEVELING is required for MANUAL_BED_LEVELING." #error "MESH_BED_LEVELING is required for MANUAL_BED_LEVELING."

View file

@ -67,7 +67,7 @@
* 203 z_offset (float) * 203 z_offset (float)
* 207 mesh_num_x (uint8 as set in firmware) * 207 mesh_num_x (uint8 as set in firmware)
* 208 mesh_num_y (uint8 as set in firmware) * 208 mesh_num_y (uint8 as set in firmware)
* 209 G29 S3 XYZ z_values[][] (float x9, by default) * 209 G29 S3 XYZ z_values[][] (float x9, by default, up to float x 81)
* *
* AUTO BED LEVELING * AUTO BED LEVELING
* 245 M851 zprobe_zoffset (float) * 245 M851 zprobe_zoffset (float)