signalk-polar-performance-plugin 0.0.50 → 0.0.52

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "signalk-polar-performance-plugin",
3
- "version": "0.0.50",
3
+ "version": "0.0.52",
4
4
  "description": "A plugin that calculates performance information based on a (CSV) polar diagram.",
5
5
  "main": "plugin/index.js",
6
6
  "scripts": {
package/plugin/index.js CHANGED
@@ -19,6 +19,11 @@ module.exports = function (app) {
19
19
  var schema = {
20
20
  // The plugin schema
21
21
  properties: {
22
+ trueWindSpeedPath: {
23
+ type: 'string',
24
+ default: 'environment.wind.speedTrue',
25
+ title: 'Wind speed path to use'
26
+ },
22
27
  beatAngle: {
23
28
  type: 'boolean',
24
29
  title:
@@ -50,6 +55,11 @@ module.exports = function (app) {
50
55
  type: 'boolean',
51
56
  title: 'Use speed over ground (SOG) as boat speed.'
52
57
  },
58
+ useSOGsource: {
59
+ type: 'string',
60
+ default: '',
61
+ title: 'Source (name.id) to filter SOG on'
62
+ },
53
63
  maxSpeed: {
54
64
  type: 'boolean',
55
65
  title:
@@ -76,7 +86,7 @@ module.exports = function (app) {
76
86
  },
77
87
  dampingBSP: {
78
88
  type: 'number',
79
- title: 'Boat speed damping damping',
89
+ title: 'Boat speed damping seconds',
80
90
  default: 1
81
91
  },
82
92
  csvTable: {
@@ -125,15 +135,18 @@ module.exports = function (app) {
125
135
  subscribe: [
126
136
  {
127
137
  path: 'navigation.speedThroughWater',
128
- policy: 'instant'
138
+ policy: 'instant',
139
+ minPeriod: 500
129
140
  },
130
141
  {
131
- path: 'environment.wind.speedTrue',
132
- policy: 'instant'
142
+ path: trueWindSpeedPath,
143
+ policy: 'instant',
144
+ minPeriod: 500
133
145
  },
134
146
  {
135
147
  path: 'environment.wind.angleTrueWater',
136
- policy: 'instant'
148
+ policy: 'instant',
149
+ minPeriod: 500
137
150
  }
138
151
  ]
139
152
  }
@@ -142,7 +155,8 @@ module.exports = function (app) {
142
155
  if (options.useSOG == true) {
143
156
  localSubscription.subscribe.push({
144
157
  path: 'navigation.speedOverGround',
145
- policy: 'instant'
158
+ policy: 'instant',
159
+ minPeriod: 500
146
160
  })
147
161
  }
148
162
  if (options.tackTrue == true) {
@@ -160,36 +174,40 @@ module.exports = function (app) {
160
174
  },
161
175
  delta => {
162
176
  delta.updates.forEach(u => {
163
- // app.debug(u.values)
164
- handleDelta(u.values)
177
+ // app.debug(u)
178
+ handleDelta(u.values,u['$source'])
165
179
  })
166
180
  }
167
181
  )
168
182
 
169
183
  // Handle delta
170
- function handleDelta (deltas) {
184
+ function handleDelta (deltas, source) {
171
185
  deltas.forEach(delta => {
172
- // app.debug('handleData: %s', JSON.stringify(delta))
186
+ app.debug('handleData (%s): %s', source, JSON.stringify(delta))
173
187
  if (
174
188
  delta.path == 'navigation.speedThroughWater' &&
175
189
  options.useSOG == false
176
190
  ) {
191
+ app.debug('STW useSOG: %j', options.useSOG)
177
192
  STW = applyDamping(delta.value, 'STW', options.dampingBSP || 0)
178
193
  BSP = STW
179
- // app.debug('speedThroughWater (STW): %d', STW)
194
+ app.debug('speedThroughWater (STW): %d', STW)
180
195
  } else if (
181
196
  delta.path == 'navigation.speedOverGround' &&
182
197
  options.useSOG == true
183
198
  ) {
184
- SOG = applyDamping(delta.value, 'SOG', options.dampingBSP || 0)
185
- BSP = SOG
186
- // app.debug('speedOverGround (SOG): %d', SOG)
199
+ app.debug('SOG useSOG: %j', options.useSOG)
200
+ if (options.useSOGsource == '' || source == options.useSOGsource) {
201
+ SOG = applyDamping(delta.value, 'SOG', options.dampingBSP || 0)
202
+ BSP = SOG
203
+ app.debug('speedOverGround (SOG) (%s): %d', source, SOG)
204
+ }
187
205
  } else if (delta.path == 'navigation.headingTrue') {
188
206
  HDG = delta.value
189
207
  // app.debug('heading (HDG): %d', HDG)
190
- } else if (delta.path == 'environment.wind.speedTrue') {
208
+ } else if (delta.path == trueWindSpeedPath) {
191
209
  TWS = applyDamping(delta.value, 'TWS', options.dampingTWS || 0)
192
- // app.debug('environment.wind.speedTrue (TWS): %d applyDamping: %d', delta.value, TWS)
210
+ // app.debug('%s (TWS): %d applyDamping: %d', trueWindSpeedPath, delta.value, TWS)
193
211
  // app.debug('TWS: %d TWA: %d BSP: %d', msToKts(TWS), radToDeg(TWA)*port, msToKts(BSP))
194
212
  sendUpdates(getPerformanceData(TWS, TWA, BSP))
195
213
  } else if (delta.path == 'environment.wind.angleTrueWater') {
@@ -200,12 +218,7 @@ module.exports = function (app) {
200
218
  port = 1
201
219
  }
202
220
  TWA = Math.abs(TWAtmp)
203
- app.debug(
204
- 'environment.wind.angleTrueWater (TWA): %s applyDamping: %s port: %d',
205
- delta.value,
206
- TWA,
207
- port
208
- )
221
+ // app.debug('environment.wind.angleTrueWater (TWA): %s applyDamping: %s port: %d', delta.value, TWA, port)
209
222
  }
210
223
  })
211
224
  }
@@ -503,12 +516,9 @@ module.exports = function (app) {
503
516
  }
504
517
  // Calculate polar performance ratio
505
518
  if (typeof performance.polarSpeed != 'undefined') {
506
- app.debug(
507
- 'performance.polarSpeedRatio = BSP (%s)/ performance.polarSpeed (%s)',
508
- msToKts(BSP).toFixed(2),
509
- msToKts(performance.polarSpeed).toFixed(2)
510
- )
519
+ // app.debug('performance.polarSpeedRatio = BSP (%s)/ performance.polarSpeed (%s)', msToKts(BSP).toFixed(2), msToKts(performance.polarSpeed).toFixed(2))
511
520
  performance.polarSpeedRatio = BSP / performance.polarSpeed
521
+ app.debug('performance.polarSpeedRatio = %s', performance.polarSpeedRatio.toFixed(2))
512
522
  if (options.VMG == true) {
513
523
  performance.velocityMadeGood = Math.abs(BSP * Math.cos(TWA))
514
524
  performance.polarVelocityMadeGood = performance.targetVMG