Skip to content

Commit ac31bbb

Browse files
apulverAndy-Big
authored andcommitted
✨ AVOID_OBSTACLES for UBL (MarlinFirmware#25256)
1 parent aeccf61 commit ac31bbb

File tree

4 files changed

+64
-9
lines changed

4 files changed

+64
-9
lines changed

Marlin/Configuration.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,6 +2080,25 @@
20802080

20812081
//#define UBL_MESH_WIZARD // Run several commands in a row to get a complete mesh
20822082

2083+
/**
2084+
* Probing not allowed within the position of an obstacle.
2085+
*/
2086+
//#define AVOID_OBSTACLES
2087+
#if ENABLED(AVOID_OBSTACLES)
2088+
#define CLIP_W 23 // Bed clip width, should be padded a few mm over its physical size
2089+
#define CLIP_H 14 // Bed clip height, should be padded a few mm over its physical size
2090+
2091+
// Obstacle Rectangles defined as { X1, Y1, X2, Y2 }
2092+
#define OBSTACLE1 { (X_BED_SIZE) / 4 - (CLIP_W) / 2, 0, (X_BED_SIZE) / 4 + (CLIP_W) / 2, CLIP_H }
2093+
#define OBSTACLE2 { (X_BED_SIZE) * 3 / 4 - (CLIP_W) / 2, 0, (X_BED_SIZE) * 3 / 4 + (CLIP_W) / 2, CLIP_H }
2094+
#define OBSTACLE3 { (X_BED_SIZE) / 4 - (CLIP_W) / 2, (Y_BED_SIZE) - (CLIP_H), (X_BED_SIZE) / 4 + (CLIP_W) / 2, Y_BED_SIZE }
2095+
#define OBSTACLE4 { (X_BED_SIZE) * 3 / 4 - (CLIP_W) / 2, (Y_BED_SIZE) - (CLIP_H), (X_BED_SIZE) * 3 / 4 + (CLIP_W) / 2, Y_BED_SIZE }
2096+
2097+
// The probed grid must be inset for G29 J. This is okay, since it is
2098+
// only used to compute a linear transformation for the mesh itself.
2099+
#define G29J_MESH_TILT_MARGIN ((CLIP_H) + 1)
2100+
#endif
2101+
20832102
#elif ENABLED(MESH_BED_LEVELING)
20842103

20852104
//===========================================================================

Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,9 +1478,17 @@ void unified_bed_leveling::smart_fill_mesh() {
14781478
#include "../../../libs/vector_3.h"
14791479

14801480
void unified_bed_leveling::tilt_mesh_based_on_probed_grid(const bool do_3_pt_leveling) {
1481-
const float x_min = probe.min_x(), x_max = probe.max_x(),
1482-
y_min = probe.min_y(), y_max = probe.max_y(),
1483-
dx = (x_max - x_min) / (param.J_grid_size - 1),
1481+
1482+
#ifdef G29J_MESH_TILT_MARGIN
1483+
const float x_min = _MAX(probe.min_x() + (G29J_MESH_TILT_MARGIN), X_MIN_POS),
1484+
x_max = _MIN(probe.max_x() - (G29J_MESH_TILT_MARGIN), X_MAX_POS),
1485+
y_min = _MAX(probe.min_y() + (G29J_MESH_TILT_MARGIN), Y_MIN_POS),
1486+
y_max = _MIN(probe.max_y() - (G29J_MESH_TILT_MARGIN), Y_MAX_POS);
1487+
#else
1488+
const float x_min = probe.min_x(), x_max = probe.max_x(),
1489+
y_min = probe.min_y(), y_max = probe.max_y();
1490+
#endif
1491+
const float dx = (x_max - x_min) / (param.J_grid_size - 1),
14841492
dy = (y_max - y_min) / (param.J_grid_size - 1);
14851493

14861494
xy_float_t points[3];

Marlin/src/module/probe.h

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ class Probe {
7272
public:
7373

7474
#if ENABLED(SENSORLESS_PROBING)
75-
typedef struct {
76-
bool x:1, y:1, z:1;
77-
} sense_bool_t;
75+
typedef struct { bool x:1, y:1, z:1; } sense_bool_t;
7876
static sense_bool_t test_sensitivity;
7977
#endif
8078

@@ -114,6 +112,32 @@ class Probe {
114112

115113
#else
116114

115+
static bool obstacle_check(const_float_t rx, const_float_t ry) {
116+
#if ENABLED(AVOID_OBSTACLES)
117+
#ifdef OBSTACLE1
118+
constexpr float obst1[] = OBSTACLE1;
119+
static_assert(COUNT(obst1) == 4, "OBSTACLE1 must define a rectangle in the form { X1, Y1, X2, Y2 }.");
120+
if (WITHIN(rx, obst1[0], obst1[2]) && WITHIN(ry, obst1[1], obst1[3])) return false;
121+
#endif
122+
#ifdef OBSTACLE2
123+
constexpr float obst2[] = OBSTACLE2;
124+
static_assert(COUNT(obst2) == 4, "OBSTACLE2 must define a rectangle in the form { X1, Y1, X2, Y2 }.");
125+
if (WITHIN(rx, obst2[0], obst2[2]) && WITHIN(ry, obst2[1], obst2[3])) return false;
126+
#endif
127+
#ifdef OBSTACLE3
128+
constexpr float obst3[] = OBSTACLE3;
129+
static_assert(COUNT(obst3) == 4, "OBSTACLE3 must define a rectangle in the form { X1, Y1, X2, Y2 }.");
130+
if (WITHIN(rx, obst3[0], obst3[2]) && WITHIN(ry, obst3[1], obst3[3])) return false;
131+
#endif
132+
#ifdef OBSTACLE4
133+
constexpr float obst4[] = OBSTACLE4;
134+
static_assert(COUNT(obst4) == 4, "OBSTACLE4 must define a rectangle in the form { X1, Y1, X2, Y2 }.");
135+
if (WITHIN(rx, obst4[0], obst4[2]) && WITHIN(ry, obst4[1], obst4[3])) return false;
136+
#endif
137+
#endif
138+
return true;
139+
}
140+
117141
/**
118142
* Return whether the given position is within the bed, and whether the nozzle
119143
* can reach the position required to put the probe at the given position.
@@ -125,12 +149,16 @@ class Probe {
125149
if (probe_relative) {
126150
return position_is_reachable(rx - offset_xy.x, ry - offset_xy.y)
127151
&& COORDINATE_OKAY(rx, min_x() - fslop, max_x() + fslop)
128-
&& COORDINATE_OKAY(ry, min_y() - fslop, max_y() + fslop);
152+
&& COORDINATE_OKAY(ry, min_y() - fslop, max_y() + fslop)
153+
&& obstacle_check(rx, ry)
154+
&& obstacle_check(rx - offset_xy.x, ry - offset_xy.y);
129155
}
130156
else {
131157
return position_is_reachable(rx, ry)
132158
&& COORDINATE_OKAY(rx + offset_xy.x, min_x() - fslop, max_x() + fslop)
133-
&& COORDINATE_OKAY(ry + offset_xy.y, min_y() - fslop, max_y() + fslop);
159+
&& COORDINATE_OKAY(ry + offset_xy.y, min_y() - fslop, max_y() + fslop)
160+
&& obstacle_check(rx, ry)
161+
&& obstacle_check(rx + offset_xy.x, ry + offset_xy.y);
134162
}
135163
}
136164

buildroot/tests/mega2560

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ ci_src_filter -y
2626
use_example_configs AnimationExample
2727
opt_set MOTHERBOARD BOARD_AZTEEG_X3_PRO LCD_LANGUAGE fr SAVED_POSITIONS 4 DEFAULT_EJERK 10 \
2828
EXTRUDERS 5 TEMP_SENSOR_1 1 TEMP_SENSOR_2 5 TEMP_SENSOR_3 20 TEMP_SENSOR_4 1000 TEMP_SENSOR_BED 1
29-
opt_enable AUTO_BED_LEVELING_UBL RESTORE_LEVELING_AFTER_G28 DEBUG_LEVELING_FEATURE G26_MESH_VALIDATION ENABLE_LEVELING_FADE_HEIGHT SKEW_CORRECTION \
29+
opt_enable AUTO_BED_LEVELING_UBL AVOID_OBSTACLES RESTORE_LEVELING_AFTER_G28 DEBUG_LEVELING_FEATURE G26_MESH_VALIDATION ENABLE_LEVELING_FADE_HEIGHT SKEW_CORRECTION \
3030
REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER LIGHTWEIGHT_UI STATUS_MESSAGE_SCROLLING SHOW_CUSTOM_BOOTSCREEN BOOT_MARLIN_LOGO_SMALL \
3131
SDSUPPORT SDCARD_SORT_ALPHA USB_FLASH_DRIVE_SUPPORT AUTO_REPORT_SD_STATUS SCROLL_LONG_FILENAMES MEDIA_MENU_AT_TOP \
3232
EEPROM_SETTINGS EEPROM_CHITCHAT GCODE_MACROS CUSTOM_MENU_MAIN FREEZE_FEATURE CANCEL_OBJECTS SOUND_MENU_ITEM \

0 commit comments

Comments
 (0)