How can I tell which blocks in my multirate model have been updated at the current time step in the generated code?

1 次查看(过去 30 天)

I have a model with various subsystems operating at different sample times. After generating code, I see that all outport data, regardless of sample period, is assigned to the one "ExtY_multirateExample_T" structure:

// External outputs (root outports fed by signals with default storage)
struct ExtY_multirateExample_T {
real_T LoRateOutport; // '<Root>/LoRateOutport'
real_T HighRateOutport; // '<Root>/HighRateOutport'
real_T BaseRateOutport; // '<Root>/BaseRateOutport'
real_T output_1hz; // '<Root>/output_1hz'
};
We have not yet finalized the sample times in our model, so we would like a flexible way for our test harness to know when to read new data.
 
1) Is there a recommended strategy to add some sort of flag/pulse in the generated code that would indicate when a certain subsystem's data is fresh (not stale)? This would indicate when a subrate's data (and its associated subsystem) gets fresh information written to it at that model step.
 
2) Is there a way to assign outport data of different sample periods to separate output data structures?

采纳的回答

MathWorks Support Team
For question 1:
One possible approach to this is to use pulse generator blocks. This approach is depicted in the attached "multirateExampleUpdated.mdl".
For the pulse generator blocks:
  • The "Pulse type" is set to "Sample based" and the sample time for the block is set to the fundamental rate of the system (in the case of "multirateExampleUpdated.mdl", this is 0.1 seconds).
  • The pulse width is set to 1, so that the pulse is only active on the first sample time when the data is fresh.
  • The "period" is set to:
(sample time of the subsystem) / (fundamental sample time of the model)
In this way, the pulse generator would only create a pulse when blocks operating at that sample time have been freshly updated.
For question 2:
Virtual buses group the desired signals into an array in the generated code. These are used in the attached example "multierateExampleUpdated.mdl". More information on virtual buses can be found at the following link:

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Deployment, Integration, and Supported Hardware 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by