June 27, 2026
Description
This is a post processing python script, which uses time based modeling of the print cooling fan based a user supplied look-up matrix to feed forward gcode commands. This enables the part fan to be at the target speed, when needed for an overhang or bridge.
Currently in all Slicers and printer firmware, the part cooling fan is called to turn on "M106 S225" at the exact same instant its required for an overhang or bridge. However, the fan itself takes multiple seconds to spool up to that RPM and is often past the feature before being effective, resulting in undercooling, curling, or failed bridges. This increasingly becomes an issue with faster print head speeds.
6-27-26 - ratrig_fan_advance_v0.1.0-beta.2
Fixed a silent crash with very large files. Added a progress indicator in the cmd window when running to see if the script has stalled. It still takes up to 2hrs to post-process a 24hr print script with many fan changes.
# ================== TUNABLE PARAMETERS ==================
# Change them only after real-world testing and note what you changed.
BRIDGE_MIN_SPEED = 175 # Fan speed (0-255) that counts as "high-cooling / bridge mode".
# Anything >= this value triggers the bridge-hold logic.
# Lower = more features treated as bridges (more aggressive hold).
# Higher = only very high fan demands get the hold treatment.
BRIDGE_END_HOLD_PERCENT = 0.82 # Target % of the high fan speed that should still be present
# at the exact end of the bridge/overhang feature.
# 0.82 = 82% (your current sweet spot).
# Increase to 0.87 for even stronger bridge end cooling.
# Decrease to 0.75 if you notice slight over-cooling after bridges.
HORIZON = 3.8 # Seconds to look ahead when bundling multiple fan changes.
# Higher = more aggressive bundling (fewer advance commands).
# Lower = more precise per-command advances.
SAFETY_MARGIN = 1.09 # Multiplier applied to calculated ramp time for safety.
# 1.09 = start the ramp 9% earlier than measured time.
# Increase (e.g. 1.12) if fan arrives a bit late.
# Decrease (e.g. 1.06) if it arrives too early.
KICK_FROM = 50 # If current fan speed is below this AND target is above KICK_TO,
KICK_TO = 160 # a short 255 burst (kick-start) is inserted.
KICK_DURATION = 0.48 # Duration (seconds) of the full-speed kick-start burst.
# Higher duration = stronger cold-start boost (good for slow fans).
# Lower = gentler kick (avoids over-cooling on short features).
# =========================================================
Disclaimer: I'm not a software engineer by trade. The code is probably not elegant or very robust. I used Grok / Opus to help debug it. I continue to test more complex parts, but I would consider this an Alpha build.
To use the script:
Install the latest version of Python.
Save the script in a file location like: C:\Scripts\RepRap_Fan_AdvanceRevA.py
In PrusaSlicer, go to the Print Settings tab, scroll to Output Options, and in the field labled Post-Processing Scripts
Enter the full command to run Python with the script name: "C:\Path\To\Your\python.exe" "C:\Path\To\fan_advance.py"
It should look like: "C:\Users\YourName\AppData\Local\Programs\Python\Python312\python.exe" "C:\Scripts\RatRig_Fan_AdvanceRevO.py"
Save the Print Settings profile with a modified name. Its easy to switch between profiles to test the script.
Modify the Script Matrix for you fan: Use notepad++. Using a stop watch or data from klipper, fill out the matrix for the various speed changes for the fan. Example of part of that matrix below. Change the "bold" number for time in seconds. Lines can be added or subtracted from the matrix, as the script will interpolate between point. The current matrix was based off of a 4028 12V fan for a RatRig Vcore4.
(0, 255, 2.5), # 0% → 100%: 2.5s Acceleration
(255, 0, 7.0), # 100% → 0%: 7.0s Deceleration
Check the gcode post script: Use the built-in PrusaSlicer Gcode preview and look at where the fan callouts come in the post processed gcode file. You should see changes similar to this Before and After.
Test Prints in Red ASA: Left- Before / Right Side-After. 25 degree overhang test, 0.2mm layer height, 0.6mm nozzle, ASA at 255C. No other changes besides running the script to add fan feed forward. For the overhang, the intended fan speed was 90% for ASA, in a heated 60C chamber.
License:
Creative Commons — Attribution
7