Duet3D Logo Duet3D
    • Tags
    • Documentation
    • Order
    • Register
    • Login

    incremental pressure advance M572 tuning macros

    Scheduled Pinned Locked Moved
    Gcode meta commands
    3
    4
    798
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • OwenDundefined
      OwenD
      last edited by OwenD

      Here are two macros that do incremental adjustments to the M572 pressure advance settings.
      One increments it every X layers and the other every X mm in Z height.

      To use, you must insert an M98 command in your slicer's "after layer change" G-code section
      The command must include these parameters

      • S = the starting value for M572
      • C = the change point interval (in layers or mm depending on which macro you use)
      • I = the amount to increase the M572 value at each change
        optionally
      • D = the extruder drive number(s) to apply the settings to. For multiple extruders separate with a colon (e.g D0:1:2). Defaults to zero if D is omitted.

      example
      Capture.PNG

      Macro to change at layer

      ; macro - PA_adjust_layer.g
      ; adjusts M72 setting at a designated frequency
      ; To be called from slicer "on layer change"
      ; must have these parameters passed.
      ; I = the amount to increment at each change
      ; C = The number of layers between each Change
      ; S = the starting point
      ; D = optional - Extruder number(s) to apply settings - for multipe extruders, separate by colon e.g. D0:1:2.  Default to zero if not present
      ; e.g. M98 P"0:/macros/tuning/PA_adjust_height.g" I0.002 C5 S0.06 D0:1
      
      if job.layer = null
      	;echo "no layer value found in object model"
      	M99 ; break out of macro if we can't get layer info yet
      else
      	;echo "processing layer " ^ job.layer 
      	
      if !exists(param.C)
         abort "no C parameter passed to macro" 
         
      
      if !exists(param.I)
      	abort "no I parameter passed to macro"
      
      if !exists(param.S)
      	abort "no S parameter passed to macro"
      
      if !exists(global.AtChangePoint)
      	global AtChangePoint=false
      	;echo "global.AtChangePoint created"
      else
      	set global.AtChangePoint = mod(job.layer,param.C) = 0 ; should only evaluate to true every X x ChangeValue
      	;echo "global.AtChangePoint set to " ^ global.AtChangePoint 
      
      if job.layer < param.C
      	if exists(param.D)
      		M572 D{param.D} S{param.S}
      	else
      		M572 D0 S{param.S}
      	
      	;echo "M572 value set to " ^ {param.S}
      else
      	if global.AtChangePoint=true
      		if !exists(global.NewValue)
      			global NewValue = floor(job.layer/param.C) * param.I + param.S
      		else
      			set global.NewValue = floor(job.layer/param.C) * param.I + param.S
      		if exists(param.D)
      			M572 D{param.D} S{global.NewValue}
      		else
      			M572 D0 S{global.NewValue}
      		echo "M572 value set to " ^ {global.NewValue}  ^ " @ Z = " ^ {move.axes[2].userPosition} ^ "mm"
      

      Macro to adjust at height

      ;PA_adjust_height.g
      ; macro - PA_adjust.g
      ; adjusts M72 setting at a designated frequency
      ; To be called from slicer "after layer change"
      ; must have these parameters passed.
      ; I = the amount to increment at each change
      ; C = The Z height in millimeters between each change
      ; S = the starting value for P/A
      ; D = optional - Extruder number(s) to apply settings - for multipe extruders, separate by colon e.g. D0:1:2. If no D parameter set, defaults to zero
      ; e.g. M98 P"0:/macros/tuning/PA_adjust_height.g" I0.002 C5 S0.06 D0:1
      
      if job.layer = null
      	echo "no layer value found in object model"
      	M99 ; break out of macro if we can't get layer info yet
      
      	
      if !exists(param.C)
         abort "no C parameter passed to macro" 
          
      
      if !exists(param.I)
      	abort "no I parameter passed to macro"
      
      if !exists(param.S)
      	abort "no S parameter passed to macro"
      	
      if !exists(global.NextHeight)
      	global NextHeight=param.C ; set initaial change point
      else
      	if job.layer = 1 ; reset in case the print was re-started
      		set global.NextHeight=param.C
      
      
      if !exists(global.AtChangePoint)
      	global AtChangePoint=false
      	;echo "global.AtChangePoint created"
      else
      	if job.layer > 1 ; after the first layer start setting the change point.
      		set global.AtChangePoint = floor(move.axes[2].userPosition) >= global.NextHeight) 
      		;echo "global.AtChangePoint set to " ^ global.AtChangePoint 
      
      if (move.axes[2].userPosition) < param.C
      	if exists(param.D)
      		M572 D{param.D} S{param.S}
      	else
      		M572 D0 S{param.S}	
      	echo "M572 value set to " ^ {param.S}
      else
      	if global.AtChangePoint=true
      		if !exists(global.NewValue)
      			global NewValue = floor(floor(move.axes[2].userPosition) /param.C) * param.I + param.S
      		else
      			set global.NewValue = floor(floor(move.axes[2].userPosition) /param.C) * param.I + param.S
      		if exists(param.D)
      			M572 D{param.D} S{global.NewValue}
      		else
      			M572 D0 S{global.NewValue}
      		echo "M572 value set to " ^ {global.NewValue}  ^ " @ Z = " ^ {move.axes[2].userPosition} ^ "mm"
      			if job.layer > 1
      		set global.NextHeight = global.NextHeight + param.C 
      		echo "next change point @ Z =  " ^ global.NextHeight ^ "mm"
      

      Both have been tested on a Duet 2 stand-alone using RRF 3.4.0beta6
      However I have only tested with a single extruder.

      PA_adjust_height.g

      PA_adjust_layer.g

      zaptaundefined PCRundefined 2 Replies Last reply Reply Quote 3
      • zaptaundefined
        zapta @OwenD
        last edited by zapta

        @Phaedrux , any thoughts on adding this macro file and layer change command here https://duet3d.dozuki.com/Wiki/Pressure_advance#Section_Simplest_Method_Possible ?

        It works on any duet 3, regardless of slicer and is easier to setup the range.

        1 Reply Last reply Reply Quote 2
        • PCRundefined
          PCR @OwenD
          last edited by

          @owend thats super nice.

          what about a "super" macro? for tuning different things?

          • PA
          • Retract
          • Input Shaping type
          • Input Shaping frequency
          OwenDundefined 1 Reply Last reply Reply Quote 0
          • OwenDundefined
            OwenD @PCR
            last edited by

            @pcr
            A single macro that could do all of that would be unwieldy and have probably too many parameters that needed to be passed to it to be user friendly.
            You could easily modify these to cater for most of your examples, though input shaping type probably isn't practical until we have arrays.

            1 Reply Last reply Reply Quote 0
            • Phaedruxundefined Phaedrux pinned this topic
            • Phaedruxundefined Phaedrux referenced this topic
            • First post
              Last post
            Unless otherwise noted, all forum content is licensed under CC-BY-SA