Why should a model not contain continuous states for production code generation?

22 visualizaciones (últimos 30 días)
In the "Simulink Modeling Guidelines for High-Integrity Systems", guideline hisl_0041 ("Configuration Parameters > Solver > Solver options") mandates to configure the solver in the model configuration parameters to a fixed-step type and the specific solver to "discrete (no continuous states)". This is justified by "Generating code for production requires a fixed-step, discrete solver.".
While I can understand that using a fixed-step solver is necessary for code generation, I am struggling with the reasoning behind having a discrete solver (and, in consequence, no continuous states within the model).
Can someone explain this reasoning to me?
  2 comentarios
René Schwarz
René Schwarz el 2 de Feb. de 2021
@yogesh s Thank you for you comment. The difference between continuous and discrete states is clear to me. The justification why models with continuous states should not be used for production code generation (with a fixed-step solver, of course), however, is not.

Iniciar sesión para comentar.

Respuestas (1)

Fangjun Jiang
Fangjun Jiang el 2 de Feb. de 2021
Editada: Fangjun Jiang el 2 de Feb. de 2021
On a model with continuous states, you can run a simulation with fixed step size using a solver, e.g. ode4. In fact, the simulation is run on a digital computer. All the arithmatic operations are discrete step by step operations. Code can be generated to match those operations and can be used in an embedded micro-controller.
At issue is the consistency or determinstic of the generated code. When you run c2d() on continuous state 1/s, the resulting discrete transfer function is quite different depending on the discretization method. The discrete transfer function determines the arithmatic operation in the generated code. Thus, the generated code would look drastically different.
For a model with continuous states, Mathworks could apply the c2d() automatically with some default settings and then generate code. There is no techincal difficulites here. But the code will look quite different depending on some settings. The generated code doesn't match with a continuous transfer function as well as with a discrete transfer function.
So Mathworks chose not to do this. They want the users to do the c2d() discretization by themselves and put the discrete states directly in the model.
>> c2d(tf(1,[1,0]),0.1,'zoh')
ans =
0.1
-----
z - 1
Sample time: 0.1 seconds
Discrete-time transfer function.
>> c2d(tf(1,[1,0]),0.1,'tustin')
ans =
0.05 z + 0.05
-------------
z - 1
Sample time: 0.1 seconds
Discrete-time transfer function.
  5 comentarios
René Schwarz
René Schwarz el 2 de Feb. de 2021
Thank you for your answer. Just to make my question a bit more clear: Simulink Coder & Embedded Coder are actually able to generate code from models with fixed-step, continuous (non-discrete) solvers such as ode4 or ode1be. The aforementioned guideline, however, requires to use a fixed-step, discrete solver for developing high-integrity systems. The justification for this is not clear to me.
I could speculate about the background for this recommendation: As continuous solvers use numerical integration to compute the model's continuous states, it might be related to the stability/convergence of integration (and, in consequence, determinism of the software execution) or that a certain numerical accuracy cannot be guaranteed within the assigned execution rate (= step size) of the generated code. But as I said, these are just speculations from my side.
Fangjun Jiang
Fangjun Jiang el 3 de Feb. de 2021
That is a good point too.
The short answer to this is that it could be done but the Mathworks chose not to do it.
The rational behind it is that it has many un-deterministics. Industry experts on embedded application, safety, etc. agreed with it.

Iniciar sesión para comentar.

Categorías

Más información sobre Simulink Coder en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by