Skip to content

Commit

Permalink
misc.
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Apr 28, 2023
1 parent 2069bb4 commit ec6eae1
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Marlin/src/gcode/calibrate/G28.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ void GcodeSuite::G28() {

#if HAS_Z_AXIS

UNUSED(needZ);UNUSED(homeZZ);
UNUSED(needZ); UNUSED(homeZZ);

// Z may home first, e.g., when homing away from the bed.
// This is also permitted when homing with a Z endstop.
Expand Down
34 changes: 22 additions & 12 deletions Marlin/src/lcd/e3v2/jyersui/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,13 @@ void CrealityDWINClass::Menu_Item_Handler(const uint8_t menu, const uint8_t item
static float mlev_z_pos = 0;
static bool use_probe = false;

#if HAS_BED_PROBE
constexpr float probe_x_min = _MAX(0 + corner_pos, X_MIN_POS + probe.offset.x, X_MIN_POS + PROBING_MARGIN) - probe.offset.x,
probe_x_max = _MIN((X_BED_SIZE + X_MIN_POS) - corner_pos, X_MAX_POS + probe.offset.x, X_MAX_POS - PROBING_MARGIN) - probe.offset.x,
probe_y_min = _MAX(0 + corner_pos, Y_MIN_POS + probe.offset.y, Y_MIN_POS + PROBING_MARGIN) - probe.offset.y,
probe_y_max = _MIN((Y_BED_SIZE + Y_MIN_POS) - corner_pos, Y_MAX_POS + probe.offset.y, Y_MAX_POS - PROBING_MARGIN) - probe.offset.y;
#endif

switch (item) {
case MLEVEL_BACK:
if (draw)
Expand All @@ -1430,14 +1437,17 @@ void CrealityDWINClass::Menu_Item_Handler(const uint8_t menu, const uint8_t item
if (use_probe) {
Popup_Handler(Level);
corner_avg = 0;
#define PROBE_X_MIN _MAX(0 + corner_pos, X_MIN_POS + probe.offset.x, X_MIN_POS + PROBING_MARGIN) - probe.offset.x
#define PROBE_X_MAX _MIN((X_BED_SIZE + X_MIN_POS) - corner_pos, X_MAX_POS + probe.offset.x, X_MAX_POS - PROBING_MARGIN) - probe.offset.x
#define PROBE_Y_MIN _MAX(0 + corner_pos, Y_MIN_POS + probe.offset.y, Y_MIN_POS + PROBING_MARGIN) - probe.offset.y
#define PROBE_Y_MAX _MIN((Y_BED_SIZE + Y_MIN_POS) - corner_pos, Y_MAX_POS + probe.offset.y, Y_MAX_POS - PROBING_MARGIN) - probe.offset.y
corner_avg += probe.probe_at_point(PROBE_X_MIN, PROBE_Y_MIN, PROBE_PT_RAISE, 0, false);
corner_avg += probe.probe_at_point(PROBE_X_MIN, PROBE_Y_MAX, PROBE_PT_RAISE, 0, false);
corner_avg += probe.probe_at_point(PROBE_X_MAX, PROBE_Y_MAX, PROBE_PT_RAISE, 0, false);
corner_avg += probe.probe_at_point(PROBE_X_MAX, PROBE_Y_MIN, PROBE_PT_STOW, 0, false);
constexpr struct { xy_pos_t p, ProbePtRaise r } points[] = {
{ { probe_x_min, probe_y_min }, PROBE_PT_RAISE },
{ { probe_x_min, probe_y_max }, PROBE_PT_RAISE },
{ { probe_x_max, probe_y_max }, PROBE_PT_RAISE },
{ { probe_x_max, probe_y_min }, PROBE_PT_STOW }
};
for (uint8_t i = 0; i < COUNT(points); i++) {
const float mz = probe.probe_at_point(points[i].p, points[i].r, 0, false);
if (isnan(mz)) { corner_avg = 0; break; }
corner_avg += mz;
}
corner_avg /= 4;
Redraw_Menu();
}
Expand All @@ -1451,7 +1461,7 @@ void CrealityDWINClass::Menu_Item_Handler(const uint8_t menu, const uint8_t item
Popup_Handler(MoveWait);
if (use_probe) {
#if HAS_BED_PROBE
sprintf_P(cmd, PSTR("G0 F4000\nG0 Z10\nG0 X%s Y%s"), dtostrf(PROBE_X_MIN, 1, 3, str_1), dtostrf(PROBE_Y_MIN, 1, 3, str_2));
sprintf_P(cmd, PSTR("G0 F4000\nG0 Z10\nG0 X%s Y%s"), dtostrf(probe_x_min, 1, 3, str_1), dtostrf(probe_y_min, 1, 3, str_2));
gcode.process_subcommands_now(cmd);
planner.synchronize();
Popup_Handler(ManualProbing);
Expand All @@ -1472,7 +1482,7 @@ void CrealityDWINClass::Menu_Item_Handler(const uint8_t menu, const uint8_t item
Popup_Handler(MoveWait);
if (use_probe) {
#if HAS_BED_PROBE
sprintf_P(cmd, PSTR("G0 F4000\nG0 Z10\nG0 X%s Y%s"), dtostrf(PROBE_X_MIN, 1, 3, str_1), dtostrf(PROBE_Y_MAX, 1, 3, str_2));
sprintf_P(cmd, PSTR("G0 F4000\nG0 Z10\nG0 X%s Y%s"), dtostrf(probe_x_min, 1, 3, str_1), dtostrf(probe_y_max, 1, 3, str_2));
gcode.process_subcommands_now(cmd);
planner.synchronize();
Popup_Handler(ManualProbing);
Expand All @@ -1493,7 +1503,7 @@ void CrealityDWINClass::Menu_Item_Handler(const uint8_t menu, const uint8_t item
Popup_Handler(MoveWait);
if (use_probe) {
#if HAS_BED_PROBE
sprintf_P(cmd, PSTR("G0 F4000\nG0 Z10\nG0 X%s Y%s"), dtostrf(PROBE_X_MAX, 1, 3, str_1), dtostrf(PROBE_Y_MAX, 1, 3, str_2));
sprintf_P(cmd, PSTR("G0 F4000\nG0 Z10\nG0 X%s Y%s"), dtostrf(probe_x_max, 1, 3, str_1), dtostrf(probe_y_max, 1, 3, str_2));
gcode.process_subcommands_now(cmd);
planner.synchronize();
Popup_Handler(ManualProbing);
Expand All @@ -1514,7 +1524,7 @@ void CrealityDWINClass::Menu_Item_Handler(const uint8_t menu, const uint8_t item
Popup_Handler(MoveWait);
if (use_probe) {
#if HAS_BED_PROBE
sprintf_P(cmd, PSTR("G0 F4000\nG0 Z10\nG0 X%s Y%s"), dtostrf(PROBE_X_MAX, 1, 3, str_1), dtostrf(PROBE_Y_MIN, 1, 3, str_2));
sprintf_P(cmd, PSTR("G0 F4000\nG0 Z10\nG0 X%s Y%s"), dtostrf(probe_x_max, 1, 3, str_1), dtostrf(probe_y_min, 1, 3, str_2));
gcode.process_subcommands_now(cmd);
planner.synchronize();
Popup_Handler(ManualProbing);
Expand Down
13 changes: 8 additions & 5 deletions Marlin/src/module/probe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ bool Probe::probe_down_to_z(const_float_t z, const_feedRate_t fr_mm_s) {
*
* @return The Z position of the bed at the current XY or NAN on error.
*/
float Probe::run_z_probe(const bool sanity_check/*=true*/, const float z_min_point/*=Z_PROBE_LOW_POINT*/, const float z_clearance/*=Z_TWEEN_SAFE_CLEARANCE*/) {
float Probe::run_z_probe(const bool sanity_check/*=true*/, const_float_t z_min_point/*=Z_PROBE_LOW_POINT*/, const_float_t z_clearance/*=Z_TWEEN_SAFE_CLEARANCE*/) {
DEBUG_SECTION(log_probe, "Probe::run_z_probe", DEBUGGING(LEVELING));

const float zoffs = SUM_TERN(HAS_HOTEND_OFFSET, -offset.z, hotend_offset[active_extruder].z);
Expand Down Expand Up @@ -742,8 +742,7 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/, const float z_min_poi

// Stop the probe before it goes too low to prevent damage.
// For known Z probe below the expected trigger point, otherwise -10mm lower.
const float z_probe_low_point = axis_is_trusted(Z_AXIS) ? zoffs + z_min_point : zoffs + z_min_point - 10.0f;

const float z_probe_low_point = zoffs + z_min_point -float((!axis_is_trusted(Z_AXIS)) * 10);
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Probe Low Point: ", z_probe_low_point);

// Double-probing does a fast probe followed by a slow probe
Expand Down Expand Up @@ -904,7 +903,8 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/, const float z_min_poi
*/
float Probe::probe_at_point(const_float_t rx, const_float_t ry, const ProbePtRaise raise_after/*=PROBE_PT_NONE*/,
const uint8_t verbose_level/*=0*/, const bool probe_relative/*=true*/, const bool sanity_check/*=true*/,
const float z_min_point/*=Z_PROBE_LOW_POINT*/, const float z_clearance/*=Z_TWEEN_SAFE_CLEARANCE*/, const bool lift_relative/*=false*/
const_float_t z_min_point/*=Z_PROBE_LOW_POINT*/, const_float_t z_clearance/*=Z_TWEEN_SAFE_CLEARANCE*/,
const bool raise_after_is_relative/*=false*/
) {
DEBUG_SECTION(log_probe, "Probe::probe_at_point", DEBUGGING(LEVELING));

Expand Down Expand Up @@ -961,7 +961,10 @@ float Probe::probe_at_point(const_float_t rx, const_float_t ry, const ProbePtRai
switch (raise_after) {
default: break;
case PROBE_PT_RAISE:
lift_relative ? do_z_clearance(current_position.z + z_clearance, false) : do_z_clearance(z_clearance);
if (raise_after_is_relative)
do_z_clearance(current_position.z + z_clearance, false);
else
do_z_clearance(z_clearance);
break;
case PROBE_PT_STOW: case PROBE_PT_LAST_STOW:
if (stow()) measured_z = NAN; // Error on stow?
Expand Down
10 changes: 6 additions & 4 deletions Marlin/src/module/probe.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,15 @@ class Probe {

static float probe_at_point(const_float_t rx, const_float_t ry, const ProbePtRaise raise_after=PROBE_PT_NONE,
const uint8_t verbose_level=0, const bool probe_relative=true, const bool sanity_check=true,
const float z_min_point=Z_PROBE_LOW_POINT, const float z_clearance=Z_TWEEN_SAFE_CLEARANCE, const bool lift_relative=false);
const_float_t z_min_point=Z_PROBE_LOW_POINT, const_float_t z_clearance=Z_TWEEN_SAFE_CLEARANCE,
const bool raise_after_is_relative=false);

static 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, const bool sanity_check=true,
const float z_min_point=Z_PROBE_LOW_POINT, float z_clearance=Z_TWEEN_SAFE_CLEARANCE, const bool lift_relative=false
const_float_t z_min_point=Z_PROBE_LOW_POINT, float z_clearance=Z_TWEEN_SAFE_CLEARANCE,
const bool raise_after_is_relative=false
) {
return probe_at_point(pos.x, pos.y, raise_after, verbose_level, probe_relative, sanity_check, z_min_point, z_clearance, lift_relative);
return probe_at_point(pos.x, pos.y, raise_after, verbose_level, probe_relative, sanity_check, z_min_point, z_clearance, raise_after_is_relative);
}

#else // !HAS_BED_PROBE
Expand Down Expand Up @@ -340,7 +342,7 @@ class Probe {

private:
static bool probe_down_to_z(const_float_t z, const_feedRate_t fr_mm_s);
static float run_z_probe(const bool sanity_check=true, const float z_min_point=Z_PROBE_LOW_POINT, const float z_clearance=Z_TWEEN_SAFE_CLEARANCE);
static float run_z_probe(const bool sanity_check=true, const_float_t z_min_point=Z_PROBE_LOW_POINT, const_float_t z_clearance=Z_TWEEN_SAFE_CLEARANCE);
};

extern Probe probe;

0 comments on commit ec6eae1

Please sign in to comment.