signalk-polar-performance-plugin 0.0.28 → 0.0.31

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/plugin/index.js +17 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "signalk-polar-performance-plugin",
3
- "version": "0.0.28",
3
+ "version": "0.0.31",
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
@@ -299,6 +299,7 @@ module.exports = function (app) {
299
299
  let VMGLower = polar[indexTWS]['Beat VMG']
300
300
  let VMGUpper = polar[indexTWS+1]['Beat VMG']
301
301
  performance.beatVMG = VMGLower + ((VMGUpper - VMGLower) * twsGapRatio)
302
+ performance.targetVMG = performance.beatVMG
302
303
  }
303
304
  } else {
304
305
  // app.debug('Downwind')
@@ -322,6 +323,7 @@ module.exports = function (app) {
322
323
  let VMGUpper = polar[indexTWS+1]['Run VMG']
323
324
  //app.debug('VMGLower: %s VMGUpper: %s', VMGLower, VMGUpper)
324
325
  performance.runVMG = VMGLower + ((VMGUpper - VMGLower) * twsGapRatio)
326
+ performance.targetVMG = performance.runVMG
325
327
  }
326
328
  }
327
329
  // Calculate opposite Tack True
@@ -408,7 +410,7 @@ module.exports = function (app) {
408
410
  performance.polarSpeedRatio = BSP / performance.polarSpeed
409
411
  if (options.VMG == true) {
410
412
  performance.velocityMadeGood = Math.abs(BSP * Math.cos(TWA))
411
- performance.polarVelocityMadeGood = Math.abs(performance.targetVelocityMadeGood * Math.cos(targetTWA))
413
+ performance.polarVelocityMadeGood = performance.targetVMG
412
414
  performance.polarVelocityMadeGoodRatio = performance.velocityMadeGood / performance.polarVelocityMadeGood
413
415
  }
414
416
  } else {
@@ -671,12 +673,26 @@ module.exports = function (app) {
671
673
  // Doesn't exist yet, make obj for unit
672
674
  damping[unit] = {Yn: Xn, dt: Date.now()}
673
675
  }
676
+ // Edge case when hovering around -pi and +pi
677
+ if (Xn > Math.PI && damping[unit].Yn < (0-Math.PI)) {
678
+ Xn = Xn - (2*Math.PI)
679
+ } else if (Xn < (0-Math.PI) && damping[unit].Yn > Math.PI) {
680
+ Xn = Xn + (2*Math.PI)
681
+ }
674
682
  // Calculate a
675
683
  let dt = (Date.now() - damping[unit].dt)/1000
676
684
  damping[unit].dt = Date.now()
677
685
  let a = dt / (RC + dt)
678
686
  // Yn = (1-a) * Yn-1 + a * Xn
679
687
  let Yn = (1-a) * (damping[unit].Yn || Xn) + a * Xn
688
+
689
+ // Fix is we go outside -pi to pi
690
+ if (Yn > Math.PI) {
691
+ Yn = Yn - Math.PI
692
+ } else if (Yn < (0-Math.PI)) {
693
+ Yn = Yn + Math.PI
694
+ }
695
+
680
696
  // Remember Yn
681
697
  damping[unit].Yn = Yn
682
698
  // app.debug('Unit: %s dt: %d a: %d obj: %s', unit, dt, a, JSON.stringify(damping[unit]))