Encapsulate probe as singleton class (#16751)

This commit is contained in:
Scott Lahteine
2020-02-01 04:21:36 -06:00
committed by GitHub
parent 43d3463d5d
commit 90b6324563
33 changed files with 341 additions and 303 deletions

View File

@ -27,7 +27,7 @@
#include "../gcode.h"
#include "../../MarlinCore.h" // for IsRunning()
#include "../../module/motion.h"
#include "../../module/probe.h" // for probe_offset
#include "../../module/probe.h" // for probe.offset
#include "../../feature/bedlevel/bedlevel.h"
/**
@ -53,8 +53,8 @@ void GcodeSuite::G42() {
#if HAS_PROBE_XY_OFFSET
if (parser.boolval('P')) {
if (hasI) destination.x -= probe_offset_xy.x;
if (hasJ) destination.y -= probe_offset_xy.y;
if (hasI) destination.x -= probe.offset_xy.x;
if (hasJ) destination.y -= probe.offset_xy.y;
}
#endif

View File

@ -64,8 +64,8 @@ void GcodeSuite::M420() {
#if ENABLED(MARLIN_DEV_MODE)
if (parser.intval('S') == 2) {
const float x_min = probe_min_x(), x_max = probe_max_x(),
y_min = probe_min_y(), y_max = probe_max_y();
const float x_min = probe.min_x(), x_max = probe.max_x(),
y_min = probe.min_y(), y_max = probe.max_y();
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
bilinear_start.set(x_min, y_min);
bilinear_grid_spacing.set((x_max - x_min) / (GRID_MAX_POINTS_X - 1),

View File

@ -269,7 +269,7 @@ G29_TYPE GcodeSuite::G29() {
#endif
vector_3 points[3];
get_three_probe_points(points);
probe.get_three_points(points);
#endif // AUTO_BED_LEVELING_3POINT
@ -392,8 +392,8 @@ G29_TYPE GcodeSuite::G29() {
xy_probe_feedrate_mm_s = MMM_TO_MMS(parser.linearval('S', XY_PROBE_SPEED));
const float x_min = probe_min_x(), x_max = probe_max_x(),
y_min = probe_min_y(), y_max = probe_max_y();
const float x_min = probe.min_x(), x_max = probe.max_x(),
y_min = probe.min_y(), y_max = probe.max_y();
if (parser.seen('H')) {
const int16_t size = (int16_t)parser.value_linear_units();
@ -452,7 +452,7 @@ G29_TYPE GcodeSuite::G29() {
#if HAS_BED_PROBE
// Deploy the probe. Probe will raise if needed.
if (DEPLOY_PROBE()) {
if (probe.deploy()) {
set_bed_leveling_enabled(abl_should_enable);
G29_RETURN(false);
}
@ -712,7 +712,7 @@ G29_TYPE GcodeSuite::G29() {
ui.status_printf_P(0, PSTR(S_FMT " %i/%i"), GET_TEXT(MSG_PROBING_MESH), int(pt_index), int(GRID_MAX_POINTS));
#endif
measured_z = faux ? 0.001f * random(-100, 101) : probe_at_point(probePos, raise_after, verbose_level);
measured_z = faux ? 0.001f * random(-100, 101) : probe.probe_at_point(probePos, raise_after, verbose_level);
if (isnan(measured_z)) {
set_bed_leveling_enabled(abl_should_enable);
@ -764,7 +764,7 @@ G29_TYPE GcodeSuite::G29() {
// Retain the last probe position
probePos = points[i];
measured_z = faux ? 0.001 * random(-100, 101) : probe_at_point(probePos, raise_after, verbose_level);
measured_z = faux ? 0.001 * random(-100, 101) : probe.probe_at_point(probePos, raise_after, verbose_level);
if (isnan(measured_z)) {
set_bed_leveling_enabled(abl_should_enable);
break;
@ -788,7 +788,7 @@ G29_TYPE GcodeSuite::G29() {
#endif
// Stow the probe. No raise for FIX_MOUNTED_PROBE.
if (STOW_PROBE()) {
if (probe.stow()) {
set_bed_leveling_enabled(abl_should_enable);
measured_z = NAN;
}
@ -923,8 +923,8 @@ G29_TYPE GcodeSuite::G29() {
planner.force_unapply_leveling(converted); // use conversion machinery
// Use the last measured distance to the bed, if possible
if ( NEAR(current_position.x, probePos.x - probe_offset_xy.x)
&& NEAR(current_position.y, probePos.y - probe_offset_xy.y)
if ( NEAR(current_position.x, probePos.x - probe.offset_xy.x)
&& NEAR(current_position.y, probePos.y - probe.offset_xy.y)
) {
const float simple_z = current_position.z - measured_z;
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Probed Z", simple_z, " Matrix Z", converted.z, " Discrepancy ", simple_z - converted.z);
@ -964,7 +964,7 @@ G29_TYPE GcodeSuite::G29() {
sync_plan_position();
#if HAS_BED_PROBE && defined(Z_AFTER_PROBING)
move_z_after_probing();
probe.move_z_after_probing();
#endif
#ifdef Z_PROBE_END_SCRIPT

View File

@ -133,7 +133,7 @@
destination.set(safe_homing_xy, current_position.z);
#if HOMING_Z_WITH_PROBE
destination -= probe_offset_xy;
destination -= probe.offset_xy;
#endif
if (position_is_reachable(destination)) {
@ -416,7 +416,7 @@ void GcodeSuite::G28(const bool always_home_all) {
#endif
#if HOMING_Z_WITH_PROBE && defined(Z_AFTER_PROBING)
move_z_after_probing();
probe.move_z_after_probing();
#endif
} // doZ

View File

@ -100,7 +100,7 @@ void ac_cleanup(
do_blocking_move_to_z(delta_clip_start_height);
#endif
#if HAS_BED_PROBE
STOW_PROBE();
probe.stow();
#endif
restore_feedrate_and_scaling();
#if HOTENDS > 1
@ -190,7 +190,7 @@ static float std_dev_points(float z_pt[NPP + 1], const bool _0p_cal, const bool
*/
static float calibration_probe(const xy_pos_t &xy, const bool stow) {
#if HAS_BED_PROBE
return probe_at_point(xy, stow ? PROBE_PT_STOW : PROBE_PT_RAISE, 0, true);
return probe.probe_at_point(xy, stow ? PROBE_PT_STOW : PROBE_PT_RAISE, 0, true);
#else
UNUSED(stow);
return lcd_probe_pt(xy);

View File

@ -133,8 +133,8 @@ void GcodeSuite::G34() {
do { // break out on error
#if NUM_Z_STEPPER_DRIVERS == 4
SERIAL_ECHOLNPGM("Quad Z Stepper Leveling not Yet Supported");
#if NUM_Z_STEPPER_DRIVERS >= 4
SERIAL_ECHOLNPGM("Alignment not supported for over 3 steppers");
break;
#endif
@ -240,7 +240,7 @@ void GcodeSuite::G34() {
if (iteration == 0 || i > 0) do_blocking_move_to_z(z_probe);
// Probe a Z height for each stepper.
const float z_probed_height = probe_at_point(z_stepper_align_pos[iprobe], raise_after, 0, true);
const float z_probed_height = probe.probe_at_point(z_stepper_align_pos[iprobe], raise_after, 0, true);
if (isnan(z_probed_height)) {
SERIAL_ECHOLNPGM("Probing failed.");
err_break = true;
@ -314,7 +314,7 @@ void GcodeSuite::G34() {
#if DISABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
// Optimize one iteration's correction based on the first measurements
if (z_align_abs > 0.0f) amplification = iteration == 1 ? _MIN(last_z_align_move[zstepper] / z_align_abs, 2.0f) : z_auto_align_amplification;
if (z_align_abs) amplification = (iteration == 1) ? _MIN(last_z_align_move[zstepper] / z_align_abs, 2.0f) : z_auto_align_amplification;
#endif
// Check for less accuracy compared to last move
@ -379,9 +379,9 @@ void GcodeSuite::G34() {
// After this operation the z position needs correction
set_axis_is_not_at_home(Z_AXIS);
// Stow the probe, as the last call to probe_at_point(...) left
// Stow the probe, as the last call to probe.probe_at_point(...) left
// the probe deployed if it was successful.
STOW_PROBE();
probe.stow();
// Home Z after the alignment procedure
process_subcommands_now_P(PSTR("G28 Z"));

View File

@ -113,8 +113,8 @@ void GcodeSuite::G76() {
}
// Ensure probe position is reachable
destination.set(
temp_comp.measure_point_x - probe_offset.x,
temp_comp.measure_point_y - probe_offset.y
temp_comp.measure_point_x - probe.offset_xy.x,
temp_comp.measure_point_y - probe.offset_xy.y
);
if (!position_is_reachable_by_probe(destination)) {
SERIAL_ECHOLNPGM("!Probe position unreachable - aborting.");
@ -209,9 +209,9 @@ void GcodeSuite::G76() {
// Do a single probe
remember_feedrate_scaling_off();
const float measured_z = probe_at_point(
destination.x + probe_offset.x,
destination.y + probe_offset.y,
const float measured_z = probe.probe_at_point(
destination.x + probe.offset_xy.x,
destination.y + probe.offset_xy.y,
PROBE_PT_NONE
);
restore_feedrate_and_scaling();
@ -318,9 +318,9 @@ void GcodeSuite::G76() {
// Do a single probe
remember_feedrate_scaling_off();
const float measured_z = probe_at_point(
destination.x + probe_offset.x,
destination.y + probe_offset.y,
const float measured_z = probe.probe_at_point(
destination.x + probe.offset_xy.x,
destination.y + probe.offset_xy.y,
PROBE_PT_NONE
);
restore_feedrate_and_scaling();

View File

@ -80,8 +80,8 @@ void GcodeSuite::M48() {
xy_float_t next_pos = current_position;
const xy_pos_t probe_pos = {
parser.linearval('X', next_pos.x + probe_offset_xy.x),
parser.linearval('Y', next_pos.y + probe_offset_xy.y)
parser.linearval('X', next_pos.x + probe.offset_xy.x),
parser.linearval('Y', next_pos.y + probe.offset_xy.y)
};
if (!position_is_reachable_by_probe(probe_pos)) {
@ -120,7 +120,7 @@ void GcodeSuite::M48() {
float mean = 0.0, sigma = 0.0, min = 99999.9, max = -99999.9, sample_set[n_samples];
// Move to the first point, deploy, and probe
const float t = probe_at_point(probe_pos, raise_after, verbose_level);
const float t = probe.probe_at_point(probe_pos, raise_after, verbose_level);
bool probing_good = !isnan(t);
if (probing_good) {
@ -169,7 +169,7 @@ 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.
const xy_pos_t noz_pos = probe_pos - probe_offset_xy;
const xy_pos_t noz_pos = probe_pos - probe.offset_xy;
next_pos.set(noz_pos.x + cos(RADIANS(angle)) * radius,
noz_pos.y + sin(RADIANS(angle)) * radius);
@ -194,7 +194,7 @@ void GcodeSuite::M48() {
} // n_legs
// Probe a single point
sample_set[n] = probe_at_point(probe_pos, raise_after, 0);
sample_set[n] = probe.probe_at_point(probe_pos, raise_after, 0);
// Break the loop if the probe fails
probing_good = !isnan(sample_set[n]);
@ -238,7 +238,7 @@ void GcodeSuite::M48() {
} // n_samples loop
}
STOW_PROBE();
probe.stow();
if (probing_good) {
SERIAL_ECHOLNPGM("Finished!");

View File

@ -27,6 +27,13 @@
#include "../gcode.h"
#include "../../module/temperature.h"
/**
* M304 - Set and/or Report the current Bed PID values
*
* P<pval> - Set the P value
* I<ival> - Set the I value
* D<dval> - Set the D value
*/
void GcodeSuite::M304() {
if (parser.seen('P')) thermalManager.temp_bed.pid.Kp = parser.value_float();
if (parser.seen('I')) thermalManager.temp_bed.pid.Ki = scalePID_i(parser.value_float());

View File

@ -46,9 +46,9 @@
&& active_extruder == 0
#endif
) {
probe_offset.z += offs;
probe.offset.z += offs;
SERIAL_ECHO_START();
SERIAL_ECHOLNPAIR(MSG_PROBE_OFFSET MSG_Z ": ", probe_offset.z);
SERIAL_ECHOLNPAIR(MSG_PROBE_OFFSET MSG_Z ": ", probe.offset.z);
}
else {
#if ENABLED(BABYSTEP_HOTEND_Z_OFFSET)
@ -98,7 +98,7 @@ void GcodeSuite::M290() {
SERIAL_ECHO_START();
#if ENABLED(BABYSTEP_ZPROBE_OFFSET)
SERIAL_ECHOLNPAIR(MSG_PROBE_OFFSET " " MSG_Z, probe_offset.z);
SERIAL_ECHOLNPAIR(MSG_PROBE_OFFSET " " MSG_Z, probe.offset.z);
#endif
#if ENABLED(BABYSTEP_HOTEND_Z_OFFSET)

View File

@ -40,8 +40,8 @@
*/
void GcodeSuite::G30() {
const xy_pos_t pos = { parser.linearval('X', current_position.x + probe_offset_xy.x),
parser.linearval('Y', current_position.y + probe_offset_xy.y) };
const xy_pos_t pos = { parser.linearval('X', current_position.x + probe.offset_xy.x),
parser.linearval('Y', current_position.y + probe.offset_xy.y) };
if (!position_is_reachable_by_probe(pos)) return;
@ -53,14 +53,14 @@ void GcodeSuite::G30() {
remember_feedrate_scaling_off();
const ProbePtRaise raise_after = parser.boolval('E', true) ? PROBE_PT_STOW : PROBE_PT_NONE;
const float measured_z = probe_at_point(pos, raise_after, 1);
const float measured_z = probe.probe_at_point(pos, raise_after, 1);
if (!isnan(measured_z))
SERIAL_ECHOLNPAIR("Bed X: ", FIXFLOAT(pos.x), " Y: ", FIXFLOAT(pos.y), " Z: ", FIXFLOAT(measured_z));
restore_feedrate_and_scaling();
#ifdef Z_AFTER_PROBING
if (raise_after == PROBE_PT_STOW) move_z_after_probing();
if (raise_after == PROBE_PT_STOW) probe.move_z_after_probing();
#endif
report_current_position();

View File

@ -30,11 +30,11 @@
/**
* G31: Deploy the Z probe
*/
void GcodeSuite::G31() { DEPLOY_PROBE(); }
void GcodeSuite::G31() { probe.deploy(); }
/**
* G32: Stow the Z probe
*/
void GcodeSuite::G32() { STOW_PROBE(); }
void GcodeSuite::G32() { probe.stow(); }
#endif // Z_PROBE_SLED

View File

@ -32,7 +32,7 @@
* M401: Deploy and activate the Z probe
*/
void GcodeSuite::M401() {
DEPLOY_PROBE();
probe.deploy();
report_current_position();
}
@ -40,9 +40,9 @@ void GcodeSuite::M401() {
* M402: Deactivate and stow the Z probe
*/
void GcodeSuite::M402() {
STOW_PROBE();
probe.stow();
#ifdef Z_AFTER_PROBING
move_z_after_probing();
probe.move_z_after_probing();
#endif
report_current_position();
}

View File

@ -39,17 +39,17 @@ void GcodeSuite::M851() {
if (!parser.seen("XYZ")) {
SERIAL_ECHOLNPAIR_P(
#if HAS_PROBE_XY_OFFSET
PSTR(MSG_PROBE_OFFSET " X"), probe_offset.x, SP_Y_STR, probe_offset.y, SP_Z_STR
PSTR(MSG_PROBE_OFFSET " X"), probe.offset_xy.x, SP_Y_STR, probe.offset_xy.y, SP_Z_STR
#else
PSTR(MSG_PROBE_OFFSET " X0 Y0 Z")
#endif
, probe_offset.z
, probe.offset.z
);
return;
}
// Start with current offsets and modify
xyz_pos_t offs = probe_offset;
xyz_pos_t offs = probe.offset;
// Assume no errors
bool ok = true;
@ -93,7 +93,7 @@ void GcodeSuite::M851() {
}
// Save the new offsets
if (ok) probe_offset = offs;
if (ok) probe.offset = offs;
}
#endif // HAS_BED_PROBE