diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index 6d7819021..141494f20 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -977,7 +977,7 @@ void setup() { #endif #if HAS_Z_SERVO_PROBE - servo_probe_init(); + probe.servo_probe_init(); #endif #if HAS_PHOTOGRAPH diff --git a/Marlin/src/core/utility.cpp b/Marlin/src/core/utility.cpp index 16d0ea17c..14f7aa708 100644 --- a/Marlin/src/core/utility.cpp +++ b/Marlin/src/core/utility.cpp @@ -83,42 +83,42 @@ void safe_delay(millis_t ms) { #if HAS_BED_PROBE #if !HAS_PROBE_XY_OFFSET - SERIAL_ECHOPAIR("Probe Offset X0 Y0 Z", probe_offset.z, " ("); + SERIAL_ECHOPAIR("Probe Offset X0 Y0 Z", probe.offset.z, " ("); #else - SERIAL_ECHOPAIR_P(PSTR("Probe Offset X"), probe_offset.x, SP_Y_STR, probe_offset.y, SP_Z_STR, probe_offset.z); - if (probe_offset.x > 0) + SERIAL_ECHOPAIR_P(PSTR("Probe Offset X"), probe.offset_xy.x, SP_Y_STR, probe.offset_xy.y, SP_Z_STR, probe.offset.z); + if (probe.offset_xy.x > 0) SERIAL_ECHOPGM(" (Right"); - else if (probe_offset.x < 0) + else if (probe.offset_xy.x < 0) SERIAL_ECHOPGM(" (Left"); - else if (probe_offset.y != 0) + else if (probe.offset_xy.y != 0) SERIAL_ECHOPGM(" (Middle"); else SERIAL_ECHOPGM(" (Aligned With"); - if (probe_offset.y > 0) { + if (probe.offset_xy.y > 0) { #if IS_SCARA SERIAL_ECHOPGM("-Distal"); #else SERIAL_ECHOPGM("-Back"); #endif } - else if (probe_offset.y < 0) { + else if (probe.offset_xy.y < 0) { #if IS_SCARA SERIAL_ECHOPGM("-Proximal"); #else SERIAL_ECHOPGM("-Front"); #endif } - else if (probe_offset.x != 0) + else if (probe.offset_xy.x != 0) SERIAL_ECHOPGM("-Center"); SERIAL_ECHOPGM(" & "); #endif - if (probe_offset.z < 0) + if (probe.offset.z < 0) SERIAL_ECHOPGM("Below"); - else if (probe_offset.z > 0) + else if (probe.offset.z > 0) SERIAL_ECHOPGM("Above"); else SERIAL_ECHOPGM("Same Z as"); diff --git a/Marlin/src/feature/bedlevel/ubl/ubl.cpp b/Marlin/src/feature/bedlevel/ubl/ubl.cpp index adafc6a19..8327b468a 100644 --- a/Marlin/src/feature/bedlevel/ubl/ubl.cpp +++ b/Marlin/src/feature/bedlevel/ubl/ubl.cpp @@ -173,10 +173,10 @@ serialprintPGM(csv ? PSTR("CSV:\n") : PSTR("LCD:\n")); } - // Add XY probe offset from extruder because probe_at_point() subtracts them when + // Add XY probe offset from extruder because probe.probe_at_point() subtracts them when // moving to the XY position to be measured. This ensures better agreement between // the current Z position after G28 and the mesh values. - const xy_int8_t curr = closest_indexes(xy_pos_t(current_position) + probe_offset_xy); + const xy_int8_t curr = closest_indexes(xy_pos_t(current_position) + probe.offset_xy); if (!lcd) SERIAL_EOL(); for (int8_t j = GRID_MAX_POINTS_Y - 1; j >= 0; j--) { diff --git a/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp b/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp index c8f3b45b0..693a4b9b2 100644 --- a/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp +++ b/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp @@ -450,7 +450,7 @@ SERIAL_ECHO(g29_pos.y); SERIAL_ECHOLNPGM(").\n"); } - const xy_pos_t near = g29_pos + probe_offset_xy; + const xy_pos_t near = g29_pos + probe.offset_xy; probe_entire_mesh(near, parser.seen('T'), parser.seen('E'), parser.seen('U')); report_current_position(); @@ -480,8 +480,8 @@ #if IS_KINEMATIC X_HOME_POS, Y_HOME_POS #else - probe_offset_xy.x > 0 ? X_BED_SIZE : 0, - probe_offset_xy.y < 0 ? Y_BED_SIZE : 0 + probe.offset_xy.x > 0 ? X_BED_SIZE : 0, + probe.offset_xy.y < 0 ? Y_BED_SIZE : 0 #endif ); } @@ -742,7 +742,7 @@ * This attempts to fill in locations closest to the nozzle's start location first. */ void unified_bed_leveling::probe_entire_mesh(const xy_pos_t &near, const bool do_ubl_mesh_map, const bool stow_probe, const bool do_furthest) { - DEPLOY_PROBE(); // Deploy before ui.capture() to allow for PAUSE_BEFORE_DEPLOY_STOW + probe.deploy(); // Deploy before ui.capture() to allow for PAUSE_BEFORE_DEPLOY_STOW #if HAS_LCD_MENU ui.capture(); @@ -768,7 +768,7 @@ ui.wait_for_release(); ui.quick_feedback(); ui.release(); - STOW_PROBE(); // Release UI before stow to allow for PAUSE_BEFORE_DEPLOY_STOW + probe.stow(); // Release UI before stow to allow for PAUSE_BEFORE_DEPLOY_STOW return restore_ubl_active_state_and_leave(); } #endif @@ -778,7 +778,7 @@ : find_closest_mesh_point_of_type(INVALID, near, true); if (best.pos.x >= 0) { // mesh point found and is reachable by probe - const float measured_z = probe_at_point( + const float measured_z = probe.probe_at_point( best.meshpos(), stow_probe ? PROBE_PT_STOW : PROBE_PT_RAISE, g29_verbose_level ); @@ -794,20 +794,20 @@ #if HAS_LCD_MENU ui.release(); #endif - STOW_PROBE(); // Release UI during stow to allow for PAUSE_BEFORE_DEPLOY_STOW + probe.stow(); // Release UI during stow to allow for PAUSE_BEFORE_DEPLOY_STOW #if HAS_LCD_MENU ui.capture(); #endif #ifdef Z_AFTER_PROBING - move_z_after_probing(); + probe.move_z_after_probing(); #endif restore_ubl_active_state_and_leave(); do_blocking_move_to_xy( - constrain(near.x - probe_offset_xy.x, MESH_MIN_X, MESH_MAX_X), - constrain(near.y - probe_offset_xy.y, MESH_MIN_Y, MESH_MAX_Y) + constrain(near.x - probe.offset_xy.x, MESH_MIN_X, MESH_MAX_X), + constrain(near.y - probe.offset_xy.y, MESH_MIN_Y, MESH_MAX_Y) ); } @@ -907,7 +907,7 @@ ui.return_to_status(); mesh_index_pair location; - xy_int8_t &lpos = location.pos; + const xy_int8_t &lpos = location.pos; do { location = find_closest_mesh_point_of_type(INVALID, pos); // It doesn't matter if the probe can't reach the NAN location. This is a manual probe. @@ -1006,7 +1006,7 @@ #endif MeshFlags done_flags{0}; - xy_int8_t &lpos = location.pos; + const xy_int8_t &lpos = location.pos; do { location = find_closest_mesh_point_of_type(SET_IN_BITMAP, pos, false, &done_flags); @@ -1294,7 +1294,7 @@ closest.distance = -99999.9f; // Get the reference position, either nozzle or probe - const xy_pos_t ref = probe_relative ? pos + probe_offset_xy : pos; + const xy_pos_t ref = probe_relative ? pos + probe.offset_xy : pos; float best_so_far = 99999.99f; @@ -1393,13 +1393,13 @@ #include "../../../libs/vector_3.h" void unified_bed_leveling::tilt_mesh_based_on_probed_grid(const bool do_3_pt_leveling) { - 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(), dx = (x_max - x_min) / (g29_grid_size - 1), dy = (y_max - y_min) / (g29_grid_size - 1); xy_float_t points[3]; - get_three_probe_points(points); + probe.get_three_points(points); float measured_z; bool abort_flag = false; @@ -1417,7 +1417,7 @@ ui.status_printf_P(0, PSTR(S_FMT " 1/3"), GET_TEXT(MSG_LCD_TILTING_MESH)); #endif - measured_z = probe_at_point(points[0], PROBE_PT_RAISE, g29_verbose_level); + measured_z = probe.probe_at_point(points[0], PROBE_PT_RAISE, g29_verbose_level); if (isnan(measured_z)) abort_flag = true; else { @@ -1438,7 +1438,7 @@ ui.status_printf_P(0, PSTR(S_FMT " 2/3"), GET_TEXT(MSG_LCD_TILTING_MESH)); #endif - measured_z = probe_at_point(points[1], PROBE_PT_RAISE, g29_verbose_level); + measured_z = probe.probe_at_point(points[1], PROBE_PT_RAISE, g29_verbose_level); #ifdef VALIDATE_MESH_TILT z2 = measured_z; #endif @@ -1460,7 +1460,7 @@ ui.status_printf_P(0, PSTR(S_FMT " 3/3"), GET_TEXT(MSG_LCD_TILTING_MESH)); #endif - measured_z = probe_at_point(points[2], PROBE_PT_STOW, g29_verbose_level); + measured_z = probe.probe_at_point(points[2], PROBE_PT_STOW, g29_verbose_level); #ifdef VALIDATE_MESH_TILT z3 = measured_z; #endif @@ -1476,9 +1476,9 @@ } } - STOW_PROBE(); + probe.stow(); #ifdef Z_AFTER_PROBING - move_z_after_probing(); + probe.move_z_after_probing(); #endif if (abort_flag) { @@ -1504,7 +1504,7 @@ ui.status_printf_P(0, PSTR(S_FMT " %i/%i"), GET_TEXT(MSG_LCD_TILTING_MESH), point_num, total_points); #endif - measured_z = probe_at_point(rpos, parser.seen('E') ? PROBE_PT_STOW : PROBE_PT_RAISE, g29_verbose_level); // TODO: Needs error handling + measured_z = probe.probe_at_point(rpos, parser.seen('E') ? PROBE_PT_STOW : PROBE_PT_RAISE, g29_verbose_level); // TODO: Needs error handling abort_flag = isnan(measured_z); @@ -1523,7 +1523,7 @@ } #endif - measured_z -= get_z_correction(rpos) /* + probe_offset.z */ ; + measured_z -= get_z_correction(rpos) /* + probe.offset.z */ ; if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR_F(" final >>>---> ", measured_z, 7); @@ -1540,9 +1540,9 @@ zig_zag ^= true; } } - STOW_PROBE(); + probe.stow(); #ifdef Z_AFTER_PROBING - move_z_after_probing(); + probe.move_z_after_probing(); #endif if (abort_flag || finish_incremental_LSF(&lsf_results)) { @@ -1728,7 +1728,7 @@ adjust_mesh_to_mean(g29_c_flag, g29_constant); #if HAS_BED_PROBE - SERIAL_ECHOLNPAIR_F("Probe Offset M851 Z", probe_offset.z, 7); + SERIAL_ECHOLNPAIR_F("Probe Offset M851 Z", probe.offset.z, 7); #endif SERIAL_ECHOLNPAIR("MESH_MIN_X " STRINGIFY(MESH_MIN_X) "=", MESH_MIN_X); serial_delay(50); diff --git a/Marlin/src/gcode/bedlevel/G42.cpp b/Marlin/src/gcode/bedlevel/G42.cpp index 28752cab8..bd6715e29 100644 --- a/Marlin/src/gcode/bedlevel/G42.cpp +++ b/Marlin/src/gcode/bedlevel/G42.cpp @@ -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 diff --git a/Marlin/src/gcode/bedlevel/M420.cpp b/Marlin/src/gcode/bedlevel/M420.cpp index 9e96b456e..70f80465e 100644 --- a/Marlin/src/gcode/bedlevel/M420.cpp +++ b/Marlin/src/gcode/bedlevel/M420.cpp @@ -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), diff --git a/Marlin/src/gcode/bedlevel/abl/G29.cpp b/Marlin/src/gcode/bedlevel/abl/G29.cpp index 7cbaefbf2..ff0581886 100644 --- a/Marlin/src/gcode/bedlevel/abl/G29.cpp +++ b/Marlin/src/gcode/bedlevel/abl/G29.cpp @@ -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 diff --git a/Marlin/src/gcode/calibrate/G28.cpp b/Marlin/src/gcode/calibrate/G28.cpp index 6d87e6f93..0b29fbc4d 100644 --- a/Marlin/src/gcode/calibrate/G28.cpp +++ b/Marlin/src/gcode/calibrate/G28.cpp @@ -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 diff --git a/Marlin/src/gcode/calibrate/G33.cpp b/Marlin/src/gcode/calibrate/G33.cpp index 2ce45359d..bfcf9153e 100644 --- a/Marlin/src/gcode/calibrate/G33.cpp +++ b/Marlin/src/gcode/calibrate/G33.cpp @@ -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); diff --git a/Marlin/src/gcode/calibrate/G34_M422.cpp b/Marlin/src/gcode/calibrate/G34_M422.cpp index 2c284de68..a35b3faef 100644 --- a/Marlin/src/gcode/calibrate/G34_M422.cpp +++ b/Marlin/src/gcode/calibrate/G34_M422.cpp @@ -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")); diff --git a/Marlin/src/gcode/calibrate/G76_M871.cpp b/Marlin/src/gcode/calibrate/G76_M871.cpp index 479f13d50..b94b56fd9 100644 --- a/Marlin/src/gcode/calibrate/G76_M871.cpp +++ b/Marlin/src/gcode/calibrate/G76_M871.cpp @@ -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(); diff --git a/Marlin/src/gcode/calibrate/M48.cpp b/Marlin/src/gcode/calibrate/M48.cpp index 75c5ed9a8..707a37fc2 100644 --- a/Marlin/src/gcode/calibrate/M48.cpp +++ b/Marlin/src/gcode/calibrate/M48.cpp @@ -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!"); diff --git a/Marlin/src/gcode/config/M304.cpp b/Marlin/src/gcode/config/M304.cpp index 3048c228d..6510bc03f 100644 --- a/Marlin/src/gcode/config/M304.cpp +++ b/Marlin/src/gcode/config/M304.cpp @@ -27,6 +27,13 @@ #include "../gcode.h" #include "../../module/temperature.h" +/** + * M304 - Set and/or Report the current Bed PID values + * + * P - Set the P value + * I - Set the I value + * D - 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()); diff --git a/Marlin/src/gcode/motion/M290.cpp b/Marlin/src/gcode/motion/M290.cpp index e5b5b7e76..7d66ae655 100644 --- a/Marlin/src/gcode/motion/M290.cpp +++ b/Marlin/src/gcode/motion/M290.cpp @@ -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) diff --git a/Marlin/src/gcode/probe/G30.cpp b/Marlin/src/gcode/probe/G30.cpp index a236ce3ed..e31f1fb27 100644 --- a/Marlin/src/gcode/probe/G30.cpp +++ b/Marlin/src/gcode/probe/G30.cpp @@ -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(); diff --git a/Marlin/src/gcode/probe/G31_G32.cpp b/Marlin/src/gcode/probe/G31_G32.cpp index 06c3c3adf..cd71f28d7 100644 --- a/Marlin/src/gcode/probe/G31_G32.cpp +++ b/Marlin/src/gcode/probe/G31_G32.cpp @@ -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 diff --git a/Marlin/src/gcode/probe/M401_M402.cpp b/Marlin/src/gcode/probe/M401_M402.cpp index aa63a7ea7..55851f304 100644 --- a/Marlin/src/gcode/probe/M401_M402.cpp +++ b/Marlin/src/gcode/probe/M401_M402.cpp @@ -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(); } diff --git a/Marlin/src/gcode/probe/M851.cpp b/Marlin/src/gcode/probe/M851.cpp index b0a63041f..2c26ebd2a 100644 --- a/Marlin/src/gcode/probe/M851.cpp +++ b/Marlin/src/gcode/probe/M851.cpp @@ -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 diff --git a/Marlin/src/lcd/extensible_ui/lib/dgus/DGUSDisplayDefinitionFYSETC.cpp b/Marlin/src/lcd/extensible_ui/lib/dgus/DGUSDisplayDefinitionFYSETC.cpp index 4d953b88c..4522617d8 100644 --- a/Marlin/src/lcd/extensible_ui/lib/dgus/DGUSDisplayDefinitionFYSETC.cpp +++ b/Marlin/src/lcd/extensible_ui/lib/dgus/DGUSDisplayDefinitionFYSETC.cpp @@ -453,7 +453,7 @@ const struct DGUS_VP_Variable ListOfVP[] PROGMEM = { VPHELPER(VP_SD_AbortPrintConfirmed, nullptr, DGUSScreenVariableHandler::DGUSLCD_SD_ReallyAbort, nullptr), VPHELPER(VP_SD_Print_Setting, nullptr, DGUSScreenVariableHandler::DGUSLCD_SD_PrintTune, nullptr), #if HAS_BED_PROBE - VPHELPER(VP_SD_Print_ProbeOffsetZ, &probe_offset.z, DGUSScreenVariableHandler::HandleProbeOffsetZChanged, &DGUSScreenVariableHandler::DGUSLCD_SendFloatAsIntValueToDisplay<2>), + VPHELPER(VP_SD_Print_ProbeOffsetZ, &probe.offset.z, DGUSScreenVariableHandler::HandleProbeOffsetZChanged, &DGUSScreenVariableHandler::DGUSLCD_SendFloatAsIntValueToDisplay<2>), #if ENABLED(BABYSTEPPING) VPHELPER(VP_SD_Print_LiveAdjustZ, nullptr, DGUSScreenVariableHandler::HandleLiveAdjustZ, nullptr), #endif diff --git a/Marlin/src/lcd/extensible_ui/lib/dgus/DGUSDisplayDefinitionHIPRECY.cpp b/Marlin/src/lcd/extensible_ui/lib/dgus/DGUSDisplayDefinitionHIPRECY.cpp index 0c25f64b6..0a6d9933c 100644 --- a/Marlin/src/lcd/extensible_ui/lib/dgus/DGUSDisplayDefinitionHIPRECY.cpp +++ b/Marlin/src/lcd/extensible_ui/lib/dgus/DGUSDisplayDefinitionHIPRECY.cpp @@ -453,7 +453,7 @@ const struct DGUS_VP_Variable ListOfVP[] PROGMEM = { VPHELPER(VP_SD_AbortPrintConfirmed, nullptr, DGUSScreenVariableHandler::DGUSLCD_SD_ReallyAbort, nullptr), VPHELPER(VP_SD_Print_Setting, nullptr, DGUSScreenVariableHandler::DGUSLCD_SD_PrintTune, nullptr), #if HAS_BED_PROBE - VPHELPER(VP_SD_Print_ProbeOffsetZ, &probe_offset.z, DGUSScreenVariableHandler::HandleProbeOffsetZChanged, &DGUSScreenVariableHandler::DGUSLCD_SendFloatAsIntValueToDisplay<2>), + VPHELPER(VP_SD_Print_ProbeOffsetZ, &probe.offset.z, DGUSScreenVariableHandler::HandleProbeOffsetZChanged, &DGUSScreenVariableHandler::DGUSLCD_SendFloatAsIntValueToDisplay<2>), #if ENABLED(BABYSTEPPING) VPHELPER(VP_SD_Print_LiveAdjustZ, nullptr, DGUSScreenVariableHandler::HandleLiveAdjustZ, nullptr), #endif diff --git a/Marlin/src/lcd/extensible_ui/lib/dgus/DGUSDisplayDefinitionOrigin.cpp b/Marlin/src/lcd/extensible_ui/lib/dgus/DGUSDisplayDefinitionOrigin.cpp index ca5605282..4d877b6b7 100644 --- a/Marlin/src/lcd/extensible_ui/lib/dgus/DGUSDisplayDefinitionOrigin.cpp +++ b/Marlin/src/lcd/extensible_ui/lib/dgus/DGUSDisplayDefinitionOrigin.cpp @@ -285,7 +285,7 @@ const struct DGUS_VP_Variable ListOfVP[] PROGMEM = { VPHELPER(VP_SD_AbortPrintConfirmed, nullptr, DGUSScreenVariableHandler::DGUSLCD_SD_ReallyAbort, nullptr), VPHELPER(VP_SD_Print_Setting, nullptr, DGUSScreenVariableHandler::DGUSLCD_SD_PrintTune, nullptr), #if HAS_BED_PROBE - VPHELPER(VP_SD_Print_ProbeOffsetZ, &probe_offset.z, DGUSScreenVariableHandler::HandleProbeOffsetZChanged, &DGUSScreenVariableHandler::DGUSLCD_SendFloatAsIntValueToDisplay<2>), + VPHELPER(VP_SD_Print_ProbeOffsetZ, &probe.offset.z, DGUSScreenVariableHandler::HandleProbeOffsetZChanged, &DGUSScreenVariableHandler::DGUSLCD_SendFloatAsIntValueToDisplay<2>), #if ENABLED(BABYSTEPPING) VPHELPER(VP_SD_Print_LiveAdjustZ, nullptr, DGUSScreenVariableHandler::HandleLiveAdjustZ, nullptr), #endif diff --git a/Marlin/src/lcd/extensible_ui/ui_api.cpp b/Marlin/src/lcd/extensible_ui/ui_api.cpp index 5e053b670..0e0a1171a 100644 --- a/Marlin/src/lcd/extensible_ui/ui_api.cpp +++ b/Marlin/src/lcd/extensible_ui/ui_api.cpp @@ -733,7 +733,7 @@ namespace ExtUI { #if EXTRUDERS > 1 && (linked_nozzles || active_extruder == 0) #endif - ) probe_offset.z += mm; + ) probe.offset.z += mm; #else UNUSED(mm); #endif @@ -771,7 +771,7 @@ namespace ExtUI { float getZOffset_mm() { #if HAS_BED_PROBE - return probe_offset.z; + return probe.offset.z; #elif ENABLED(BABYSTEP_DISPLAY_TOTAL) return (planner.steps_to_mm[Z_AXIS] * babystep.axis_total[BS_TODO_AXIS(Z_AXIS)]); #else @@ -782,7 +782,7 @@ namespace ExtUI { void setZOffset_mm(const float value) { #if HAS_BED_PROBE if (WITHIN(value, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) - probe_offset.z = value; + probe.offset.z = value; #elif ENABLED(BABYSTEP_DISPLAY_TOTAL) babystep.add_mm(Z_AXIS, (value - getZOffset_mm())); #else diff --git a/Marlin/src/lcd/menu/menu.cpp b/Marlin/src/lcd/menu/menu.cpp index 2bae1258e..9c3cf057d 100644 --- a/Marlin/src/lcd/menu/menu.cpp +++ b/Marlin/src/lcd/menu/menu.cpp @@ -406,7 +406,7 @@ void scroll_screen(const uint8_t limit, const bool is_menu) { ui.encoderPosition = 0; const float diff = planner.steps_to_mm[Z_AXIS] * babystep_increment, - new_probe_offset = probe_offset.z + diff, + new_probe_offset = probe.offset.z + diff, new_offs = #if ENABLED(BABYSTEP_HOTEND_Z_OFFSET) do_probe ? new_probe_offset : hotend_offset[active_extruder].z - diff @@ -418,7 +418,7 @@ void scroll_screen(const uint8_t limit, const bool is_menu) { babystep.add_steps(Z_AXIS, babystep_increment); - if (do_probe) probe_offset.z = new_offs; + if (do_probe) probe.offset.z = new_offs; #if ENABLED(BABYSTEP_HOTEND_Z_OFFSET) else hotend_offset[active_extruder].z = new_offs; #endif @@ -432,10 +432,10 @@ void scroll_screen(const uint8_t limit, const bool is_menu) { MenuEditItemBase::draw_edit_screen(GET_TEXT(MSG_HOTEND_OFFSET_Z), LCD_Z_OFFSET_FUNC(hotend_offset[active_extruder].z)); else #endif - MenuEditItemBase::draw_edit_screen(GET_TEXT(MSG_ZPROBE_ZOFFSET), LCD_Z_OFFSET_FUNC(probe_offset.z)); + MenuEditItemBase::draw_edit_screen(GET_TEXT(MSG_ZPROBE_ZOFFSET), LCD_Z_OFFSET_FUNC(probe.offset.z)); #if ENABLED(BABYSTEP_ZPROBE_GFX_OVERLAY) - if (do_probe) _lcd_zoffset_overlay_gfx(probe_offset.z); + if (do_probe) _lcd_zoffset_overlay_gfx(probe.offset.z); #endif } } diff --git a/Marlin/src/lcd/menu/menu_advanced.cpp b/Marlin/src/lcd/menu/menu_advanced.cpp index ec03a0066..471d1eeb9 100644 --- a/Marlin/src/lcd/menu/menu_advanced.cpp +++ b/Marlin/src/lcd/menu/menu_advanced.cpp @@ -497,9 +497,11 @@ void menu_cancelobject(); void menu_probe_offsets() { START_MENU(); BACK_ITEM(MSG_ADVANCED_SETTINGS); - EDIT_ITEM(float51sign, MSG_ZPROBE_XOFFSET, &probe_offset.x, -(X_BED_SIZE), X_BED_SIZE); - EDIT_ITEM(float51sign, MSG_ZPROBE_YOFFSET, &probe_offset.y, -(Y_BED_SIZE), Y_BED_SIZE); - EDIT_ITEM(LCD_Z_OFFSET_TYPE, MSG_ZPROBE_ZOFFSET, &probe_offset.z, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX); + #if HAS_PROBE_XY_OFFSET + EDIT_ITEM(float51sign, MSG_ZPROBE_XOFFSET, &probe.offset.x, -(X_BED_SIZE), X_BED_SIZE); + EDIT_ITEM(float51sign, MSG_ZPROBE_YOFFSET, &probe.offset.y, -(Y_BED_SIZE), Y_BED_SIZE); + #endif + EDIT_ITEM(LCD_Z_OFFSET_TYPE, MSG_ZPROBE_ZOFFSET, &probe.offset.z, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX); END_MENU(); } #endif diff --git a/Marlin/src/lcd/menu/menu_bed_leveling.cpp b/Marlin/src/lcd/menu/menu_bed_leveling.cpp index 6cc40cab6..d16d4670a 100644 --- a/Marlin/src/lcd/menu/menu_bed_leveling.cpp +++ b/Marlin/src/lcd/menu/menu_bed_leveling.cpp @@ -279,7 +279,7 @@ void menu_bed_leveling() { #if ENABLED(BABYSTEP_ZPROBE_OFFSET) SUBMENU(MSG_ZPROBE_ZOFFSET, lcd_babystep_zoffset); #elif HAS_BED_PROBE - EDIT_ITEM(LCD_Z_OFFSET_TYPE, MSG_ZPROBE_ZOFFSET, &probe_offset.z, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX); + EDIT_ITEM(LCD_Z_OFFSET_TYPE, MSG_ZPROBE_ZOFFSET, &probe.offset.z, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX); #endif #if ENABLED(LEVEL_BED_CORNERS) diff --git a/Marlin/src/lcd/menu/menu_configuration.cpp b/Marlin/src/lcd/menu/menu_configuration.cpp index c23017c3e..31d46816e 100644 --- a/Marlin/src/lcd/menu/menu_configuration.cpp +++ b/Marlin/src/lcd/menu/menu_configuration.cpp @@ -317,14 +317,11 @@ void menu_configuration() { #if ENABLED(BABYSTEP_ZPROBE_OFFSET) SUBMENU(MSG_ZPROBE_ZOFFSET, lcd_babystep_zoffset); #elif HAS_BED_PROBE - EDIT_ITEM(LCD_Z_OFFSET_TYPE, MSG_ZPROBE_ZOFFSET, &probe_offset.z, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX); + EDIT_ITEM(LCD_Z_OFFSET_TYPE, MSG_ZPROBE_ZOFFSET, &probe.offset.z, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX); #endif const bool busy = printer_busy(); if (!busy) { - // - // Delta Calibration - // #if EITHER(DELTA_CALIBRATION_MENU, DELTA_AUTO_CALIBRATION) SUBMENU(MSG_DELTA_CALIBRATE, menu_delta_calibrate); #endif diff --git a/Marlin/src/module/configuration_store.cpp b/Marlin/src/module/configuration_store.cpp index 85b0b850b..05b67c984 100644 --- a/Marlin/src/module/configuration_store.cpp +++ b/Marlin/src/module/configuration_store.cpp @@ -587,12 +587,12 @@ void MarlinSettings::postprocess() { #if HAS_FILAMENT_SENSOR const bool &runout_sensor_enabled = runout.enabled; #else - const bool runout_sensor_enabled = true; + constexpr bool runout_sensor_enabled = true; #endif #if HAS_FILAMENT_SENSOR && defined(FILAMENT_RUNOUT_DISTANCE_MM) const float &runout_distance_mm = runout.runout_distance(); #else - const float runout_distance_mm = 0; + constexpr float runout_distance_mm = 0; #endif _FIELD_TEST(runout_sensor_enabled); EEPROM_WRITE(runout_sensor_enabled); @@ -643,7 +643,12 @@ void MarlinSettings::postprocess() { // { _FIELD_TEST(probe_offset); - EEPROM_WRITE(probe_offset); + #if HAS_BED_PROBE + const xyz_pos_t &zpo = probe.offset; + #else + constexpr xyz_pos_t zpo{0}; + #endif + EEPROM_WRITE(zpo); } // @@ -1458,7 +1463,7 @@ void MarlinSettings::postprocess() { // { #if HAS_FILAMENT_SENSOR - bool &runout_sensor_enabled = runout.enabled; + const bool &runout_sensor_enabled = runout.enabled; #else bool runout_sensor_enabled; #endif @@ -1515,7 +1520,7 @@ void MarlinSettings::postprocess() { { _FIELD_TEST(probe_offset); #if HAS_BED_PROBE - xyz_pos_t &zpo = probe_offset; + const xyz_pos_t &zpo = probe.offset; #else xyz_pos_t zpo; #endif @@ -1609,7 +1614,7 @@ void MarlinSettings::postprocess() { { _FIELD_TEST(bltouch_last_written_mode); #if ENABLED(BLTOUCH) - bool &bltouch_last_written_mode = bltouch.last_written_mode; + const bool &bltouch_last_written_mode = bltouch.last_written_mode; #else bool bltouch_last_written_mode; #endif @@ -2120,14 +2125,14 @@ void MarlinSettings::postprocess() { // { #if ENABLED(BACKLASH_GCODE) - xyz_float_t &backlash_distance_mm = backlash.distance_mm; - uint8_t &backlash_correction = backlash.correction; + const xyz_float_t &backlash_distance_mm = backlash.distance_mm; + const uint8_t &backlash_correction = backlash.correction; #else float backlash_distance_mm[XYZ]; uint8_t backlash_correction; #endif #if ENABLED(BACKLASH_GCODE) && defined(BACKLASH_SMOOTHING_MM) - float &backlash_smoothing_mm = backlash.smoothing_mm; + const float &backlash_smoothing_mm = backlash.smoothing_mm; #else float backlash_smoothing_mm; #endif @@ -2461,10 +2466,10 @@ void MarlinSettings::reset() { constexpr float dpo[] = NOZZLE_TO_PROBE_OFFSET; static_assert(COUNT(dpo) == 3, "NOZZLE_TO_PROBE_OFFSET must contain offsets for X, Y, and Z."); #if HAS_PROBE_XY_OFFSET - LOOP_XYZ(a) probe_offset[a] = dpo[a]; + LOOP_XYZ(a) probe.offset[a] = dpo[a]; #else - probe_offset.x = probe_offset.y = 0; - probe_offset.z = dpo[Z_AXIS]; + probe.offset.x = probe.offset.y = 0; + probe.offset.z = dpo[Z_AXIS]; #endif #endif @@ -3216,13 +3221,13 @@ void MarlinSettings::reset() { CONFIG_ECHO_START(); SERIAL_ECHOLNPAIR_P( #if HAS_PROBE_XY_OFFSET - PSTR(" M851 X"), LINEAR_UNIT(probe_offset_xy.x), - SP_Y_STR, LINEAR_UNIT(probe_offset_xy.y), + PSTR(" M851 X"), LINEAR_UNIT(probe.offset_xy.x), + SP_Y_STR, LINEAR_UNIT(probe.offset_xy.y), SP_Z_STR #else PSTR(" M851 X0 Y0 Z") #endif - , LINEAR_UNIT(probe_offset.z) + , LINEAR_UNIT(probe.offset.z) ); #endif diff --git a/Marlin/src/module/delta.cpp b/Marlin/src/module/delta.cpp index bed5cd24c..cb2d432e3 100644 --- a/Marlin/src/module/delta.cpp +++ b/Marlin/src/module/delta.cpp @@ -95,7 +95,7 @@ void recalc_delta_settings() { float delta_calibration_radius() { return calibration_radius_factor * ( #if HAS_BED_PROBE - FLOOR((DELTA_PRINTABLE_RADIUS) - _MAX(HYPOT(probe_offset_xy.x, probe_offset_xy.y), MIN_PROBE_EDGE)) + FLOOR((DELTA_PRINTABLE_RADIUS) - _MAX(HYPOT(probe.offset_xy.x, probe.offset_xy.y), MIN_PROBE_EDGE)) #else DELTA_PRINTABLE_RADIUS #endif @@ -251,7 +251,7 @@ void home_delta() { // Move all carriages together linearly until an endstop is hit. current_position.z = (delta_height + 10 #if HAS_BED_PROBE - - probe_offset.z + - probe.offset.z #endif ); line_to_current_position(homing_feedrate(Z_AXIS)); diff --git a/Marlin/src/module/motion.cpp b/Marlin/src/module/motion.cpp index 50092406c..f63555d28 100644 --- a/Marlin/src/module/motion.cpp +++ b/Marlin/src/module/motion.cpp @@ -280,7 +280,7 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) { , true #endif ); - xyze_pos_t &cartes = pos; + const xyze_pos_t &cartes = pos; #endif if (axis == ALL_AXES) current_position = cartes; @@ -547,7 +547,7 @@ void restore_feedrate_and_scaling() { soft_endstop.min[axis] = base_min_pos(axis); soft_endstop.max[axis] = (axis == Z_AXIS ? delta_height #if HAS_BED_PROBE - - probe_offset.z + - probe.offset.z #endif : base_max_pos(axis)); @@ -1281,7 +1281,7 @@ void do_homing_move(const AxisEnum axis, const float distance, const feedRate_t #if HOMING_Z_WITH_PROBE && HAS_HEATED_BED && ENABLED(WAIT_FOR_BED_HEATER) // Wait for bed to heat back up between probing points if (axis == Z_AXIS && distance < 0 && thermalManager.isHeatingBed()) { - serialprintPGM(msg_wait_for_bed_heating); + serialprintPGM(probe.msg_wait_for_bed_heating); #if HAS_DISPLAY LCD_MESSAGEPGM(MSG_BED_HEATING); #endif @@ -1307,7 +1307,7 @@ void do_homing_move(const AxisEnum axis, const float distance, const feedRate_t if (is_home_dir) { #if HOMING_Z_WITH_PROBE && QUIET_PROBING - if (axis == Z_AXIS) probing_pause(true); + if (axis == Z_AXIS) probe.set_probing_paused(true); #endif // Disable stealthChop if used. Enable diag1 pin on driver. @@ -1347,7 +1347,7 @@ void do_homing_move(const AxisEnum axis, const float distance, const feedRate_t if (is_home_dir) { #if HOMING_Z_WITH_PROBE && QUIET_PROBING - if (axis == Z_AXIS) probing_pause(false); + if (axis == Z_AXIS) probe.set_probing_paused(false); #endif endstops.validate_homing_move(); @@ -1397,7 +1397,7 @@ void set_axis_is_at_home(const AxisEnum axis) { #elif ENABLED(DELTA) current_position[axis] = (axis == Z_AXIS ? delta_height #if HAS_BED_PROBE - - probe_offset.z + - probe.offset.z #endif : base_home_pos(axis)); #else @@ -1411,9 +1411,9 @@ void set_axis_is_at_home(const AxisEnum axis) { if (axis == Z_AXIS) { #if HOMING_Z_WITH_PROBE - current_position.z -= probe_offset.z; + current_position.z -= probe.offset.z; - if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("*** Z HOMED WITH PROBE (Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) ***\n> probe_offset.z = ", probe_offset.z); + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("*** Z HOMED WITH PROBE (Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) ***\n> probe.offset.z = ", probe.offset.z); #else @@ -1509,7 +1509,7 @@ void homeaxis(const AxisEnum axis) { // Homing Z towards the bed? Deploy the Z probe or endstop. #if HOMING_Z_WITH_PROBE - if (axis == Z_AXIS && DEPLOY_PROBE()) return; + if (axis == Z_AXIS && probe.deploy()) return; #endif // Set flags for X, Y, Z motor locking @@ -1751,7 +1751,7 @@ void homeaxis(const AxisEnum axis) { // Put away the Z probe #if HOMING_Z_WITH_PROBE - if (axis == Z_AXIS && STOW_PROBE()) return; + if (axis == Z_AXIS && probe.stow()) return; #endif #if DISABLED(DELTA) && defined(HOMING_BACKOFF_MM) diff --git a/Marlin/src/module/motion.h b/Marlin/src/module/motion.h index eafa5ca84..a159bdd4b 100644 --- a/Marlin/src/module/motion.h +++ b/Marlin/src/module/motion.h @@ -329,7 +329,7 @@ void homeaxis(const AxisEnum axis); // Return true if the both nozzle and the probe can reach the given point. // Note: This won't work on SCARA since the probe offset rotates with the arm. inline bool position_is_reachable_by_probe(const float &rx, const float &ry) { - return position_is_reachable(rx - probe_offset.x, ry - probe_offset.y) + return position_is_reachable(rx - probe.offset_xy.x, ry - probe.offset_xy.y) && position_is_reachable(rx, ry, ABS(MIN_PROBE_EDGE)); } @@ -369,9 +369,9 @@ void homeaxis(const AxisEnum axis); * nozzle must be be able to reach +10,-10. */ inline bool position_is_reachable_by_probe(const float &rx, const float &ry) { - return position_is_reachable(rx - probe_offset_xy.x, ry - probe_offset_xy.y) - && WITHIN(rx, probe_min_x() - slop, probe_max_x() + slop) - && WITHIN(ry, probe_min_y() - slop, probe_max_y() + slop); + return position_is_reachable(rx - probe.offset_xy.x, ry - probe.offset_xy.y) + && WITHIN(rx, probe.min_x() - slop, probe.max_x() + slop) + && WITHIN(ry, probe.min_y() - slop, probe.max_y() + slop); } #endif // HAS_BED_PROBE diff --git a/Marlin/src/module/planner.cpp b/Marlin/src/module/planner.cpp index 351b08989..9f5a5c5c5 100644 --- a/Marlin/src/module/planner.cpp +++ b/Marlin/src/module/planner.cpp @@ -2779,7 +2779,7 @@ void Planner::set_max_acceleration(const uint8_t axis, float targetValue) { const xyze_float_t &max_acc_edit_scaled = max_accel_edit; #else constexpr xyze_float_t max_accel_edit = DEFAULT_MAX_ACCELERATION; - const xyze_float_t max_acc_edit_scaled = max_accel_edit * 2; + constexpr xyze_float_t max_acc_edit_scaled = max_accel_edit * 2; #endif limit_and_warn(targetValue, axis, PSTR("Acceleration"), max_acc_edit_scaled); #endif @@ -2796,7 +2796,7 @@ void Planner::set_max_feedrate(const uint8_t axis, float targetValue) { const xyze_float_t &max_fr_edit_scaled = max_fr_edit; #else constexpr xyze_float_t max_fr_edit = DEFAULT_MAX_FEEDRATE; - const xyze_float_t max_fr_edit_scaled = max_fr_edit * 2; + constexpr xyze_float_t max_fr_edit_scaled = max_fr_edit * 2; #endif limit_and_warn(targetValue, axis, PSTR("Feedrate"), max_fr_edit_scaled); #endif diff --git a/Marlin/src/module/probe.cpp b/Marlin/src/module/probe.cpp index 5710614e0..ef11a5212 100644 --- a/Marlin/src/module/probe.cpp +++ b/Marlin/src/module/probe.cpp @@ -21,7 +21,7 @@ */ /** - * probe.cpp + * module/probe.cpp */ #include "../inc/MarlinConfig.h" @@ -84,14 +84,14 @@ #define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE) #include "../core/debug_out.h" +Probe probe; -xyz_pos_t probe_offset; // Initialized by settings.load() +xyz_pos_t Probe::offset; // Initialized by settings.load() #if HAS_PROBE_XY_OFFSET - xyz_pos_t &probe_offset_xy = probe_offset; + const xyz_pos_t &Probe::offset_xy = probe.offset; #endif - #if ENABLED(Z_PROBE_SLED) #ifndef SLED_DOCKING_OFFSET @@ -104,7 +104,7 @@ xyz_pos_t probe_offset; // Initialized by settings.load() * stow[in] If false, move to MAX_X and engage the solenoid * If true, move to MAX_X and release the solenoid */ - static void dock_sled(bool stow) { + static void dock_sled(const bool stow) { if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("dock_sled(", stow, ")"); // Dock sled a bit closer to ensure proper capturing @@ -118,7 +118,7 @@ xyz_pos_t probe_offset; // Initialized by settings.load() #elif ENABLED(TOUCH_MI_PROBE) // Move to the magnet to unlock the probe - void run_deploy_moves_script() { + inline void run_deploy_moves_script() { #ifndef TOUCH_MI_DEPLOY_XPOS #define TOUCH_MI_DEPLOY_XPOS X_MIN_POS #elif TOUCH_MI_DEPLOY_XPOS > X_MAX_BED @@ -153,7 +153,7 @@ xyz_pos_t probe_offset; // Initialized by settings.load() } // Move down to the bed to stow the probe - void run_stow_moves_script() { + inline void run_stow_moves_script() { const xyz_pos_t oldpos = current_position; endstops.enable_z_probe(false); do_blocking_move_to_z(TOUCH_MI_RETRACT_Z, MMM_TO_MMS(HOMING_FEEDRATE_Z)); @@ -162,7 +162,7 @@ xyz_pos_t probe_offset; // Initialized by settings.load() #elif ENABLED(Z_PROBE_ALLEN_KEY) - void run_deploy_moves_script() { + inline void run_deploy_moves_script() { #ifdef Z_PROBE_ALLEN_KEY_DEPLOY_1 #ifndef Z_PROBE_ALLEN_KEY_DEPLOY_1_FEEDRATE #define Z_PROBE_ALLEN_KEY_DEPLOY_1_FEEDRATE 0.0 @@ -200,7 +200,7 @@ xyz_pos_t probe_offset; // Initialized by settings.load() #endif } - void run_stow_moves_script() { + inline void run_stow_moves_script() { #ifdef Z_PROBE_ALLEN_KEY_STOW_1 #ifndef Z_PROBE_ALLEN_KEY_STOW_1_FEEDRATE #define Z_PROBE_ALLEN_KEY_STOW_1_FEEDRATE 0.0 @@ -241,7 +241,8 @@ xyz_pos_t probe_offset; // Initialized by settings.load() #endif // Z_PROBE_ALLEN_KEY #if QUIET_PROBING - void probing_pause(const bool p) { + + void Probe::set_probing_paused(const bool p) { #if ENABLED(PROBING_HEATERS_OFF) thermalManager.pause(p); #endif @@ -262,16 +263,17 @@ xyz_pos_t probe_offset; // Initialized by settings.load() #endif ); } + #endif // QUIET_PROBING /** * Raise Z to a minimum height to make room for a probe to move */ -inline void do_probe_raise(const float z_raise) { - if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("do_probe_raise(", z_raise, ")"); +void Probe::do_z_raise(const float z_raise) { + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Probe::move_z(", z_raise, ")"); float z_dest = z_raise; - if (probe_offset.z < 0) z_dest -= probe_offset.z; + if (offset.z < 0) z_dest -= offset.z; NOMORE(z_dest, Z_MAX_POS); @@ -351,11 +353,15 @@ FORCE_INLINE void probe_specific_action(const bool deploy) { #endif } -// returns false for ok and true for failure -bool set_probe_deployed(const bool deploy) { +/** + * Attempt to deploy or stow the probe + * + * Return TRUE if the probe could not be deployed/stowed + */ +bool Probe::set_deployed(const bool deploy) { if (DEBUGGING(LEVELING)) { - DEBUG_POS("set_probe_deployed", current_position); + DEBUG_POS("Probe::set_deployed", current_position); DEBUG_ECHOLNPAIR("deploy: ", deploy); } @@ -378,7 +384,7 @@ bool set_probe_deployed(const bool deploy) { #endif if (deploy_stow_condition && unknown_condition) - do_probe_raise(_MAX(Z_CLEARANCE_BETWEEN_PROBES, Z_CLEARANCE_DEPLOY_PROBE)); + do_z_raise(_MAX(Z_CLEARANCE_BETWEEN_PROBES, Z_CLEARANCE_DEPLOY_PROBE)); #if EITHER(Z_PROBE_SLED, Z_PROBE_ALLEN_KEY) if (axis_unhomed_error( @@ -433,7 +439,7 @@ bool set_probe_deployed(const bool deploy) { #ifdef Z_AFTER_PROBING // After probing move to a preferred Z position - void move_z_after_probing() { + void Probe::move_z_after_probing() { if (current_position.z != Z_AFTER_PROBING) { do_blocking_move_to_z(Z_AFTER_PROBING); current_position.z = Z_AFTER_PROBING; @@ -450,11 +456,11 @@ bool set_probe_deployed(const bool deploy) { */ #if HAS_HEATED_BED && ENABLED(WAIT_FOR_BED_HEATER) - const char msg_wait_for_bed_heating[25] PROGMEM = "Wait for bed heating...\n"; + PGM_P Probe::msg_wait_for_bed_heating[25] PROGMEM = "Wait for bed heating...\n"; #endif -static bool do_probe_move(const float z, const feedRate_t fr_mm_s) { - if (DEBUGGING(LEVELING)) DEBUG_POS(">>> do_probe_move", current_position); +bool Probe::move_to_z(const float z, const feedRate_t fr_mm_s) { + if (DEBUGGING(LEVELING)) DEBUG_POS(">>> Probe::move_to_z", current_position); #if HAS_HEATED_BED && ENABLED(WAIT_FOR_BED_HEATER) // Wait for bed to heat back up between probing points @@ -482,7 +488,7 @@ static bool do_probe_move(const float z, const feedRate_t fr_mm_s) { #endif #if QUIET_PROBING - probing_pause(true); + set_probing_paused(true); #endif // Move down until the probe is triggered @@ -504,7 +510,7 @@ static bool do_probe_move(const float z, const feedRate_t fr_mm_s) { ; #if QUIET_PROBING - probing_pause(false); + set_probing_paused(false); #endif // Re-enable stealthChop if used. Disable diag1 pin on driver. @@ -530,7 +536,7 @@ static bool do_probe_move(const float z, const feedRate_t fr_mm_s) { // Tell the planner where we actually are sync_plan_position(); - if (DEBUGGING(LEVELING)) DEBUG_POS("<<< do_probe_move", current_position); + if (DEBUGGING(LEVELING)) DEBUG_POS("<<< Probe::move_to_z", current_position); return !probe_triggered; } @@ -543,19 +549,19 @@ static bool do_probe_move(const float z, const feedRate_t fr_mm_s) { * * @return The Z position of the bed at the current XY or NAN on error. */ -static float run_z_probe() { +float Probe::run_z_probe() { - if (DEBUGGING(LEVELING)) DEBUG_POS(">>> run_z_probe", current_position); + if (DEBUGGING(LEVELING)) DEBUG_POS(">>> Probe::run_z_probe", current_position); // Stop the probe before it goes too low to prevent damage. // If Z isn't known then probe to -10mm. - const float z_probe_low_point = TEST(axis_known_position, Z_AXIS) ? -probe_offset.z + Z_PROBE_LOW_POINT : -10.0; + const float z_probe_low_point = TEST(axis_known_position, Z_AXIS) ? -offset.z + Z_PROBE_LOW_POINT : -10.0; // Double-probing does a fast probe followed by a slow probe #if TOTAL_PROBING == 2 // Do a first probe at the fast speed - if (do_probe_move(z_probe_low_point, MMM_TO_MMS(Z_PROBE_SPEED_FAST))) { + if (move_to_z(z_probe_low_point, MMM_TO_MMS(Z_PROBE_SPEED_FAST))) { if (DEBUGGING(LEVELING)) { DEBUG_ECHOLNPGM("FAST Probe fail!"); DEBUG_POS("<<< run_z_probe", current_position); @@ -574,10 +580,10 @@ static float run_z_probe() { // If the nozzle is well over the travel height then // move down quickly before doing the slow probe - const float z = Z_CLEARANCE_DEPLOY_PROBE + 5.0 + (probe_offset.z < 0 ? -probe_offset.z : 0); + const float z = Z_CLEARANCE_DEPLOY_PROBE + 5.0 + (offset.z < 0 ? -offset.z : 0); if (current_position.z > z) { // Probe down fast. If the probe never triggered, raise for probe clearance - if (!do_probe_move(z, MMM_TO_MMS(Z_PROBE_SPEED_FAST))) + if (!move_to_z(z, MMM_TO_MMS(Z_PROBE_SPEED_FAST))) do_blocking_move_to_z(current_position.z + Z_CLEARANCE_BETWEEN_PROBES, MMM_TO_MMS(Z_PROBE_SPEED_FAST)); } #endif @@ -587,7 +593,7 @@ static float run_z_probe() { #endif #if TOTAL_PROBING > 2 - float probes_total = 0; + float probes_z_sum = 0; for ( #if EXTRA_PROBING uint8_t p = 0; p < TOTAL_PROBING; p++ @@ -598,7 +604,7 @@ static float run_z_probe() { #endif { // Probe downward slowly to find the bed - if (do_probe_move(z_probe_low_point, MMM_TO_MMS(Z_PROBE_SPEED_SLOW))) { + if (move_to_z(z_probe_low_point, MMM_TO_MMS(Z_PROBE_SPEED_SLOW))) { if (DEBUGGING(LEVELING)) { DEBUG_ECHOLNPGM("SLOW Probe fail!"); DEBUG_POS("<<< run_z_probe", current_position); @@ -622,7 +628,7 @@ static float run_z_probe() { } } #elif TOTAL_PROBING > 2 - probes_total += z; + probes_z_sum += z; #else UNUSED(z); #endif @@ -653,11 +659,11 @@ static float run_z_probe() { // Return the average value of all remaining probes. for (uint8_t i = min_avg_idx; i <= max_avg_idx; i++) - probes_total += probes[i]; + probes_z_sum += probes[i]; #endif - const float measured_z = probes_total * RECIPROCAL(MULTIPLE_PROBING); + const float measured_z = probes_z_sum * RECIPROCAL(MULTIPLE_PROBING); #elif TOTAL_PROBING == 2 @@ -689,10 +695,10 @@ static float run_z_probe() { * - Raise to the BETWEEN height * - Return the probed Z position */ -float probe_at_point(const float &rx, const float &ry, const ProbePtRaise raise_after/*=PROBE_PT_NONE*/, const uint8_t verbose_level/*=0*/, const bool probe_relative/*=true*/) { +float Probe::probe_at_point(const float &rx, const float &ry, const ProbePtRaise raise_after/*=PROBE_PT_NONE*/, const uint8_t verbose_level/*=0*/, const bool probe_relative/*=true*/) { if (DEBUGGING(LEVELING)) { DEBUG_ECHOLNPAIR( - ">>> probe_at_point(", LOGICAL_X_POSITION(rx), ", ", LOGICAL_Y_POSITION(ry), + ">>> Probe::probe_at_point(", LOGICAL_X_POSITION(rx), ", ", LOGICAL_Y_POSITION(ry), ", ", raise_after == PROBE_PT_RAISE ? "raise" : raise_after == PROBE_PT_STOW ? "stow" : "none", ", ", int(verbose_level), ", ", probe_relative ? "probe" : "nozzle", "_relative)" @@ -702,9 +708,12 @@ float probe_at_point(const float &rx, const float &ry, const ProbePtRaise raise_ // TODO: Adapt for SCARA, where the offset rotates xyz_pos_t npos = { rx, ry }; - if (probe_relative) { - if (!position_is_reachable_by_probe(npos)) return NAN; // The given position is in terms of the probe - npos -= probe_offset_xy; // Get the nozzle position + if (probe_relative) { // The given position is in terms of the probe + if (!position_is_reachable_by_probe(npos)) { + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Position Not Reachable"); + return NAN; + } + npos -= offset_xy; // Get the nozzle position } else if (!position_is_reachable(npos)) return NAN; // The given position is in terms of the nozzle @@ -724,38 +733,38 @@ float probe_at_point(const float &rx, const float &ry, const ProbePtRaise raise_ do_blocking_move_to(npos); float measured_z = NAN; - if (!DEPLOY_PROBE()) { - measured_z = run_z_probe() + probe_offset.z; + if (!deploy()) { + measured_z = run_z_probe() + offset.z; const bool big_raise = raise_after == PROBE_PT_BIG_RAISE; if (big_raise || raise_after == PROBE_PT_RAISE) do_blocking_move_to_z(current_position.z + (big_raise ? 25 : Z_CLEARANCE_BETWEEN_PROBES), MMM_TO_MMS(Z_PROBE_SPEED_FAST)); else if (raise_after == PROBE_PT_STOW) - if (STOW_PROBE()) measured_z = NAN; + if (stow()) measured_z = NAN; } if (verbose_level > 2) { SERIAL_ECHOPAIR_F("Bed X: ", LOGICAL_X_POSITION(rx), 3); - SERIAL_ECHOPAIR_F(" Y: ", LOGICAL_Y_POSITION(ry), 3); - SERIAL_ECHOLNPAIR_F(" Z: ", measured_z, 3); + SERIAL_ECHOPAIR_F( " Y: ", LOGICAL_Y_POSITION(ry), 3); + SERIAL_ECHOLNPAIR_F( " Z: ", measured_z, 3); } feedrate_mm_s = old_feedrate_mm_s; if (isnan(measured_z)) { - STOW_PROBE(); + stow(); LCD_MESSAGEPGM(MSG_LCD_PROBING_FAILED); SERIAL_ERROR_MSG(MSG_ERR_PROBING_FAILED); } - if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< probe_at_point"); + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< Probe::probe_at_point"); return measured_z; } #if HAS_Z_SERVO_PROBE - void servo_probe_init() { + void Probe::servo_probe_init() { /** * Set position of Z Servo Endstop * diff --git a/Marlin/src/module/probe.h b/Marlin/src/module/probe.h index a6e8bf4ea..5cf0ecc25 100644 --- a/Marlin/src/module/probe.h +++ b/Marlin/src/module/probe.h @@ -22,132 +22,150 @@ #pragma once /** - * probe.h - Move, deploy, enable, etc. + * module/probe.h - Move, deploy, enable, etc. */ #include "../inc/MarlinConfig.h" #if HAS_BED_PROBE - - extern xyz_pos_t probe_offset; - - #if HAS_PROBE_XY_OFFSET - extern xyz_pos_t &probe_offset_xy; - #else - constexpr xy_pos_t probe_offset_xy{0}; - #endif - - bool set_probe_deployed(const bool deploy); - #ifdef Z_AFTER_PROBING - void move_z_after_probing(); - #endif - enum ProbePtRaise : unsigned char { - PROBE_PT_NONE, // No raise or stow after run_z_probe - PROBE_PT_STOW, // Do a complete stow after run_z_probe - PROBE_PT_RAISE, // Raise to "between" clearance after run_z_probe + enum ProbePtRaise : uint8_t { + PROBE_PT_NONE, // No raise or stow after run_z_probe + PROBE_PT_STOW, // Do a complete stow after run_z_probe + PROBE_PT_RAISE, // Raise to "between" clearance after run_z_probe PROBE_PT_BIG_RAISE // Raise to big clearance after run_z_probe }; - float probe_at_point(const float &rx, const float &ry, const ProbePtRaise raise_after=PROBE_PT_NONE, const uint8_t verbose_level=0, const bool probe_relative=true); - inline float probe_at_point(const xy_pos_t &pos, const ProbePtRaise raise_after=PROBE_PT_NONE, const uint8_t verbose_level=0, const bool probe_relative=true) { - return probe_at_point(pos.x, pos.y, raise_after, verbose_level, probe_relative); - } - #define DEPLOY_PROBE() set_probe_deployed(true) - #define STOW_PROBE() set_probe_deployed(false) - #if HAS_HEATED_BED && ENABLED(WAIT_FOR_BED_HEATER) - extern const char msg_wait_for_bed_heating[25]; - #endif - -#else - - constexpr xyz_pos_t probe_offset{0}; - constexpr xy_pos_t probe_offset_xy{0}; - - #define DEPLOY_PROBE() - #define STOW_PROBE() - #endif -#if HAS_BED_PROBE || HAS_LEVELING - #if IS_KINEMATIC - constexpr float printable_radius = ( - #if ENABLED(DELTA) - DELTA_PRINTABLE_RADIUS - #elif IS_SCARA - SCARA_PRINTABLE_RADIUS - #endif - ); +class Probe { +public: - inline float probe_radius() { - return printable_radius - _MAX(MIN_PROBE_EDGE, HYPOT(probe_offset_xy.x, probe_offset_xy.y)); + #if HAS_BED_PROBE + + static xyz_pos_t offset; + + // Use offset_xy for read only access + // More optimal the XY offset is known to always be zero. + #if HAS_PROBE_XY_OFFSET + static const xyz_pos_t &offset_xy; + #else + static constexpr xy_pos_t offset_xy{0}; + #endif + + static bool set_deployed(const bool deploy); + + #ifdef Z_AFTER_PROBING + static void move_z_after_probing(); + #endif + static float probe_at_point(const float &rx, const float &ry, const ProbePtRaise raise_after=PROBE_PT_NONE, const uint8_t verbose_level=0, const bool probe_relative=true); + static inline float probe_at_point(const xy_pos_t &pos, const ProbePtRaise raise_after=PROBE_PT_NONE, const uint8_t verbose_level=0, const bool probe_relative=true) { + return probe_at_point(pos.x, pos.y, raise_after, verbose_level, probe_relative); } + #if HAS_HEATED_BED && ENABLED(WAIT_FOR_BED_HEATER) + static PGM_P msg_wait_for_bed_heating[25]; + #endif + + #else + + static constexpr xyz_pos_t offset{0}; + static constexpr xy_pos_t offset_xy{0}; + + static bool set_deployed(const bool) { return false; } + #endif - inline float probe_min_x() { - return ( - #if IS_KINEMATIC - (X_CENTER) - probe_radius() - #else - _MAX((X_MIN_BED) + (MIN_PROBE_EDGE_LEFT), (X_MIN_POS) + probe_offset_xy.x) - #endif - ); - } - inline float probe_max_x() { - return ( - #if IS_KINEMATIC - (X_CENTER) + probe_radius() - #else - _MIN((X_MAX_BED) - (MIN_PROBE_EDGE_RIGHT), (X_MAX_POS) + probe_offset_xy.x) - #endif - ); - } - inline float probe_min_y() { - return ( - #if IS_KINEMATIC - (Y_CENTER) - probe_radius() - #else - _MAX((Y_MIN_BED) + (MIN_PROBE_EDGE_FRONT), (Y_MIN_POS) + probe_offset_xy.y) - #endif - ); - } - inline float probe_max_y() { - return ( - #if IS_KINEMATIC - (Y_CENTER) + probe_radius() - #else - _MIN((Y_MAX_BED) - (MIN_PROBE_EDGE_BACK), (Y_MAX_POS) + probe_offset_xy.y) - #endif - ); - } + static inline bool deploy() { return set_deployed(true); } + static inline bool stow() { return set_deployed(false); } - #if NEEDS_THREE_PROBE_POINTS - // Retrieve three points to probe the bed. Any type exposing set(X,Y) may be used. - template - inline void get_three_probe_points(T points[3]) { - #if ENABLED(HAS_FIXED_3POINT) - points[0].set(PROBE_PT_1_X, PROBE_PT_1_Y); - points[1].set(PROBE_PT_2_X, PROBE_PT_2_Y); - points[2].set(PROBE_PT_3_X, PROBE_PT_3_Y); - #else - #if IS_KINEMATIC - constexpr float SIN0 = 0.0, SIN120 = 0.866025, SIN240 = -0.866025, - COS0 = 1.0, COS120 = -0.5 , COS240 = -0.5; - points[0].set((X_CENTER) + probe_radius() * COS0, (Y_CENTER) + probe_radius() * SIN0); - points[1].set((X_CENTER) + probe_radius() * COS120, (Y_CENTER) + probe_radius() * SIN120); - points[2].set((X_CENTER) + probe_radius() * COS240, (Y_CENTER) + probe_radius() * SIN240); - #else - points[0].set(probe_min_x(), probe_min_y()); - points[1].set(probe_max_x(), probe_min_y()); - points[2].set((probe_max_x() - probe_min_x()) / 2, probe_max_y()); + #if HAS_BED_PROBE || HAS_LEVELING + #if IS_KINEMATIC + static constexpr float printable_radius = ( + #if ENABLED(DELTA) + DELTA_PRINTABLE_RADIUS + #elif IS_SCARA + SCARA_PRINTABLE_RADIUS #endif - #endif + ); + + static inline float probe_radius() { + return printable_radius - _MAX(MIN_PROBE_EDGE, HYPOT(offset_xy.x, offset_xy.y)); + } + #endif + + static inline float min_x() { + return ( + #if IS_KINEMATIC + (X_CENTER) - probe_radius() + #else + _MAX((X_MIN_BED) + (MIN_PROBE_EDGE_LEFT), (X_MIN_POS) + offset_xy.x) + #endif + ); } + static inline float max_x() { + return ( + #if IS_KINEMATIC + (X_CENTER) + probe_radius() + #else + _MIN((X_MAX_BED) - (MIN_PROBE_EDGE_RIGHT), (X_MAX_POS) + offset_xy.x) + #endif + ); + } + static inline float min_y() { + return ( + #if IS_KINEMATIC + (Y_CENTER) - probe_radius() + #else + _MAX((Y_MIN_BED) + (MIN_PROBE_EDGE_FRONT), (Y_MIN_POS) + offset_xy.y) + #endif + ); + } + static inline float max_y() { + return ( + #if IS_KINEMATIC + (Y_CENTER) + probe_radius() + #else + _MIN((Y_MAX_BED) - (MIN_PROBE_EDGE_BACK), (Y_MAX_POS) + offset_xy.y) + #endif + ); + } + + #if NEEDS_THREE_PROBE_POINTS + // Retrieve three points to probe the bed. Any type exposing set(X,Y) may be used. + template + static inline void get_three_points(T points[3]) { + #if ENABLED(HAS_FIXED_3POINT) + points[0].set(PROBE_PT_1_X, PROBE_PT_1_Y); + points[1].set(PROBE_PT_2_X, PROBE_PT_2_Y); + points[2].set(PROBE_PT_3_X, PROBE_PT_3_Y); + #else + #if IS_KINEMATIC + constexpr float SIN0 = 0.0, SIN120 = 0.866025, SIN240 = -0.866025, + COS0 = 1.0, COS120 = -0.5 , COS240 = -0.5; + points[0].set((X_CENTER) + probe_radius() * COS0, (Y_CENTER) + probe_radius() * SIN0); + points[1].set((X_CENTER) + probe_radius() * COS120, (Y_CENTER) + probe_radius() * SIN120); + points[2].set((X_CENTER) + probe_radius() * COS240, (Y_CENTER) + probe_radius() * SIN240); + #else + points[0].set(min_x(), min_y()); + points[1].set(max_x(), min_y()); + points[2].set((max_x() - min_x()) / 2, max_y()); + #endif + #endif + } + #endif + + #endif // HAS_BED_PROBE + + #if HAS_Z_SERVO_PROBE + static void servo_probe_init(); #endif -#endif -#if HAS_Z_SERVO_PROBE - void servo_probe_init(); -#endif + #if QUIET_PROBING + static void set_probing_paused(const bool p); + #endif -#if QUIET_PROBING - void probing_pause(const bool p); -#endif +private: + static bool move_to_z(const float z, const feedRate_t fr_mm_s); + static void do_z_raise(const float z_raise); + static float run_z_probe(); +}; + +extern Probe probe;