Calculating filament usage/total extrusion amount from G-code
-
I'm trying to create custom g-code analyzer with python.
I managed to get calculating absolute extrusion values accurately but relative extrusion
values are more than +/-20% off of values that slicer gives.When using relative extrusion is the total extrusion amount only sum of all
extrusion values in g-code (E#### - values)? -
@Visionary said in Calculating filament usage/total extrusion amount from G-code:
When using relative extrusion is the total extrusion amount only sum of all
extrusion values in g-code (E#### - values)?Yes, it should be. Bear in mind that you'll get negative amounts when doing retractions - does you code take account of that?
If you think about it, the firmware has to convert all absolute extruder moves to relative in order to calculate how much filament to extrude for any given move.
All moves are relative to something. It's just that absolute values are the position of the filament relative to the position it was in at the beginning of a print, whereas relative moves are relative to the last known position (the end of the previous move).
-
It does take negative values into account too.
I just found the reason why it didn't work correctly:
I have loop that looks for E-commands in each row/line and if it finds them it assigns it to a variable.
If next or any number of lines after it don't have E-command the variable does not change and
is summed multiple times. Now I get accurate value: better than -/+0.1% values when compared to slicer.At first I was skeptical if retracts and extrudes were only things affecting total extrusion amount.
Thanks for confirming that they were. -
@Visionary I'd guess that the total the slicer produces is calculated the same way. Which kind of begs the question, if the slicer produces the answer, why do you need to calculate it?
-
It is for a school project. G-code analyzer that I'm creating does few other things too such as looks for faulty values in the code.