[Simulink] Rate limiter dynamic with a variable-step solver
15 ビュー (過去 30 日間)
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 :)
回答 (3 件)
Ryan G 2013 年 9 月 13 日
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.
Steve Theberge 2019 年 3 月 29 日
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:
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:
up_z = 0.99*up;
dn_z = 0.99*dn;
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));
up_z = up;
dn_z = dn;
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).