signalk-polar-performance-plugin 0.0.22 → 0.0.23
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 +45 -7
package/package.json
CHANGED
package/plugin/index.js
CHANGED
|
@@ -5,6 +5,7 @@ module.exports = function (app) {
|
|
|
5
5
|
var plugin = {}
|
|
6
6
|
var unsubscribes = []
|
|
7
7
|
var timers = []
|
|
8
|
+
var damping = {}
|
|
8
9
|
|
|
9
10
|
plugin.id = 'signalk-polar-performance-plugin'
|
|
10
11
|
plugin.name = 'Polar performance plugin'
|
|
@@ -49,6 +50,21 @@ module.exports = function (app) {
|
|
|
49
50
|
type: 'boolean',
|
|
50
51
|
title: 'Enable writing of maximum speed angle and boat speed for a given TWS'
|
|
51
52
|
},
|
|
53
|
+
dampingTWA: {
|
|
54
|
+
type: 'number',
|
|
55
|
+
title: 'True Wind Angle damping factor (0 = no damping, 1 = full damping)',
|
|
56
|
+
default: 0
|
|
57
|
+
},
|
|
58
|
+
dampingTWS: {
|
|
59
|
+
type: 'number',
|
|
60
|
+
title: 'True Wind Speed damping factor (0 = no damping, 1 = full damping)',
|
|
61
|
+
default: 0
|
|
62
|
+
},
|
|
63
|
+
dampingBSP: {
|
|
64
|
+
type: 'number',
|
|
65
|
+
title: 'Boat speed damping factor (0 = no damping, 1 = full damping)',
|
|
66
|
+
default: 0
|
|
67
|
+
},
|
|
52
68
|
csvTable: {
|
|
53
69
|
type: "string",
|
|
54
70
|
title: "Copy/paste the csv content of the polar in http://jieter.github.io/orc-data/site/ style."
|
|
@@ -141,20 +157,21 @@ module.exports = function (app) {
|
|
|
141
157
|
deltas.forEach(delta => {
|
|
142
158
|
// app.debug('handleData: %s', JSON.stringify(delta))
|
|
143
159
|
if (delta.path == 'navigation.speedThroughWater') {
|
|
144
|
-
STW = delta.value
|
|
160
|
+
STW = applyDamping (delta.value, 'BSP', options.dampingBSP || 0, 3)
|
|
145
161
|
BSP = STW
|
|
146
162
|
// app.debug('speedThroughWater (STW): %d', STW)
|
|
147
163
|
} else if (delta.path == 'navigation.speedOverGround') {
|
|
148
|
-
SOG = delta.value
|
|
164
|
+
SOG = applyDamping (delta.value, 'BSP', options.dampingBSP || 0, 3)
|
|
149
165
|
BSP = SOG
|
|
150
166
|
// app.debug('speedThroughWater (STW): %d', STW)
|
|
151
167
|
} else if (delta.path == 'navigation.headingTrue') {
|
|
152
168
|
HDG = delta.value
|
|
153
169
|
// app.debug('heading (HDG): %d', HDG)
|
|
154
170
|
} else if (delta.path == 'environment.wind.speedTrue') {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
app.debug('TWS: %d
|
|
171
|
+
// applyDamping (Xn, unit, a, n)
|
|
172
|
+
TWS = applyDamping (delta.value, 'TWS', options.dampingTWS || 0, 3)
|
|
173
|
+
// app.debug('environment.wind.speedTrue (TWS): %d applyDamping: %d', delta.value, TWS)
|
|
174
|
+
// app.debug('TWS: %d TWA: %d BSP: %d', msToKts(TWS), radToDeg(TWA)*port, msToKts(BSP))
|
|
158
175
|
sendUpdates(getPerformanceData(TWS, TWA, BSP))
|
|
159
176
|
} else if (delta.path == 'environment.wind.angleTrueWater') {
|
|
160
177
|
if (delta.value < 0) {
|
|
@@ -162,7 +179,8 @@ module.exports = function (app) {
|
|
|
162
179
|
} else {
|
|
163
180
|
port = 1
|
|
164
181
|
}
|
|
165
|
-
TWA = Math.abs(delta.value)
|
|
182
|
+
TWA = Math.abs(applyDamping (delta.value, 'TWA', options.dampingTWA || 0, 1))
|
|
183
|
+
// app.debug('environment.wind.angleTrueWater (TWA): %s applyDamping: %s', radToDeg(delta.value).toFixed(0), radToDeg(TWA).toFixed(0))
|
|
166
184
|
}
|
|
167
185
|
})
|
|
168
186
|
}
|
|
@@ -210,10 +228,12 @@ module.exports = function (app) {
|
|
|
210
228
|
if (typeof perfObj.polarSpeed != 'undefined') {
|
|
211
229
|
values.push({path: 'performance.polarSpeed', value: roundDec(perfObj.polarSpeed)})
|
|
212
230
|
values.push({path: 'performance.polarSpeedRatio', value: roundDec(perfObj.polarSpeedRatio)})
|
|
213
|
-
if (
|
|
231
|
+
if (typeof perfObj.velocityMadeGood != 'undefined') {
|
|
214
232
|
values.push({path: 'performance.velocityMadeGood', value: roundDec(perfObj.velocityMadeGood)})
|
|
215
233
|
values.push({path: 'performance.polarVelocityMadeGood', value: roundDec(perfObj.polarVelocityMadeGood)})
|
|
234
|
+
metas.push({path: 'performance.polarVelocityMadeGood', value: {"units": "m/s"}})
|
|
216
235
|
values.push({path: 'performance.polarVelocityMadeGoodRatio', value: roundDec(perfObj.polarVelocityMadeGoodRatio)})
|
|
236
|
+
metas.push({path: 'performance.polarVelocityMadeGoodRatio', value: {"units": "ratio"}})
|
|
217
237
|
}
|
|
218
238
|
}
|
|
219
239
|
if (typeof perfObj.maxSpeed != 'undefined') {
|
|
@@ -616,6 +636,23 @@ module.exports = function (app) {
|
|
|
616
636
|
}
|
|
617
637
|
return data
|
|
618
638
|
}
|
|
639
|
+
|
|
640
|
+
function applyDamping (Xn, unit, a, n) {
|
|
641
|
+
if (typeof damping[unit] == 'undefined') {
|
|
642
|
+
// Doesn't exist yet, make array for unit
|
|
643
|
+
damping[unit] = {Yn: []}
|
|
644
|
+
}
|
|
645
|
+
// Yn = a * Yn-1 + (1-a) * Xn
|
|
646
|
+
let Yn = a * (damping[unit]['Yn'][n-1] || Xn) + (1-a) * Xn
|
|
647
|
+
// Add Yn to begin of Yn array
|
|
648
|
+
damping[unit]['Yn'].push(Yn)
|
|
649
|
+
// Remove last value from Yn array if needed
|
|
650
|
+
if (damping[unit]['Yn'].length > n+1) {
|
|
651
|
+
damping[unit]['Yn'].shift()
|
|
652
|
+
}
|
|
653
|
+
// app.debug('Unit: %s array: %s', unit, damping[unit]['Yn'].join(','))
|
|
654
|
+
return Yn
|
|
655
|
+
}
|
|
619
656
|
}
|
|
620
657
|
|
|
621
658
|
plugin.stop = function () {
|
|
@@ -655,3 +692,4 @@ function roundDec (value) {
|
|
|
655
692
|
value = Number(value.toFixed(3))
|
|
656
693
|
return value
|
|
657
694
|
}
|
|
695
|
+
|