signalk-polar-performance-plugin 0.0.30 → 0.0.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/plugin/index.js +14 -0
package/package.json
CHANGED
package/plugin/index.js
CHANGED
|
@@ -673,12 +673,26 @@ module.exports = function (app) {
|
|
|
673
673
|
// Doesn't exist yet, make obj for unit
|
|
674
674
|
damping[unit] = {Yn: Xn, dt: Date.now()}
|
|
675
675
|
}
|
|
676
|
+
// Edge case when hovering around -pi and +pi
|
|
677
|
+
if (Xn > Math.PI && damping[unit].Yn < (0-Math.PI)) {
|
|
678
|
+
Xn = Xn - (2*Math.PI)
|
|
679
|
+
} else if (Xn < (0-Math.PI) && damping[unit].Yn > Math.PI) {
|
|
680
|
+
Xn = Xn + (2*Math.PI)
|
|
681
|
+
}
|
|
676
682
|
// Calculate a
|
|
677
683
|
let dt = (Date.now() - damping[unit].dt)/1000
|
|
678
684
|
damping[unit].dt = Date.now()
|
|
679
685
|
let a = dt / (RC + dt)
|
|
680
686
|
// Yn = (1-a) * Yn-1 + a * Xn
|
|
681
687
|
let Yn = (1-a) * (damping[unit].Yn || Xn) + a * Xn
|
|
688
|
+
|
|
689
|
+
// Fix is we go outside -pi to pi
|
|
690
|
+
if (Yn > Math.PI) {
|
|
691
|
+
Yn = Yn - Math.PI
|
|
692
|
+
} else if (Yn < (0-Math.PI)) {
|
|
693
|
+
Yn = Yn + Math.PI
|
|
694
|
+
}
|
|
695
|
+
|
|
682
696
|
// Remember Yn
|
|
683
697
|
damping[unit].Yn = Yn
|
|
684
698
|
// app.debug('Unit: %s dt: %d a: %d obj: %s', unit, dt, a, JSON.stringify(damping[unit]))
|