speedandcurrent 2.3.1 → 2.3.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 +17 -1
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -39,6 +39,17 @@ function isCogOverrideActive(groundSpeedPolar, speedThreshold) {
39
39
  && sogHandler.value < speedThreshold;
40
40
  }
41
41
 
42
+ /**
43
+ * Leeway is the angle of the corrected boatspeed vector, so a small lateral
44
+ * correction divided by a near-zero magnitude yields a large, meaningless angle.
45
+ */
46
+ function isLeewayValid(speed, speedThreshold, navigationStateHandler) {
47
+ if (!(speed >= speedThreshold)) return false;
48
+ const state = navigationStateHandler?.state;
49
+ if (state?.ready !== true) return true;
50
+ return !ALWAYS_BLOCKING_NAVIGATION_STATES.has(normalizeNavigationState(navigationStateHandler.value));
51
+ }
52
+
42
53
  function evaluateLearningMode({ options = {}, navigationState, stabilizingUntil = 0, stabilizingReason = null, now = Date.now() }) {
43
54
  const normalizedNavigationState = normalizeNavigationState(navigationState?.value);
44
55
  const navigationGateReady = navigationState?.ready === true;
@@ -833,7 +844,11 @@ module.exports = function (app) {
833
844
  else if (rawAttitude.ready) {
834
845
  if (correctedBoatSpeed.magnitude > 0) {
835
846
  const { correction, variance } = table.getCorrection(correctedBoatSpeed.magnitude, rawAttitude.value?.roll);
836
- speedCorrection.setVectorValue(correction, variance);
847
+ const leewayValid = isLeewayValid(correctedBoatSpeed.magnitude, minSpeed, navigationStateHandler);
848
+ speedCorrection.setVectorValue(
849
+ { x: correction.x, y: leewayValid ? correction.y : 0 },
850
+ { x: variance.x, y: leewayValid ? variance.y : 0 }
851
+ );
837
852
  correctedBoatSpeed.add(speedCorrection);
838
853
  }
839
854
  // Current estimation and residual also require heading (to rotate into ground frame).
@@ -1050,6 +1065,7 @@ module.exports._test = {
1050
1065
  getShortStabilizingMs,
1051
1066
  evaluateLearningMode,
1052
1067
  isCogOverrideActive,
1068
+ isLeewayValid,
1053
1069
  evaluateObservationGate,
1054
1070
  getDerivedObservationStatus,
1055
1071
  buildNavigationStateStatus,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "speedandcurrent",
3
- "version": "2.3.1",
3
+ "version": "2.3.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": {
@@ -41,7 +41,7 @@
41
41
  },
42
42
  "dependencies": {
43
43
  "kalman-filter": "^2.3.0",
44
- "signalkutilities": "^3.1.0"
44
+ "signalkutilities": "^3.1.2"
45
45
  },
46
46
  "files": [
47
47
  "icon.png",