Skip to content

Commit 17edff8

Browse files
committed
✨ Chameleon3D Filament Changer
1 parent ade6dbf commit 17edff8

File tree

14 files changed

+490
-9
lines changed

14 files changed

+490
-9
lines changed

Marlin/Configuration.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@
392392
* PRUSA_MMU3 : Průša MMU3 (Requires MK3S extruder with motion sensor and MMU firmware version 3.x.x, EXTRUDERS = 5)
393393
* EXTENDABLE_EMU_MMU2 : MMU with configurable number of filaments (ERCF, SMuFF or similar with Průša MMU2 compatible firmware)
394394
* EXTENDABLE_EMU_MMU2S : MMUS with configurable number of filaments (ERCF, SMuFF or similar with Průša MMU2 compatible firmware)
395+
* CHAMELEON : Chameleon with up to 4 switchable filaments
395396
*
396397
* Requires NOZZLE_PARK_FEATURE to park print head in case MMU unit fails.
397398
* See additional options in Configuration_adv.h.

Marlin/Configuration_adv.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4633,6 +4633,37 @@
46334633

46344634
#endif // HAS_PRUSA_MMU2 || HAS_PRUSA_MMU3
46354635

4636+
#if HAS_CHAMELEON
4637+
4638+
#define CHAMELEON_BUTTON1_X X_MAX_POS // Button 1 depressed position
4639+
#define CHAMELEON_BUTTON2_X X_MIN_POS // Button 2 depressed position (Used for EXTRUDERS > 2)
4640+
//#define CHAMELEON_TOOLCHANGE_Y Y_CENTER // A standard Y position for all tool-changes
4641+
//#define CHAMELEON_TOOLCHANGE_Z Z_MAX_POS // Enable and adjust if the switch is top-mounted
4642+
4643+
// Design the ramming sequence to first retract out of the hotend,
4644+
// then do blob elimination at the tip, then retract all the way
4645+
// back out of the feeder splitter.
4646+
#define CHAMELEON_RAMMING_SEQUENCE \
4647+
{ -10, 10000 }, /* < fast (shape) */ \
4648+
{ -40, 600 }, /* < slow (cool) */ \
4649+
{ +50, 10000 }, /* > fast (shape) */ \
4650+
{ -10, 10000 }, /* < fast (shape) */ \
4651+
{ -40, 600 }, /* < slow (cool) */ \
4652+
{ +51, 10000 }, /* > fast (unblob) */ \
4653+
{ -11, 10000 }, /* < fast (shape) */ \
4654+
{ +11, 10000 }, /* > fast (unblob) */ \
4655+
{ -11, 10000 }, /* < fast (shape) */ \
4656+
{ +11, 10000 }, /* > fast (unblob) */ \
4657+
{ -11, 10000 }, /* < fast (shape) */ \
4658+
{ -40, 100 }, /* < slow (cool) */ \
4659+
{ -110, 10000 }, /* < fast (shape) */ \
4660+
{ +40, 1000 }, /* > fast (shape) */ \
4661+
{ -40, 1000 }, /* < fast (shape) */ \
4662+
{ +40, 1000 }, /* > fast (shape) */ \
4663+
{ -130, 5000 } /* < fast (unload) */
4664+
4665+
#endif // HAS_CHAMELEON
4666+
46364667
/**
46374668
* Advanced Print Counter settings
46384669
* @section stats

Marlin/src/core/macros.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,12 @@
307307
#define GANG_N_1(N,K) _GANG_N(N,K,K,K,K,K,K,K,K,K,K,K,K,K,K,K,K)
308308

309309
// Expansion of some list items
310+
#define LIST_32(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,AA,BB,CC,DD,EE,FF,...) A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,AA,BB,CC,DD,EE,FF
311+
#define LIST_31(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,AA,BB,CC,DD,EE,...) A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,AA,BB,CC,DD,EE
312+
#define LIST_30(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,AA,BB,CC,DD,...) A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,AA,BB,CC,DD
313+
#define LIST_29(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,AA,BB,CC,...) A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,AA,BB,CC
314+
#define LIST_28(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,AA,BB,...) A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,TU,V,W,X,Y,Z,AA,BB
315+
#define LIST_27(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,AA,...) A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,AA
310316
#define LIST_26(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,...) A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z
311317
#define LIST_25(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,...) A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y
312318
#define LIST_24(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,...) A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X
@@ -572,6 +578,17 @@
572578
#define INC_18 19
573579
#define INC_19 20
574580
#define INC_20 21
581+
#define INC_21 22
582+
#define INC_22 23
583+
#define INC_23 24
584+
#define INC_24 25
585+
#define INC_25 26
586+
#define INC_26 27
587+
#define INC_27 28
588+
#define INC_28 29
589+
#define INC_29 30
590+
#define INC_30 31
591+
#define INC_31 32
575592
#define INCREMENT_(n) INC_##n
576593
#define INCREMENT(n) INCREMENT_(n)
577594

@@ -607,6 +624,23 @@
607624
#define DEC_13 12
608625
#define DEC_14 13
609626
#define DEC_15 14
627+
#define DEC_16 15
628+
#define DEC_17 16
629+
#define DEC_18 17
630+
#define DEC_19 18
631+
#define DEC_20 19
632+
#define DEC_21 20
633+
#define DEC_22 21
634+
#define DEC_23 22
635+
#define DEC_24 23
636+
#define DEC_25 24
637+
#define DEC_26 25
638+
#define DEC_27 26
639+
#define DEC_28 27
640+
#define DEC_29 28
641+
#define DEC_30 29
642+
#define DEC_31 30
643+
#define DEC_32 31
610644
#define DECREMENT_(n) DEC_##n
611645
#define DECREMENT(n) DECREMENT_(n)
612646

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/**
2+
* Marlin 3D Printer Firmware
3+
* Copyright (c) 2023 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4+
*
5+
* Based on Sprinter and grbl.
6+
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
23+
#include "../../inc/MarlinConfig.h"
24+
25+
#if HAS_CHAMELEON
26+
27+
#include "chameleon.h"
28+
//#include "../../MarlinCore.h"
29+
#include "../../module/planner.h"
30+
#include "../../module/stepper.h"
31+
#include "../../lcd/marlinui.h"
32+
33+
//#define DEBUG_OUT ENABLED(DEBUG_CHAMELEON)
34+
#include "../../core/debug_out.h"
35+
36+
Chameleon chameleon;
37+
38+
struct E_Step {
39+
float extrude;
40+
feedRate_t feedRate;
41+
};
42+
43+
// Change tools the Chameleon 3D way
44+
void Chameleon::tool_change(const uint8_t index) {
45+
const uint8_t switches = active_extruder ^ index;
46+
if (!switches) return;
47+
48+
ui.status_printf(0, GET_TEXT_F(MSG_MMU2_LOADING_FILAMENT), int(index + 1));
49+
50+
#ifdef CHAMELEON_TOOLCHANGE_Y
51+
current_position.y = CHAMELEON_TOOLCHANGE_Y;
52+
#endif
53+
#ifdef CHAMELEON_TOOLCHANGE_Z
54+
NOLESS(current_position.z, CHAMELEON_TOOLCHANGE_Z);
55+
line_to_current_position(5000);
56+
#endif
57+
if (switches & 0x1) {
58+
current_position.x = CHAMELEON_BUTTON1_X + (X_CENTER > (CHAMELEON_BUTTON1_X)) ? 10 : -10;
59+
}
60+
else {
61+
#if EXTRUDERS > 2
62+
if (switches & 0x2)
63+
current_position.x = CHAMELEON_BUTTON2_X + (X_CENTER > (CHAMELEON_BUTTON2_X)) ? 10 : -10;
64+
#endif
65+
}
66+
line_to_current_position(5000);
67+
68+
static constexpr E_Step ramming_sequence[] PROGMEM = { CHAMELEON_RAMMING_SEQUENCE };
69+
execute_extruder_sequence(ramming_sequence, COUNT(ramming_sequence));
70+
71+
toggle(switches);
72+
73+
active_extruder = index;
74+
75+
ui.reset_status();
76+
}
77+
78+
// Execute a list of E moves
79+
void Chameleon::execute_extruder_sequence(const E_Step * const sequence, const uint8_t steps) {
80+
planner.synchronize();
81+
stepper.enable_extruder();
82+
83+
const E_Step *step = sequence;
84+
85+
for (uint8_t i = 0; i < steps; ++i) {
86+
const float es = pgm_read_float(&(step->extrude));
87+
const uint16_t fr_or_ms = pgm_read_float(&(step->feedRate));
88+
89+
DEBUG_ECHO_MSG("Move E", es, " @ ", fr_or_ms);
90+
91+
if (es) {
92+
current_position.e += es;
93+
line_to_current_position(MMM_TO_MMS(fr_or_ms));
94+
planner.synchronize();
95+
}
96+
else
97+
safe_delay(fr_or_ms);
98+
99+
step++;
100+
}
101+
102+
// Reset E to 0 for the new extruder tool
103+
current_position.e = 0;
104+
sync_plan_position_e();
105+
106+
stepper.disable_extruder();
107+
}
108+
109+
// Bump the switches needed to change feeders
110+
void Chameleon::toggle(const uint8_t switches) {
111+
if (switches & 0x1) {
112+
current_position.x = CHAMELEON_BUTTON1_X;
113+
line_to_current_position(2000);
114+
current_position.x += (X_CENTER > (CHAMELEON_BUTTON1_X)) ? 10 : -10;
115+
line_to_current_position(2000);
116+
}
117+
#if EXTRUDERS > 2
118+
if (switches & 0x2) {
119+
current_position.x = CHAMELEON_BUTTON2_X;
120+
line_to_current_position(2000);
121+
current_position.x += (X_CENTER > (CHAMELEON_BUTTON2_X)) ? 10 : -10;
122+
line_to_current_position(2000);
123+
}
124+
#endif
125+
planner.synchronize();
126+
}
127+
128+
#endif // HAS_CHAMELEON

Marlin/src/feature/mmu/chameleon.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Marlin 3D Printer Firmware
3+
* Copyright (c) 2023 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4+
*
5+
* Based on Sprinter and grbl.
6+
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
#pragma once
23+
24+
#include <stdint.h>
25+
26+
struct E_Step;
27+
28+
class Chameleon {
29+
public:
30+
Chameleon() {}
31+
static void tool_change(const uint8_t new_tool);
32+
33+
private:
34+
static void execute_extruder_sequence(const E_Step * const sequence, const uint8_t steps);
35+
static void toggle(const uint8_t switches);
36+
};
37+
38+
extern Chameleon chameleon;

Marlin/src/gcode/gcode.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,8 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
458458
case 80: G80(); break; // G80: Reset the current motion mode
459459
#endif
460460

461-
case 90: set_relative_mode(false); break; // G90: Absolute Mode
462-
case 91: set_relative_mode(true); break; // G91: Relative Mode
461+
case 90: G90(); break; // G90: Absolute Mode
462+
case 91: G91(); break; // G91: Relative Mode
463463

464464
case 92: G92(); break; // G92: Set current axis position(s)
465465

Marlin/src/gcode/gcode.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,9 @@ class GcodeSuite {
632632
static void G80();
633633
#endif
634634

635+
static void G90() { set_relative_mode(false); }
636+
static void G91() { set_relative_mode(true); }
637+
635638
static void G92();
636639

637640
#if ENABLED(CALIBRATION_GCODE)

Marlin/src/inc/Conditionals-1-axes.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
#define _PRUSA_MMU2 2
9898
#define _PRUSA_MMU2S 3
9999
#define _PRUSA_MMU3 4
100+
#define _CHAMELEON 5
100101
#define _EXTENDABLE_EMU_MMU2 12
101102
#define _EXTENDABLE_EMU_MMU2S 13
102103
#define _EXTENDABLE_EMU_MMU3 14
@@ -111,6 +112,8 @@
111112
#define HAS_PRUSA_MMU2S 1
112113
#elif _MMU % 10 == _PRUSA_MMU3
113114
#define HAS_PRUSA_MMU3 1
115+
#elif _MMU % 10 == _CHAMELEON
116+
#define HAS_CHAMELEON 1
114117
#endif
115118
#if _MMU == _EXTENDABLE_EMU_MMU2 || _MMU == _EXTENDABLE_EMU_MMU2S
116119
#define HAS_EXTENDABLE_MMU 1
@@ -121,6 +124,7 @@
121124
#undef _PRUSA_MMU2
122125
#undef _PRUSA_MMU2S
123126
#undef _PRUSA_MMU3
127+
#undef _CHAMELEON
124128
#undef _EXTENDABLE_EMU_MMU2
125129
#undef _EXTENDABLE_EMU_MMU2S
126130
#undef _EXTENDABLE_EMU_MMU3
@@ -157,7 +161,7 @@
157161
#define E_STEPPERS EXTRUDERS
158162
#define E_MANUAL EXTRUDERS
159163

160-
#elif HAS_PRUSA_MMU2 || HAS_PRUSA_MMU3 // Průša Multi-Material Unit v2/v3
164+
#elif HAS_PRUSA_MMU2 || HAS_PRUSA_MMU3 || HAS_CHAMELEON // Multi-Material Unit
161165

162166
#define E_STEPPERS 1
163167
#define E_MANUAL 1

Marlin/src/inc/SanityCheck.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,13 +646,22 @@ static_assert(COUNT(arm) == LOGICAL_AXES, "AXIS_RELATIVE_MODES must contain " _L
646646
#endif
647647
#endif
648648

649+
#if HAS_CHAMELEON
650+
#if EXTRUDERS > 32
651+
#undef SINGLENOZZLE
652+
#error "CHAMELEON only supports up to 32 EXTRUDERS. Please update your Configuration."
653+
#endif
654+
#endif
655+
649656
/**
650657
* Options only for EXTRUDERS > 1
651658
*/
652659
#if HAS_MULTI_EXTRUDER
653660

