matlabvariablessimulinksample-rate

How can I have a variable sample time for logging data in simulink?


I have a model in simulink which controls a real time application. I have a predefined testplan, which is basically a table, which is processed line by line with a stateflow chart. In some of the steps it is very important to log in very small time steps to see the details of how the application is coping with the input. For other steps in the testplan it is not very important to log this many steps, because I have to condition my test rig again or something similar. The "variable sample-rate" can be a multiple of the base sample rate for the model. Is there a way to log this data with different sample times for each of the lines? The testplan could look like in the picture below. For every line in the command there is the matching sample time. In my stateflow chart I use the the value in every single line to send something to my test rig. And in a feedback loop it will go to the next line in the testplan if the requirements are met. that the targetvalue is reached.

Testplan:

testplan

Stateflow chart process: Stateflow chart process

I defined the sample times for each line in the testplan itself and gave out the value through my staeflow chart which process the whole testplan. I tried using a matlab function block to write the variable to the base workspace. This variable I then used in to workspace block as sample time. Curio sly it changed the sample time of the to workspace block for the first processed line, but kept it that way for the whole simulation. I also tried the same with the rate transition block.


Solution

  • You could put your logging into a triggered subsystem, and fire the logging events from your Stateflow chart.

    To illustrate, I'm going to set up a model which switches between a sample rate of 0.1 and 0.01 every second so I don't need the rate table you've got, but either way we have some logging rate dt.

    main system

    The stateflow chart could be within your existing stateflow, or just output dt from your stateflow into another chart like this one:

    chart

    The output event is triggered every dt seconds, and we can use this event to trigger the logging subsystem. In my example I've just got a scope within the subsystem, but you could do anything:

    triggered subsystem

    You can see this working in the scope's output, with smooth/fast logging for 1 second, then coarse logging for 1 second:

    scope