;=========================================================== ;===== L-End G-code for Bambu Lab P1S WITH AMS ============= ;===== Author: Justagwas =================================== ;===== Date: 2026-05-22 ==================================== ;=========================================================== ; This end script is the "L" profile for the Bambu Lab P1S. ; It retracts filament, performs a spiral lift, and moves to the purge area. ; The nozzle is primed, purged, cooled to the unload range, and wiped with a moderate wipe sequence. ; Filament is unloaded via the AMS, then the nozzle and bed heaters are turned off. ; The nozzle is wiped with bed leveling disabled, then leveling is re-enabled. ; Timelapse recording is stopped if it was enabled. ; The bed is moved to a safe height, the toolhead is parked, and motion settings are reset. ; Fans run a shortened ventilation/cooldown stage, then all fans are turned off and motor currents are reduced. ;===== Ensure motion buffer is clear ======================= M400 ; Wait for all moves to finish M83 ; Relative extrusion mode ;===== Reset motor currents and acceleration =============== M17 X1.2 Y1.2 Z0.75 ; Restore default motor currents M204 S10000 ; Reset acceleration M1002 set_gcode_claim_speed_level :5 ; Internal speed mode reset M83 ; Relative extrusion mode ;===== Initial retraction ================================== G92 E0 ; Zero extruder position G1 E-0.5 F600 ; Retract 0.5mm to relieve pressure M104 S160 ; Begin cooling to 160C (non-blocking) ;===== Spiral lift and retreat ============================= G91 ; Switch to relative positioning G1 Z1 X5 Y5 F3000 ; Lift Z +1mm and move G1 X-10 Y5 F3000 G1 X5 Y-10 F3000 G1 Z2 X5 Y5 F3000 G90 ; Back to absolute positioning G1 Z{max_layer_z + 2} F900 ; Clear tallest print before XY travel G1 E-1.5 F1200 ; Retract 1.5mm further ;===== Move to safe park position ========================== M400 ; Ensure moves are done G1 X65 Y265 F12000 ; Move head to purge/park area M400 S3 ; Wait for moves to complete M106 P1 S255 ; Part cooling fan 100% G92 E0 ; Reset extruder G1 E-2 F1200 ; Retract 2mm further M400 ; Wait for completion G92 E0 ; Reset extruder M400 ; Wait ;===== Wiping movements (balanced) ========================= ; Perform a moderate wipe sequence to clean the nozzle G1 E-2 F1200 ; Retract 2mm G1 X70 F9000 ; Wipe to X70 G1 X95 F12000 ; Wipe to X95 G1 X70 F9000 ; Back to X70 G1 X160 F12000 ; Longer wipe to X160 G1 X70 F9000 ; Back to X70 G1 X95 F12000 ; Wipe again G1 X70 F9000 ; Back M400 ; Ensure retract done G1 E-2 F1200 ; Retract 2mm M400 ; Wait for wipes to finish G4 S1 ; Brief dwell ;===== Lower fan and dwell ================================= G1 X88 F9000 ; Move near wipe area G1 X89 F500 ; Precise positioning M106 P1 S150 ; Lower part fan to ~59% G4 S1 ; Short dwell ;===== Cool to <=160 before AMS ============================ M109 S160 ; Wait until nozzle reaches 160C G1 X70 F9000 ; Wipe quickly G1 X95 F12000 ; Wipe back G1 X70 F9000 ; Back G1 X95 F12000 ; Wipe G1 X70 F9000 ; Back ;===== AMS unload sequence (balanced) ====================== M620 S255 ; Enter AMS unload state G1 X20 Y50 F12000 ; Move to cut area G1 Y-3 ; Lower to cutter T255 ; Select cutter tool G1 E6 F800 ; Push filament to clear inlet G1 X65 F12000 ; Move away from cutter G1 Y265 ; Move to retract position M621 S255 ; Complete AMS unload ;===== Cool nozzle/bed fully =============================== M104 S0 ; Turn off nozzle heater M140 S0 ; Turn off bed heater ;===== Wipe nozzle with ABL off (balanced) ================= M1002 gcode_claim_action :14 ; Declare wipe action G29.2 S0 ; Disable ABL compensation G1 X65 Y265 F8000 ; Begin wipe G1 X100 F5000 ; Wipe right G1 X70 F15000 ; Wipe back quickly G1 X100 F5000 ; Wipe right G1 X70 F15000 ; Wipe back M400 ; Wait for completion ;===== Re-enable ABL and vibration suppression ============= G29.2 S1 ; Re-enable ABL compensation M975 S1 ; Enable resonance compensation M1002 gcode_claim_action :0 ; Clear wipe action state ;===== Stop timelapse recording safely ===================== M622.1 S1 ; End timelapse block M1002 judge_flag timelapse_record_flag M622 J1 ; If recording is active then: M400 ; Wait for buffer M991 S0 P-1 ; Stop timelapse recording M400 S2 ; Wait for stop M623 ; End conditional block M400 ; Final wait to ensure commands complete ;===== Lower heatbed safely ================================ M17 S ; Reset motors M17 Z0.4 ; Reduce Z holding current {if (max_layer_z + 100.0) < 248} G1 Z{max_layer_z + 100.0} F600; Lower Z 100mm if safe {else} G1 Z248 F600 ; Otherwise lower near max {endif} M400 P100 ; Wait G90 ; Absolute positioning G1 X128 Y250 F3600 ; Park head ;===== Reset motion settings =============================== M220 S100 ; Reset feedrate M201.2 K1.0 ; Reset tuning M73.2 R1.0 ; Reset print time calc M1002 set_gcode_claim_speed_level :0 ; Clear speed claim ;===== Fast cooldown (high fans, shortened) ================ M106 P1 S200 ; Part fan ~78% M106 P2 S200 ; Aux fan ~78% M106 P3 S200 ; Chamber fan ~78% M400 S20 ; Run for 20s ;===== Second cooldown (medium) ============================ M106 P1 S100 ; Part fan ~39% M106 P2 S100 ; Aux fan ~39% M106 P3 S125 ; Chamber fan ~49% M400 S10 ; Run for 10s ;===== Turn off all fans =================================== M106 P1 S0 ; Part fan off M106 P2 S0 ; Aux fan off M106 P3 S0 ; Chamber fan off ; M710 S0 ; MC board fan off ;===== Lower motor currents ================================ M17 X0.8 Y0.8 Z0.5 ; Reduce holding current for idle ;===== Final state ========================================= M1002 gcode_claim_action :0 ; Clear any remaining action state ; END