654661
#ifndef MAX_EXTRUDERS
655-
#if HAS_EXTENDABLE_MMU
662+
#if HAS_CHAMELEON
663+
#define MAX_EXTRUDERS 32
664+
#elif HAS_EXTENDABLE_MMU
656665
#define MAX_EXTRUDERS 15
657666
#else
658667
#define MAX_EXTRUDERS 8

Marlin/src/module/stepper/indirection.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,12 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset
668668
#define FWD_E_DIR(E) do{ E0_DIR_WRITE(TEST(E, 0) ? HIGH : LOW ); }while(0)
669669
#define REV_E_DIR(E) do{ E0_DIR_WRITE(TEST(E, 0) ? LOW : HIGH); }while(0)
670670

671+
#elif ENABLED(CHAMELEON) // One multiplexed stepper driver, reversed on T2/T3, T6/T7, T10/T11, etc.
672+
673+
#define E_STEP_WRITE(E,V) E0_STEP_WRITE(V)
674+
#define NORM_E_DIR(E) do{ E0_DIR_WRITE(TEST(E, 1) ? HIGH : LOW ); }while(0)
675+
#define REV_E_DIR(E) do{ E0_DIR_WRITE(TEST(E, 1) ? LOW : HIGH); }while(0)
676+
671677
#elif E_STEPPERS > 1
672678

673679
#if E_STEPPERS > 7

0 commit comments

Comments
 (0)