signalk-polar-performance-plugin 0.0.4 → 0.0.6

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/README.md CHANGED
@@ -9,6 +9,7 @@ The following paths are read
9
9
  - navigation.speedThroughWater
10
10
  - environment.wind.speedTrue
11
11
  - environment.wind.angleTrueWater
12
+ - navigation.speedOverGround (optional)
12
13
 
13
14
  ## Plugin configuration
14
15
  ### Polar diagram
@@ -30,11 +31,11 @@ In the plugin configuration you can toggle the following options:
30
31
  - Optimal Wind Angle (diff between TWA and environment.wind.directionTrue)
31
32
  - Polar Boat Speed (performance.polarSpeed)
32
33
  - Polar Speed Ratio (performance.polarSpeedRatio)
34
+ - Plugin option to use SOG as boat speed
35
+ - Wind angle for maximum speed at this wind speed
33
36
 
34
37
  ### To-do list
35
38
  - Fill up the ends of the polar diagram
36
- - A switch to use SOG as boat speed
37
- - Wind angle for maximum speed at this wind speed
38
39
  - Improved interpolation
39
40
  - Make moment to do calculation smarter/configurable
40
41
  - Create polar from live data
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "signalk-polar-performance-plugin",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
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
@@ -28,6 +28,14 @@ module.exports = function (app) {
28
28
  type: 'boolean',
29
29
  title: 'Enable calculation of Optimal Wind Angle (difference between TWA and beat/run angle (depends on beat/run angle)'
30
30
  },
31
+ useSOG: {
32
+ type: 'boolean',
33
+ title: 'Use speed over ground (SOG) as boat speed.'
34
+ },
35
+ maxSpeed: {
36
+ type: 'boolean',
37
+ title: 'Enable writing of maximum speed angle and boat speed for a given TWS'
38
+ },
31
39
  csvTable: {
32
40
  type: "string",
33
41
  title: "Enter csv with polar in http://jieter.github.io/orc-data/site/ style."
@@ -75,6 +83,14 @@ module.exports = function (app) {
75
83
  ]
76
84
  }
77
85
 
