0
votes

I have the model of a dynamic system in Simulink (I cannot change the programming framework). It can be described as an oscillator subject to periodic oscillations. I am trying to control its motion, in particular, to maximize it (for energy generation).

With latching control (a popular control strategy), the idea is to 'latch', i.e. lock in place, the device when its velocity is 0 for a predefined time, and then release it until its velocity reaches 0 again.

So, what I need to do in Simulink is to output a signal 1 once the velocity signal reaches (or is close to) 0, hold it constant for a time period (at 1), then release it (the signal becomes 0), and repeat the process once the velocity reaches 0 again.

I have found a good blog on holding signals constant in Simulink: http://blogs.mathworks.com/simulink/2014/08/06/how-do-you-hold-the-value-of-a-signal/

However, in my case, I have two conditions for determining the signal: the magnitude of the velocity and the time within the time period. Now, the problem is that as soon as the period is finished, and the device is released (signal = 0), the velocity is still very small, which could result in an incorrect signal of 1 if an if-loop is used.

I think using an S-function may be the best solution, but then I will have to use a fixed time-step. Are there any Simulink-native solutions for this problem?

1
Is the hold time always the same? How do you determine that the hold period should not start again if after holding the velocity is still small? (BTW, why do you think an S-Function will force you to use a fixed step? That is highly unlikely to be the case.)Phil Goddard
The hold time is always the same. This is because the excitation force is oscillatory. As a result, the latching, or holding, will occur once for positive displacement and once when the displacement is negative during each wave cycle.Enrico Anderlini
I had the feeling using an S-function would require a fixed step because I was planning on using the number of calls to determine the duration of the hold with persistent memory.Enrico Anderlini

1 Answers

0
votes

I ended up using a Matlab function as a temporary solution, and it is very effective. I have taken inspiration from https://uk.mathworks.com/matlabcentral/answers/11323-hold-true-value-for-finite-length-of-time u is the velocity signal.

function y = fcn(u,nlatch)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This function is used to determine the latching signal.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Using persistent memory:
persistent tick started sign;
% Initialize variables:
if isempty(tick)
    tick = 0;
    started = 0;
    sign = (u>0);
end
U=0;      % no latching         
s=(u>0);

if s~=sign
    started = 1;
end

if started
    if tick<nlatch
        tick=tick+1;
        U = 1;
    else
        tick = 0;
        started = 0;
        sign = s;
    end 
end

y = U;

end

However, as I mentioned, I have to use a fixed step solver, which is no big deal to me, but it can create problems to other users.

If anyone has a more "Simulink-native" solution, please let me know!

Edit I have now modified the function: the latching is now applied when there is a change in sign in the velocity signal rather than looking at a small magnitude as earlier on (abs(u)<0.005), which was too case-specific.

A colleague of mine has also found a Simulink-native solution: Simulink model However, the Matlab function is faster (less computing intensive) when the same time step is employed. Maybe the least computing-intensive solution is a C S-function.