Skip to content

Instantly share code, notes, and snippets.

@cellularmitosis
Last active January 14, 2024 02:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cellularmitosis/9f604a0e84e9788b7f6e8fb1020545cb to your computer and use it in GitHub Desktop.
Save cellularmitosis/9f604a0e84e9788b7f6e8fb1020545cb to your computer and use it in GitHub Desktop.
"EZOFF": Easy offsets and keepouts for Marlin firmware

Blog 2022/9/26

<- previous | index | next ->

"EZOFF": Easy offsets and keepouts for Marlin firmware

The Marlin 3D printer firmware project has support for setting travel limits:

// The size of the printable area
#define X_BED_SIZE 235
#define Y_BED_SIZE 235

// Travel limits (linear=mm, rotational=°) after homing, corresponding to endstop positions.
#define X_MIN_POS 0
#define Y_MIN_POS 0
#define Z_MIN_POS 0
#define X_MAX_POS X_BED_SIZE
#define Y_MAX_POS Y_BED_SIZE
#define Z_MAX_POS 250

I tried to use these to create "keepout" areas (i.e. to avoid hitting the binder clips at the edges of my printer bed) but I found it difficult to understand how to use them properly, and kept triggering compiler errors:

In file included from Marlin/src/HAL/AVR/../../inc/MarlinConfig.h:49:0,
                 from Marlin/src/HAL/AVR/HAL.cpp:24:
Marlin/src/HAL/AVR/../../inc/SanityCheck.h:819:1: error: static assertion failed: Movement bounds (Y_MIN_POS, Y_MAX_POS) are too narrow to contain Y_BED_SIZE.
 static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS) are too narrow to contain Y_BED_SIZE.");

After taking the time to understand these errors, I came up with the following constants and formulas which are easier (for me) to understand.

// @section geometry

// "EZOFF" bed geometry (offsets + keepouts).
// Note: Tell your slicer to use a bed size with all of your keepouts subtracted.
// For example, with a physical bed size of 235x235 and keepouts of (5,5,25,10),
// use a bed size 225x200 in your slicer to keep your prints centered.

#define EZOFF_X_PHYSICAL_BED_SIZE 235
#define EZOFF_Y_PHYSICAL_BED_SIZE 235

#define EZOFF_X_CENTER_OFFSET 0
#define EZOFF_Y_CENTER_OFFSET 0

#define EZOFF_X_LEFT_KEEPOUT 5
#define EZOFF_X_RIGHT_KEEPOUT 5
#define EZOFF_Y_FRONT_KEEPOUT 25
#define EZOFF_Y_REAR_KEEPOUT 10

// Don't edit these formulas:

#define X_MIN_POS (0 - EZOFF_X_CENTER_OFFSET - EZOFF_X_LEFT_KEEPOUT)
#define X_MAX_POS (EZOFF_X_PHYSICAL_BED_SIZE - EZOFF_X_LEFT_KEEPOUT - EZOFF_X_RIGHT_KEEPOUT - EZOFF_X_CENTER_OFFSET)
#define X_BED_SIZE (X_MAX_POS - X_MIN_POS)

#define Y_MIN_POS (0 - EZOFF_Y_CENTER_OFFSET - EZOFF_Y_FRONT_KEEPOUT)
#define Y_MAX_POS (EZOFF_Y_PHYSICAL_BED_SIZE - EZOFF_Y_FRONT_KEEPOUT - EZOFF_Y_REAR_KEEPOUT - EZOFF_Y_CENTER_OFFSET)
#define Y_BED_SIZE (Y_MAX_POS - Y_MIN_POS)

Enjoy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment