How to decrease sample rate to run a model in real time?

1 view (last 30 days)
Hi,
I have a steering model (attached, as an .mdl but only runs as .slx) which I want to modify so that it can run in real time on a target computer. The problem is that when I switch to a fixed step solver, I need a step of max 10^-5 to avoid singularity and it has to be 10^-3.
Can someone please help with an advice on how to modify the model so that I can decrease the sample rate?
  3 Comments
Marta
Marta on 16 Oct 2014
Thanks Tony, are you able to see/download the files now?
Marta
Marta on 3 Nov 2014
Thanks for your input Jon. Yes, the requirement was based on the capabilities of the target

Sign in to comment.

Answers (1)

Jon Boerner
Jon Boerner on 16 Oct 2014
Moved: Steve Miller on 20 Nov 2022
After a quick look, there are a few things I noticed:
  • There are a number of memory blocks in your controller. When using a fixed-step solver with memory blocks, you are effectively discretizing your controller to the rate of the solver. It looks like your controller is meant to be a continuous controller, so the discretization may not be what you want. If you take out the memory blocks the model still runs and you can up the sample time to 1e-4.
  • If you look at the scope you have, with a step-size of 1e-3, before the simulation terminates itself, you can see that the dynamics of the system are faster than the solver step-size. You can tell by the choppiness of the signal. I assume the controller being discretized is the issue, since it should have faster dynamics than the plant, and 1e-3 seems close to working. It could also be that the plant is too fast to be solved at 1e-3, however.
My suggestion would be to:
  1. Run a simulation of just your plant with the solver at a timestep of 1e-3 and make sure the results are accurate for different inputs (without the controller)
  2. Take the controller subsystem and turn it into a variant subsystem (one variant with a continuous controller, and one with a discretized controller), and quickly convert your controller to a discrete controller with a rate of 1e-3 for the second variant. Confirm that the discrete controller is stable and then try the model with it.
Lastly, why do you need a step size of 1e-3? Is that the maximum rate of the target machine you are going to be using? Usually target machines can go faster if the model is simpler (less calculations/time step -> time steps can be shorter), so I am curious how you came up with the 1e-3 requirement.

Tags

Community Treasure Hunt

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

Start Hunting!