Commit f3f98ca8 authored by Andrew Flegg's avatar Andrew Flegg

Fix averaging behaviour to avoid issues at 180/-180 deg

parent e0acc209
......@@ -49,7 +49,7 @@ Accelerometer {
var mean = rawAngle // Total of values contributing to the next
var count = 1 // How many items we're counting
for (var i = 1; i < previousAngle.length; i++) {
if (Math.abs((rawAngle - previousAngle[i]) / rawAngle) < 0.2) {
if (Math.abs((rawAngle - previousAngle[i]) / 360) < 0.25) {
mean += previousAngle[i]
count++
}
......@@ -57,13 +57,13 @@ Accelerometer {
}
set[previousAngle.length - 1] = rawAngle
previousAngle = set
var newAngle = mean / count
var newAngle = Math.round(100 * mean / count) / 100 - calibration[1]
set = []
mean = rawDip
count = 1
for (var i = 1; i < previousDip.length; i++) {
if (Math.abs((rawDip - previousDip[i]) / rawDip) < 0.2) {
if (Math.abs(rawDip - previousDip[i]) < 0.25) {
mean += previousDip[i]
count++
}
......@@ -71,7 +71,7 @@ Accelerometer {
}
set[previousDip.length - 1] = rawDip
previousDip = set
var newDip = mean / count
var newDip = Math.round(1000 * mean / count) / 1000 - calibration[0]
if (newDip != self.dip || newAngle != self.angle) {
self.dip = newDip
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment