Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mixing Extruder Feature #3655

Closed

Conversation

thinkyhead
Copy link
Member

@thinkyhead thinkyhead commented May 1, 2016

Most of the email I receive about Marlin concerns this feature. So here is the implementation built on top of the current RCBugFix for those interested parties.

  • New feature option MIXING_EXTRUDER_FEATURE
  • Support for M163, M164 as in Repetier Host
  • Additional command M165 to set the mix in one line
  • Optional support for ABCDHI mixing parameters in G1 commands (reference implementation)

Concise diff: https://github.com/MarlinFirmware/Marlin/pull/3655/files?w=1

@thinkyhead thinkyhead force-pushed the rc_mixing_extruder branch 3 times, most recently from 8df81dc to 4a1feb7 Compare May 4, 2016 00:47
@jbrazio
Copy link
Contributor

jbrazio commented May 4, 2016

@thinkyhead this is exactly the type of PR that does not fit on a RC as not every change can be encapsulated inside an #if ENABLED(MIXING_EXTRUDER_FEATURE) (or better an #if ENABLED(EXPERIMENTAL_MIXING_EXTRUDER_FEATURE)).

@thinkyhead
Copy link
Member Author

thinkyhead commented May 4, 2016

@jbrazio This is not intended to be merged at this time. It's an exhibit. Sorry for the confusion.

not every change can be encapsulated

AFAIK every change is in fact "encapsulated." With the feature off, Marlin should behave as usual. There might be one or two stylistic patches piggybacking here.

@thinkyhead thinkyhead added S: Don't Merge Work in progress or under discussion. Needs: Testing Testing is needed for this change labels May 4, 2016
@jbrazio
Copy link
Contributor

jbrazio commented May 4, 2016

You're right, but a fully encapsulated change don't mess with existing code for instance, this one does a lot of rework on Marlin_main.cpp.

@thinkyhead
Copy link
Member Author

thinkyhead commented May 4, 2016

The only "rework" I can see is the code in gcode_T and actually it's not much. The reason it looks like a lot is due to changed indentation. Here's a diff without the whitespace changes.

@jbrazio
Copy link
Contributor

jbrazio commented May 4, 2016

No please ! It's ok, I only frown a bit for RC but you already clarified that.

@thinkyhead
Copy link
Member Author

In the long run, as with other features, it would be nice to encapsulate. But that might mean a bigger binary.

@thinkyhead thinkyhead force-pushed the rc_mixing_extruder branch 2 times, most recently from bf8e844 to f103012 Compare May 5, 2016 21:14
@thinkyhead thinkyhead force-pushed the rc_mixing_extruder branch from f103012 to 70b0ff2 Compare May 20, 2016 23:23
@thinkyhead thinkyhead force-pushed the rc_mixing_extruder branch from 70b0ff2 to b459bd0 Compare May 27, 2016 02:03
@thinkyhead thinkyhead force-pushed the rc_mixing_extruder branch 7 times, most recently from 0d366c5 to 1c41799 Compare June 5, 2016 00:11
@thinkyhead
Copy link
Member Author

thinkyhead commented Jun 5, 2016

The LIN_ADVANCE feature #3676 should be merged ahead of this, and then this can be patched up to support LIN_ADVANCE.

@thinkyhead thinkyhead force-pushed the rc_mixing_extruder branch 2 times, most recently from 7e6644d to 29e3e38 Compare June 12, 2016 00:07
@jbrazio jbrazio added this to the 1.1.0 milestone Jul 18, 2016
@thinkyhead thinkyhead deleted the rc_mixing_extruder branch July 20, 2016 01:00
@jbrazio jbrazio modified the milestone: 1.1.0 Jul 23, 2016
@manitas532
Copy link

Hola a Todos.
tengo una prusa i3 con mega2560 y ramps 1.4, y e conprado cyclops y no se como actualizar mi marlin para tener funcion de mesclar colores,, alguien podria ayudarme a configurar mi marlin?

Gracias.

@emartinez167
Copy link
Contributor

emartinez167 commented Sep 27, 2016

There is no colour mixing support in Marlin yet. And also very few Spanish
speaking people in the team so please try to use English for a quicker
response.

@manitas532
Copy link

Sorry for not translate. So I can not use it? .o There any solution? Canbiando plate or marlin .....

@emartinez167
Copy link
Contributor

emartinez167 commented Sep 27, 2016

I know there are is at least one Marlin fork that had done it but I can't
remember the name. Team, can anyone tell us which fork has done this? Was
it Kimbra?

@manitas532
Copy link

This can be http://www.marlinkimbra.it/?p=559? My problem is I'm new configuration not only step change but little more could you help me ?. I have saved my marlin

@emartinez167
Copy link
Contributor

emartinez167 commented Sep 28, 2016

