speedandcurrent 1.7.1 → 1.7.3

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/index.js +18 -11
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -45,6 +45,9 @@ module.exports = function (app) {
45
45
  showStatistics: false
46
46
  };
47
47
 
48
+ const isReadyAndFresh = (input) => !!input && input.ready === true && !input.stale;
49
+
50
+
48
51
  function readOptions() {
49
52
  const stored = app.readPluginOptions();
50
53
  const raw = stored && stored.configuration ? stored.configuration : (stored || {});
@@ -358,6 +361,14 @@ module.exports = function (app) {
358
361
  noCurrent.ySmoother.reset(0,0);
359
362
  PolarSmoother.send(app, plugin.id, [noCurrent]);
360
363
 
364
+ MessageHandler.setMeta(app, plugin.id, 'navigation.leewayAngle', {
365
+ units: 'rad',
366
+ description: 'Leeway Angle',
367
+ displayUnits: {
368
+ category: 'angle'
369
+ }
370
+ });
371
+
361
372
 
362
373
  // boat speed — STW magnitude is optionally forwarded; leeway angle passOn is always false
363
374
  const rawBoatSpeedPolar = new Polar(app, plugin.id, 'boatSpeed');
@@ -529,25 +540,22 @@ module.exports = function (app) {
529
540
  */
530
541
  function correct(wellUnderway) {
531
542
  // prepare iteration
543
+ if (!isReadyAndFresh(rawAttitude) || !isReadyAndFresh(rawBoatSpeed) || !isReadyAndFresh(rawHeading)) return;
532
544
  const heel = rawAttitude.value?.roll;
533
545
  const speed = rawBoatSpeed.magnitude;
534
546
  const theta = rawHeading.value;
535
547
  //app.debug(`Heel: ${SI.toDegrees(heel).toFixed(1)}°, Speed: ${SI.toKnots(speed).toFixed(2)} kn, Heading: ${SI.toDegrees(theta).toFixed(1)}°`);
536
- if (!Number.isFinite(heel) || !Number.isFinite(speed) || !Number.isFinite(theta)) {
537
- //app.debug("Invalid input data");
538
- return;
539
- }
540
-
548
+
541
549
  correctedBoatSpeed.copyFrom(rawBoatSpeed);
542
550
  speedCorrection.setVectorValue({ x: 0, y: 0 }) ;
543
- if (speed > 0 && !rawAttitude.stale ) {
551
+ if (speed > 0 ) {
544
552
  const { correction, variance } = table.getCorrection(speed, heel);
545
553
  speedCorrection.setVectorValue(correction, variance);
546
554
  correctedBoatSpeed.add(speedCorrection);
547
555
  }
548
556
  Polar.send(app, plugin.id, [correctedBoatSpeed]);
549
557
  // estimate current
550
- if (wellUnderway && !rawGroundSpeed.stale) {
558
+ if (wellUnderway && isReadyAndFresh(rawGroundSpeed)) {
551
559
  boatSpeedRefGround.copyFrom(correctedBoatSpeed);
552
560
  boatSpeedRefGround.rotate(theta);
553
561
  rawCurrent.copyFrom(rawGroundSpeed);
@@ -568,15 +576,14 @@ module.exports = function (app) {
568
576
  * @param {number} [minSpeed=0] - The minimum speed threshold (in SI units) required to update the correction table.
569
577
  */
570
578
  function updateTable(assumeCurrent = false, minSpeed = 0) {
579
+ if (!isReadyAndFresh(smoothedAttitude) || !isReadyAndFresh(smoothedBoatSpeed) || !isReadyAndFresh(smoothedHeading) || !isReadyAndFresh(smoothedGroundSpeed)) return;
571
580
  // prepare iteration
572
581
  const heel = smoothedAttitude.value.roll;
573
582
  const speed = smoothedBoatSpeed.magnitude;
574
583
  const theta = smoothedHeading.value;
575
584
 
576
- if (!Number.isFinite(heel) || !Number.isFinite(speed) || !Number.isFinite(theta)) return;
577
-
578
- // update correction table
579
- if (speed > minSpeed && !smoothedAttitude.stale && !smoothedHeading.stale && !smoothedGroundSpeed.stale) {
585
+ // update correction table
586
+ if (speed > minSpeed ) {
580
587
  table.update(speed, heel, smoothedGroundSpeed, assumeCurrent ? smoothedCurrent : noCurrent, smoothedBoatSpeed, theta);
581
588
  }
582
589
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "speedandcurrent",
3
- "version": "1.7.1",
3
+ "version": "1.7.3",
4
4
  "description": "A plugin that automatically corrects boat speed and calculates current and leeway using sensor fusion.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "kalman-filter": "^2.3.0",
34
- "signalkutilities": "^1.8.0"
34
+ "signalkutilities": "^1.9.1"
35
35
  },
36
36
  "files": [
37
37
  "index.js",