"duration" function in stateflow using fixed-point datatype for time

I created an mpt.parameter for a time variable. Since time is in ms, I assigned data type as fixdt(0,16,0.001,0)
time_s = mpt.Parameter;
time_s.CoderInfo.Alias = 'Ts';
time_s.Description = 'Time in ms';
time_s.DataType = 'fixdt(0,16,0.001,0)';
time_s.Unit = 's';
time_s.Value = 0.5;
Now in one of my stateflow transition between states, I need to use this time variable. i.e: [duration(t > 20) > time_s]
Matlab thowrs error as below:
In fi > non-fi, or non-fi > fi, the non-fi must be a constant. Transition '[durat...time_s]'"duration(t > 20) > time_s"
Component:Stateflow | Category:Coder error
Error while generating code for chart Chart.
ps: I need fixdt(0,16,0.001,0) since I need to generate fixed point code and cannot afford using single or double or any Integer type.
Is there a workaround for this? Thanks in advance

回答 (1 件)

stozaki
stozaki 2020 年 1 月 25 日
編集済み: stozaki 2020 年 1 月 25 日

0 投票

't' is a reserved word of the double data type. Therefore, you cannot set attributes such as data type.
I thought that using the after function was one of the workarounds. I have attached a sample model.

4 件のコメント

Renish Ramegowda
Renish Ramegowda 2020 年 1 月 27 日
Thanks for the reply.
As per your suggestion, I changed variable "t" to "out_t".
My requirement was to start timer only after "out_t > 20" and it should be true till the time "time_s" is elapsed.
I'm attaching the model for your reference.
stozaki
stozaki 2020 年 1 月 27 日
編集済み: stozaki 2020 年 1 月 27 日
You can avoid errors by not using absolute time in the temporal operator inside the Chart block.
Or could you consider using fi objects?
% I have modified the answer.
Renish Ramegowda
Renish Ramegowda 2020 年 1 月 27 日
Thanks again.
For me, the transition shall happen only after the point, t > 20 is true and then from that point 0.5 sec is completed. Also in between 0.5 sec timer running, if t > 20 condition becomes false, then the time needs to be reset.
for such scenerio, "duration" function was very useful but issue is, it wont accept fixed point data type for time value. For my requirement, all values can only be fixedpoint data type since floting values cannot be accepted in code generation
Question: Why "duration" function dont accept fixed datatype input?
stozaki
stozaki 2020 年 1 月 30 日
Temporal Logic,
When using Event-Based (tick/CLK): Positive integer
When using Absolute-Time (sec/msec): It is just a positive number, that is, a double type.
So, My model uses Event-Based Temporal Logic. This is a workaround.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeSimulink Functions についてさらに検索

製品

リリース

R2019a

質問済み:

2020 年 1 月 24 日

コメント済み:

2020 年 1 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by