If you plan to use Kimbra's Marlin, I think it is better if you contact him
directly, particularly on the colour mixing part. Not sure who can help
from this team. @thinkyhead?

@manitas532
Copy link

Ok thanks'll ask. Also if someone here can help seguire thread.

Thank you

@emartinez167
Copy link
Contributor

emartinez167 commented Sep 28, 2016

No problem

@thinkyhead
Copy link
Member Author

thinkyhead commented Sep 28, 2016

@manitas532 Actually, @emartinez167 is mistaken. There is color mixing support in Marlin 1.1.0. I'm the developer who implemented it. But it doesn't support the extra "stirring" motor that some extruders include. If you need help in configuring it, let me know and I will do what I can to help. It probably needs some testing and feedback, because there are very few people using it. This would be a good opportunity to fix it up.

/**
 * "Mixing Extruder"
 *   - Adds a new code, M165, to set the current mix factors.
 *   - Extends the stepping routines to move multiple steppers in proportion to the mix.
 *   - Optional support for Repetier Host M163, M164, and virtual extruder.
 *   - This implementation supports only a single extruder.
 *   - Enable DIRECT_MIXING_IN_G1 for Pia Taubert's reference implementation
 */
//#define MIXING_EXTRUDER
#if ENABLED(MIXING_EXTRUDER)
  #define MIXING_STEPPERS 2        // Number of steppers in your mixing extruder
  #define MIXING_VIRTUAL_TOOLS 16  // Use the Virtual Tool method with M163 and M164
  //#define DIRECT_MIXING_IN_G1    // Allow ABCDHI mix factors in G1 movement commands
#endif

@emartinez167
Copy link
Contributor

emartinez167 commented Sep 28, 2016

Sorry for that. I thought it was still in development mode.

@manitas532
Copy link

manitas532 commented Sep 28, 2016

@thinkyhead please.. I don't have idea what I must do. If I can send you my marlin you will configure me this?? I'm afraid because I don't know do and I'm looked since 2 month ago.. Thank you for all

@manitas532
Copy link

alguien podría ayudarme a configurarlo el marlin para cyclops mixter?es que no consigo configurarlo me da errores
thanks
Marlin-Marlin_v1 (cama 220V).zip

@thinkyhead
Copy link
Member Author

thinkyhead commented Oct 2, 2016

@manitas532 All you need to do is enable MIXING_EXTRUDER and set MIXING_STEPPERS as needed. Everything else is as usual.

With the feature enabled, you can then use M163, M164, M165 to manage mixing in your GCode files. Some slicers may already know how to do mixing, or you may have to edit your GCode by hand to add the necessary commands. When using mixing you usually want to include a "wipe tower" to purge material between color changes. But when doing something like a vase you can just allow the mix to gradually change.

Documentation on these commands:

/**
 * M163: Set a single mix factor for a mixing extruder
 *       This is called "weight" by some systems.
 *
 *   S[index]   The channel index to set
 *   P[float]   The mix value
 *
 */

/**
 * M164: Store the current mix factors as a virtual tool.
 *
 *   S[index]   The virtual tool to store
 *
 */

M163 S0 Pn sets the mix proportion (0.0 through 1.0) for the first extruder.
M163 S1 Pn sets the mix proportion (0.0 through 1.0) for the second extruder.
These proportions should add up to 1.0. They will be "normalized."

M164 S1 will save the mix as tool index number 1.
T1 will select the mix stored as tool number 1.

@manitas532
Copy link

manitas532 commented Oct 5, 2016

@thinkyhead . Thank you very much, My problem is that not compile. But thanks also

@thinkyhead
Copy link
Member Author

thinkyhead commented Oct 6, 2016

@manitas532 If it fails to compile, post your configuration.
Either a bug will be fixed, or your configuration will be corrected.

@mkc2000
Copy link

mkc2000 commented Nov 10, 2016

@ thinkyhead
I am using Marlin 1.1.0-RC7 FW
I can get the G1 mixing to function properly but it has to be placed in every extruder line (currently using 3 extruders)...

G1 A0.2 B0.2 C0.6 E10

I have tried the format:

M163 S0 P5
M163 S1 P1
M163 S2 P0
M164 S0

also

M163 S0 P0.2
M163 S1 P0.2
M163 S2 P0.6
M164 S0

then initiating T0 by:

M104 T0 S240
G92 E0
M109 T0 S240

My extruder moves do nothing with the m codes...

I am using Repetier-Host V1.6.2 and have set my virtual extruders set but the M163, M164 method is not working. I have also tried a variety of M165 commands :( nothing

Any suggestions? Also is there a way to have the G1 method inserted only once at each colour change, rather than every extrusion move??

Also a few more questions because I think they will be quick answers for you ;)

What is the max number of MIXING_STEPPERS? 4 or depending on hardware? I am using Ramps 1.4 with X3 Stepper Expander and plan on 5 MIXING_STEPPERS

