Add M851 X Y probe offsets (#15202)

This commit is contained in:
InsanityAutomation
2019-09-24 22:29:21 -04:00
committed by Scott Lahteine
parent ebc9a8a0b0
commit df1e51258a
151 changed files with 1009 additions and 1878 deletions

View File

@ -47,10 +47,12 @@ void GcodeSuite::G42() {
set_destination_from_current();
if (hasI) destination[X_AXIS] = _GET_MESH_X(ix);
if (hasJ) destination[Y_AXIS] = _GET_MESH_Y(iy);
if (parser.boolval('P')) {
if (hasI) destination[X_AXIS] -= X_PROBE_OFFSET_FROM_EXTRUDER;
if (hasJ) destination[Y_AXIS] -= Y_PROBE_OFFSET_FROM_EXTRUDER;
}
#if HAS_BED_PROBE
if (parser.boolval('P')) {
if (hasI) destination[X_AXIS] -= zprobe_offset[X_AXIS];
if (hasJ) destination[Y_AXIS] -= zprobe_offset[Y_AXIS];
}
#endif
const float fval = parser.linearval('F');
if (fval > 0.0) feedrate_mm_s = MMM_TO_MMS(fval);

View File

@ -64,10 +64,12 @@ void GcodeSuite::M420() {
#if ENABLED(MARLIN_DEV_MODE)
if (parser.intval('S') == 2) {
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
bilinear_start[X_AXIS] = MIN_PROBE_X;
bilinear_start[Y_AXIS] = MIN_PROBE_Y;
bilinear_grid_spacing[X_AXIS] = (MAX_PROBE_X - (MIN_PROBE_X)) / (GRID_MAX_POINTS_X - 1);
bilinear_grid_spacing[Y_AXIS] = (MAX_PROBE_Y - (MIN_PROBE_Y)) / (GRID_MAX_POINTS_Y - 1);
const float x_min = probe_min_x(), x_max = probe_max_x(),
y_min = probe_min_y(), y_max = probe_max_y();
bilinear_start[X_AXIS] = x_min;
bilinear_start[Y_AXIS] = y_min;
bilinear_grid_spacing[X_AXIS] = (x_max - x_min) / (GRID_MAX_POINTS_X - 1);
bilinear_grid_spacing[Y_AXIS] = (y_max - y_min) / (GRID_MAX_POINTS_Y - 1);
#endif
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) {
@ -76,11 +78,11 @@ void GcodeSuite::M420() {
ExtUI::onMeshUpdate(x, y, Z_VALUES(x, y));
#endif
}
SERIAL_ECHOPGM("Simulated " STRINGIFY(GRID_MAX_POINTS_X) "x" STRINGIFY(GRID_MAX_POINTS_X) " mesh ");
SERIAL_ECHOPAIR(" (", MIN_PROBE_X);
SERIAL_CHAR(','); SERIAL_ECHO(MIN_PROBE_Y);
SERIAL_ECHOPAIR(")-(", MAX_PROBE_X);
SERIAL_CHAR(','); SERIAL_ECHO(MAX_PROBE_Y);
SERIAL_ECHOPGM("Simulated " STRINGIFY(GRID_MAX_POINTS_X) "x" STRINGIFY(GRID_MAX_POINTS_Y) " mesh ");
SERIAL_ECHOPAIR(" (", x_min);
SERIAL_CHAR(','); SERIAL_ECHO(y_min);
SERIAL_ECHOPAIR(")-(", x_max);
SERIAL_CHAR(','); SERIAL_ECHO(y_max);
SERIAL_ECHOLNPGM(")");
}
#endif

View File

@ -393,16 +393,16 @@ G29_TYPE GcodeSuite::G29() {
if (parser.seen('H')) {
const int16_t size = (int16_t)parser.value_linear_units();
left_probe_bed_position = _MAX(X_CENTER - size / 2, MIN_PROBE_X);
right_probe_bed_position = _MIN(left_probe_bed_position + size, MAX_PROBE_X);
front_probe_bed_position = _MAX(Y_CENTER - size / 2, MIN_PROBE_Y);
back_probe_bed_position = _MIN(front_probe_bed_position + size, MAX_PROBE_Y);
left_probe_bed_position = _MAX(X_CENTER - size / 2, probe_min_x());
right_probe_bed_position = _MIN(left_probe_bed_position + size, probe_max_x());
front_probe_bed_position = _MAX(Y_CENTER - size / 2, probe_min_y());
back_probe_bed_position = _MIN(front_probe_bed_position + size, probe_max_y());
}
else {
left_probe_bed_position = parser.seenval('L') ? (int)RAW_X_POSITION(parser.value_linear_units()) : LEFT_PROBE_BED_POSITION;
right_probe_bed_position = parser.seenval('R') ? (int)RAW_X_POSITION(parser.value_linear_units()) : RIGHT_PROBE_BED_POSITION;
front_probe_bed_position = parser.seenval('F') ? (int)RAW_Y_POSITION(parser.value_linear_units()) : FRONT_PROBE_BED_POSITION;
back_probe_bed_position = parser.seenval('B') ? (int)RAW_Y_POSITION(parser.value_linear_units()) : BACK_PROBE_BED_POSITION;
left_probe_bed_position = parser.seenval('L') ? (int)RAW_X_POSITION(parser.value_linear_units()) : _MAX(X_CENTER - X_BED_SIZE / 2, probe_min_x());
right_probe_bed_position = parser.seenval('R') ? (int)RAW_X_POSITION(parser.value_linear_units()) : _MIN(left_probe_bed_position + X_BED_SIZE, probe_max_x());
front_probe_bed_position = parser.seenval('F') ? (int)RAW_Y_POSITION(parser.value_linear_units()) : _MAX(Y_CENTER - Y_BED_SIZE / 2, probe_min_y());
back_probe_bed_position = parser.seenval('B') ? (int)RAW_Y_POSITION(parser.value_linear_units()) : _MIN(front_probe_bed_position + Y_BED_SIZE, probe_max_y());
}
if (
@ -947,8 +947,8 @@ G29_TYPE GcodeSuite::G29() {
planner.leveling_active = false;
// Use the last measured distance to the bed, if possible
if ( NEAR(current_position[X_AXIS], xProbe - (X_PROBE_OFFSET_FROM_EXTRUDER))
&& NEAR(current_position[Y_AXIS], yProbe - (Y_PROBE_OFFSET_FROM_EXTRUDER))
if ( NEAR(current_position[X_AXIS], xProbe - zprobe_offset[X_AXIS])
&& NEAR(current_position[Y_AXIS], yProbe - zprobe_offset[Y_AXIS])
) {
const float simple_z = current_position[Z_AXIS] - measured_z;
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Probed Z", simple_z, " Matrix Z", converted[Z_AXIS], " Discrepancy ", simple_z - converted[Z_AXIS]);

View File

@ -136,8 +136,8 @@
destination[Z_AXIS] = current_position[Z_AXIS]; // Z is already at the right height
#if HOMING_Z_WITH_PROBE
destination[X_AXIS] -= X_PROBE_OFFSET_FROM_EXTRUDER;
destination[Y_AXIS] -= Y_PROBE_OFFSET_FROM_EXTRUDER;
destination[X_AXIS] -= zprobe_offset[X_AXIS];
destination[Y_AXIS] -= zprobe_offset[Y_AXIS];
#endif
if (position_is_reachable(destination[X_AXIS], destination[Y_AXIS])) {

View File

@ -77,8 +77,8 @@ void GcodeSuite::M48() {
float X_current = current_position[X_AXIS],
Y_current = current_position[Y_AXIS];
const float X_probe_location = parser.linearval('X', X_current + X_PROBE_OFFSET_FROM_EXTRUDER),
Y_probe_location = parser.linearval('Y', Y_current + Y_PROBE_OFFSET_FROM_EXTRUDER);
const float X_probe_location = parser.linearval('X', X_current + zprobe_offset[X_AXIS]),
Y_probe_location = parser.linearval('Y', Y_current + zprobe_offset[Y_AXIS]);
if (!position_is_reachable_by_probe(X_probe_location, Y_probe_location)) {
SERIAL_ECHOLNPGM("? (X,Y) out of bounds.");
@ -165,8 +165,8 @@ void GcodeSuite::M48() {
while (angle < 0.0) angle += 360.0; // outside of this range. It looks like they behave correctly with
// numbers outside of the range, but just to be safe we clamp them.
X_current = X_probe_location - (X_PROBE_OFFSET_FROM_EXTRUDER) + cos(RADIANS(angle)) * radius;
Y_current = Y_probe_location - (Y_PROBE_OFFSET_FROM_EXTRUDER) + sin(RADIANS(angle)) * radius;
X_current = X_probe_location - zprobe_offset[X_AXIS] + cos(RADIANS(angle)) * radius;
Y_current = Y_probe_location - zprobe_offset[Y_AXIS] + sin(RADIANS(angle)) * radius;
#if DISABLED(DELTA)
LIMIT(X_current, X_MIN_POS, X_MAX_POS);

View File

@ -229,7 +229,7 @@
* M701 - Load filament (Requires FILAMENT_LOAD_UNLOAD_GCODES)
* M702 - Unload filament (Requires FILAMENT_LOAD_UNLOAD_GCODES)
* M810-M819 - Define/execute a G-code macro (Requires GCODE_MACROS)
* M851 - Set Z probe's Z offset in current units. (Negative = below the nozzle.)
* M851 - Set Z probe's XYZ offsets in current units. (Negative values: X=left, Y=front, Z=below)
* M852 - Set skew factors: "M852 [I<xy>] [J<xz>] [K<yz>]". (Requires SKEW_CORRECTION_GCODE, and SKEW_CORRECTION_FOR_Z for IJ)
* M860 - Report the position of position encoder modules.
* M861 - Report the status of position encoder modules.

View File

@ -42,9 +42,9 @@
&& active_extruder == 0
#endif
) {
zprobe_zoffset += offs;
zprobe_offset[Z_AXIS] += offs;
SERIAL_ECHO_START();
SERIAL_ECHOLNPAIR(MSG_PROBE_Z_OFFSET ": ", zprobe_zoffset);
SERIAL_ECHOLNPAIR(MSG_PROBE_OFFSET MSG_Z ": ", zprobe_offset[Z_AXIS]);
}
#if ENABLED(BABYSTEP_HOTEND_Z_OFFSET)
else {

View File

@ -39,8 +39,8 @@
* E Engage the probe for each probe (default 1)
*/
void GcodeSuite::G30() {
const float xpos = parser.linearval('X', current_position[X_AXIS] + X_PROBE_OFFSET_FROM_EXTRUDER),
ypos = parser.linearval('Y', current_position[Y_AXIS] + Y_PROBE_OFFSET_FROM_EXTRUDER);
const float xpos = parser.linearval('X', current_position[X_AXIS] + zprobe_offset[X_AXIS]),
ypos = parser.linearval('Y', current_position[Y_AXIS] + zprobe_offset[Y_AXIS]);
if (!position_is_reachable_by_probe(xpos, ypos)) return;

View File

@ -28,17 +28,43 @@
#include "../../feature/bedlevel/bedlevel.h"
#include "../../module/probe.h"
/**
* M851: Set the nozzle-to-probe offsets in current units
*/
void GcodeSuite::M851() {
if (parser.seenval('Z')) {
const float value = parser.value_linear_units();
if (WITHIN(value, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX))
zprobe_zoffset = value;
else
SERIAL_ERROR_MSG("?Z out of range (" STRINGIFY(Z_PROBE_OFFSET_RANGE_MIN) " to " STRINGIFY(Z_PROBE_OFFSET_RANGE_MAX) ")");
// Show usage with no parameters
if (!parser.seen("XYZ")) {
SERIAL_ECHO_START();
SERIAL_ECHOLNPAIR(MSG_PROBE_OFFSET " X", zprobe_offset[X_AXIS],
" Y", zprobe_offset[Y_AXIS],
" Z", zprobe_offset[Z_AXIS]);
return;
}
SERIAL_ECHO_START();
SERIAL_ECHOLNPAIR(MSG_PROBE_Z_OFFSET ": ", zprobe_zoffset);
// Get the modified offsets
const float offs[] = {
parser.floatval('X', zprobe_offset[X_AXIS]),
parser.floatval('Y', zprobe_offset[Y_AXIS]),
parser.floatval('Z', zprobe_offset[Z_AXIS])
};
// Error-check
if (!WITHIN(offs[X_AXIS], -(X_BED_SIZE), X_BED_SIZE)) {
SERIAL_ERROR_MSG("?X out of range (-" STRINGIFY(X_BED_SIZE) " to " STRINGIFY(X_BED_SIZE) ")");
return;
}
if (!WITHIN(offs[Y_AXIS], -(Y_BED_SIZE), Y_BED_SIZE)) {
SERIAL_ERROR_MSG("?Y out of range (-" STRINGIFY(Y_BED_SIZE) " to " STRINGIFY(Y_BED_SIZE) ")");
return;
}
if (!WITHIN(offs[Z_AXIS], Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) {
SERIAL_ERROR_MSG("?Z out of range (" STRINGIFY(Z_PROBE_OFFSET_RANGE_MIN) " to " STRINGIFY(Z_PROBE_OFFSET_RANGE_MAX) ")");
return;
}
// Save the new offsets
LOOP_XYZ(a) zprobe_offset[a] = offs[a];
}
#endif // HAS_BED_PROBE