Skip to content

Commit

Permalink
✨ NOZZLE_CLEAN_PATTERN_* (MarlinFirmware#25666)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
  • Loading branch information
2 people authored and EvilGremlin committed May 17, 2023
1 parent e247262 commit d1eeb43
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 142 deletions.
28 changes: 18 additions & 10 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -2409,23 +2409,31 @@
//#define NOZZLE_CLEAN_FEATURE

#if ENABLED(NOZZLE_CLEAN_FEATURE)
// Default number of pattern repetitions
#define NOZZLE_CLEAN_STROKES 12
#define NOZZLE_CLEAN_PATTERN_LINE // Provide 'G12 P0' - a simple linear cleaning pattern
#define NOZZLE_CLEAN_PATTERN_ZIGZAG // Provide 'G12 P1' - a zigzag cleaning pattern
#define NOZZLE_CLEAN_PATTERN_CIRCLE // Provide 'G12 P2' - a circular cleaning pattern
// Default number of triangles
#define NOZZLE_CLEAN_TRIANGLES 3
// Default pattern to use when 'P' is not provided to G12. One of the enabled options above.
#define NOZZLE_CLEAN_DEFAULT_PATTERN 0

#if ENABLED(NOZZLE_CLEAN_PATTERN_LINE)
#define NOZZLE_CLEAN_STROKES 12 // Default number of pattern repetitions
#endif

#if ENABLED(NOZZLE_CLEAN_PATTERN_ZIGZAG)
#define NOZZLE_CLEAN_TRIANGLES 3 // Default number of triangles
#endif

// Specify positions for each tool as { { X, Y, Z }, { X, Y, Z } }
// Dual hotend system may use { { -20, (Y_BED_SIZE / 2), (Z_MIN_POS + 1) }, { 420, (Y_BED_SIZE / 2), (Z_MIN_POS + 1) }}
#define NOZZLE_CLEAN_START_POINT { { 30, 30, (Z_MIN_POS + 1) } }
#define NOZZLE_CLEAN_END_POINT { { 100, 60, (Z_MIN_POS + 1) } }

// Circular pattern radius
#define NOZZLE_CLEAN_CIRCLE_RADIUS 6.5
// Circular pattern circle fragments number
#define NOZZLE_CLEAN_CIRCLE_FN 10
// Middle point of circle
#define NOZZLE_CLEAN_CIRCLE_MIDDLE NOZZLE_CLEAN_START_POINT
#if ENABLED(NOZZLE_CLEAN_PATTERN_CIRCLE)
#define NOZZLE_CLEAN_CIRCLE_RADIUS 6.5 // (mm) Circular pattern radius
#define NOZZLE_CLEAN_CIRCLE_FN 10 // Circular pattern circle number of segments
#define NOZZLE_CLEAN_CIRCLE_MIDDLE NOZZLE_CLEAN_START_POINT // Middle point of circle
#endif

// Move the nozzle to the initial position after cleaning
#define NOZZLE_CLEAN_GOBACK
Expand Down
14 changes: 10 additions & 4 deletions Marlin/src/gcode/feature/clean/G12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,16 @@ void GcodeSuite::G12() {
}
#endif

const uint8_t pattern = parser.ushortval('P', 0),
strokes = parser.ushortval('S', NOZZLE_CLEAN_STROKES),
objects = parser.ushortval('T', NOZZLE_CLEAN_TRIANGLES);
const float radius = parser.linearval('R', NOZZLE_CLEAN_CIRCLE_RADIUS);
const uint8_t pattern = (
#if COUNT_ENABLED(NOZZLE_CLEAN_PATTERN_LINE, NOZZLE_CLEAN_PATTERN_ZIGZAG, NOZZLE_CLEAN_PATTERN_CIRCLE) > 1
parser.ushortval('P', NOZZLE_CLEAN_DEFAULT_PATTERN)
#else
NOZZLE_CLEAN_DEFAULT_PATTERN
#endif
);
const uint8_t strokes = TERN0(NOZZLE_CLEAN_PATTERN_LINEAR, parser.ushortval('S', NOZZLE_CLEAN_STROKES)),
objects = TERN0(NOZZLE_CLEAN_PATTERN_ZIGZAG, parser.ushortval('T', NOZZLE_CLEAN_TRIANGLES));
const float radius = TERN0(NOZZLE_CLEAN_PATTERN_CIRCLE, parser.linearval('R', NOZZLE_CLEAN_CIRCLE_RADIUS));

const bool seenxyz = parser.seen("XYZ");
const uint8_t cleans = (!seenxyz || parser.boolval('X') ? _BV(X_AXIS) : 0)
Expand Down
15 changes: 15 additions & 0 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -3816,6 +3816,21 @@ static_assert(_PLUS_TEST(4), "HOMING_FEEDRATE_MM_M values must be positive.");
#undef _CLEAN_ASSERT
#endif

/**
* Sanity check nozzle cleaning pattern settings
*/
#if ENABLED(NOZZLE_CLEAN_FEATURE)
#if NONE(NOZZLE_CLEAN_PATTERN_LINE, NOZZLE_CLEAN_PATTERN_ZIGZAG, NOZZLE_CLEAN_PATTERN_CIRCLE)
#error "NOZZLE_CLEAN_FEATURE requires at least one of NOZZLE_CLEAN_PATTERN_LINE, NOZZLE_CLEAN_PATTERN_ZIGZAG, and/or NOZZLE_CLEAN_PATTERN_CIRCLE."
#elif NOZZLE_CLEAN_DEFAULT_PATTERN == 0 && DISABLED(NOZZLE_CLEAN_PATTERN_LINE)
#error "NOZZLE_CLEAN_DEFAULT_PATTERN 0 (LINE) is not available. Enable NOZZLE_CLEAN_PATTERN_LINE or set a different NOZZLE_CLEAN_DEFAULT_PATTERN."
#elif NOZZLE_CLEAN_DEFAULT_PATTERN == 1 && DISABLED(NOZZLE_CLEAN_PATTERN_ZIGZAG)
#error "NOZZLE_CLEAN_DEFAULT_PATTERN 1 (ZIGZAG) is not available. Enable NOZZLE_CLEAN_PATTERN_ZIGZAG or set a different NOZZLE_CLEAN_DEFAULT_PATTERN."
#elif NOZZLE_CLEAN_DEFAULT_PATTERN == 2 && DISABLED(NOZZLE_CLEAN_PATTERN_CIRCLE)
#error "NOZZLE_CLEAN_DEFAULT_PATTERN 2 (CIRCLE) is not available. Enable NOZZLE_CLEAN_PATTERN_CIRCLE or set a different NOZZLE_CLEAN_DEFAULT_PATTERN."
#endif
#endif

/**
* Sanity check for MIXING_EXTRUDER & DISTINCT_E_FACTORS these are not compatible
*/
Expand Down
Loading

0 comments on commit d1eeb43

Please sign in to comment.