How can I use sample time internally in Stateflow

28 visualizzazioni (ultimi 30 giorni)
GK
GK il 15 Giu 2019
Risposto: Todd il 17 Ott 2024
Hello,
My fixed solver discrete type model has sample time of 20ms.
I want to use this sample time in Stateflow to start a counter and increment it in 20ms time.
How can I use this sample time in Stateflow?
Thank you.
Note: If sample time changes, the counter should take the updated sample time.

Risposta accettata

GK
GK il 4 Lug 2019
Also I found another solution on the mentioned mathworks link:
https://in.mathworks.com/matlabcentral/answers/54995-how-to-access-fundamental-sample-time-value-within-a-simulink-model
  1 Commento
Dana Schwanke
Dana Schwanke il 27 Giu 2022
The information at that link does not seem to answer the question of determining a chart's sample time from inside the chart. Could you please elaborate or post the code you discovered?

Accedi per commentare.

Più risposte (2)

Krishna Anne
Krishna Anne il 17 Giu 2019
At the init trigger of your SF diagram start an independent counter and increment it by 1 (loop around). This way even if your solver settings change will be aligned with the counts as that many time samples.
Also, please remember that this is not the real definition of sample time, Simulink only mimics as per your solver settings. See the documentation about solver carefully.
  1 Commento
GK
GK il 4 Lug 2019
Hi,
It is not clear how to use the counter with incremeting 1 can be used as timer.
Where should I initialize the counter? Where should I increment the counter?
Also my timer starts incrementing only when external condition become true.
Could you elaborate?

Accedi per commentare.


Todd
Todd il 17 Ott 2024
Came here to look for a better solution. Here are two imperfect solutions.
1) Use temporal logic, ex. after(5,sec). This makes the chart much easier to read, but in my simple case generates way more code than necessary. Also, duration seems to always generate doubles. I would use temporal logic for anything more complicated than a debounce.
2) Input the task rate and use the Weighted Sample Time block. Look out for unintended doubles.

Categorie

Scopri di più su Simulink Functions in Help Center e File Exchange

Tag

Prodotti


Release

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by