How can I use complex numbers and non-finite number in PLC Coder?

3 次查看(过去 30 天)

Most of the functions that I am working on are polynomial solvers for a specific case of a problem. As such, 'inf' and 'nan' are possible outputs of these functions when there is no solution. Are there any typical workarounds for projection of that sort of thing?
I’m supposing that I can detect the case and the return a value that is impossible (in my case a negative number) or something like that, but I do wonder. I have to work with complex numbers as potential solutions, so I’m counting on the PLC coder to create the complex number structure in Structured Text, etc.

I am also using a Beckhoff PLC.

采纳的回答

MathWorks Support Team
As for the limitations of the PLC Coder in general, I would recommend referring to this documentation page:
The problem with non-finite numbers such as Inf and NaN is that those are handled in an implementation specific manner and are not currently standardized by IEC 61131-3. An example of which is Codesys, which there is a function GetLRealSpecialVal which accepts an Enum which would indicate Inf or NaN. To read more about this please refer to the following documentation:
Since you are using Beckhoff there is RealIsNaN, however, we didn't find anything that would return a value indicating that the value is 'Inf' or 'NaN' like the function for Codesys. For more information on the RealIsNaN function please refer to the following documentation:
A workaround for this could be to define the function which uses Inf or NaN and define this function as 'Externally Defined'. For more information on this setting please refer to the following documentation:
With this setting, the call site to the function is kept, but the definition/declaration of the function is removed from the generated code. You would then have to handwrite your own function for this in Standard Text code directly in your IDE environment and it would integrate with the generated code. 
Additionally, if you generate code with a NaN value this will trigger a conformance check error from the model. For the sake of code generation you could replace this with a '0' but still define it as 'Externally Defined' and handcode the whole function directly in your IDE.
In the end, since the support for nonfinite numbers is not standardized you will have to use a solution that is implementation specific. This may involve reworking the design of any MATLAB code as well.
For complex numbers, code generation is not officially supported. However, there are no currently known unsupported cases, and so code will still be generated.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink PLC Coder 的更多信息

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by