RollRegions not defined for calls to %roll: The roll argument to %roll must be a nonempty vector of numbers or ranges

1 visualizzazione (ultimi 30 giorni)
What would cause RollRegions NOT to be defined, so that I can't use it in the TLC file?
I have an S function with a tlc file.
In the past I have successfully used the %roll directive such as:
%roll sigIdx = RollRegions, lcv = RollThreshold, block, "Roller", rollVars
However, with a particular S function I receive the following error when I try to build the code:
The roll argument to %roll must be a nonempty vector of numbers or ranges
It appears that RollRegions just isn't defined, although, according to documentation:
For blocks, the variable RollRegions is automatically computed and placed in the Block record.
I can see, in the .rtw file, that Simulink knows the RollRegions for the relevant port of the relevant block instance, as it appears within the Block {...} constuct for the relevant S function instance, as:
DataInputPort {
...
RollRegions [0, 1, 2:4]
}
which is correct for the relevant input port of the single instance of the S function in my test model.
There are 2 single signals at different memory addresses feeding the input port elements [0] and [1],
and then an array of 3 signals at contiguous memory addresses feeding elements [2:4].
So RollRegions appears to be correctly defined within the Block {} construct, but when I try to use RollRegions in the tlc file, it seems to be undefined???

Risposte (2)

Kartik
Kartik il 17 Apr 2023
Hi,
It is possible that the RollRegions variable is not being properly propagated to the TLC file. Here are a few things you can try:
  1. Make sure that the S-function has been properly compiled and loaded into MATLAB. You can try recompiling the S-function and rebuilding the code.
  2. Make sure that the RollRegions variable is being properly referenced in the TLC file. Double-check the syntax of your %roll directive to make sure that you are using the correct variable name and that it is being referenced in the correct scope.
  3. Try adding a check for the existence of RollRegions in the TLC file before using it. You can use the MATLAB function "isfield" to check if the variable exists in the Block record.
  4. If none of the above suggestions work, you can try using the "get_param" function to directly retrieve the RollRegions property from the block.

Andrew Roscoe
Andrew Roscoe il 10 Ott 2023
Modificato: Andrew Roscoe il 10 Ott 2023
I'm still searching for an answer on this question, although I have a workaround.
Essentially I am using the workaround which is just to use a %foreach construct to create a basic long list of the code lines in the built code. It works, but if my input signal had 100 elements, I would end up with 100 code lines, when a %roll directive could produce a much neater for loop in the built C code, if the input signal array was contiguous in memory.
So I have fallen back to (for example):
%assign u_width = LibBlockInputSignalWidth(0)
%foreach i = %<u_width>
... do the stuff for this input signal array element
%endforeach
But I still don't know why %roll and RollRegions don't work. I know I have used them in the past before, to good effect. In those cases, I was using %roll and RollRegions within TLC code that existed inside
%function Outputs(block, system)
I am wondering if the reason that %roll and RollRegions don't work in my present application(s) is that I am trying to use them to set up pointers, for example to input signal arrays, and so the place I am trying to use %roll and RollRegions is within the TLC code of:
%function Start(block, system)
Would this explain why RollRegions is returning an empty vector []?
There is some more digging. During the code build, if I pretend to prepare to use %roll and RollRegions within %function Start(), and IF I can catch the file .rtw file which is created (and then destroyed/cleaned) as part of the build process, it DOES include RollRegions that look sensible, i.e. for an S function taking a signal of width 10 at input port 1 (zero based), the rtw file contains (for input port 1 of the relevant S function instance)
DataInputPort {
SignalSrc [b982, b981, b980, b979, b978@4]
SignalOffset [0, 0, 0, 0, 4:7]
SignalRegion [0@1 ,1@1 ,2@1 ,3@1 ,4@4]
CGTypeIdx 57
RollRegions [0, 1, 2, 3, 4:7]
}
But in the final built code, if I print out the RollRegions that I would have tried to use, using a TLC line like the below, just before I try and use them in a %roll construct:
// %<Type>, %<Tag> : Start(). RollRegions for rollVars "%<rollVars>" is "%<RollRegions>"
it reports ' // S-Function, MySFunction : Start(). RollRegions for rollVars "[u1]" is "[]" '
So it's like the RollRegions vector was correctly discovered, and temporarily stored in the .rtw file, but then not applied, lost, discarded, or otherwise reset to '[]' before it could be applied.
????

Prodotti


Release

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by