speedandcurrent 1.7.2 → 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.
- package/index.js +10 -11
- 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 || {});
|
|
@@ -537,25 +540,22 @@ module.exports = function (app) {
|
|
|
537
540
|
*/
|
|
538
541
|
function correct(wellUnderway) {
|
|
539
542
|
// prepare iteration
|
|
543
|
+
if (!isReadyAndFresh(rawAttitude) || !isReadyAndFresh(rawBoatSpeed) || !isReadyAndFresh(rawHeading)) return;
|
|
540
544
|
const heel = rawAttitude.value?.roll;
|
|
541
545
|
const speed = rawBoatSpeed.magnitude;
|
|
542
546
|
const theta = rawHeading.value;
|
|
543
547
|
//app.debug(`Heel: ${SI.toDegrees(heel).toFixed(1)}°, Speed: ${SI.toKnots(speed).toFixed(2)} kn, Heading: ${SI.toDegrees(theta).toFixed(1)}°`);
|
|
544
|
-
|
|
545
|
-
//app.debug("Invalid input data");
|
|
546
|
-
return;
|
|
547
|
-
}
|
|
548
|
-
|
|
548
|
+
|
|
549
549
|
correctedBoatSpeed.copyFrom(rawBoatSpeed);
|
|
550
550
|
speedCorrection.setVectorValue({ x: 0, y: 0 }) ;
|
|
551
|
-
if (speed > 0
|
|
551
|
+
if (speed > 0 ) {
|
|
552
552
|
const { correction, variance } = table.getCorrection(speed, heel);
|
|
553
553
|
speedCorrection.setVectorValue(correction, variance);
|
|
554
554
|
correctedBoatSpeed.add(speedCorrection);
|
|
555
555
|
}
|
|
556
556
|
Polar.send(app, plugin.id, [correctedBoatSpeed]);
|
|
557
557
|
// estimate current
|
|
558
|
-
if (wellUnderway &&
|
|
558
|
+
if (wellUnderway && isReadyAndFresh(rawGroundSpeed)) {
|
|
559
559
|
boatSpeedRefGround.copyFrom(correctedBoatSpeed);
|
|
560
560
|
boatSpeedRefGround.rotate(theta);
|
|
561
561
|
rawCurrent.copyFrom(rawGroundSpeed);
|
|
@@ -576,15 +576,14 @@ module.exports = function (app) {
|
|
|
576
576
|
* @param {number} [minSpeed=0] - The minimum speed threshold (in SI units) required to update the correction table.
|
|
577
577
|
*/
|
|
578
578
|
function updateTable(assumeCurrent = false, minSpeed = 0) {
|
|
579
|
+
if (!isReadyAndFresh(smoothedAttitude) || !isReadyAndFresh(smoothedBoatSpeed) || !isReadyAndFresh(smoothedHeading) || !isReadyAndFresh(smoothedGroundSpeed)) return;
|
|
579
580
|
// prepare iteration
|
|
580
581
|
const heel = smoothedAttitude.value.roll;
|
|
581
582
|
const speed = smoothedBoatSpeed.magnitude;
|
|
582
583
|
const theta = smoothedHeading.value;
|
|
583
584
|
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
// update correction table
|
|
587
|
-
if (speed > minSpeed && !smoothedAttitude.stale && !smoothedHeading.stale && !smoothedGroundSpeed.stale) {
|
|
585
|
+
// update correction table
|
|
586
|
+
if (speed > minSpeed ) {
|
|
588
587
|
table.update(speed, heel, smoothedGroundSpeed, assumeCurrent ? smoothedCurrent : noCurrent, smoothedBoatSpeed, theta);
|
|
589
588
|
}
|
|
590
589
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "speedandcurrent",
|
|
3
|
-
"version": "1.7.
|
|
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.
|
|
34
|
+
"signalkutilities": "^1.9.1"
|
|
35
35
|
},
|
|
36
36
|
"files": [
|
|
37
37
|
"index.js",
|