signalk-polar-performance-plugin 0.0.49 → 0.0.51

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 +30 -25
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "signalk-polar-performance-plugin",
3
- "version": "0.0.49",
3
+ "version": "0.0.51",
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
@@ -50,6 +50,11 @@ module.exports = function (app) {
50
50
  type: 'boolean',
51
51
  title: 'Use speed over ground (SOG) as boat speed.'
52
52
  },
53
+ useSOGsource: {
54
+ type: 'string',
55
+ default: '',
56
+ title: 'Source (name.id) to filter SOG on'
57
+ },
53
58
  maxSpeed: {
54
59
  type: 'boolean',
55
60
  title:
@@ -76,7 +81,7 @@ module.exports = function (app) {
76
81
  },
77
82
  dampingBSP: {
78
83
  type: 'number',
79
- title: 'Boat speed damping damping',
84
+ title: 'Boat speed damping seconds',
80
85
  default: 1
81
86
  },
82
87
  csvTable: {
@@ -125,15 +130,18 @@ module.exports = function (app) {
125
130
  subscribe: [
126
131
  {
127
132
  path: 'navigation.speedThroughWater',
128
- policy: 'instant'
133
+ policy: 'instant',
134
+ minPeriod: 500
129
135
  },
130
136
  {
131
137
  path: 'environment.wind.speedTrue',
132
- policy: 'instant'
138
+ policy: 'instant',
139
+ minPeriod: 500
133
140
  },
134
141
  {
135
142
  path: 'environment.wind.angleTrueWater',
136
- policy: 'instant'
143
+ policy: 'instant',
144
+ minPeriod: 500
137
145
  }
138
146
  ]
139
147
  }
@@ -142,7 +150,8 @@ module.exports = function (app) {
142
150
  if (options.useSOG == true) {
143
151
  localSubscription.subscribe.push({
144
152
  path: 'navigation.speedOverGround',
145
- policy: 'instant'
153
+ policy: 'instant',
154
+ minPeriod: 500
146
155
  })
147
156
  }
148
157
  if (options.tackTrue == true) {
@@ -160,30 +169,34 @@ module.exports = function (app) {
160
169
  },
161
170
  delta => {
162
171
  delta.updates.forEach(u => {
163
- // app.debug(u.values)
164
- handleDelta(u.values)
172
+ // app.debug(u)
173
+ handleDelta(u.values,u['$source'])
165
174
  })
166
175
  }
167
176
  )
168
177
 
169
178
  // Handle delta
170
- function handleDelta (deltas) {
179
+ function handleDelta (deltas, source) {
171
180
  deltas.forEach(delta => {
172
- // app.debug('handleData: %s', JSON.stringify(delta))
181
+ app.debug('handleData (%s): %s', source, JSON.stringify(delta))
173
182
  if (
174
183
  delta.path == 'navigation.speedThroughWater' &&
175
184
  options.useSOG == false
176
185
  ) {
186
+ app.debug('STW useSOG: %j', options.useSOG)
177
187
  STW = applyDamping(delta.value, 'STW', options.dampingBSP || 0)
178
188
  BSP = STW
179
- // app.debug('speedThroughWater (STW): %d', STW)
189
+ app.debug('speedThroughWater (STW): %d', STW)
180
190
  } else if (
181
191
  delta.path == 'navigation.speedOverGround' &&
182
192
  options.useSOG == true
183
193
  ) {
184
- SOG = applyDamping(delta.value, 'SOG', options.dampingBSP || 0)
185
- BSP = SOG
186
- // app.debug('speedOverGround (SOG): %d', SOG)
194
+ app.debug('SOG useSOG: %j', options.useSOG)
195
+ if (options.useSOGsource == '' || source == options.useSOGsource) {
196
+ SOG = applyDamping(delta.value, 'SOG', options.dampingBSP || 0)
197
+ BSP = SOG
198
+ app.debug('speedOverGround (SOG) (%s): %d', source, SOG)
199
+ }
187
200
  } else if (delta.path == 'navigation.headingTrue') {
188
201
  HDG = delta.value
189
202
  // app.debug('heading (HDG): %d', HDG)
@@ -200,12 +213,7 @@ module.exports = function (app) {
200
213
  port = 1
201
214
  }
202
215
  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
- )
216
+ // app.debug('environment.wind.angleTrueWater (TWA): %s applyDamping: %s port: %d', delta.value, TWA, port)
209
217
  }
210
218
  })
211
219
  }
@@ -250,7 +258,7 @@ module.exports = function (app) {
250
258
  addValue('performance.beatAngleVelocityMadeGood', perfObj.beatVMG)
251
259
  if (options.targetTWA === true) {
252
260
  addValue('performance.targetVelocityMadeGood', perfObj.beatVMG, {
253
- units: 'rad'
261
+ units: 'm/s'
254
262
  })
255
263
  }
256
264
  }
@@ -503,12 +511,9 @@ module.exports = function (app) {
503
511
  }
504
512
  // Calculate polar performance ratio
505
513
  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
- )
514
+ // app.debug('performance.polarSpeedRatio = BSP (%s)/ performance.polarSpeed (%s)', msToKts(BSP).toFixed(2), msToKts(performance.polarSpeed).toFixed(2))
511
515
  performance.polarSpeedRatio = BSP / performance.polarSpeed
516
+ app.debug('performance.polarSpeedRatio = %s', performance.polarSpeedRatio.toFixed(2))
512
517
  if (options.VMG == true) {
513
518
  performance.velocityMadeGood = Math.abs(BSP * Math.cos(TWA))
514
519
  performance.polarVelocityMadeGood = performance.targetVMG