@stepan-ozana
Thanks, that looks great! I'll modify the schema a little more to match the conventions of the other blocks and include it in the installation.
administrators
-
RE: EKF example
-
RE: EKF example
@stepan-ozana Thank you for your valuable insights! Your contribution to the collection of examples is greatly appreciated.
In the original 'EKF.zip' file mentioned at the beginning of this thread, the timing parameters were incorrectly set—my apologies for that. The best way to correct them is by changing the start and stop values in the task1 block to -1, as outlined in the manual. The log message 'CoreWarning GTimer: Period overtime.' appears whenever the task execution exceeds the maximum allowed time, which can be observed in Diagnostics. If this warning appears in the log while the Max time in Diagnostics does not exceed the allocated execution time (20 ms in the case of EKF.zip), it indicates an error.
We would greatly appreciate any further insights and improvements from your side. I had planned to simulate measurement noise similarly to your approach—by adding white noise to the measurement vector—but I hadn’t considered process noise. For your reference, I’m sharing the updated version of the example, which includes your reference model and the corrected timing parameters.
-
RE: EKF example
@stepan-ozana
First of all, thank you very much for adding the reference model. If you agree, I would like to add this model to the example on EKF, which is already part of the daily version of REXYGEN.As for the timing. I think the problem may be in the Python block, which takes significantly longer to execute than the native blocks. Try looking in the Diagnostics and at the statistics on the execution of the task.
-
RE: Exchanging data between tasks
@carvin Hi carvin,
thanks for your feedback. I would suggest to use the SRTF function block with some certain subsystem (e.g. "sybsystem_slow") within your fast task.
Would that solve your issue?
Cheers,
Tomas -
RE: Exchanging data between tasks
@stepan-ozana Hi Stepan,
Thank you for your question. It is possible to set the start of task execution as soon as the previous task ends. More details in TASK documentation: https://www.rexygen.com/doc/ENGLISH/MANUALS/BRef/TASK.html#x26-250002
Information between tasks should be always sent via Inports and Outports if possible (SETPx function blocks can introduce undesired inverse of priorities when sending data between tasks).
Second part - "on demand" execution:
Thanks for sharing your solution! It is also possible to use SRTF function block (Set run-time flags):
Doc: https://www.rexygen.com/doc/ENGLISH/MANUALS/BRef/SRTF.html#x21-200002If you need any assistance just let me know.
Cheers,
Tomas -
RE: EKF example
EKF - Linear System Model
This document describes the use of the Extended Kalman Filter (EKF) in the REXYGEN environment for state estimation of a linear system.
System Description
The system is described by the following differential equations:
\begin{aligned} \frac{dx(t)}{dt} &= f(x(t), u(t)) + w(t),\\ y(t) &= h(x(t), u(t)) + v(t),\\ \hat{x}(t) &\sim \mathcal{N}(x, P),\\ w(t) &\sim \mathcal{N}(0, Q),\\ v(t) &\sim \mathcal{N}(0, R). \end{aligned}
where:
- $ x(t) $ is the state vector,
- $ u(t) $ is the input vector,
- $ y(t) $ is the output vector,
- $ w(t) $ is the process noise,
- $ v(t) $ is the measurement noise,
- $ \hat{x}(t) $ is the estimated state vector,
- $ x $ is the mean (expected value),
- $ P $ is the state estimation covariance matrix,
- $ Q $ is the process noise covariance matrix,
- $ R $ is the measurement noise covariance matrix.
State Model of the System
The system dynamics are defined by the function $ f(x(t), u(t)) $:
f(x(t), u(t)) = \begin{bmatrix} \frac{dx_1(t)}{dt} \\ \frac{dx_2(t)}{dt} \\ \frac{dx_3(t)}{dt} \\ \frac{dx_4(t)}{dt} \end{bmatrix} = \begin{bmatrix} -x_1(t) + x_2(t) \\ -x_2(t) + x_3(t) \\ -x_3(t) + x_4(t) \\ -x_4(t) + u_1(t) \end{bmatrix}.
Jacobian of the State Function
The Jacobian $ f(x, u) $ with respect to the state vector $ x $ is given as:
\frac{df(x(t), u(t))}{dx} = \begin{bmatrix} -1 & 1 & 0 & 0 \\ 0 & -1 & 1 & 0 \\ 0 & 0 & -1 & 1 \\ 0 & 0 & 0 & -1 \end{bmatrix}
Output Measurements
The first set of output measurements (which, in this example, depend linearly on the state variables) for input EKF:nz = 1 is defined as:
y(t) = h_1(x(t), u(t)) = \begin{bmatrix} x_1(t) \\ 2 x_2(t) + 0.5 x_4(t) \end{bmatrix},
with the corresponding Jacobian:
\frac{dh_1(x(t), u(t))}{dt} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 2 & 0 & 0.5 \\ \end{bmatrix}.
The second set of output measurements (for input EKF:nz = 2) is not used.
The system description is programmed into the REXLANG block.
This description serves as a basis for implementing the EKF in REXYGEN using the EKF function block. Further details can be found in the official documentation: EKF Block in REXYGEN.
-
RE: EKF example
@bech Hi,
here is a Markdown file describing the system, which is implemented in the REXLANG block. To view the equations correctly, copy the file's contents into an online editor, such as this one: https://markdownlivepreview.org -
RE: Input reference to a matrix or vector
Hi Carvin,
Thanks for the question. With all the provided information I don't see anything suspicious. Please, can you share the whole project (mdl files at minimum) just to see all other information and configuration which are not visible from the screenshot?
Just be aware that arrays and vectors in REXYGEN are connected by references so the flow of "information" is different from ordinary "wire" flow where the wire starts somewhere and goes somewhere else. Contrary reference contains the same data in every instance.
Kind regards,
Tomas -
RE: EKF example
@bech Hi,
I'm sending an example of using EKF for a linear model. Please take a look at the code in the REXLANG block. Unfortunately, I don't have time to document the example in more detail right now. However, I should have time next week, so I'll send an improved version then.
Best regards,
Jan
EKF.zip -
RE: Rexcore-runtime not Running after installation
@gninaus Hi Guenther,
the fix is available in our daily build repository: https://download.rexcontrols.cz/partner/daily/
Feel free to test it and report back.
Kind Regards,
Tomas