In Repetier-Host can I setup 5 scripts of 16 virtual mixing values - 80 colours?

Thanks!

mixing def code:

#define MIXING_EXTRUDER
#if ENABLED(MIXING_EXTRUDER)
  #define MIXING_STEPPERS 3 // Number of steppers in your mixing extruder
  #define MIXING_VIRTUAL_TOOLS 16 // Use the Virtual Tool method with M163 and M164
  #define DIRECT_MIXING_IN_G1 // Allow ABCDHI mix factors in G1 movement commands
#endif

@thinkyhead
Copy link
Member Author

thinkyhead commented Nov 12, 2016

Hi @mkc2000 — Sorry to hear there's trouble in mixing-land. It hasn't been widely tested, so this is a good chance to make sure it's in proper working order. I'd recommend taking the M163+M164 or M165 approach and creating virtual tools. When you want to select a virtual tool (a defined color mix), you have to issue T0, T1, T2, etc. on a line by itself.

What is the max number of MIXING_STEPPERS

It should be set to the number of steppers that you have on the mixing extruder.

In Repetier-Host can I setup 5 scripts of 16 virtual mixing values - 80 colours?

With MIXING_VIRTUAL_TOOLS 16 you can store up to 16 colors at once and activate them with T0-T15. Each mix will have up to 3 components (red, blue, yellow?) with your current setup, and up to 5 components (add in white and black!) once you have 5 mixing steppers.

When mixing, any values for mixing factors will work, but they are always "normalized" when they're stored. So for your example:

M163 S0 P5
M163 S1 P1
M163 S2 P0
M164 S5

T5

This mix will be stored as Tool #5 with 5/6ths of color 1 (0.8333), plus 1/6th of color 2 (0.1667), and no color 3 (0.0). (So they will always add up to 1.0.)

The command M104 T0 S240 doesn't activate tool 0. In this case the parameter T0 simply overrides whatever the current tool is, so that extruder 0 will start heating.

@thinkyhead thinkyhead removed Needs: Testing Testing is needed for this change S: Don't Merge Work in progress or under discussion. labels Nov 12, 2016
@Blue-Marlin
Copy link
Contributor

(red, blue, yellow?)

Ideally yellow, cyan, magenta, (black, white). In a colour (paper) printer you can omit white - that's provided by the paper.
Red, Green, Blue is for mixing light only.

@mkc2000
Copy link

mkc2000 commented Nov 13, 2016

Thanks for the reply Scott.
Yes I am trying the M163 M164 M165 approach but the extruders do not move at all unless I use the G1 approach...
and yes Blue-Marlin my colours are listed below... I do have 5 extruders CYMKW but I want to get 3 colour mixing working first ;)
I run the following M163 M164 code as a macro from the #"1" storage macro in Repetier-Host V1.6.2 before executing my program.
Then I run a program as in the example below. But every line with an E value generates a
(Warning: Mix factors must add up to 1.0. Scaling) message and the extruders do not move only XYZ.
Do you have a sample program that has worked for you or someone else?

; Cyan
M163 S0 P1
M163 S1 P0
M163 S2 P0
M164 S0 P1

; Ocean
M163 S0 P5
M163 S1 P1
M163 S2 P0
M164 S1

; Blue
M163 S0 P1
M163 S1 P1
M163 S2 P0
M164 S2

; Violet
M163 S0 P1
M163 S1 P5
M163 S2 P0
M164 S3

; Magenta
M163 S0 P0
M163 S1 P1
M163 S2 P0
M164 S4

; Raspberry
M163 S0 P0
M163 S1 P5
M163 S2 P1
M164 S5

; Red
M163 S0 P0
M163 S1 P1
M163 S2 P1
M164 S6

; Orange
M163 S0 P0
M163 S1 P1
M163 S2 P5
M164 S7

; Yellow
M163 S0 P0
M163 S1 P0
M163 S2 P1
M164 S8

; Spring Green
M163 S0 P1
M163 S1 P0
M163 S2 P5
M164 S9

; Green
M163 S0 P1
M163 S1 P0
M163 S2 P1
M164 S10

; Turquoise
M163 S0 P5
M163 S1 P0
M163 S2 P1
M164 S11

; Cyan-Brown
M163 S0 P2
M163 S1 P1
M163 S2 P1
M164 S12

; Magenta-Brown
M163 S0 P1
M163 S1 P2
M163 S2 P1
M164 S13

; Yellow-Brown
M163 S0 P1
M163 S1 P1
M163 S2 P2
M164 S14

; Brown
M163 S0 P1
M163 S1 P1
M163 S2 P1
M164 S15

Program below generated with the Cura slicer in Repetier:


