Skip to main content

Engineering the Marlin Linear Advance K-factor Calibration Pattern Generator for Duet

I love Marlin Firmware.
What they have managed to squeeze into the 8bit 16mhz microcontrollers is impressive.
But what is even more impressive, is their documentation. The Marlin documentation is far and above anything I have seen for an open source project.
In addition to great documentation, they provide some very useful tools. Like the K-Factor Pattern Generator for calibrating Linear Advance in Marlin.

I wish Duet provided a similar tool, as I find it invaluable for calibrating your pressure advance settings.
What I have managed to do, is use the developer tools of the Chrome browser to edit the javascript and modify a few things to make it work.
Why go through such lengths?
Well, for a direct drive extruder the calibration values for duet are very low, and very sensitive.
how sensitive? I have found differences in value changes of 0.00002
And because I don't take "close enough" as an answer, I had to dig in and make the script fit the resolution I require.
At first I thought I'd download a copy of the marlin documentation source code and edit it that way. If you've looked at it, you'll find it's a lot of trouble to get the dev environment setup.
Instead, I found a hidden dev feature of Chrome that allows you to use a local copy of a file to overwrite the online version. But first, you need to enable it. Make sure you open up the K-Factor Pattern Generator first, then use the guide from Chrome to enable the local overrides.
Opening the developer tools for Chrome

Once you have enabled local overrides for the site, open up the dev tools, click on the sources tab on the top, and Page on the left and look for the k-factor.js file under tools/lin_advance folder.

k-factor.js on the marlin site

Right Click on the k-factor.js and click Save For Overrides.
Open up the overrides tab and make sure the checkbox Enable Local Overrides is checked.
Editing the k-factor.js file
We're going to do two things. Change all of the 'M900 K' instances to 'M572 D0 S' and increase the precision to 5 points (by changing the Math.round10() occurances).
Click on the k-factor.js file and look for the lines that have M900 in them by using the search box.
The first occurrence should be (Line 266 on my version):
'M900 K0 ; Set K-factor 0\n' +
Replace with:
'M572 D0 S0 ; Set K-factor 0\n' +

Next is (Line 458):
gcode += 'M900 K' + Math.round10(i, -3) + ' ; set K-factor\n' +
Replace with:
gcode += 'M572 D0 S' + Math.round10(i, -5) + ' ; set K-factor\n' +

Next (Line 467):
gcode += 'M900 K' + Math.round10(i, -3) + ' ; set K-factor\n' +
Replace with:
gcode += 'M572 D0 S' + Math.round10(i, -5) + ' ; set K-factor\n' +

Next (Line 487):
gcode += 'M900 K' + Math.round10(i, -3) + ' ; set K-factor\n' +
Replace with:
gcode += 'M572 D0 S' + Math.round10(i, -5) + ' ; set K-factor\n' +

Now to increase the number of digits printed, search for createGlyphs
Line 292 on my version:
createGlyphs(numStartX, numStartY + (stepping * LINE_SPACING), basicSettings, Math.round10(i, -3)) +
Replace with:
createGlyphs(numStartX, numStartY + (stepping * LINE_SPACING), basicSettings, Math.round10(i, -5)) +

Now go back to your browser with the K-Factor Calibration page open, and enter in your settings, then click Generate G-Code.
I have found for PLA that the value is typically between 0.02-0.03
On my Aero the specific value is 0.02825

Comments

Popular posts from this blog

Engineering my cat into keychain charm.

 Cats. What can I say that hasn't already been said. But this is about a process to turn a picture of my cat into a lithophane. The difficulty: the shape should match the outline of the cat. To go about this I needed 4 tools: image editing software, an image to lithophane converter, Inkscape, and a STL editor. The first step was to isolate my cat in the picture: This was probably the most time consuming aspect, carefully tracing her outline and removing the background. For this I used paint.net but you can use whatever you are familiar with. The result: After isolating her I also made a 2nd image, which will be used later for creating the outline. This image is simply the area where the background was but filled black, the inverse of above. You can see I smoothed the edges a bit too: The next step is to use a lithophane generator to create the STL. My favorite is:  http://3dp.rocks/lithophane/  . You will want to use a flat model, turn off the border, and set base/stand d...

Reverse Engineering a Wand Vibrator

You ever want to take apart something prohibitively expensive and find out what's inside? I do, all the time. Lucky for me this cast aluminum massager is broken (it won't turn off). So I get to try to fix it (hopefully). It's likely just a bad mosfet. But it'd be fun to upgrade. It's surprisingly low power. 19.5W, 13v @ 1.5A 13v is a bit strange to see, but whatever. Could very likely be replaced by a 12v supply without significant loss in power. One screw came out halfway and appears to stop. Maybe it has a retaining clip? The other at the end won't budge. Time for a bigger screwdriver. It took a bit of prying. The retaining ring is glued on (I was worried it was screwed on). A bit of wiggling and it's free. The screw that I thought had a retaining clip actually has a screw standoff to hold the PCB in. I might try to take them apart, but it's not necessary to. And now for what you've all been waiting for. It's an incredibly simple...