[Simulink] Rate limiter dynamic with a variable-step solver

20 visualizaciones (últimos 30 días)
Franck
Franck el 12 de Sept. de 2013
Respondida: Steve Theberge el 29 de Mzo. de 2019
Hi everybody,
i need to use a "rate limiter dynamic" block in my Simulink model. But, the latter runs only with a fixed-step solver. Anybody have an idea to code an alternative solution to do this operation ? A precision : i just want to fixe a variable slew rate limitation ; the falling rate limitation is always equal to -inf.
Thanks in advance :)

Respuestas (3)

Ryan G
Ryan G el 13 de Sept. de 2013
You could put a rate transition on the input signal to the block. This would make the input signal fixed sample time and resolve the error. Otherwise, you would have to derive this manually. The challenge with variable time steps is that you need to somehow determine how big the time step is.
If you look at the error it points you to the Ts block under the mask. This outputs the signals sample time (fixed). If you did this for variable step you could setup like this using clock and memory blocks with a summing junction:
(clock) -> (memory) -> (-) (clock) -> (+) = time step
This time step should give you similar results. I can't guarantee the accuracy versus the shipping block.

Franck
Franck el 24 de Sept. de 2013
Hello Ryan,
and thanks for your response. I'm sorry to answer so later. I tried all your solutions. The rate transition solution doesn't work, because it makes an error during the beginning of the model execution. I also tried to compute the time step of the input signal like you advice me, but it doesn't indicate the same value like the 'Ts' block. So it doesn't give similar results. I am resolved to use as many 'rate limiter' blocks as I needed. In fact, i have only to modify during the time the slew rate among ten values. I tinkered a solution with ten 'rate limiter' blocks which are activated only one by one with ten 'enabled subsystems'. Do you think it is a good solution ?
Thanks again :)

Steve Theberge
Steve Theberge el 29 de Mzo. de 2019
This is the solution I came up with, it's not elegant so I would like to know if someone came up with something better. I created a subsystem with the following blocks inside:
Ratelimit.jpg
The Rate Limiter block runs in variable step solvers but doesn't have input ports for rate limits, these are set in the Parameters inside the block. It so happens that you can change these parameters while the simulation is running, either manually by double clicking the block or by using the set_param command. Here I am using an embedded MATLAB function (the block named "Set_param for RateLimit") to do this. The code inside this block is as follows:
function RtLim(up,dn)
eml.extrinsic('evalin');
eml.extrinsic('set_param');
eml.extrinsic('num2str');
persistent up_z;
persistent dn_z;
if (isempty(up_z))
up_z = 0.99*up;
dn_z = 0.99*dn;
end
if up_z ~= up || dn_z ~= dn
evalin('caller', 'blocknameWS = gcb;'); %get full name of current block
blockname = evalin('caller', 'blocknameWS(1:end-35);');%removes "Set_param for Ratelimit/ SFunction " from end of string
blockname = [blockname 'Rate Limiter']; %concatenate "Rate Limiter" to end of string
set_param(blockname, 'risingSlewLimit', num2str(up));
set_param(blockname, 'fallingSlewLimit', num2str(dn));
end
up_z = up;
dn_z = dn;
end
This code builds the full block name of the rate limiter block and stores the string in the variable "blockname". Then it uses that in the set_param command. That way the subsystem can be copied and pasted in other areas of the model and renamed and it will work without having to change anything inside (Note: careful if you rename the rate limiter block since the code depends on that name and also if you rename the Embedded MATLAB function since the code depends on that name being a certain length. Also note that here I am checking if the rate settings have changed before calling the evalin and set_param commands (in my case they only change occasionally so the model executes faster if I don't constantly execute the evalin and set_param commands for nothing).

Categorías

Más información sobre Programmatic Model Editing en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by