Page MenuHomeAleph Objects Inc

Custom Gcode at a Specific Layer
Closed, ResolvedPublic

Description

We have recently introduced backlash compensation into Marlin FW. In order to get the most of this new feature, we will need a modification to Cura Engine.

Currently Cura will insert a "Layer X" into the gcode for ease of navigation. We would like to include a gcode command at each layer in order to determine where we are at.

The current proposed gcode commands are awaiting upstream approval https://github.com/MarlinFirmware/Marlin/issues/10826 Quick Reference for this:

"M425 Z" after a "G29" enables backlash compensation with the measured value.
"M425 Z" enables backlash compensation with a user specified value.
"M425 S" sets the smoothing distance, a value of 3 mm seems to work good.

The above three items can be inserted into the start gcode with a variable.

"M425 F" sets a value from 0 to 1 which is multiplied by the backlash distance. This command is meant for use by the slicer, and allows it to "fade" away the backlash compensation gradually over several layers, or to turn it off completely after the first layer (with a "M425 F0").

Currently to implement fade, Cura will need to be modified to insert M425 F(1-(Current layer / total fade layers) at each layer.

A different option would be to have Cura insert a command at each layer defining it, and we can modify Marlin to handle fade distances via EEPROM

Event Timeline

karrad created this task.May 25 2018, 11:34 AM
karrad triaged this task as High priority.
karrad created this object with edit policy "Restricted Project (Project)".

I have put in a request for another GCODE for allowing Cura to let Marlin know the layer (G92 Ln)

https://github.com/MarlinFirmware/Marlin/issues/10848

If this is accepted, then "M425 Fn" would be modified to mean "fade backlash compensation in n layers."
Then the start GCODE could be modified as such:

G29 ; Probe bed and measure backlash
M425 Z  ; Use measured backlash distance
M425 F3 S3 ; Use smoothing of 3mm and fade backlash compensation in three layers

At the moment, I think it is premature to allow these values to be tuned in Cura. Until we know for sure there is a benefit in varying those values for the average user, I think we simply set them to the values in the start GCODE.

@Steven Adding you on this one for input as well.

Just an update, Thinkyhead wants us to use "M532 X<progress_percent> L<layer>", since other firmwares already implement that GCODE.

Currently the USB plugin is inserting the progress as "M73" periodically, but I think that instead CuraEngine should insert "M532 X<progress_percent> L<layer>" at each layer, perhaps right after it prints the "Layer:" comment.

karrad added a comment.Jun 8 2018, 7:07 AM

Testing on Achemon shows that with very lower layer heights, turning off fade after 1 layer results in strip outs. This is caused by the increased back pressure when no longer compensating for the high side of the bed. Testing longer fade out periods

marcio added a comment.Jun 8 2018, 7:45 AM

@karrad: This is yet another reason why backlash compensation probably ought to be done in the slicing engine. When varying layer heights, it is also necessary to adjust extrusion amount. This kind of math is the bread and butter of the slicer. Of course, doing backlash compensation in the slicer means there is no way to read out the actual backlash value from the printer, so it's kind of a catch-22.

karrad added a comment.Jun 8 2018, 7:56 AM

@marcio Yup, as this appears to be layer height dependent to what degree we will need to fade, and over how many layers it makes the most sense to tie these in with profiles. We will need to tune them for our recommended parameters, but customers will need to adjust them in the field. Putting this into the custom slicing settings opposed to post processing makes the most sense to me.

@alexei thoughts?

alexei added a comment.Jun 8 2018, 8:11 AM

@karrad , @marcio

The thing is that backlash value is unique for every printer, and G-code should be the same for all printers...

So we have a problem here:

  1. Backlash is measured and stored in Marlin
  2. If Cura is responsible for compensation, the generated G-code should somehow read the value and adjust on-the-fly. I don't think it would be possible even if we introduce conditional G-code. And even then the same G-code should work from SD card.

To proceed with backlash compensation we'll need to handle backlash completely in Marlin IMHO.

karrad added a comment.EditedJun 8 2018, 8:31 AM

backlash value is unique for every printer

M425 Z in the start Gcode will use the measured backlash for each printer and store it.

generated G-code should somehow read the value and adjust on-the-fly

M425 F uses a percentage of the measured backlash. By inserting M425 F% going from 100% on layer 0, scaling down to the number of layers set it will compensate specifically for each machine. Once fade is off, we insert M425 F0 at each layer, or stop inserting the custom commands after the first 0.

G-code should be the same for all printers...

More testing is required, but we did see negative effects of backlash compensation enabled on machines that did not require it. This was seen higher up in the print, and was not noticeable in the first few layers using a standard tool head, and heights of 0.25mm. At that height, turning off fade after the first layer was successful. We will need to test with the extremes of our manufacturing tolerance to determine the correct number of fade layers per layer height. We will need to find the "sweet spot" where fade fixes the high end of our variance, without negatively affecting the low end of our variance.

we'll need to handle backlash completely in Marlin IMHO.

We have been able to show that the number of layers required to fade is dependent upon layer height. We cannot set a value in marlin for a tool heads that have a wide range of layer heights. On the upcoming 1.2mm tool head, we will be able to print a full mm of height. (0.2mm to 1.2mm) How would marlin determine the fade height, based upon the gcode set layer height?

alexei added a comment.Jun 8 2018, 8:49 AM

@karrad

In this pseudo G-code, could you insert the commands you'll need to handle backlash compensation?

    <start.gcode>

    <wipe.gcode>

; Layer 1
    <layer-1.gcode>
; Layer 2
    <layer-2.gcode>
...
; Layer N
    <layer-N.gcode>

    <end.gcode>
karrad added a comment.EditedJun 8 2018, 9:03 AM

@alexei That is exactly what we are looking at having Cura do. We just need to have the number of layers adjustable per profile, and cannot expect a user to manually enter these.

Start gcode requirements:
G29
M425 Z ; Use measured Z Backlash value

(inserted into gcode)

Layer 0
M425 F1

Layer 1
M425 F.75

Layer 2
M425 F.5

Layer 3
M425 F.25

Layer 4
M425 F0

Layer 5
M425 F0

This would represent Fade to no backlash compensation after 4 layers.

@karrad, so instead of modifying layers (with possible discontinuity and resulting stripping) Marlin should handle the backlash fade.
With only start G-code modifications in slicer:

    <start.gcode>

    <wipe.gcode>
G29
M425 Z <number_of_layers_to_fade x layer_height_mm>

; Layer 1
    <layer-1.gcode>
; Layer 2
    <layer-2.gcode>
...
; Layer N
    <layer-N.gcode>

    <end.gcode>

This would also allow to implement backlash compensation correctly in other than CuraLE slicers.

alexei renamed this task from CuraEngine Request: Custom Gcode at a Specific Layer to Custom Gcode at a Specific Layer.Jun 11 2018, 7:39 PM
alexei added a project: Marlin.

@alexei Some models will can have hundreds if not thousands of layers, what if a customer wants to fade the entire length and stop on the last layer? How we would create a stock start gcode for that?

karrad assigned this task to alexei.Jun 15 2018, 2:28 PM
karrad moved this task from Restricted Project Column to Restricted Project Column on the Restricted Project board.

@karrad, The option to fade Z backlash is added to rCT and rCTE under this ticket branches.

alexei closed this task as Resolved.Jun 20 2018, 11:01 AM

Backlash fading option is merged to master.

@victor_larchenko This is looking good! I will continue to test with various machine and tool heads