speedandcurrent 1.1.0 → 1.3.0

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/CHANGELOG.md CHANGED
@@ -16,3 +16,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
16
16
  - Case error in filename that prevented the webapp from displaying the correction table
17
17
  - Corrected speed through water is now calculated when the correction table is fixed
18
18
 
19
+ ## [1.3.0] - ntb
20
+ ### Changed
21
+ - Simplified code
22
+ - Less CPU usage
23
+ ### Added
24
+ - Option to set the source for input paths
25
+ - Smart heartbeat. Calculations will run right after an update of the path that has the lowest update frequency
26
+ - Oversampling for quick update inputs to get better variance
27
+ ### Fixed
28
+ - Angles are now reported in the appropriate range, 0 to 2 * PI or -PI to PI, depending on path
@@ -9,19 +9,20 @@ class CorrectionTable extends Table2D{
9
9
 
10
10
 
11
11
  static fromJSON(data, stability) {
12
- const table = new CorrectionTable(data.row, data.col, stability);
12
+ const table = new CorrectionTable(data.id, data.row, data.col, stability);
13
13
  table.table = data.table.map(row => row.map(cellData => CorrectionEstimator.fromJSON(cellData)));
14
14
  return table;
15
15
  }
16
16
 
17
- constructor(row, col, stability=5) {
18
- super(row, col, CorrectionEstimator, CorrectionEstimator.getFilterModel(stability));
19
- this.id = "correctionTable";
20
- this.label = "Correction Table";
17
+ constructor(id, row, col, stability=5) {
18
+ super(id, row, col, CorrectionEstimator, CorrectionEstimator.getFilterModel(stability));
19
+ this.lastUpdatedCell = null;
21
20
  }
22
21
 
23
22
  update(speed, heel, groundSpeed, current, boatSpeed, heading) {
24
- this.getCell(speed, heel)?.update(groundSpeed, current, boatSpeed, heading);
23
+ const cell = this.getCell(speed, heel);
24
+ cell?.update(groundSpeed, current, boatSpeed, heading);
25
+ this.lastUpdatedCell = cell;
25
26
  }
26
27
 
27
28
  getKalmanCorrection(speed, heel) {
@@ -53,15 +54,26 @@ class CorrectionTable extends Table2D{
53
54
  if (totalWeightX == 0 || totalWeightY == 0) return { x: 0, y: 0 };
54
55
  x = x / totalWeightX;
55
56
  y = y / totalWeightY;
56
- return { x, y };
57
+ return { x:x, y:y };
57
58
 
58
59
  }
59
60
 
60
- getInfo() {
61
+ report() {
61
62
  return {
63
+ id: this.id,
62
64
  row: { min: this.min[0], max: this.max[0], step: this.step[0] },
63
65
  col: { min: this.min[1], max: this.max[1], step: this.step[1] },
64
- table: this.table.map(row => row.map(correction => correction.getInfo()))
66
+ table: this.table.map(row =>
67
+ row.map(correction => {
68
+ const cellReport = correction.report();
69
+ // Mark selected if this is the last updated cell
70
+ cellReport.displayAttributes = {
71
+ selected: correction === this.lastUpdatedCell
72
+ };
73
+ return cellReport;
74
+ })
75
+ ),
76
+ displayAttributes: this.displayAttributes
65
77
  };
66
78
  }
67
79
 
@@ -101,7 +113,7 @@ class CorrectionEstimator {
101
113
  }
102
114
 
103
115
  update(groundSpeed, current, boatSpeed, heading) {
104
- if (groundSpeed.n < 2 || current.n < 2 || boatSpeed.n < 2) return;
116
+ if(groundSpeed.n < 2 || current.n < 2 || boatSpeed.n < 2) return;
105
117
  // Rotation matrix for -theta
106
118
  const cosTheta = Math.cos(heading);
107
119
  const sinTheta = Math.sin(heading);
@@ -120,9 +132,9 @@ class CorrectionEstimator {
120
132
  ]
121
133
  );
122
134
 
123
- var groundVector = rotateValue(groundSpeed.obs);
124
- var currentVector = rotateValue(current.obs);
125
- var boatVector = boatSpeed.obs;
135
+ var groundVector = rotateValue(groundSpeed.vector);
136
+ var currentVector = rotateValue(current.vector);
137
+ var boatVector = boatSpeed.vector;
126
138
 
127
139
  const observation = [
128
140
  -boatVector[0] + groundVector[0] - currentVector[0],
@@ -145,7 +157,7 @@ class CorrectionEstimator {
145
157
  }
146
158
 
147
159
 
148
- getInfo() {
160
+ report() {
149
161
  return { x: this.x, y: this.y, N: this.N };
150
162
  }
151
163