do not use es2015 here
This commit is contained in:
parent
9b1b8252bb
commit
245977c2e8
1 changed files with 72 additions and 73 deletions
27
third-party/kalman.js
vendored
27
third-party/kalman.js
vendored
|
@ -11,8 +11,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class KalmanFilter {
|
function KalmanFilter(params) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create 1-dimensional kalman filter
|
* Create 1-dimensional kalman filter
|
||||||
* @param {Number} options.R Process noise
|
* @param {Number} options.R Process noise
|
||||||
|
@ -22,14 +21,13 @@ class KalmanFilter {
|
||||||
* @param {Number} options.C Measurement vector
|
* @param {Number} options.C Measurement vector
|
||||||
* @return {KalmanFilter}
|
* @return {KalmanFilter}
|
||||||
*/
|
*/
|
||||||
constructor({R = 1, Q = 1, A = 1, B = 0, C = 1} = {}) {
|
|
||||||
|
|
||||||
this.R = R; // noise power desirable
|
this.R = typeof params.R == "undefined" ? 1 : params.R; // noise power desirable
|
||||||
this.Q = Q; // noise power estimated
|
this.Q = typeof params.Q == "undefined" ? 1 : params.Q; // noise power estimated
|
||||||
|
|
||||||
this.A = A;
|
this.A = typeof params.A == "undefined" ? 1 : params.A;
|
||||||
this.C = C;
|
this.C = typeof params.C == "undefined" ? 1 : params.C;
|
||||||
this.B = B;
|
this.B = typeof params.B == "undefined" ? 0 : params.B;
|
||||||
this.cov = NaN;
|
this.cov = NaN;
|
||||||
this.x = NaN; // estimated signal without noise
|
this.x = NaN; // estimated signal without noise
|
||||||
}
|
}
|
||||||
|
@ -40,8 +38,9 @@ class KalmanFilter {
|
||||||
* @param {Number} u Control
|
* @param {Number} u Control
|
||||||
* @return {Number}
|
* @return {Number}
|
||||||
*/
|
*/
|
||||||
filter(z, u = 0) {
|
KalmanFilter.prototype.filter = function (z, u) {
|
||||||
|
if (typeof u == "undefined")
|
||||||
|
u = 0;
|
||||||
if (isNaN(this.x)) {
|
if (isNaN(this.x)) {
|
||||||
this.x = (1 / this.C) * z;
|
this.x = (1 / this.C) * z;
|
||||||
this.cov = (1 / this.C) * this.Q * (1 / this.C);
|
this.cov = (1 / this.C) * this.Q * (1 / this.C);
|
||||||
|
@ -67,7 +66,7 @@ class KalmanFilter {
|
||||||
* Return the last filtered measurement
|
* Return the last filtered measurement
|
||||||
* @return {Number}
|
* @return {Number}
|
||||||
*/
|
*/
|
||||||
lastMeasurement() {
|
KalmanFilter.prototype.lastMeasurement = function () {
|
||||||
return this.x;
|
return this.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,7 +74,7 @@ class KalmanFilter {
|
||||||
* Set measurement noise Q
|
* Set measurement noise Q
|
||||||
* @param {Number} noise
|
* @param {Number} noise
|
||||||
*/
|
*/
|
||||||
setMeasurementNoise(noise) {
|
KalmanFilter.prototype.setMeasurementNoise = function (noise) {
|
||||||
this.Q = noise;
|
this.Q = noise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +82,7 @@ class KalmanFilter {
|
||||||
* Set the process noise R
|
* Set the process noise R
|
||||||
* @param {Number} noise
|
* @param {Number} noise
|
||||||
*/
|
*/
|
||||||
setProcessNoise(noise) {
|
KalmanFilter.prototype.setProcessNoise = function (noise) {
|
||||||
this.R = noise;
|
this.R = noise;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue