signalk-polar-performance-plugin 0.0.33 → 0.0.34
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 +26 -17
package/package.json
CHANGED
package/plugin/index.js
CHANGED
|
@@ -175,19 +175,19 @@ module.exports = function (app) {
|
|
|
175
175
|
HDG = delta.value
|
|
176
176
|
// app.debug('heading (HDG): %d', HDG)
|
|
177
177
|
} else if (delta.path == 'environment.wind.speedTrue') {
|
|
178
|
-
// applyDamping (Xn, unit, a, n)
|
|
179
178
|
TWS = applyDamping (delta.value, 'TWS', options.dampingTWS || 0)
|
|
180
179
|
// app.debug('environment.wind.speedTrue (TWS): %d applyDamping: %d', delta.value, TWS)
|
|
181
180
|
// app.debug('TWS: %d TWA: %d BSP: %d', msToKts(TWS), radToDeg(TWA)*port, msToKts(BSP))
|
|
182
181
|
sendUpdates(getPerformanceData(TWS, TWA, BSP))
|
|
183
182
|
} else if (delta.path == 'environment.wind.angleTrueWater') {
|
|
184
|
-
|
|
183
|
+
let TWAtmp = applyDamping (delta.value, 'TWA', options.dampingTWA || 0)
|
|
184
|
+
if (TWAtmp < 0) {
|
|
185
185
|
port = -1
|
|
186
186
|
} else {
|
|
187
187
|
port = 1
|
|
188
188
|
}
|
|
189
|
-
|
|
190
|
-
app.debug('environment.wind.angleTrueWater (TWA): %s applyDamping: %s',
|
|
189
|
+
TWA = Math.abs(TWAtmp)
|
|
190
|
+
app.debug('environment.wind.angleTrueWater (TWA): %s applyDamping: %s port: %d', delta.value, TWA, port)
|
|
191
191
|
}
|
|
192
192
|
})
|
|
193
193
|
}
|
|
@@ -353,15 +353,15 @@ module.exports = function (app) {
|
|
|
353
353
|
for (let indexTWA = 0 ; indexTWA < lowerTWA.length-1; indexTWA++) {
|
|
354
354
|
let lowerTWAlower = lowerTWA[indexTWA]
|
|
355
355
|
let lowerTWAupper = lowerTWA[indexTWA+1]
|
|
356
|
-
// app.debug('lowerTWAlower: %s lowerTWAupper: %s', lowerTWAlower, lowerTWAupper)
|
|
357
356
|
if (TWA >= lowerTWAlower.twa && TWA <= lowerTWAupper.twa) {
|
|
357
|
+
// app.debug('lowerTWAlower: %s lowerTWAupper: %s', JSON.stringify(lowerTWAlower), JSON.stringify(lowerTWAupper))
|
|
358
358
|
// Now find upperTWA
|
|
359
359
|
for (let indexTWA = 0 ; indexTWA < upperTWA.length-1; indexTWA++) {
|
|
360
360
|
let upperTWAlower = upperTWA[indexTWA]
|
|
361
361
|
let upperTWAupper = upperTWA[indexTWA+1]
|
|
362
362
|
if (TWA >= upperTWAlower.twa && TWA <= upperTWAupper.twa) {
|
|
363
363
|
// Found the 4 points
|
|
364
|
-
// app.debug('lowerTWAlower: %d TWA: %d lowerTWAupper: %d', lowerTWAlower.twa, TWA, lowerTWAupper.twa)
|
|
364
|
+
// app.debug('lowerTWAlower: %d TWA: %d lowerTWAupper: %d', radToDeg(lowerTWAlower.twa), radToDeg(TWA), radToDeg(lowerTWAupper.twa))
|
|
365
365
|
// Calculate gap ratio
|
|
366
366
|
let gap = lowerTWAupper.twa - lowerTWAlower.twa
|
|
367
367
|
let twaGapRatio = (1 / gap) * (TWA - lowerTWAlower.twa)
|
|
@@ -372,7 +372,7 @@ module.exports = function (app) {
|
|
|
372
372
|
let upperTBS = upperTWAlower.tbs + ((upperTWAupper.tbs - upperTWAlower.tbs) * twaGapRatio)
|
|
373
373
|
// Calculate polar boat speed
|
|
374
374
|
performance.polarSpeed = lowerTBS + ((upperTBS - lowerTBS) * twsGapRatio)
|
|
375
|
-
// app.debug('lowerTBS: %d TBS: %d upperTBS: %d', lowerTBS, performance.polarSpeed, upperTBS)
|
|
375
|
+
// app.debug('lowerTBS: %d TBS: %d upperTBS: %d', msToKts(lowerTBS), performance.polarSpeed, msToKts(upperTBS))
|
|
376
376
|
break
|
|
377
377
|
}
|
|
378
378
|
}
|
|
@@ -680,12 +680,18 @@ module.exports = function (app) {
|
|
|
680
680
|
// Doesn't exist yet, make obj for unit
|
|
681
681
|
damping[unit] = {Yn: Xn, dt: Date.now()}
|
|
682
682
|
}
|
|
683
|
-
// Edge case when hovering around -pi and +pi
|
|
684
|
-
if (
|
|
685
|
-
Xn
|
|
686
|
-
|
|
687
|
-
|
|
683
|
+
// Edge case when hovering around -pi and +pi for TWA
|
|
684
|
+
if (unit == 'TWA') {
|
|
685
|
+
if (Xn > halfPi && damping[unit].Yn < (halfPi * -1)) {
|
|
686
|
+
// app.debug('applyDamping: unit: %s Xn: %d > %d Yn: %d < %d -2Pi', unit, Xn, halfPi, damping[unit].Yn, halfPi * -1)
|
|
687
|
+
Xn = Xn - (2*Math.PI)
|
|
688
|
+
} else if (Xn < (halfPi * -1) && damping[unit].Yn > halfPi) {
|
|
689
|
+
// app.debug('applyDamping: unit: %s Xn: %d < %d Yn: %d > %d +2Pi', unit, Xn, halfPi * -1, damping[unit].Yn, halfPi)
|
|
690
|
+
Xn = Xn + (2*Math.PI)
|
|
691
|
+
}
|
|
688
692
|
}
|
|
693
|
+
|
|
694
|
+
// app.debug('applyDamping: unit: %s Xn: %d Yn: %d ', unit, Xn, damping[unit].Yn)
|
|
689
695
|
// Calculate a
|
|
690
696
|
let dt = (Date.now() - damping[unit].dt)/1000
|
|
691
697
|
damping[unit].dt = Date.now()
|
|
@@ -693,16 +699,19 @@ module.exports = function (app) {
|
|
|
693
699
|
// Yn = (1-a) * Yn-1 + a * Xn
|
|
694
700
|
let Yn = (1-a) * (damping[unit].Yn || Xn) + a * Xn
|
|
695
701
|
|
|
696
|
-
// Fix
|
|
697
|
-
if (
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
702
|
+
// Fix if we go outside -pi to pi
|
|
703
|
+
if (unit == 'TWA') {
|
|
704
|
+
if (Yn > Math.PI) {
|
|
705
|
+
Yn = Yn - 2*Math.PI
|
|
706
|
+
} else if (Yn < Math.PI * -1) {
|
|
707
|
+
Yn = Yn + 2*Math.PI
|
|
708
|
+
}
|
|
701
709
|
}
|
|
702
710
|
|
|
703
711
|
// Remember Yn
|
|
704
712
|
damping[unit].Yn = Yn
|
|
705
713
|
// app.debug('Unit: %s dt: %d a: %d obj: %s', unit, dt, a, JSON.stringify(damping[unit]))
|
|
714
|
+
// app.debug('applyDamping: unit: %s new Yn: %d ', unit, damping[unit].Yn)
|
|
706
715
|
return Yn
|
|
707
716
|
}
|
|
708
717
|
}
|