Hi,
Edited: formatted code snippet
I am trying to write a model that will find be the suitable shaft speed of my machine based in a reference input signal. I want to search the table for the threshold value of the reference input and find the corresponding shaft speed. I do not want to interpolate so CombiTimeTable is not a good choice.
The table length (always two columns) is arbitrary and I do want the code to be as simple as possible. I therefore started with a for-loop stepping through the table. If then use a when-loop to define my event. An if-loop does not work, won't compile (I do not know why).
Now, when I test my model giving both constant Real as input and Real ramp the model works fine and does exactly what I expect it to do. However, when I insert my model into the complete system model, it does nothing. Input is now Real constant, but the model outputs only the value zero (which is not even in the table...).
Anyone with any idea on what might be wrong?
Code below:
model RefIntoSpeedConversionTest "Sets shaft speed from reference input level"
Modelica.Blocks.Interfaces.RealInput RefIn;
discrete Modelica.Blocks.Interfaces.RealOutput RPM;
parameter Real speedtable[:, :] = [0, 1200; 200, 1200; 380, 1200; 450, 1400; 550, 1600; 650, 1800; 750, 1950; 850, 2100; 1000, 2100; 1200, 2100] ;
parameter Integer length = size(speedtable, 1) - 1;
algorithm
for i in 1:length loop
when speedtable[i, 1] <= RefIn and RefIn < speedtable[i + 1, 1] then
RPM := speedtable[i, 2];
end when;
end for;
end RefIntoSpeedConversionTest;
Regards,
Martin