[GUIDE] Marlin Firmware Retract

Adding Go Faster Stripes to your 3D Printer
Post Reply
Mystikal
Posts: 4
Joined: Mon Feb 05, 2018 1:02 am

[GUIDE] Marlin Firmware Retract

Post: # 296Post Mystikal
Mon Feb 05, 2018 11:54 am

Marlin Firmware Retract
Introduction
Hi guys! Since I've discovered Marlin Firmware Retract (or FwRetract) I've been loving it. It's an awesome feature that allows one simple thing: it teaches the firmware HOW to retract and allow the slicer to simply tell WHEN to retract.

By doing this way, we have 3 major improvement:
1) We can edit retract settings while printing, by just using gcode or the LCD screen
2) We can use the same gcode on multiple machine with different retract settings
3) We don't need to reslice our model if we change them

Sadly, I've found that many don't use them or doesn't even know it's a feature that exist, mostly due to the fact that you need to fiddle a little with the slicer to support it (nothing hard, we'll take care in this guide)

It's higly suggested to use this feature with EEPROM settings, otherwise you'll need to flash the firmware every change

Usefull links

Part 1: Enable FwRetract in Marlin

First of all, we need to enable FwRetract in Marlin. We just need to open our editor, open the file Configuration_adv.h and search (usually Ctrl+F) for the world FWRETRACT. It's usually around line 830. The section we need to edit should looks like this:

Code: Select all

/**
 * Firmware-based and LCD-controlled retract
 *
 * Add G10 / G11 commands for automatic firmware-based retract / recover.
 * Use M207 and M208 to define parameters for retract / recover.
 *
 * Use M209 to enable or disable auto-retract.
 * With auto-retract enabled, all G1 E moves within the set range
 * will be converted to firmware-based retract/recover moves.
 *
 * Be sure to turn off auto-retract during filament change.
 *
 * Note that M207 / M208 / M209 settings are saved to EEPROM.
 *
 */
//#define FWRETRACT  // ONLY PARTIALLY TESTED
#if ENABLED(FWRETRACT)
  #define MIN_AUTORETRACT 0.1             // When auto-retract is on, convert E moves of this length and over
  #define MAX_AUTORETRACT 10.0            // Upper limit for auto-retract conversion
  #define RETRACT_LENGTH 3                // Default retract length (positive mm)
  #define RETRACT_LENGTH_SWAP 13          // Default swap retract length (positive mm), for extruder change
  #define RETRACT_FEEDRATE 45             // Default feedrate for retracting (mm/s)
  #define RETRACT_ZLIFT 0                 // Default retract Z-lift
  #define RETRACT_RECOVER_LENGTH 0        // Default additional recover length (mm, added to retract length when recovering)
  #define RETRACT_RECOVER_LENGTH_SWAP 0   // Default additional swap recover length (mm, added to retract length when recovering from extruder change)
  #define RETRACT_RECOVER_FEEDRATE 8      // Default feedrate for recovering from retraction (mm/s)
  #define RETRACT_RECOVER_FEEDRATE_SWAP 8 // Default feedrate for recovering from swap retraction (mm/s)
#endif
The part between the /* and */ it's just an intro about this feature, so we can just ignore it.

To begin, we enable this function by removing the // before #define FWRETRACT and we check every settings one by one.
  1. #define MIN_AUTORETRACT 0.1: This value is used for Automatic Firmware Retraction. We will not use it in this guide and the Marlin developer themself suggest to not use it. More on this later
  2. #define MAX_AUTORETRACT 10.0: This value is used for Automatic Firmware Retraction. We will not use it in this guide and the Marlin developer themself suggest to not use it. More on this later
  3. #define RETRACT_LENGTH 3: The amount (in mm) of filament to retract
  4. #define RETRACT_LENGTH_SWAP 13: The amount (in mm) of filament to retract when changing extruder
  5. #define RETRACT_FEEDRATE 45: The speed (in mm/s) for retract
  6. #define RETRACT_ZLIFT 0: How much (in mm) the nozzle should raise when retracting. If you want to use it, just set it a little more than your average layer height. I've put 0.21. This feature is also called Z-Hop
  7. #define RETRACT_RECOVER_LENGTH 0: When recovering, how much ADDITIONAL mm of filament should be pushed. Usually, this value is used to push LESS filament when recovering, if some filament start oozing before the retract movement ends and may prevent a blob. For example, if you want to recover 0.2 mm less, just put -0.2
  8. #define RETRACT_RECOVER_LENGTH_SWAP 0: Same as the previous value, but for extruder swap
  9. #define RETRACT_RECOVER_FEEDRATE 8: The speed for recovering filament. You can just put the same value as RETRACT_FEEDRATE
  10. #define RETRACT_RECOVER_FEEDRATE_SWAP 8: Same as previous value, but for extruder swap
We will be able to change this value later using Gcode or the LCD, but It's a good idea to put your retract settings here as a starting point

After you've set everything, just flash the firmware and we're good to go!


Part 2: Set up your slicer

Now that the firmware is ready, we need to tell our slicer that, instead of writing the standard retract and recover Gcode (a G1 command followed by the retraction parameter), now it just need to send G10 to retract and G11 to recover.

As I write this guide, I've only used Simplify3D and Cura. If needed I'll add more slicer to this section.

Part 2.1: Simplify3D
Simplify3D doesn't support G10/G11 command by themself, so we will put some placeholder values to the retract settings, and we will replace those strings with G10 and G11 command.

First of all, we need to make sure the option Allow zeroing of extrusion distances (i.e. G92 E0) under the G-Code tab is enabled. This way, the slicer will set to 0 the extrusion distance every loop and every retraction will have the same G-Code.

Image

After this, we will set our retraction settings with some placeholder values. Under the Extruder tab, I've set 1 mm of retraction at 100 mm/s (or 6000 mm/min) but they will not affect our print in any way. We just need them to replace them with G10/G11 code.
This way, our retraction gcode will look like these:
  • G1 E-1.0000 F6000 to retract
  • G1 E0.0000 F6000 to recover
Image

Finally, we go to the Script tab and, in the "Additional terminal command for post processing" we need to insert this code:

Code: Select all

{REPLACE "G1 E-1.0000 F6000\n" "G10\n"}
{REPLACE "G1 E0.0000 F6000\n" "G11\n"}
{REPLACE "G1 E0.0000 F1800\n" "G11\n"}
The first 2 lines will replace our retract and recover in all our gcode. There is a bug (I think) in Simplify3D that, when moving from the skirt to the item, it will recover at only 30% speed. The last REPLACE will take care of it.

Image

Our slicer is ready! We can check that we have G10 and G11 command in our gcode to see if everything works and maybe do a 3DBenchy to check it

Part 2.2: Cura

Cura natively support G10/G11 while using Marlin (Volumetric) flavor for Gcode due to the fact that Volumetric extrusion adds more portability to the gcode, in the same ways Firmware retraction does. This, however, require a whole guide by itself, that I want to write.

I've tried to use post-processing to add G10/G11 but, due to the fact that Post-processing setting aren't persistent in Cura, they need to be set again every time you open the software, so it's not ideal

I'll definitely write a guide about volumetric extrusion as soon as possibile, and I will link it here when it's done.

Part 3: Automatic Firmware Retraction

Marlin can detect retract and recover movement (a gcode line with G0 E) in GCode and, with Automatic Firmware Retract (aka AutoRetract aka AFR) can ignore their parameter and use it's FwRetract settings instead.

However, this may cause some problem with the Gcode and it's highly not suggested to leave on. You will find more information on Marlin documentation

Part 4: Gcode and Configuration

Once you've enabled FwRetract, you'll find a new option under your "Control" menu. Here, you'll able to change every parameter we've set before in the firmware about retraction, even while printing. This, is probably the most common and easy way to fine tune them

However, you can change this value by using G-code too. The 2 command we'll need are:

M207 [F<feedrate>] [S<length>] [W<length>] [Z<length>]
With this command we can set every parameter about the retraction. Every one of them is optional.
  • [F<feedrate>] will change the feedrate (speed) of retraction, in mm/min
  • [S<length>] will change the lenght of retraction, in mm
  • [W<length>] will change the lenght of retraction for extruder swap, in mm
  • [Z<length>] will change the Z-lift (Z-hop), in mm
M208 [F<feedrate>] [S<length>] [W<length>]
With this command we can set every parameter about recover. Every one of them is optional.
  • [F<feedrate>] will change the feedrate (speed) of recover, in mm/min
  • [S<length>] will change the additional lenght for recover, in mm
  • [W<length>] will change the additional lenght for recover for extruder swap, in mm
Save the changes in the EEPROM (with LCD or with M500) if you want and you're done!

Conclusion

I really hope you'll find this guide usefull. Sadly, I'm not a native english speaker, so there may be a few errors with the language in this guide. I hope you'll forgive me and let me know if I need to fix something.

Happy retracting!
Last edited by Mystikal on Mon Feb 05, 2018 11:33 pm, edited 1 time in total.



User avatar
LrdSatyr8
Posts: 28
Joined: Thu Jan 11, 2018 2:35 pm

Re: Marlin Firmware Retract

Post: # 305Post LrdSatyr8
Mon Feb 05, 2018 2:37 pm

Ok maybe I'm confused here... but doesn't the slicer already create the retraction commands based on the slicer settings when it's creating the gcode to print? I really don't understand what this would do to improve the current way I print and how my retraction settings work perfectly now as it is. Am I missing something here?
Whatever you do, don't tighten the nuts against the acrylic too much... you'll regret it!

Mystikal
Posts: 4
Joined: Mon Feb 05, 2018 1:02 am

Re: Marlin Firmware Retract

Post: # 306Post Mystikal
Mon Feb 05, 2018 2:56 pm

LrdSatyr8 wrote:
Mon Feb 05, 2018 2:37 pm
Ok maybe I'm confused here... but doesn't the slicer already create the retraction commands based on the slicer settings when it's creating the gcode to print? I really don't understand what this would do to improve the current way I print and how my retraction settings work perfectly now as it is. Am I missing something here?
Ok, this is the point.

Normally, when a slicer wants to retract it will generate a gcode like this:

Code: Select all

G0 E-1.000 F2100 ; Retract for 1mm at 35 mm/s
G1 ... ; Move
G1 ... ; Move
G1 ... ; Move
G0 E0.000 F2100 ; Recover to E0 at 35 mm/s
With Firmware retraction, the gcode generated will look like this

Code: Select all

G10 ; Retract
G1 ... ; Move
G1 ... ; Move
G1 ... ; Move
G11 ; Recover
It's the firmware that knows how to retract and how to recover, the slicer just tells it to do it.

By itself, doing this change won't improve your print but just think at a couple of scenarios:
  • You start a print and, in the middle of the print, you notice some stringing. With firmware retraction you can just use the lcd to give a little bit of lenght and fix the problem
  • You need to print the same file in 4 different printer (or 4 different material with different retraction value), all with their settings. You just slice the model once, and the printer will do the rest
  • You have a bunch of gcode that you keep printing. You change your filament brand and you need new retraction settings. Normally you should reslice every gcode, with firmware retraction you just set it in the printer and it's done
It's a little improvement, I know, but it comes with 0 drawbacks, except for a little bit of initial configuration

User avatar
LrdSatyr8
Posts: 28
Joined: Thu Jan 11, 2018 2:35 pm

Re: Marlin Firmware Retract

Post: # 311Post LrdSatyr8
Mon Feb 05, 2018 7:03 pm

Ahhhh... Now I understand! Thank you!
Whatever you do, don't tighten the nuts against the acrylic too much... you'll regret it!

thamask
Posts: 11
Joined: Wed Jan 10, 2018 2:33 pm

Re: [GUIDE] Marlin Firmware Retract

Post: # 349Post thamask
Wed Feb 07, 2018 11:26 am

Great guide, thanks.

ModMike
Posts: 26
Joined: Thu Feb 08, 2018 3:07 pm

Re: [GUIDE] Marlin Firmware Retract

Post: # 625Post ModMike
Fri Mar 02, 2018 5:19 am

Nice write up on a great tip, thanks.

Post Reply