86
+ // Additional subscribes based on options
87
+ if (options.useSOG == true) {
88
+ localSubscription.subscribe.push({
89
+ path: 'navigation.speedOverGround',
90
+ policy: 'instant'
91
+ })
92
+ }
93
+
78
94
  app.subscriptionmanager.subscribe(
79
95
  localSubscription,
80
96
  unsubscribes,
@@ -97,6 +113,10 @@ module.exports = function (app) {
97
113
  STW = delta.value
98
114
  BSP = STW
99
115
  // app.debug('speedThroughWater (STW): %d', STW)
116
+ } else if (delta.path == 'navigation.speedOverGround') {
117
+ SOG = delta.value
118
+ BSP = SOG
119
+ // app.debug('speedThroughWater (STW): %d', STW)
100
120
  } else if (delta.path == 'environment.wind.speedTrue') {
101
121
  TWS = delta.value
102
122
  // app.debug('environment.wind.speedTrue (TWS): %d', TWS)
@@ -142,6 +162,12 @@ module.exports = function (app) {
142
162
  values.push({path: 'performance.polarSpeed', value: roundDec(perfObj.polarSpeed)})
143
163
  values.push({path: 'performance.polarSpeedRatio', value: roundDec(perfObj.polarSpeedRatio)})
144
164
  }
165
+ if (typeof perfObj.maxSpeed != 'undefined') {
166
+ values.push({path: 'performance.maxSpeed', value: roundDec(perfObj.maxSpeed)})
167
+ metas.push({path: 'performance.maxSpeed', value: {"units": "m/s"}})
168
+ values.push({path: 'performance.maxSpeedAngle', value: roundDec(perfObj.maxSpeedAngle)})
169
+ metas.push({path: 'performance.maxSpeedAngle', value: {"units": "rad"}})
170
+ }
145
171
 
146
172
  app.debug('sendUpdates: %s', JSON.stringify(values))
147
173
  app.handleMessage(plugin.id, {
@@ -230,17 +256,25 @@ module.exports = function (app) {
230
256
  // Calculate upper tws boat speed
231
257
  let upperTBS = upperTWAlower.tbs + ((upperTWAupper.tbs - upperTWAlower.tbs) * twaGapRatio)
232
258
 
233
- // Calculate target boat speed
259
+ // Calculate polar performance
234
260
  performance.polarSpeed = lowerTBS + ((upperTBS - lowerTBS) * twsGapRatio)
235
261
  // app.debug('lowerTBS: %d TBS: %d upperTBS: %d', lowerTBS, performance.polarSpeed, upperTBS)
236
262
 
237
- // Calculate polar performance
263
+ // Calculate polar performance ratio
238
264
  performance.polarSpeedRatio = (1 / performance.polarSpeed) * BSP
239
-
265
+ break
240
266
  }
241
267
  }
242
-
243
- // Calculate polar performance ratio
268
+ if (options.maxSpeed == true) {
269
+ let lowerMax = polar[indexTWS]['Max speed']
270
+ let upperMax = polar[indexTWS+1]['Max speed']
271
+ let maxSpeed = lowerMax + ((upperMax - lowerMax) * twsGapRatio)
272
+ performance.maxSpeed = maxSpeed
273
+ let lowerMaxAngle = polar[indexTWS]['Max speed angle']
274
+ let upperMaxAngle = polar[indexTWS+1]['Max speed angle']
275
+ let maxSpeedAngle = lowerMaxAngle + ((upperMaxAngle - lowerMaxAngle) * twsGapRatio)
276
+ performance.maxSpeedAngle = maxSpeedAngle
277
+ }
244
278
  } else {
245
279
  // app.debug('%d not >= %d && <= %d', TWS, lower, upper)
246
280
  }
@@ -289,17 +323,16 @@ module.exports = function (app) {
289
323
  if (row[index] != 0) {
290
324
  polar[index-1][angleName] = degToRad(angle)
291
325
  polar[index-1][VMGName] = roundDec(Number((row[index]) * Math.abs(Math.cos(angle))))
292
- app.debug('polar[index-1]: %s', polar[index-1])
293
326
  if (typeof polar[index-1]['twa'] == 'undefined') {
294
327
  polar[index-1]['twa'] = []
295
328
  }
296
- app.debug('polar[index-1]: %s', polar[index-1])
297
- app.debug('Adding TargetBoatSpeed')
298
- let Obj = {"twa": degToRad(angle), "tbs": ktsToMs(Number(row[index]))}
299
- app.debug('Obj: %s', JSON.stringify(Obj))
329
+ let tbs = ktsToMs(Number(row[index]))
330
+ let Obj = {"twa": degToRad(angle), "tbs": tbs}
300
331
  polar[index-1]['twa'] = polar[index-1]['twa'].concat(Obj)
301
- app.debug('polar[index-1]["twa"]: %s', polar[index-1]['twa'])
302
- app.debug('polar: %s', JSON.stringify(polar))
332
+ if (typeof polar[index-1]['Max speed'] == 'undefined' || tbs > polar[index-1]['Max speed']) {
333
+ polar[index-1]['Max speed'] = tbs
334
+ polar[index-1]['Max speed angle'] = degToRad(angle)
335
+ }
303
336
  }
304
337
  }
305
338
  } else {
@@ -309,9 +342,13 @@ module.exports = function (app) {
309
342
  if (typeof polar[index-1].twa == 'undefined') {
310
343
  polar[index-1].twa = []
311
344
  }
312
- let Obj = {"twa": angle, "tbs": ktsToMs(Number(row[index]))}
345
+ let tbs = ktsToMs(Number(row[index]))
346
+ let Obj = {"twa": angle, "tbs": tbs}
313
347
  polar[index-1]['twa'] = polar[index-1]['twa'].concat(Obj)
314
- app.debug('polar: %s', JSON.stringify(polar))
348
+ if (tbs > polar[index-1]['Max speed']) {
349
+ polar[index-1]['Max speed'] = tbs
350
+ polar[index-1]['Max speed angle'] = angle
351
+ }
315
352
  }
316
353
  }
317
354
  })