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

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

Reverse engineering the Tuya WiFi IR Remote

Three devices. They all do the same thing (IR Transceiver) using the same app (Tuya smart home?) I hate apps. These are Bluetooth/wifi devices. They could simply host web pages and an API. Instead you must use their app. To that I say NO! So let's find out what makes them tick. There's no screws on these, so time to bring out the opening tools. Not bad. Just a few clips. A wiggle here and a wiggle there and it's open. The IR Filter plastic doesn't look transparent at all, and it's kind of thick. I tested the IR filter with my IR fan remote, it worked perfectly. Here are pictures through the filters. I'm no light spectrum'ologist person, but wouldn't the pinkish one be a better filter? First look at the PCBs, Two have the same CBU WiFi module, one is different, the w3bs. CBU Module Datasheet: https://developer.tu