Skip to content

Instantly share code, notes, and snippets.

@rmeissn
Last active September 17, 2025 07:05
Show Gist options
  • Select an option

  • Save rmeissn/f24294a20b57c870abf1c9e760e54954 to your computer and use it in GitHub Desktop.

Select an option

Save rmeissn/f24294a20b57c870abf1c9e760e54954 to your computer and use it in GitHub Desktop.
Flashforge Adventurer 3 Cura

The firmware of the Flashforge Adventurer 3 seems to understand only a subset of typical marlin gcode:

  • no G0 support (use G1 instead)
  • if XYZ coordinates are combined within G1, the bed leveling mesh seems to be ignored (use two G1 (one for Z and one for XY) instead)
  • M140 does not support decimal point numbers (only e.g. S50 instead of S50.0)
  • M104 does not support decimal point numbers (only e.g. S50 instead of S50.0)
  • no relative E value support (cura produces absolute E values either way)
  • a Z-Offset needs to be included in each Z coordinate if required (use cura Z-Offset plugin and tick "extensive z-offset processing")

-> I've created a bash script to convert cura gcode to flashforge gcode. I'm not sure I've covered all edge cases, but it seems to work.

X: 150mm
Y: 150mm
Z: 150mm
Build_Plate: Rectangular
Origin at Center: Tick
Heated Bed: Tick
Heated Build Volume: false
G-Code Flavor: Marlin
xmin: -20
ymin: -10
xmax: 10
ymax: 10
gantry hight: 150
no of extruders: 1
Apply Extruder Offset: Tick
M104 S0 T0 ; Hotend to 0°C
M140 S0 T0 ; Bed to 0°C
G162 Z F1800 ; Move Z Axes to Maximum
G28 X Y ; Home XY
M132 X Y A B ; Recall home offsets
M652 ; ???
G91 ; Relative Positioning
M18 ; Disable Steppers
M107 ;Turn-off fan
M140 S{material_bed_temperature} T0
M104 S{material_print_temperature} T0
M104 S0 T1 ; Tool 1 to 0°C
M107 ; Fan off
M900 K0.000 T0 ; K-Factor to 0
G90 ; Absolute Positioning
G28 ; Home XYZ
M132 X Y Z A B ; Recall home offsets
G1 Z50.250 F420 ; Move Z to 50mm
G161 X Y F3300 ; Move Axes to Minimum
M7 T0 ; Stabilize bed temperature
M6 T0 ; Stabilize extruder temperature
M651 S255 ; Set case fan on
M108 T0 ; Break and Continue
#!/bin/bash
# use as: transform_cura_to_flashforge.sh xxx.gcode
ConvertedGCode=$(cat $1)
# replace temperature of kind xx.0 to just xx
M140=$(echo "$ConvertedGCode" | grep M140)
while IFS= read -r line; do
convertedLine=$(echo "$line" | sed -E 's/S([0-9]+)\.0/S\1/g')
ConvertedGCode="${ConvertedGCode//$line/$convertedLine}"
done <<< "$M140"
M104=$(echo "$ConvertedGCode" | grep M104)
while IFS= read -r line; do
convertedLine=$(echo "$line" | sed -E 's/S([0-9]+)\.0/S\1/g')
ConvertedGCode="${ConvertedGCode//$line/$convertedLine}"
done <<< "$M104"
# seperate each G0 with Z coordinate into two G1 commands
linesWithZ=$(echo "$ConvertedGCode" | grep G0 | grep ' Z.*\.')
while IFS= read -r line; do
# Extracting relevant parts
speed=$(echo "$line" | awk -F '[ ;]' '{print $2}')
x=$(echo "$line" | awk -F '[ ;]' '{print $3}')
y=$(echo "$line" | awk -F '[ ;]' '{print $4}')
z=$(echo "$line" | awk -F '[ ;]' '{print $5}')
# Creating the new lines
z_line="G1 F420 ${z}0"
xy_line="G1 $speed $x $y"
# Printing the new lines
replacement=$(printf "%s\n%s\n" "$z_line" "$xy_line")
#echo "$line"
#echo $replacement
# Replacing within the original text
ConvertedGCode="${ConvertedGCode//$line/$replacement}"
# the following lines are currently not working
#ConvertedGCode=$(echo "$ConvertedGCode" | sed -e "s/\$line/\$replacement/g")
#ConvertedGCode=$(echo "$ConvertedGCode" | sed -e "s/$line/$replacement/g")
done <<< "$linesWithZ"
# Convert each remaining G0 to G1
ConvertedGCode=$(echo "$ConvertedGCode" | sed -e 's/G0/G1/g')
ending='.gcode'
convertedFile=${1%$ending}\-converted.g
echo "$ConvertedGCode" > $convertedFile
@dbaarda
Copy link

dbaarda commented Aug 3, 2025

FTR my experiments with post-processing scripts are at https://github.com/dbaarda/workspace-tools/tree/main/3DPrinting. It's a bit of a mess where I'm dumping random stream-of-consciousness thoughts and experiments, but I plan to tidy it up and make it generally useful.

It currently includes stuff for generating arbitrary gcode tests and post-processing of existing gcode. It includes advanced pressure advance and thermal models, and runs the gcode through a simulator to calculate nozzle extrusion and temperatures, which it can then use to adjust the gcode to dynamically change retract/restore/draw extrusions and fan speeds to better achieve the desired output.

The advanced pressure advance model takes into account the print-surface back-pressure which means the advance depends not only on the nozzle extrusion velocity, but also the line-width (which depends on the extrusion velocity, line velocity, and layer height). So far this model seems to be accounting pretty well for the non-linearity problems with the simple extrusion-velocity model. It doesn't yet take into account bridging and overhangs, but when it does it should be a better approach than OrcaSlicer's attempts to deal with this using adaptive pressure advance.

From this model the post processing filter can optionally dynamically adjust retract/restore distances, dynamically adjust draw/move extrusion amounts, and/or vebose output logging of the modelled over/under extrusion. It does extrusion adjustments based on accumulated nozzle pressure from past extrusion and required nozzle pressure for future extrusion, and the logging gives the modelled results. The idea is this can show and adjust the gcode to include pressure advance compensation for printers that don't support pressure advance. It could also maybe give better or improved results for printers that do implement the more limited pressure advance model, but I haven't implemented that bit yet.

The thermal model takes into account heat in the extruded fillament and cooling rates based on fan speeds to calculate the heat remaining on the current top layer. This model is less refined because I gave up on using it when I realised the AD3's fan controls were too primitive to implement PWM control in gcode, and my ASA print output problems were mostly pressure advance related anyway. I might get back to it at some point, at the very least abstract it out so that it's optional in the code and less messy, not just toggled via cmdline args.

The post processing filter does implement optional dynamic fan-speed control based on the heat model to target a desired top layer heat level, using both fan speed adjustments for printers that support that (the AD3 doesn't) and PWM toggling in gcode for printers that don't (but it doesn't work for the AD3 because it doesn't push fan on-off commands into the execution queue).

It also does a bit of AD3 and FlashPrint specific cleanups, but I've mostly made them optional now I'm starting to use OrcaSlicer.

So far I've already seen significant quality improvements from the dynamic retract/restore distances, and I'm starting to get there with the dynamic extrusion rate adjustments but it still needs some tweaks. In retrospect it's pretty obvious that retract/restore actually relieves/restores the accumulated nozzle pressure advance, and thus should depend on the extrusion speeds before/after, and I'm amazed nobody else seems to be doing this.

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