Skip to content

Commit

Permalink
add two point calibration support (#336)
Browse files Browse the repository at this point in the history
Thank you @vitotai
  • Loading branch information
vitotai authored Jan 31, 2020
1 parent 6d55d57 commit a8171bd
Showing 1 changed file with 110 additions and 36 deletions.
146 changes: 110 additions & 36 deletions tools/calibration/calibration.htm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<html>
<html lang="en">

<head>
<title>iSpindel Calibration</title>
Expand Down Expand Up @@ -298,30 +298,39 @@
var td4 = document.createElement("td");
td4.className = "pl_sg";
td4.innerHTML = this.points[i][1].toFixed(precision);

var tdfi = document.createElement("td");
tdfi.className = "pl_1stvalue";
tdfi.innerHTML = (typeof window.firstValue != "undefined")? window.firstValue[i].toFixed(precision):"-";


var tdf = document.createElement("td");
tdf.className = "pl_1sterror";
tdf.innerHTML =(typeof window.firstError != "undefined")? window.firstError[i].toFixed(precision):"-";


var td5i = document.createElement("td");
td5i.className = "pl_2ndvalue";
if (typeof window.secValue != "undefined")
td5i.innerHTML = window.secValue[i].toFixed(precision);
td5i.innerHTML = (typeof window.secValue != "undefined")? window.secValue[i].toFixed(precision):"-";

var td5 = document.createElement("td");
td5.className = "pl_2nderror";
if (typeof window.secondError != "undefined")
td5.innerHTML = window.secondError[i].toFixed(precision);
td5.innerHTML =(typeof window.secondError != "undefined")? window.secondError[i].toFixed(precision):"-";

var td6i = document.createElement("td");
td6i.className = "pl_3rdvalue";
if (typeof window.thirdValue != "undefined")
td6i.innerHTML = window.thirdValue[i].toFixed(precision);
td6i.innerHTML =(typeof window.thirdValue != "undefined")? window.thirdValue[i].toFixed(precision):"-";


var td6 = document.createElement("td");
td6.className = "pl_3rderror";
if (typeof window.thirdError != "undefined")
td6.innerHTML = window.thirdError[i].toFixed(precision);
td6.innerHTML =(typeof window.thirdError != "undefined")? window.thirdError[i].toFixed(precision):"-";

tr.appendChild(td1);
tr.appendChild(td2);
tr.appendChild(td4);
tr.appendChild(tdfi);
tr.appendChild(tdf);
tr.appendChild(td5i);
tr.appendChild(td5);
tr.appendChild(td6i);
Expand All @@ -336,57 +345,117 @@
}
},
regression: function() {
if (this.points.length < 2) return;
$("#firstpoly").html("");
$("#secondpoly").html("");
$("#thirdpoly").html("");

var thirdRegression = regression('polynomial', this.points, 3, {
if (this.points.length < 2) return;
var firstRegression =regression('polynomial', this.points, 1, {
precision: 9
});
var secondRegression,thirdRegression;
if(this.points.length > 2){
secondRegression = regression('polynomial', this.points, 2, {
precision: 9
});
var secondRegression = regression('polynomial', this.points, 2, {
}
if(this.points.length > 3){
thirdRegression = regression('polynomial', this.points, 3, {
precision: 9
});
}

// Plot the result
$.plot($('#graph'), [{
data: thirdRegression.points,
label: '3rd'
}, {
data: secondRegression.points,
label: '2nd'
}, {
var lines=[ {
data: firstRegression.points,
label: '1st'
},
{
data: this.points,
lines: {
show: false
},
points: {
show: true
}
}, ]);
$("#secondpoly").html(secondRegression.string);
$("#thirdpoly").html(thirdRegression.string);
} ];
if(this.points.length > 2){
lines.push({
data: secondRegression.points,
label: '2nd'
});
}
if(this.points.length > 3){
lines.push( {
data: thirdRegression.points,
label: '3rd'
});
}

$.plot($('#graph'), lines);
$("#firstpoly").html(firstRegression.string);
if(this.points.length > 2) $("#secondpoly").html(secondRegression.string);
if(this.points.length > 3) $("#thirdpoly").html(thirdRegression.string);
// caluate errors
var secoe, thridoe;

var first_error = [];
var first_value = [];
var firstoe = firstRegression.equation;

var sec_error = [];
var sec_value = [];
var secoe = secondRegression.equation;
if(this.points.length > 2) secoe = secondRegression.equation;

var third_error = [];
var third_value = [];
var thirdcoe = thirdRegression.equation;
if(this.points.length > 3) thirdcoe = thirdRegression.equation;

for (var i = 0; i < this.points.length; i++) {
var x = this.points[i][0];
var x2 = x * x;
var x3 = x2 * x;
var y = this.points[i][1]
var s = secoe[0] + secoe[1] * x + secoe[2] * x2;
var t = thirdcoe[0] + thirdcoe[1] * x + thirdcoe[2] * x2 + thirdcoe[3] * x3;
sec_error.push(s - y);
third_error.push(t - y);
sec_value.push(s);
third_value.push(t);

var f = firstoe[0] + firstoe[1] * x;
first_error.push(f - y);
first_value.push(f);

if(this.points.length > 2){
var s = secoe[0] + secoe[1] * x + secoe[2] * x2;
sec_error.push(s - y);
sec_value.push(s);
}

if(this.points.length > 3){
var t = thirdcoe[0] + thirdcoe[1] * x + thirdcoe[2] * x2 + thirdcoe[3] * x3;
third_error.push(t - y);
third_value.push(t);
}
}
window.firstError = first_error;
window.equation1st = firstoe;
window.firstValue = first_value;
if(this.points.length > 2){
window.secondError = sec_error;
window.equation2nd = secoe;
window.secValue = sec_value;
}else if (typeof window.secondError != "undefined"){
delete( window.secondError);
delete( window.equation2nd);
delete( window.secValue);
}

if(this.points.length > 3){
window.equation3rd = thirdcoe;
window.thirdValue = third_value;
window.thirdError = third_error;
}else if (typeof window.equation3rd != "undefined"){
delete( window.equation3rd);
delete( window.thirdValue);
delete( window.thirdError);
}
window.secondError = sec_error;
window.thirdError = third_error;
window.equation2nd = secoe;
window.equation3rd = thirdcoe;
window.secValue = sec_value;
window.thirdValue = third_value;

},
adddata: function() {
var tilt = parseFloat($("#tiltinput").val());
Expand Down Expand Up @@ -583,6 +652,8 @@
<th></th>
<th>Tilt</th>
<th><span class="plato-row">Plato</span> <span class="sg-row">SG</span> </th>
<th>Degree 1 Value</th>
<th>Degree 1 Error</th>
<th>Degree 2 Value</th>
<th>Degree 2 Error</th>
<th>Degree 3 Value</th>
Expand All @@ -594,6 +665,9 @@
<div id="graph"></div>
</td>
<tr>
<tr>
<td colspan="2">Degree 1:<span id="firstpoly"></span></td>
</tr>
<tr>
<td colspan="2">Degree 2:<span id="secondpoly"></span></td>
</tr>
Expand Down

0 comments on commit a8171bd

Please sign in to comment.