;Generated with Cura_SteamEngine 15.01
; Default start code
G28 ; Home extruder
G1 Z15 F100
M107 ; Turn off fan
G90 ; Absolute positioning
M82 ; Extruder in absolute mode
M190 S60
; Activate all used extruder
M104 T0 S240
G92 E0 ; Reset extruder position
; Wait for all used extruders to reach temperature
M109 T0 S240
;Layer count: 1
;LAYER:0
M107
G0 F9000 X3.652 Y32.175 Z0.300
;TYPE:SKIRT
G1 F1800 X20.312 Y32.175 E0.83117
G1 X20.312 Y48.835 E1.66234
G1 X3.652 Y48.835 E2.49351
G1 X3.652 Y32.175 E3.32468
G0 F9000 X4.052 Y32.575
G1 F1800 X19.912 Y32.575 E4.11594
G1 X19.912 Y48.435 E4.90720
G1 X4.052 Y48.435 E5.69846
G1 X4.052 Y32.575 E6.48972
G0 F9000 X4.452 Y32.975
G1 F1800 X19.512 Y32.975 E7.24106
G1 X19.512 Y48.035 E7.99241
G1 X4.452 Y48.035 E8.74376
G1 X4.452 Y32.975 E9.49510
G1 F2400 E5.49510
G0 F9000 X4.452 Y32.975 Z5.101
; Default end code
;G1 X0 Y0 Z130 ; Get extruder out of way. Uncomment to use!
M107 ; Turn off fan
; Disable all extruder
G91 ; Relative positioning
T0
G1 E-1 ; Reduce filament pressure
M104 T0 S0
M104 T1 S0
M104 T2 S0
M104 T3 S0
M104 T4 S0
M104 T5 S0
M104 T6 S0
M104 T7 S0
M104 T8 S0
M104 T9 S0
M104 T10 S0
M104 T11 S0
M104 T12 S0
M104 T13 S0
M104 T14 S0
M104 T15 S0
G90 ; Absolute positioning
G92 E0 ; Reset extruder position
M140 S0 ; Disable heated bed
M84 ; Turn steppers off

@mkc2000
Copy link

mkc2000 commented Nov 13, 2016

I am thinking something Marlin_main.cpp
is mix_total getting calculated properly?
Should I comment out #define DIRECT_MIXING_IN_G1 in Configuration.h??

#if ENABLED(MIXING_EXTRUDER)

  void normalize_mix() {
    float mix_total = 0.0;
    for (int i = 0; i < MIXING_STEPPERS; i++) {
      float v = mixing_factor[i];
      if (v < 0) v = mixing_factor[i] = 0;
      mix_total += v;
    }
    // Scale all values if they don't add up to ~1.0
    if (mix_total < 0.9999 || mix_total > 1.0001) {
      SERIAL_PROTOCOLLNPGM("Warning: Mix factors must add up to 1.0. Scaling.");
      float mix_scale = 1.0 / mix_total;
      for (int i = 0; i < MIXING_STEPPERS; i++)
        mixing_factor[i] *= mix_scale;
    }
  }

  #if ENABLED(DIRECT_MIXING_IN_G1)
    // Get mixing parameters from the GCode
    // Factors that are left out are set to 0
    // The total "must" be 1.0 (but it will be normalized)
    void gcode_get_mix() {
      const char* mixing_codes = "ABCDHI";
      for (int i = 0; i < MIXING_STEPPERS; i++)
        mixing_factor[i] = code_seen(mixing_codes[i]) ? code_value_float() : 0;

      normalize_mix();
    }
  #endif

@mkc2000
Copy link

mkc2000 commented Nov 13, 2016

Answered my own question...
Commenting out #define DIRECT_MIXING_IN_G1 in Configuration.h did the trick.

@thinkyhead
Copy link
Member Author

True. You can't use both options. The solution is either for us to add a sanity check and prevent compiling with both options, or to change gcode_get_mix in this general manner:

void gcode_get_mix() {
  const char* mixing_codes = "ABCDHI";
  for (int i = 0; i < MIXING_STEPPERS; i++) {
-   float v = code_seen(mixing_codes[i]) ? code_value_float() : 0.0;
+   float v = code_seen(mixing_codes[i]) ? code_value_float() : RECIPROCAL(mixing_factor[i]);
    NOLESS(v, 0.0);
    mixing_factor[i] = RECIPROCAL(v);
  }
  normalize_mix();
}

The reason for using 0.0 for an omitted mix factor is so you don't have to specify all of them on every G1, but just the ones you want to include. Since this is a non-standard feature, it might go away in the long run. Meanwhile I will come up with a patch to allow them to work together, and so that when G1 sets the mix, the next G1 without any mix factors won't clear it.

@thinkyhead
Copy link
Member Author

Fixed with #5228. If you include any mix factors with G1, it's a whole new mix. If you include no mix factors with G1 then the previous mix is preserved.

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

Successfully merging this pull request may close these issues.

8 participants