kalman-filter

bradzilla84/kalman-filter/kalman-filter

The variables are X for the filtered value, Q for the process noise, R for the sensor noise, P for the estimated error and K for the Kalman Gain. The state of the filter is defined by the values of these variables. The initial values for p is not very important since it is adjusted during the process. It must be just high enough to narrow down. The initial value for the readout is also not very important, since it is updated during the process. But tweaking the values for the process noise and sensor noise is essential to get clear readouts.
kalman-filter
@/kalman-filter
The variables are X for the filtered value, Q for the process noise, R for the sensor noise, P for the estimated error and K for the Kalman Gain. The state of the filter is defined by the values of these variables. The initial values for p is not very important since it is adjusted during the process. It must be just high enough to narrow down. The initial value for the readout is also not very important, since it is updated during the process. But tweaking the values for the process noise and sensor noise is essential to get clear readouts.
Xnumber
Value of interest
Qnumber
Process noise covariance
Rnumber
Measurement noise covariance
Pnumber
Estimation error covariance
Knumber
Kalman gain
kalman-filter
X
Q
R
P
K
VAL
PNoise
SNoise
EError
EErrornumber
EstimatedError
SNoisenumber
SensorNoise
PNoisenumber
ProcessNoise
VALnumber
Filtered Value
To use the node in your project you should have the bradzilla84/kalman-filter library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

#pragma XOD require "https://github.com/bachagas/Kalman"


{{#global}}
#include <Kalman.h>
{{/global}}

struct State {
    uint8_t mem[sizeof(Kalman)];
};


{{ GENERATED_CODE }}

void evaluate(Context ctx) {

    if (isSettingUp()) {
        auto state = getState(ctx);
        // Create a new object in the memory area reserved previously.
        auto kalman = new (state->mem) Kalman(getValue<input_Q>(ctx),getValue<input_R>(ctx), getValue<input_P>(ctx), getValue<input_K>(ctx));
        return;
    }

    auto state = getState(ctx);
    auto kalman = reinterpret_cast<Kalman*>(state->mem);

    emitValue<output_VAL>(ctx, kalman->getFilteredValue(getValue<input_X>(ctx)));
    emitValue<output_PNoise>(ctx, kalman->getProcessNoise());
    emitValue<output_SNoise>(ctx, kalman->getSensorNoise());
    emitValue<output_EError>(ctx, kalman->getEstimatedError());
}