Automatic Bed Leveling with Conditional Gcode Iterations



  • @Phaedrux Thanks for sharing. Do you use filament/config.g or just use slicer start code?


  • Moderator

    @Kolbi said in Automatic Bed Leveling with Conditional Gcode Iterations:

    @Phaedrux Thanks for sharing. Do you use filament/config.g or just use slicer start code?

    I haven't used the filaments function for a long time. I use prusa slicer and cura interchangeably. I use prusa slicer for the filaments library and refer to it when I'm setting up a print in Cura.



  • @Phaedrux As of thus far, me too. For some reason, it feels a bit to foreign to me to offload stuff from the slicer's start and end code spots. I do plan to slowly start migrating stuff over but only after I have everything else on point.



  • @Phaedrux For prime line I made a crude random(ish) number generator to not get a 'prime line gutter' on my plates. It gives a numeric swing of 9 to -9.

    floor(10*(cos(sqrt(sensors.analog[0].lastReading * state.upTime))))
    

    So for the prime line, it would be (using Y as an example / with a .1mm randomness, targeted at -2):

    Before:
    G1 X0 Z0.6 Y-3.0 F3000.0;
    
    After:
    G1 X0 Z0.6 Y{-2+(0.1*(floor(10*(cos(sqrt(sensors.analog[0].lastReading * state.upTime))))))} F3000.0;
    

    So my use is to have the M98 P"0:/sys/PrimeLine.g" called after temps are set and obtained by the slicer's gcode.

    ;M98 P"0:/sys/PrimeLine.g"
    ;This sets up the prime to be initiated at a 'randomized' Y positon from -1.1 to -2.9
    G1 X0 Z0.6 Y{-2+(0.1*(floor(10*(cos(sqrt(sensors.analog[0].lastReading * state.upTime))))))} F3000.0;
    G92 E0.0
    G1 Z0.2 X100.0 E30.0 F1000.0 ; prime line
    G92 E0.0
    


  • @Kolbi said in Automatic Bed Leveling with Conditional Gcode Iterations:

    For some reason, it feels a bit to foreign to me to offload stuff from the slicer's start and end code spots.

    My goal was to have as little filament related items (like temps) in the slicer since I hoped to avoid going back to the slicer to generate a new gcode file just to change a temp.

    So far that approach is working for me.

    YMMV.

    Good luck.

    Frederick



  • @fcwilt That is my eventual goal also, but because from within the slicer - I use inner-slicer variables, that portion would get somewhat lost?
    I'm slowly brain-storming different ways to skin-the-cat, but as of this moment, it feels like I happen to be dealing with skinning Schrödinger's cat.



  • @Kolbi said in Automatic Bed Leveling with Conditional Gcode Iterations:

    @fcwilt I use inner-slicer variables, that portion would get somewhat lost?

    I have not found that to be a problem - yet. What variables do you use?

    I'm slowly brain-storming different ways to skin-the-cat, but as of this moment, it feels like I happen to be dealing with skinning Schrödinger's cat.

    Hard to skin a cat that won't stay in one place.

    Frederick



  • @fcwilt said in Automatic Bed Leveling with Conditional Gcode Iterations:

    What variables do you use

    Mostly the temps for hotend and bed.
    While I do use the filament option in duet/dwc to get me to the overall-generic temp for the chosen/loaded filament type, I still use the slicer to vary the temps for each different brand/batch of the filament within the choose type range. I'll most likely use the start.g script to do most of the setup and prime line, then the slicer start-gcode could bring the temps to the exact settings, and then start printing. This would simplify switch between slicers and give a one-stop-shop to adjust the starting sequence as needed.

    Cheers,
    Kolbi



  • @Kolbi

    Thanks for the info.

    I make an filament entry in the DWC for each filament brand/kind/color that I find needs different settings. Currently the settings that I control in the config file for each filament are the temps and the extrusion multiplier.

    My goal was to allow using different slicers with as little duplication as possible by moving what I can to the Duet.

    In the three slicers I use they each call two macros "print_begin.g" and "print_end.g"

    I tried using start.g but it is called before the slicers set temps whereas the locations in the slicer to call "print_begin.g" happen just before the gcode that actually prints the object. So my filament config files get to override any slicer temp settings.

    Frederick



  • @fcwilt All makes sense. I guess it just goes back to cats, preference to work-flow, and ingrained habit.

    Cheers,
    Kolbi



  • @Kolbi said in Automatic Bed Leveling with Conditional Gcode Iterations:

    @fcwilt All makes sense. I guess it just goes back to cats, preference to work-flow, and ingrained habit.

    Cheers,
    Kolbi

    I'm a dog person myself. They don't insist on hiding their location. 😉

    Frederick



  • @fcwilt Me too - that's why I only talk about skinning cats 😂



  • @fcwilt , @Phaedrux , @bearer
    During the day's events, I thought of the above conversations and formulated and blend of both ways (dwc/slicer stop/stop gcodes) to handle filament specific settings. I just made the following setups - all is working very well. It is very basic/generic but will grow from here.
    Let me know any thoughts.

    /sys/start.g:

    ; 0:/sys/start.g
    ; Executed before each print - BEFORE ANY SLICER CODE IS RAN
    
    ;M280 P0 S160                                    ; BLTouch, alarm release
    ;G4 P100                                         ; BLTouch, delay for release command
    M572 D0 S0.0                                     ; clear pressure advance
    M703                                             ; Execute loaded filement's config.g
    G28                                              ; Home all
    
    ; if using BLTouch probe, use the following line:
    G1 Z100                                          ; Last chance to check nozzle cleanliness
    ; if using Pinda type probe, use the following line to place probe center of bed to heat the probe
    ;G1 Z5 X100 Y100                                 ; Place nozzle center of bed, 5mm up
    
    M220 S100                                        ; Set speed factor back to 100% in case it was changed
    M221 S100                                        ; Set extrusion factor back to 100% in case it was changed
    M290 R0 S0                                       ; Clear babystepping
    M106 S0                                          ; Turn part cooling blower off if it is on
    M116                                             ; wait for all temperatures
    G32                                              ; Level bed
    G29                                              ; Bed mesh
    G90                                              ; Absolute Positioning
    M83                                              ; Extruder relative mode
    M98 P"0:/sys/current-sense-normal.g"             ; Ensure that motor currents and sense are set for printing 
    G1 X0 Y0 Z2                                      ; Final position before slicer's temp is reached and primeline is printed.
     
    ; The primeline macro is executed by the slicer gcode to enable direct printing
    ; of the primeline at the objects temp and to immediately print the object
    ; following primeline completion. 
    
    ; Slicer generated gcode takes it away from here
    

    /filaments/PETG/config.g

    M300 S1000 P200 G4 P500 M300 S3000 P300          ; play some tones
    M140 S75                                         ; set bed temp
    M104 S150                                        ; set extruder warm-up temp
                                                     ; active temp set from slicer gcode 
    
    ; Insert additional filament specific settings here
    

    ideaMaker Start GCode:

    ; ideaMaker Start G-Code
    
    ; Set nozzle and bed to the specific temperatures declared within this slicer
    M140 S{temperature_heatbed}                      ; set bed temp
    M104 S{temperature_extruder1}                    ; set extruder temp
    M116                                             ; wait for all temperatures
    
    ; Run macro to print primeline at a 'randomized' Y positon from -1.1 to -2.9
    M98 P"0:/sys/primeLine.g"                        ; primeline macro
    
    ; Set pressure advance
    M572 D0 S0.07                                    ; set pressure advance
    

    /sys/primeline.g:

    ; 0:/sys/primeline.g
    ; Print prime-line at a 'randomized' Y positon from -1.1 to -2.9
    
    G1 X0 Z0.6 Y{-2+(0.1*(floor(10*(cos(sqrt(sensors.analog[0].lastReading * state.upTime))))))} F3000.0;
    G92 E0.0                                                   ; set E position to 0
    G1 Z0.2 X100.0 E30.0 F1000.0                               ; prime line
    G92 E0.0                                                   ; set E position to 0
    M400                                                       ; finish all current moves / clear the buffer
    

    ideaMaker/S3D/PS End GCode:

    ; ideaMaker End G-Code
    M400                                             ; Make sure all moves are complete
    M0                                               ; Stop everything and run sys/stop.g
    

    /sys/stop.g:

    ; 0:/sys/stop.g
    ; called when M0 (Stop) is run (e.g. when a print from SD card is cancelled)
    
    M83                                                        ; Set extruder to relative mode
    M104 S-273                                                 ; turn off hotend
    M140 S-273                                                 ; turn off heatbed
    M107                                                       ; turn off fan
    G1 F1000.0                                                 ; set feed rate
    G1 E-2                                                     ; retract
    G1 X110 Y200 Z205 F3000                                    ; place nozzle center/top
    M400                                                       ; Clear queue
    M18 YXE                                                    ; unlock X, Y, and E axis
    

    Simplify3D Start GCode:

    ; Simplify3D Start G-Code
    
    ; Set nozzle and bed to the specific temperatures declared within this slicer
    M140 S[bed0_temperature]                         ; set bed temp
    M104 S[extruder0_temperature]                    ; set extruder temp
    M116                                             ; wait for all temperatures
    
    ; Run macro to print primeline at a 'randomized' Y positon from -1.1 to -2.9
    M98 P"0:/sys/primeLine.g"                        ; primeline macro
    
    ; Set pressure advance
    M572 D0 S0.07                                    ; set pressure advance
    

    PrusaSlicer Start GCode:

    ; PrusaSlicer Start G-Code:
    
    ; Set nozzle and bed to the specific temperatures declared within this slicer
    M140 S[first_layer_bed_temperature]              ; set bed temp
    M104 S[first_layer_temperature]                  ; set extruder temp
    M116                                             ; wait for all temperatures
    
    ; Run macro to print primeline at a 'randomized' Y positon from -1.1 to -2.9
    M98 P"0:/sys/primeLine.g"                        ; primeline macro
    
    ; Set pressure advance
    M572 D0 S0.07                                    ; set pressure advance
    

    Cheers,
    Kolbi



  • Hi,

    Just FYI you don't need both M140 and M190.

    They both set the temp and activate the heater.

    The difference is that M140 doesn't wait for the temp to be reached whereas M190 does.

    The same applies to M104 and M109.

    There is also M116. From the docs, M116 by itself it does:

    waits for all temperatures and other slowly-changing variables to arrive at their set values.

    Frederick


  • Moderator

    @Kolbi said in Automatic Bed Leveling with Conditional Gcode Iterations:

    For some reason, it feels a bit to foreign to me to offload stuff from the slicer's start and end code spots.

    When you use multiple slicers it makes it a lot easier to manage.



  • Thanks @fcwilt! I didn't know I was messing that up. I re-read the gcode documentation on this, I believe the following would be the most efficient.

    M104 S[first_layer_temperature]                  ; set extruder temp
    M140 S[first_layer_bed_temperature]              ; set bed temp
    M116                                             ; waits for all temperatures
    


  • @Kolbi said in Automatic Bed Leveling with Conditional Gcode Iterations:

    Thanks @fcwilt! I didn't know I was messing that up. I re-read the gcode documentation on this, I believe the following would be the most efficient.

    M104 S[first_layer_temperature]                  ; set extruder temp
    M140 S[first_layer_bed_temperature]              ; set bed temp
    M116                                             ; waits for all temperatures
    

    Yes that should work fine.

    Now what I and others do is start the heating and then do other things that don't need to wait on the temps, like homing.

    When all of the "other" things are done then you can use the M116 to wait before proceeding to the next steps.

    It can save a bit of time.

    Frederick



  • @fcwilt said in Automatic Bed Leveling with Conditional Gcode Iterations:

    Now what I and others do is start the heating and then do other things that don't need to wait on the temps, like homing.

    Thanks much! Made changes to above post. 🙂

    Cheers,
    Kolbi



  • With all sorted discussed above, I have no actual contents in the following files: tfree0.g, tpost.g, tpre0.g

    Can I delete these files from the sdcard or will this throw an error?



  • @Kolbi said in Automatic Bed Leveling with Conditional Gcode Iterations:

    With all sorted discussed above, I have no actual contents in the following files: tfree0.g, tpost.g, tpre0.g

    Can I delete these files from the sdcard or will this throw an error?

    When in doubt you can always rename them while you use your printer to see if an error occurs. Then you can undo the rename if it turns out you need them.

    When I do that sort of thing I add .HIDE to the end of the name so tfree.g becomes tgree.g.HIDE


    Now I don't think you need these files - I think that are used when changing from one tool to another.

    I've never had a printer with more than one tool so I've never had these files.

    Frederick



  • @fcwilt Thanks Frederick!


Log in to reply