signalk-polar-performance-plugin 0.0.5 → 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
@@ -32,10 +32,10 @@ In the plugin configuration you can toggle the following options:
32
32
  - Polar Boat Speed (performance.polarSpeed)
33
33
  - Polar Speed Ratio (performance.polarSpeedRatio)
34
34
  - Plugin option to use SOG as boat speed
35
+ - Wind angle for maximum speed at this wind speed
35
36
 
36
37
  ### To-do list
37
38
  - Fill up the ends of the polar diagram
38
- - Wind angle for maximum speed at this wind speed
39
39
  - Improved interpolation
40
40
  - Make moment to do calculation smarter/configurable
41
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.5",
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
@@ -32,6 +32,10 @@ module.exports = function (app) {
32
32
  type: 'boolean',
33
33
  title: 'Use speed over ground (SOG) as boat speed.'
34
34
  },
35
+ maxSpeed: {
36
+ type: 'boolean',
37
+ title: 'Enable writing of maximum speed angle and boat speed for a given TWS'
38
+ },
35
39
  csvTable: {
36
40
  type: "string",
37
41
  title: "Enter csv with polar in http://jieter.github.io/orc-data/site/ style."
@@ -158,6 +162,12 @@ module.exports = function (app) {
158
162
  values.push({path: 'performance.polarSpeed', value: roundDec(perfObj.polarSpeed)})
159
163
  values.push({path: 'performance.polarSpeedRatio', value: roundDec(perfObj.polarSpeedRatio)})
160
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
+ }
161
171
 
162
172
  app.debug('sendUpdates: %s', JSON.stringify(values))
163
173
  app.handleMessage(plugin.id, {
@@ -246,17 +256,25 @@ module.exports = function (app) {
246
256
  // Calculate upper tws boat speed
247
257
  let upperTBS = upperTWAlower.tbs + ((upperTWAupper.tbs - upperTWAlower.tbs) * twaGapRatio)
248
258
 
249
- // Calculate target boat speed
259
+ // Calculate polar performance
250
260
  performance.polarSpeed = lowerTBS + ((upperTBS - lowerTBS) * twsGapRatio)
251
261
  // app.debug('lowerTBS: %d TBS: %d upperTBS: %d', lowerTBS, performance.polarSpeed, upperTBS)
252
262
 
253
- // Calculate polar performance
263
+ // Calculate polar performance ratio
254
264
  performance.polarSpeedRatio = (1 / performance.polarSpeed) * BSP
255
-
265
+ break
256
266
  }
257
267
  }
258
-
259
- // 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
+ }
260
278
  } else {
261
279
  // app.debug('%d not >= %d && <= %d', TWS, lower, upper)
262
280
  }
@@ -305,17 +323,16 @@ module.exports = function (app) {
305
323
  if (row[index] != 0) {
306
324
  polar[index-1][angleName] = degToRad(angle)
307
325
  polar[index-1][VMGName] = roundDec(Number((row[index]) * Math.abs(Math.cos(angle))))
308
- app.debug('polar[index-1]: %s', polar[index-1])
309
326
  if (typeof polar[index-1]['twa'] == 'undefined') {
310
327
  polar[index-1]['twa'] = []
311
328
  }
312
- app.debug('polar[index-1]: %s', polar[index-1])
313
- app.debug('Adding TargetBoatSpeed')
314
- let Obj = {"twa": degToRad(angle), "tbs": ktsToMs(Number(row[index]))}
315
- app.debug('Obj: %s', JSON.stringify(Obj))
329
+ let tbs = ktsToMs(Number(row[index]))
330
+ let Obj = {"twa": degToRad(angle), "tbs": tbs}
316
331
  polar[index-1]['twa'] = polar[index-1]['twa'].concat(Obj)
317
- app.debug('polar[index-1]["twa"]: %s', polar[index-1]['twa'])
318
- 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
+ }
319
336
  }
320
337
  }
321
338
  } else {
@@ -325,9 +342,13 @@ module.exports = function (app) {
325
342
  if (typeof polar[index-1].twa == 'undefined') {
326
343
  polar[index-1].twa = []
327
344
  }
328
- let Obj = {"twa": angle, "tbs": ktsToMs(Number(row[index]))}
345
+ let tbs = ktsToMs(Number(row[index]))
346
+ let Obj = {"twa": angle, "tbs": tbs}
329
347
  polar[index-1]['twa'] = polar[index-1]['twa'].concat(Obj)
330
- 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
+ }
331
352
  }
332
353
  }
333
354
  })