1

I've developed a controller in Simulink and am trying to export it as a pure C class using Simulink coder for deployment on our microcontroller. We are using a fixed step solver in simulation, however, when the exported code gets used on our actual plant, the actual step size may change depending on load of the processor.

My concern is this: say I have set the fixed time step as 0.05s in simulation (and therefore the exported code assumes it is being executed every 0.05s), but then the microprocessor sometimes executes after 0.1s, and sometimes after 0.03s, etc. I think this would cause some unwanted behaviour.

Is there a way to have Simulink coder create a variable for step-time that we can adjust during run time? That is, measure how long it has been since the last execution, and then fill in the variable during each execution.

For an analogy, in videogame programming the update functions usually include a dt parameter so we know how long its been since the last frame.

The only solution I can find is to manually search and replace the step size in all the integrator blocks after the code has been generated. This, however, seems error prone.

Adriaan
  • 17,741
  • 7
  • 42
  • 75
Jeff
  • 11
  • 1
  • 1
    I suspect this can't be done, although it might depend on the actual code generation target that you're using. You should play around with parameterizing the sample times as `Simulink.Parameter` objects (and probably making their storage class `ImportedExtern`) and see if that gets you any further. – Phil Goddard Jan 29 '19 at 03:40
  • I have tried playing around with making the sample time a `Simulink.Parameter` and changing the storage class - no luck there so far! – Jeff Feb 20 '19 at 18:20

0 Answers0