1

Let us assume that I have a continuous system in Simulink to be controlled. First, I apply a Kalman filter to estimate the states of the system. In the next stage, I will use the estimated state (x_hat) in an embedded MATLAB function which calls a model predictive controller function my_mpc like so:

function [u]= emd_fcn(x_hat , r,  t,  Ts)  

      % x_hat:  estimated state,  r: reference to be tracked, 
      t: clock time,   Ts: sampling  period

      %#codegen
      coder.extrinsic('my_mpc');  % to call the function my_mpc 

       ----- % some initialization code

      if mod(t, Ts)==0

            u=my_mpc(x, r)

      else
            u=-----; % some code.

      end


end  

However, since the clock time t is a variable, mod(t, Ts) == 0 will not be the case. My question is: how can we detect the sampling instant to apply the discrete mpc control input to the continuous system?

Priidu Neemre
  • 2,813
  • 2
  • 39
  • 40
user3489173
  • 45
  • 1
  • 9

1 Answers1

0

You should just make the controller discrete. Right click on the MATLAB Function block, select Block Parameters, and specify a discrete sample time.

Phil Goddard
  • 10,571
  • 1
  • 16
  • 28