Auto-Tramming a RailCore Using conditional GCode



  • So, here's how I'm iterating through auto-tramming to level a RailCore. This can be cleaned up once we have variables, but even still, it's very cool (and confirmed working)!

    First, to simplify, I moved my "G32" commands for probing the bed into a macro called "bedlevel". So I can use that like a function. (Feature request: can we send arguments to macros? Then they really would be functions!)

    ;bedlevel
    ;Call from auto-level Routine in bed.g
    
    ;Run initial 4 point leveling routine
    G30 P0 X15 Y45 Z-99999
    G30 P1 X15 Y275 Z-99999
    ;G30 P2 X275 Y150 Z-99999 S3
    G30 P2 X275 Y275 Z-99999
    G30 P3 X275 Y45 Z-99999 S3
    

    Now that those commands are there, the following can go in your bed.g
    The goal is to level across the bed to a deviation of < 0.01, and then do another round, and have that round within 0.005 of the previous. If not, it repeats.

    M561                         ; clear any existing bed transform
    ; If the printer hasn't been homed, home it
    if !move.axes[0].homed || !move.axes[1].homed || !move.axes[2].homed
      G28
    
    ;Move up 7.5mm in Z to clear the bed  
    G1 Z7.5
    
    ;Run an initial auto-tramming
    M98 P"/macros/bedlevel"
    
    while true
      if iterations = 5
        abort "Too many auto calibration attempts"
      if move.initialDeviation.deviation < 0.01 
        if move.calibrationDeviation.deviation < move.initialDeviation.deviation + 0.005
          if move.calibrationDeviation.deviation > move.initialDeviation.deviation - 0.005
            break
      echo "Repeating calibration because initial deviation (" ^ move.initialDeviation.deviation ^ "mm) must be < 0.01"
      echo "and (" ^ move.calibrationDeviation.deviation ^ "mm) must be within 0.005 of initialDeviation"
    
      M98 P"/macros/bedlevel"
    
    echo "Auto calibration successful, deviation", move.calibrationDeviation.deviation ^ "mm"
    echo "Auto calibration successful, initialDeviation", move.initialDeviation.deviation ^ "mm"  
        
    G28 Z
    
    G1 X0 Y0 F24000
    


  • Here is sample output from running this (I intentionally got out of level, and also changed my leadscrew locations to make it take longer to converge):

    ad3a43ad-21c7-4e12-9563-0ff12a327eeb-image.png



  • Confirmed working, but as an addendum to anyone reading this , this does require RepRapFirmware for Duet 2 WiFi/Ethernet 3.01-beta1+1 (2020-01-15b2)

    RepRapFirmware for Duet 2 WiFi/Ethernet 3.01-beta1 (2020-01-14b3) gives "unknown value initialDeviation.deviation" errors.

    Thanks dc42



  • Upvoted for "tramming".



  • Here's another macro, "Pre-Print-Checks" to make sure the printer has been trammed and is homed before starting a print (this would be run in start.g, or out of your startup gcode). I check tramming first because homing is part of the tramming script above.

    ;If the printer hasn't been trammed, tram it
    echo move.calibrationDeviation.deviation ^ move.initialDeviation.deviation ^ move.calibrationDeviation.mean ^ move.initialDeviation.mean
    
    if move.initialDeviation.deviation > 0.01 
      echo "You need to tram, initial deviation is > 0.01 " ^ move.initialDeviation.deviation
      G32
      abort
    if move.calibrationDeviation.deviation > move.initialDeviation.deviation + 0.005
      echo "You need to tram, deviation is not within 0.005 of initial deviation " ^ move.calibrationDeviation.deviation ^ " " ^ move.initialDeviation.deviation
      G32
      abort
    if move.calibrationDeviation.deviation < move.initialDeviation.deviation - 0.005
      echo "You need to tram, deviation is not within 0.005 of initial deviation " ^ move.calibrationDeviation.deviation ^ " " ^ move.initialDeviation.deviation
      G32
      abort
    
    if move.initialDeviation.deviation == 0
      if move.initialDeviation.mean == 0
        if move.calibrationDeviation.deviation == 0
          if move.calibrationDeviation.mean == 0
            echo "You need to tram, or you hit the lotto and got all zeroes"
            G32
            abort
    
    ; If the printer hasn't been homed, home it
    if !move.axes[0].homed || !move.axes[1].homed || !move.axes[2].homed
      echo "Printer Not homed, homing"
      G28
      abort
    else
      echo "Printer is homed"
    


  • @kraegar Thanks for sharing.

    @ Moderators I can't help thinking that we could do with a separate section and or repository where users can post the clever things that are doing with conditional gcode.



  • @deckingman I agree 100% that conditional GCode is going to need its own section 🙂 Heck, just my posts on it may need their own section, I'm geeking out over here.



  • @kraegar said in Auto-Tramming a RailCore Using conditional GCode:

    @deckingman I agree 100% that conditional GCode is going to need its own section 🙂 Heck, just my posts on it may need their own section, I'm geeking out over here.

    I'm stuck 10,000 miles away from my printer but itching to play with conditional gcode 🙂



  • @deckingman I wouldn't worry too much just yet...

    Now when variables arrive, then we're talking!


Log in to reply