154 lines
5.0 KiB
JavaScript
154 lines
5.0 KiB
JavaScript
let allAccSerial = []
|
|
let allSerialCoords = []
|
|
|
|
let ctx = document.getElementById('accChart').getContext('2d');
|
|
let accChart = new Chart(ctx, {
|
|
type: 'line',
|
|
data: {
|
|
labels: [],
|
|
datasets: [{
|
|
label: 'Ublox Horizontal acc. (m)',
|
|
backgroundColor: 'rgba(255, 255, 255, 1)',
|
|
borderColor: 'rgba(255, 255, 255, 1)',
|
|
borderWidth: 1,
|
|
fill: false,
|
|
pointRadius: 0.5,
|
|
lineTension: 0.5,
|
|
data: []
|
|
},
|
|
{
|
|
label: 'Smartphone Horizontal acc. (m)',
|
|
backgroundColor: 'rgb(185,190,45)',
|
|
borderColor: 'rgb(185,190,45)',
|
|
borderWidth: 1,
|
|
fill: false,
|
|
pointRadius: 0.5,
|
|
lineTension: 0.5,
|
|
data: []
|
|
},
|
|
{
|
|
label: 'Distance Ublox - Smartphone (m)',
|
|
backgroundColor: 'rgba(30, 130, 76, 1)',
|
|
borderColor: 'rgba(30, 130, 76, 1)',
|
|
borderWidth: 1,
|
|
fill: false,
|
|
pointRadius: 0.5,
|
|
lineTension: 0.5,
|
|
data: []
|
|
}]
|
|
},
|
|
options: {
|
|
scales: {
|
|
yAxes: [{
|
|
ticks: {
|
|
min: 0,
|
|
max: 20,
|
|
}
|
|
}],
|
|
xAxes: [{
|
|
type: 'time',
|
|
time: {
|
|
unit: 'second'
|
|
}
|
|
}]
|
|
},
|
|
animation: {
|
|
duration: 0
|
|
}
|
|
}
|
|
});
|
|
|
|
function addDistances(data){
|
|
let serialHAccs = data.map(el => {
|
|
return el.ser.HAcc
|
|
})
|
|
let tcpHAccs = data.map(el => {
|
|
return el.tcp.HAcc
|
|
})
|
|
|
|
let distances = data.map((el, i, arr) => {
|
|
// return distVincenty(el.ser.Position, el.tcp.Position)
|
|
const plaindist = distVincenty(el.ser.Position, el.tcp.Position)
|
|
arr[i]['distance'] = plaindist
|
|
arr[i]['distanceClean'] = plaindist - (el.ser.Speed / 1000 * el.differenceMs)
|
|
arr[i]['distanceCleanAbs'] = plaindist - Math.abs(el.ser.Speed / 1000 * el.differenceMs)
|
|
return plaindist //- Math.abs(el.ser.Speed / 1000 * el.differenceMs)
|
|
})
|
|
|
|
let tcpTimes = data.map(el => {
|
|
return el.tcp.Timestamp
|
|
})
|
|
|
|
accChart.data.labels = tcpTimes
|
|
accChart.data.datasets[0].data = serialHAccs
|
|
accChart.data.datasets[1].data = tcpHAccs
|
|
accChart.data.datasets[2].data = distances
|
|
accChart.update()
|
|
}
|
|
|
|
function distanceInMetersBetweenEarthCoordinates(coord1, coord2) {
|
|
let long1 = coord1[0]
|
|
let lat1 = coord1[1]
|
|
let long2 = coord2[0]
|
|
let lat2 = coord2[1]
|
|
|
|
let earthRadiusM = 6371000
|
|
|
|
let phi1 = lat1 * Math.PI / 180
|
|
let phi2 = lat2 * Math.PI / 180
|
|
|
|
let dlat = (lat2-lat1) * Math.PI / 180
|
|
let dlong = (long2 - long1) * Math.PI / 180
|
|
|
|
let a = Math.sin(dlat/2) * Math.sin(dlat/2) +
|
|
Math.cos(phi1) * Math.cos(phi2) *
|
|
Math.sin(dlong/2) * Math.sin(dlong/2)
|
|
let c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a))
|
|
return earthRadiusM * c
|
|
}
|
|
|
|
|
|
Number.prototype.toRad = function () { return this * Math.PI / 180; }
|
|
|
|
function distVincenty(coord1, coord2) {
|
|
const lon1 = coord1[0]
|
|
const lat1 = coord1[1]
|
|
const lon2 = coord2[0]
|
|
const lat2 = coord2[1]
|
|
const a = 6378137, b = 6356752.314245, f = 1/298.257223563; // WGS-84 ellipsoid params
|
|
let L = (lon2-lon1).toRad()
|
|
let U1 = Math.atan((1-f) * Math.tan(lat1.toRad()));
|
|
let U2 = Math.atan((1-f) * Math.tan(lat2.toRad()));
|
|
let sinU1 = Math.sin(U1), cosU1 = Math.cos(U1);
|
|
let sinU2 = Math.sin(U2), cosU2 = Math.cos(U2);
|
|
|
|
let lambda = L, lambdaP, iterLimit = 100;
|
|
do {
|
|
let sinLambda = Math.sin(lambda), cosLambda = Math.cos(lambda);
|
|
let sinSigma = Math.sqrt((cosU2*sinLambda) * (cosU2*sinLambda) +
|
|
(cosU1*sinU2-sinU1*cosU2*cosLambda) * (cosU1*sinU2-sinU1*cosU2*cosLambda));
|
|
if (sinSigma===0) return 0; // co-incident points
|
|
let cosSigma = sinU1*sinU2 + cosU1*cosU2*cosLambda;
|
|
let sigma = Math.atan2(sinSigma, cosSigma);
|
|
let sinAlpha = cosU1 * cosU2 * sinLambda / sinSigma;
|
|
let cosSqAlpha = 1 - sinAlpha*sinAlpha;
|
|
let cos2SigmaM = cosSigma - 2*sinU1*sinU2/cosSqAlpha;
|
|
if (isNaN(cos2SigmaM)) cos2SigmaM = 0; // equatorial line: cosSqAlpha=0 (§6)
|
|
let C = f/16*cosSqAlpha*(4+f*(4-3*cosSqAlpha));
|
|
lambdaP = lambda;
|
|
lambda = L + (1-C) * f * sinAlpha *
|
|
(sigma + C*sinSigma*(cos2SigmaM+C*cosSigma*(-1+2*cos2SigmaM*cos2SigmaM)));
|
|
} while (Math.abs(lambda-lambdaP) > 1e-12 && --iterLimit>0);
|
|
|
|
if (iterLimit===0) return NaN // formula failed to converge
|
|
|
|
let uSq = cosSqAlpha * (a*a - b*b) / (b*b);
|
|
let A = 1 + uSq/16384*(4096+uSq*(-768+uSq*(320-175*uSq)));
|
|
let B = uSq/1024 * (256+uSq*(-128+uSq*(74-47*uSq)));
|
|
let deltaSigma = B*sinSigma*(cos2SigmaM+B/4*(cosSigma*(-1+2*cos2SigmaM*cos2SigmaM)-
|
|
B/6*cos2SigmaM*(-3+4*sinSigma*sinSigma)*(-3+4*cos2SigmaM*cos2SigmaM)));
|
|
let s = b*A*(sigma-deltaSigma);
|
|
|
|
s = s.toFixed(3); // round to 1mm precision
|
|
return s;
|
|
} |