LucidWolf / easy-delta-pie

Setup code for Reprap Deltas
GNU General Public License v3.0
4 stars 2 forks source link

Wrong results in rod length? #1

Closed luxarts closed 5 years ago

luxarts commented 6 years ago

Hello! As I commented before I'm implementing the rod calibration into my web interface. I translated you Java code to JavaScript but when I test it and compare the results with Purple's spreadsheet the numbers differs too much.

This is the JavaScript code:

function getNewRodLength(r, dx, lx, l){
    var eps = 0.001;

    // r = horizontal rod radius
    // dx = diagonal rod lenght
    // lx = expected length
    // l = measured length

    var d; //diagonal rod length real
    var Dh = Math.sqrt(dx*dx-(r-lx)*(r-lx)) - Math.sqrt(dx*dx - r*r); //Delta h

    var loops = 1;
    d = dx;
    var act, der;

    for(var i=0 ; i<loops ; i++){
        act = equ3(d,r,Dh,l);
        if(Math.abs(act) < eps)break;

        der = (equ3(d+eps,r,Dh,l) - equ3(d,r,Dh,l))/eps;
        d = d-act/der;
    }
    return Math.round(d*100)/100; //Round number to 2 decimals
}

function equ3(d, r, Dh, l){
    return r-l-Math.sqrt(d*d-Math.pow(Math.sqrt(d*d-r*r) + Dh, 2));
}

My testing parameters are:

r = 131.95mm
dx = 251mm
lx = 100mm
l =104mm

With the code above I get 3.07 while with the spreadsheet I get 0.96.

I think the problem is that in the spreadsheet the correction is calculated based in the others measures and not individual. I really dont understand the formulas in the spreadsheet (actually I understand them but they are too long and it's impossible to me to analize what it's doing). I tried to get the formula based on the PDF notes of Purple but I still don't get results.

What do you think? Maybe I'm making a mistake using the function (which I doubt because it's a simple function call and watched how do you use it).

BTW, I tried to put the values in diagonal correction in Repetier but the measurements after calibrating again are nearly the same.

LucidWolf commented 5 years ago

Sorry I hope you figured it out. I rarely log on to Github.
I am using a newton-rasphons method to solve which requires a guess and then goal seeks the solution buy the derivative of the function . https://en.wikipedia.org/wiki/Newton%27s_method

The fact that you only ran 1 loop means you did not converge on the solution state. I am still surprised it was that off. You should be getting closer to the answer. I hard coded it to 5 since it seemed to only take around 3 loops.
Technically you run until error is under a value you find acceptable. It can loop forever on some functions so its best to pick a hard cut off for iterations and warn the user if it didn't solve.

Purples equations are long because Matlab used an approximation series to solve for a non-linear equation. (Which is the way i would have done it if I didn't have to code it later.) Matlab's long equation is similar to how a polygon line fit or Fourier series works.

I added a test main in the diagonal correction and i get a new rod length of 253.88 for your inputs similar to my spreadsheet on thingiverse.

If you want to see the difference between the methods my spreadsheet has a 2nd tab where i compare the difference between the methods.